Commit 15c3406a by Martin Radev Committed by Commit Bot

Restructure InstanceID initialization to fix HLSL warning

This patch casts gl_InstanceID to uint before doing division by the number of views to circumvent the HLSL compiler's warning on performance degradation. BUG=angleproject:2062 TEST=angle_end2end_tests Change-Id: I326530ee112f34f82becdec5239edd5054c4104f Reviewed-on: https://chromium-review.googlesource.com/655298 Commit-Queue: Martin Radev <mradev@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 95644f92
...@@ -56,20 +56,11 @@ void InitializeViewIDAndInstanceID(TIntermTyped *viewIDSymbol, ...@@ -56,20 +56,11 @@ void InitializeViewIDAndInstanceID(TIntermTyped *viewIDSymbol,
const TSymbolTable &symbolTable, const TSymbolTable &symbolTable,
TIntermSequence *initializers) TIntermSequence *initializers)
{ {
// Create a signed numberOfViews node. // Create an unsigned numberOfViews node.
TConstantUnion *numberOfViewsConstant = new TConstantUnion(); TConstantUnion *numberOfViewsUnsignedConstant = new TConstantUnion();
numberOfViewsConstant->setIConst(static_cast<int>(numberOfViews)); numberOfViewsUnsignedConstant->setUConst(numberOfViews);
TIntermConstantUnion *numberOfViewsIntSymbol = TIntermConstantUnion *numberOfViewsUint =
new TIntermConstantUnion(numberOfViewsConstant, TType(EbtInt, EbpHigh, EvqConst)); new TIntermConstantUnion(numberOfViewsUnsignedConstant, TType(EbtUInt, EbpHigh, EvqConst));
// Create a gl_InstanceID / numberOfViews node.
TIntermBinary *normalizedInstanceID =
new TIntermBinary(EOpDiv, CreateGLInstanceIDSymbol(symbolTable), numberOfViewsIntSymbol);
// Create a InstanceID = gl_InstanceID / numberOfViews node.
TIntermBinary *instanceIDInitializer =
new TIntermBinary(EOpAssign, instanceIDSymbol->deepCopy(), normalizedInstanceID);
initializers->push_back(instanceIDInitializer);
// Create a uint(gl_InstanceID) node. // Create a uint(gl_InstanceID) node.
TIntermSequence *glInstanceIDSymbolCastArguments = new TIntermSequence(); TIntermSequence *glInstanceIDSymbolCastArguments = new TIntermSequence();
...@@ -77,15 +68,24 @@ void InitializeViewIDAndInstanceID(TIntermTyped *viewIDSymbol, ...@@ -77,15 +68,24 @@ void InitializeViewIDAndInstanceID(TIntermTyped *viewIDSymbol,
TIntermAggregate *glInstanceIDAsUint = TIntermAggregate::CreateConstructor( TIntermAggregate *glInstanceIDAsUint = TIntermAggregate::CreateConstructor(
TType(EbtUInt, EbpHigh, EvqTemporary), glInstanceIDSymbolCastArguments); TType(EbtUInt, EbpHigh, EvqTemporary), glInstanceIDSymbolCastArguments);
// Create an unsigned numberOfViews node. // Create a uint(gl_InstanceID) / numberOfViews node.
TConstantUnion *numberOfViewsUnsignedConstant = new TConstantUnion(); TIntermBinary *normalizedInstanceID =
numberOfViewsUnsignedConstant->setUConst(numberOfViews); new TIntermBinary(EOpDiv, glInstanceIDAsUint, numberOfViewsUint);
TIntermConstantUnion *numberOfViewsUintSymbol =
new TIntermConstantUnion(numberOfViewsUnsignedConstant, TType(EbtUInt, EbpHigh, EvqConst)); // Create an int(uint(gl_InstanceID) / numberOfViews) node.
TIntermSequence *normalizedInstanceIDCastArguments = new TIntermSequence();
normalizedInstanceIDCastArguments->push_back(normalizedInstanceID);
TIntermAggregate *normalizedInstanceIDAsInt = TIntermAggregate::CreateConstructor(
TType(EbtInt, EbpHigh, EvqTemporary), normalizedInstanceIDCastArguments);
// Create an InstanceID = int(uint(gl_InstanceID) / numberOfViews) node.
TIntermBinary *instanceIDInitializer =
new TIntermBinary(EOpAssign, instanceIDSymbol->deepCopy(), normalizedInstanceIDAsInt);
initializers->push_back(instanceIDInitializer);
// Create a uint(gl_InstanceID) % numberOfViews node. // Create a uint(gl_InstanceID) % numberOfViews node.
TIntermBinary *normalizedViewID = TIntermBinary *normalizedViewID =
new TIntermBinary(EOpIMod, glInstanceIDAsUint, numberOfViewsUintSymbol); new TIntermBinary(EOpIMod, glInstanceIDAsUint->deepCopy(), numberOfViewsUint->deepCopy());
// Create a ViewID_OVR = uint(gl_InstanceID) % numberOfViews node. // Create a ViewID_OVR = uint(gl_InstanceID) % numberOfViews node.
TIntermBinary *viewIDInitializer = TIntermBinary *viewIDInitializer =
......
...@@ -753,10 +753,10 @@ TEST_F(WEBGLMultiviewVertexShaderOutputCodeTest, ViewIDAndInstanceIDHaveCorrectV ...@@ -753,10 +753,10 @@ TEST_F(WEBGLMultiviewVertexShaderOutputCodeTest, ViewIDAndInstanceIDHaveCorrectV
compile(shaderString, SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW); compile(shaderString, SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW);
EXPECT_TRUE(foundInAllGLSLCode("ViewID_OVR = (uint(gl_InstanceID) % 3u)")); EXPECT_TRUE(foundInAllGLSLCode("ViewID_OVR = (uint(gl_InstanceID) % 3u)"));
EXPECT_TRUE(foundInAllGLSLCode("InstanceID = (gl_InstanceID / 3)")); EXPECT_TRUE(foundInAllGLSLCode("InstanceID = int((uint(gl_InstanceID) / 3u))"));
EXPECT_TRUE(foundInHLSLCode("ViewID_OVR = (uvec1(gl_InstanceID) % 3)")); EXPECT_TRUE(foundInHLSLCode("ViewID_OVR = (uvec1(gl_InstanceID) % 3)"));
EXPECT_TRUE(foundInHLSLCode("InstanceID = (gl_InstanceID / 3)")); EXPECT_TRUE(foundInHLSLCode("InstanceID = ivec1((uvec1(gl_InstanceID) / 3))"));
} }
// The test checks that the directive enabling GL_OVR_multiview is not outputted if the extension is // The test checks that the directive enabling GL_OVR_multiview is not outputted if the extension is
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment