Commit 346dd7c7 by John Kessenich Committed by GitHub

Merge pull request #1051 from LoopDawg/bug-1049

HLSL: allow split type in InputPatch template type, & HS return types.
parents ba6a3c29 4a145dbf
......@@ -3555,7 +3555,7 @@ spv::Id TGlslangToSpvTraverser::handleUserFunctionCall(const glslang::TIntermAgg
const glslang::TIntermSequence& glslangArgs = node->getSequence();
const glslang::TQualifierList& qualifiers = node->getQualifierList();
// Encapsulate lvalue logic, used in two places below, for safety.
// Encapsulate lvalue logic, used in several places below, for safety.
const auto isLValue = [](int qualifier, const glslang::TType& paramType) -> bool {
return qualifier != glslang::EvqConstReadOnly || paramType.containsOpaque();
};
......
......@@ -32,7 +32,7 @@ vertex spacing = equal_spacing
0:? 'm_cpid' ( temp uint)
0:? 'm_cpid' ( in uint InvocationID)
0:26 move second child to first child ( temp structure{ temp 3-component vector of float cpoint})
0:26 indirect index ( temp structure{ temp 3-component vector of float cpoint})
0:26 indirect index (layout( location=0) out structure{ temp 3-component vector of float cpoint})
0:? '@entryPointOutput' (layout( location=0) out 4-element array of structure{ temp 3-component vector of float cpoint})
0:? 'm_cpid' ( in uint InvocationID)
0:26 Function Call: @main(struct-VS_OUT-vf31[4];u1; ( temp structure{ temp 3-component vector of float cpoint})
......@@ -146,7 +146,7 @@ vertex spacing = equal_spacing
0:? 'm_cpid' ( temp uint)
0:? 'm_cpid' ( in uint InvocationID)
0:26 move second child to first child ( temp structure{ temp 3-component vector of float cpoint})
0:26 indirect index ( temp structure{ temp 3-component vector of float cpoint})
0:26 indirect index (layout( location=0) out structure{ temp 3-component vector of float cpoint})
0:? '@entryPointOutput' (layout( location=0) out 4-element array of structure{ temp 3-component vector of float cpoint})
0:? 'm_cpid' ( in uint InvocationID)
0:26 Function Call: @main(struct-VS_OUT-vf31[4];u1; ( temp structure{ temp 3-component vector of float cpoint})
......
......@@ -28,7 +28,7 @@ vertex spacing = equal_spacing
0:? 'ip' ( temp 4-element array of structure{ temp 3-component vector of float cpoint})
0:? 'ip' (layout( location=0) in 4-element array of structure{ temp 3-component vector of float cpoint})
0:26 move second child to first child ( temp structure{ temp 3-component vector of float cpoint})
0:26 indirect index ( temp structure{ temp 3-component vector of float cpoint})
0:26 indirect index (layout( location=0) out structure{ temp 3-component vector of float cpoint})
0:? '@entryPointOutput' (layout( location=0) out 4-element array of structure{ temp 3-component vector of float cpoint})
0:? 'InvocationId' ( in uint InvocationID)
0:26 Function Call: @main(struct-VS_OUT-vf31[4]; ( temp structure{ temp 3-component vector of float cpoint})
......@@ -140,7 +140,7 @@ vertex spacing = equal_spacing
0:? 'ip' ( temp 4-element array of structure{ temp 3-component vector of float cpoint})
0:? 'ip' (layout( location=0) in 4-element array of structure{ temp 3-component vector of float cpoint})
0:26 move second child to first child ( temp structure{ temp 3-component vector of float cpoint})
0:26 indirect index ( temp structure{ temp 3-component vector of float cpoint})
0:26 indirect index (layout( location=0) out structure{ temp 3-component vector of float cpoint})
0:? '@entryPointOutput' (layout( location=0) out 4-element array of structure{ temp 3-component vector of float cpoint})
0:? 'InvocationId' ( in uint InvocationID)
0:26 Function Call: @main(struct-VS_OUT-vf31[4]; ( temp structure{ temp 3-component vector of float cpoint})
......
......@@ -28,7 +28,7 @@ vertex spacing = equal_spacing
0:? 'ip' ( temp 4-element array of structure{ temp 3-component vector of float cpoint})
0:? 'ip' (layout( location=0) in 4-element array of structure{ temp 3-component vector of float cpoint})
0:26 move second child to first child ( temp structure{ temp 3-component vector of float cpoint})
0:26 indirect index ( temp structure{ temp 3-component vector of float cpoint})
0:26 indirect index (layout( location=0) out structure{ temp 3-component vector of float cpoint})
0:? '@entryPointOutput' (layout( location=0) out 4-element array of structure{ temp 3-component vector of float cpoint})
0:? 'InvocationId' ( in uint InvocationID)
0:26 Function Call: @main(struct-VS_OUT-vf31[4]; ( temp structure{ temp 3-component vector of float cpoint})
......@@ -140,7 +140,7 @@ vertex spacing = equal_spacing
0:? 'ip' ( temp 4-element array of structure{ temp 3-component vector of float cpoint})
0:? 'ip' (layout( location=0) in 4-element array of structure{ temp 3-component vector of float cpoint})
0:26 move second child to first child ( temp structure{ temp 3-component vector of float cpoint})
0:26 indirect index ( temp structure{ temp 3-component vector of float cpoint})
0:26 indirect index (layout( location=0) out structure{ temp 3-component vector of float cpoint})
0:? '@entryPointOutput' (layout( location=0) out 4-element array of structure{ temp 3-component vector of float cpoint})
0:? 'InvocationId' ( in uint InvocationID)
0:26 Function Call: @main(struct-VS_OUT-vf31[4]; ( temp structure{ temp 3-component vector of float cpoint})
......
hlsl.hull.5.tesc
ERROR: 0:0: '' : unimplemented: PCF input patch without entry point input patch parameter
ERROR: 1 compilation errors. No code generated.
Shader version: 500
vertices = 3
vertex spacing = fractional_odd_spacing
triangle order = cw
ERROR: node is still EOpNull!
0:25 Function Definition: HS_ConstFunc(struct-HS_Input-vf4-vf41[3]; ( temp structure{ temp 3-element array of float fTessFactor, temp float fInsideTessFactor})
0:25 Function Parameters:
0:25 'I' ( in 3-element array of structure{ temp 4-component vector of float m_Position, temp 4-component vector of float m_Normal})
0:? Sequence
0:26 Sequence
0:26 move second child to first child ( temp structure{ temp 3-element array of float fTessFactor, temp float fInsideTessFactor})
0:26 'O' ( temp structure{ temp 3-element array of float fTessFactor, temp float fInsideTessFactor})
0:26 Constant:
0:26 0.000000
0:26 0.000000
0:26 0.000000
0:26 0.000000
0:28 move second child to first child ( temp float)
0:28 fInsideTessFactor: direct index for structure ( temp float)
0:28 'O' ( temp structure{ temp 3-element array of float fTessFactor, temp float fInsideTessFactor})
0:28 Constant:
0:28 1 (const int)
0:28 add ( temp float)
0:28 direct index ( temp float)
0:28 m_Position: direct index for structure ( temp 4-component vector of float)
0:28 direct index ( temp structure{ temp 4-component vector of float m_Position, temp 4-component vector of float m_Normal})
0:28 'I' ( in 3-element array of structure{ temp 4-component vector of float m_Position, temp 4-component vector of float m_Normal})
0:28 Constant:
0:28 0 (const int)
0:28 Constant:
0:28 0 (const int)
0:28 Constant:
0:28 3 (const int)
0:28 direct index ( temp float)
0:28 m_Normal: direct index for structure ( temp 4-component vector of float)
0:28 direct index ( temp structure{ temp 4-component vector of float m_Position, temp 4-component vector of float m_Normal})
0:28 'I' ( in 3-element array of structure{ temp 4-component vector of float m_Position, temp 4-component vector of float m_Normal})
0:28 Constant:
0:28 0 (const int)
0:28 Constant:
0:28 1 (const int)
0:28 Constant:
0:28 3 (const int)
0:30 Branch: Return with expression
0:30 'O' ( temp structure{ temp 3-element array of float fTessFactor, temp float fInsideTessFactor})
0:39 Function Definition: @main(u1; ( temp structure{ temp 4-component vector of float m_Position})
0:39 Function Parameters:
0:39 'cpid' ( in uint)
0:? Sequence
0:40 Sequence
0:40 move second child to first child ( temp structure{ temp 4-component vector of float m_Position})
0:40 'output' ( temp structure{ temp 4-component vector of float m_Position})
0:40 Constant:
0:40 0.000000
0:40 0.000000
0:40 0.000000
0:40 0.000000
0:41 move second child to first child ( temp 4-component vector of float)
0:41 m_Position: direct index for structure ( temp 4-component vector of float)
0:41 'output' ( temp structure{ temp 4-component vector of float m_Position})
0:41 Constant:
0:41 0 (const int)
0:41 Constant:
0:41 0.000000
0:41 0.000000
0:41 0.000000
0:41 0.000000
0:42 Branch: Return with expression
0:42 'output' ( temp structure{ temp 4-component vector of float m_Position})
0:39 Function Definition: main( ( temp void)
0:39 Function Parameters:
0:? Sequence
0:39 move second child to first child ( temp uint)
0:? 'cpid' ( temp uint)
0:? 'cpid' ( in uint InvocationID)
0:39 Sequence
0:39 move second child to first child ( temp 4-component vector of float)
0:39 direct index ( out 4-component vector of float Position)
0:? '@entryPointOutput.m_Position' ( out 3-element array of 4-component vector of float Position)
0:39 Constant:
0:39 0 (const int)
0:39 m_Position: direct index for structure ( temp 4-component vector of float)
0:39 Function Call: @main(u1; ( temp structure{ temp 4-component vector of float m_Position})
0:? 'cpid' ( temp uint)
0:39 Constant:
0:39 0 (const int)
0:? Linker Objects
0:? '@entryPointOutput.m_Position' ( out 3-element array of 4-component vector of float Position)
0:? 'cpid' ( in uint InvocationID)
Linked tessellation control stage:
Shader version: 500
vertices = 3
vertex spacing = fractional_odd_spacing
triangle order = cw
ERROR: node is still EOpNull!
0:25 Function Definition: HS_ConstFunc(struct-HS_Input-vf4-vf41[3]; ( temp structure{ temp 3-element array of float fTessFactor, temp float fInsideTessFactor})
0:25 Function Parameters:
0:25 'I' ( in 3-element array of structure{ temp 4-component vector of float m_Position, temp 4-component vector of float m_Normal})
0:? Sequence
0:26 Sequence
0:26 move second child to first child ( temp structure{ temp 3-element array of float fTessFactor, temp float fInsideTessFactor})
0:26 'O' ( temp structure{ temp 3-element array of float fTessFactor, temp float fInsideTessFactor})
0:26 Constant:
0:26 0.000000
0:26 0.000000
0:26 0.000000
0:26 0.000000
0:28 move second child to first child ( temp float)
0:28 fInsideTessFactor: direct index for structure ( temp float)
0:28 'O' ( temp structure{ temp 3-element array of float fTessFactor, temp float fInsideTessFactor})
0:28 Constant:
0:28 1 (const int)
0:28 add ( temp float)
0:28 direct index ( temp float)
0:28 m_Position: direct index for structure ( temp 4-component vector of float)
0:28 direct index ( temp structure{ temp 4-component vector of float m_Position, temp 4-component vector of float m_Normal})
0:28 'I' ( in 3-element array of structure{ temp 4-component vector of float m_Position, temp 4-component vector of float m_Normal})
0:28 Constant:
0:28 0 (const int)
0:28 Constant:
0:28 0 (const int)
0:28 Constant:
0:28 3 (const int)
0:28 direct index ( temp float)
0:28 m_Normal: direct index for structure ( temp 4-component vector of float)
0:28 direct index ( temp structure{ temp 4-component vector of float m_Position, temp 4-component vector of float m_Normal})
0:28 'I' ( in 3-element array of structure{ temp 4-component vector of float m_Position, temp 4-component vector of float m_Normal})
0:28 Constant:
0:28 0 (const int)
0:28 Constant:
0:28 1 (const int)
0:28 Constant:
0:28 3 (const int)
0:30 Branch: Return with expression
0:30 'O' ( temp structure{ temp 3-element array of float fTessFactor, temp float fInsideTessFactor})
0:39 Function Definition: @main(u1; ( temp structure{ temp 4-component vector of float m_Position})
0:39 Function Parameters:
0:39 'cpid' ( in uint)
0:? Sequence
0:40 Sequence
0:40 move second child to first child ( temp structure{ temp 4-component vector of float m_Position})
0:40 'output' ( temp structure{ temp 4-component vector of float m_Position})
0:40 Constant:
0:40 0.000000
0:40 0.000000
0:40 0.000000
0:40 0.000000
0:41 move second child to first child ( temp 4-component vector of float)
0:41 m_Position: direct index for structure ( temp 4-component vector of float)
0:41 'output' ( temp structure{ temp 4-component vector of float m_Position})
0:41 Constant:
0:41 0 (const int)
0:41 Constant:
0:41 0.000000
0:41 0.000000
0:41 0.000000
0:41 0.000000
0:42 Branch: Return with expression
0:42 'output' ( temp structure{ temp 4-component vector of float m_Position})
0:39 Function Definition: main( ( temp void)
0:39 Function Parameters:
0:? Sequence
0:39 move second child to first child ( temp uint)
0:? 'cpid' ( temp uint)
0:? 'cpid' ( in uint InvocationID)
0:39 Sequence
0:39 move second child to first child ( temp 4-component vector of float)
0:39 direct index ( out 4-component vector of float Position)
0:? '@entryPointOutput.m_Position' ( out 3-element array of 4-component vector of float Position)
0:39 Constant:
0:39 0 (const int)
0:39 m_Position: direct index for structure ( temp 4-component vector of float)
0:39 Function Call: @main(u1; ( temp structure{ temp 4-component vector of float m_Position})
0:? 'cpid' ( temp uint)
0:39 Constant:
0:39 0 (const int)
0:? Linker Objects
0:? '@entryPointOutput.m_Position' ( out 3-element array of 4-component vector of float Position)
0:? 'cpid' ( in uint InvocationID)
SPIR-V is not generated for failed compile or link
......@@ -29,7 +29,7 @@ triangle order = cw
0:? 'cpid' ( temp uint)
0:? 'cpid' ( in uint InvocationID)
0:27 move second child to first child ( temp structure{ temp 3-component vector of float val})
0:27 indirect index ( temp structure{ temp 3-component vector of float val})
0:27 indirect index (layout( location=0) out structure{ temp 3-component vector of float val})
0:? '@entryPointOutput' (layout( location=0) out 3-element array of structure{ temp 3-component vector of float val})
0:? 'cpid' ( in uint InvocationID)
0:27 Function Call: @main(struct-hs_in_t-vf31[3];u1; ( temp structure{ temp 3-component vector of float val})
......@@ -229,7 +229,7 @@ triangle order = cw
0:? 'cpid' ( temp uint)
0:? 'cpid' ( in uint InvocationID)
0:27 move second child to first child ( temp structure{ temp 3-component vector of float val})
0:27 indirect index ( temp structure{ temp 3-component vector of float val})
0:27 indirect index (layout( location=0) out structure{ temp 3-component vector of float val})
0:? '@entryPointOutput' (layout( location=0) out 3-element array of structure{ temp 3-component vector of float val})
0:? 'cpid' ( in uint InvocationID)
0:27 Function Call: @main(struct-hs_in_t-vf31[3];u1; ( temp structure{ temp 3-component vector of float val})
......
......@@ -36,7 +36,7 @@ triangle order = cw
0:? 'cpid' ( temp uint)
0:? 'cpid' ( in uint InvocationID)
0:28 move second child to first child ( temp structure{ temp 3-component vector of float val})
0:28 indirect index ( temp structure{ temp 3-component vector of float val})
0:28 indirect index (layout( location=0) out structure{ temp 3-component vector of float val})
0:? '@entryPointOutput' (layout( location=0) out 3-element array of structure{ temp 3-component vector of float val})
0:? 'cpid' ( in uint InvocationID)
0:28 Function Call: @main(struct-hs_in_t-vf31[3];u1; ( temp structure{ temp 3-component vector of float val})
......@@ -82,7 +82,7 @@ triangle order = cw
0:? '@patchConstantResult' ( temp structure{ temp 3-element array of float tfactor, temp float flInFactor})
0:? Function Call: PCF(struct-hs_out_t-vf31[3];struct-hs_in_t-vf31[3]; ( temp structure{ temp 3-element array of float tfactor, temp float flInFactor})
0:? 'pcf_out' ( temp 3-element array of structure{ temp 3-component vector of float val})
0:? 'i' (layout( location=0) in 3-element array of structure{ temp 3-component vector of float val})
0:? 'i' ( temp 3-element array of structure{ temp 3-component vector of float val})
0:? Sequence
0:? move second child to first child ( temp float)
0:? direct index ( patch out float TessLevelOuter)
......@@ -245,7 +245,7 @@ triangle order = cw
0:? 'cpid' ( temp uint)
0:? 'cpid' ( in uint InvocationID)
0:28 move second child to first child ( temp structure{ temp 3-component vector of float val})
0:28 indirect index ( temp structure{ temp 3-component vector of float val})
0:28 indirect index (layout( location=0) out structure{ temp 3-component vector of float val})
0:? '@entryPointOutput' (layout( location=0) out 3-element array of structure{ temp 3-component vector of float val})
0:? 'cpid' ( in uint InvocationID)
0:28 Function Call: @main(struct-hs_in_t-vf31[3];u1; ( temp structure{ temp 3-component vector of float val})
......@@ -291,7 +291,7 @@ triangle order = cw
0:? '@patchConstantResult' ( temp structure{ temp 3-element array of float tfactor, temp float flInFactor})
0:? Function Call: PCF(struct-hs_out_t-vf31[3];struct-hs_in_t-vf31[3]; ( temp structure{ temp 3-element array of float tfactor, temp float flInFactor})
0:? 'pcf_out' ( temp 3-element array of structure{ temp 3-component vector of float val})
0:? 'i' (layout( location=0) in 3-element array of structure{ temp 3-component vector of float val})
0:? 'i' ( temp 3-element array of structure{ temp 3-component vector of float val})
0:? Sequence
0:? move second child to first child ( temp float)
0:? direct index ( patch out float TessLevelOuter)
......@@ -568,7 +568,7 @@ triangle order = cw
87: 30(ptr) AccessChain 67(pcf_out) 81
Store 87 86
90: 20 Load 67(pcf_out)
91: 11 Load 42(i)
91: 11 Load 40(i)
92:22(hs_pcf_t) FunctionCall 26(PCF(struct-hs_out_t-vf31[3];struct-hs_in_t-vf31[3];) 90 91
Store 89(@patchConstantResult) 92
98: 97(ptr) AccessChain 89(@patchConstantResult) 29 29
......
......@@ -29,7 +29,7 @@ triangle order = ccw
0:? 'ip' ( temp 3-element array of structure{ temp 3-component vector of float cpoint})
0:? 'ip' (layout( location=0) in 3-element array of structure{ temp 3-component vector of float cpoint})
0:26 move second child to first child ( temp structure{ temp 3-component vector of float cpoint})
0:26 indirect index ( temp structure{ temp 3-component vector of float cpoint})
0:26 indirect index (layout( location=0) out structure{ temp 3-component vector of float cpoint})
0:? '@entryPointOutput' (layout( location=0) out 3-element array of structure{ temp 3-component vector of float cpoint})
0:? 'InvocationId' ( in uint InvocationID)
0:26 Function Call: @main(struct-VS_OUT-vf31[3]; ( temp structure{ temp 3-component vector of float cpoint})
......@@ -85,7 +85,7 @@ triangle order = ccw
0:? 'ip' ( temp 3-element array of structure{ temp 3-component vector of float cpoint})
0:? 'ip' (layout( location=0) in 3-element array of structure{ temp 3-component vector of float cpoint})
0:26 move second child to first child ( temp structure{ temp 3-component vector of float cpoint})
0:26 indirect index ( temp structure{ temp 3-component vector of float cpoint})
0:26 indirect index (layout( location=0) out structure{ temp 3-component vector of float cpoint})
0:? '@entryPointOutput' (layout( location=0) out 3-element array of structure{ temp 3-component vector of float cpoint})
0:? 'InvocationId' ( in uint InvocationID)
0:26 Function Call: @main(struct-VS_OUT-vf31[3]; ( temp structure{ temp 3-component vector of float cpoint})
......
// Test mixed InputPatch structure: user and builtin members. Hull shaders involve extra
// logic in this case due to patch constant function call synthesis.
// This example tests the main EP and the PCF EP both having an input patch.
struct HS_Main_Output
{
float4 m_Position : SV_POSITION ;
};
struct HS_Output
{
float fTessFactor [ 3 ] : SV_TessFactor ;
float fInsideTessFactor : SV_InsideTessFactor ;
};
struct HS_Input
{
float4 m_Position : SV_POSITION;
float4 m_Normal : TEXCOORD2;
};
HS_Output HS_ConstFunc ( InputPatch < HS_Input , 3 > I )
{
HS_Output O = (HS_Output)0;
O.fInsideTessFactor = I [ 0 ].m_Position.w + I [ 0 ].m_Normal.w;
return O;
}
[ domain ( "tri" ) ]
[ partitioning ( "fractional_odd" ) ]
[ outputtopology ( "triangle_cw" ) ]
[ patchconstantfunc ( "HS_ConstFunc" ) ]
[ outputcontrolpoints ( 3 ) ]
HS_Main_Output main( InputPatch < HS_Input , 3 > I , uint cpid : SV_OutputControlPointID )
{
HS_Main_Output output = ( HS_Main_Output ) 0 ;
output.m_Position = 0;
return output ;
}
// Test mixed InputPatch structure: user and builtin members. Hull shaders involve extra
// logic in this case due to patch constant function call synthesis.
// This example tests the PCF EP having an InputPatch, but the main EP does not.
struct HS_Main_Output
{
float4 m_Position : SV_POSITION ;
};
struct HS_Output
{
float fTessFactor [ 3 ] : SV_TessFactor ;
float fInsideTessFactor : SV_InsideTessFactor ;
};
struct HS_Input
{
float4 m_Position : SV_POSITION;
float4 m_Normal : TEXCOORD2;
};
HS_Output HS_ConstFunc ( InputPatch < HS_Input , 3 > I )
{
HS_Output O = (HS_Output)0;
O.fInsideTessFactor = I [ 0 ].m_Position.w + I [ 0 ].m_Normal.w;
return O;
}
[ domain ( "tri" ) ]
[ partitioning ( "fractional_odd" ) ]
[ outputtopology ( "triangle_cw" ) ]
[ patchconstantfunc ( "HS_ConstFunc" ) ]
[ outputcontrolpoints ( 3 ) ]
HS_Main_Output main( uint cpid : SV_OutputControlPointID )
{
HS_Main_Output output = ( HS_Main_Output ) 0 ;
output.m_Position = 0;
return output ;
}
......@@ -164,6 +164,8 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.hull.1.tesc", "main"},
{"hlsl.hull.2.tesc", "main"},
{"hlsl.hull.3.tesc", "main"},
{"hlsl.hull.4.tesc", "main"},
{"hlsl.hull.5.tesc", "main"},
{"hlsl.hull.void.tesc", "main"},
{"hlsl.hull.ctrlpt-1.tesc", "main"},
{"hlsl.hull.ctrlpt-2.tesc", "main"},
......
......@@ -1999,6 +1999,11 @@ TIntermNode* HlslParseContext::transformEntryPoint(const TSourceLoc& loc, TFunct
TParameter& param = userFunction[i];
argVars.push_back(makeInternalVariable(*param.name, *param.type));
argVars.back()->getWritableType().getQualifier().makeTemporary();
// Track the input patch, which is the only non-builtin supported by hull shader PCF.
if (param.getDeclaredBuiltIn() == EbvInputPatch)
inputPatch = argVars.back();
TIntermSymbol* arg = intermediate.addSymbol(*argVars.back());
handleFunctionArgument(&callee, callingArgs, arg);
if (param.type->getQualifier().isParamInput()) {
......@@ -2039,7 +2044,10 @@ TIntermNode* HlslParseContext::transformEntryPoint(const TSourceLoc& loc, TFunct
TIntermTyped* element = intermediate.addIndex(EOpIndexIndirect, intermediate.addSymbol(*entryPointOutput),
invocationIdSym, loc);
element->setType(callReturn->getType());
// Set the type of the array element being dereferenced
const TType derefElementType(entryPointOutput->getType(), 0);
element->setType(derefElementType);
returnAssign = handleAssign(loc, EOpAssign, element, callReturn);
} else {
......@@ -2215,9 +2223,6 @@ void HlslParseContext::remapEntryPointIO(TFunction& function, TVariable*& return
synthesizeEditedInput(paramType);
TVariable* argAsGlobal = makeIoVariable(function[i].name->c_str(), paramType, EvqVaryingIn);
inputs.push_back(argAsGlobal);
if (function[i].getDeclaredBuiltIn() == EbvInputPatch)
inputPatch = argAsGlobal;
}
if (paramType.getQualifier().isParamOutput()) {
TVariable* argAsGlobal = makeIoVariable(function[i].name->c_str(), paramType, EvqVaryingOut);
......@@ -2561,14 +2566,25 @@ TIntermTyped* HlslParseContext::handleAssign(const TSourceLoc& loc, TOperator op
if (left->getAsOperator() && left->getAsOperator()->getOp() == EOpMatrixSwizzle)
return handleAssignToMatrixSwizzle(loc, op, left, right);
const bool isSplitLeft = wasSplit(left);
const bool isSplitRight = wasSplit(right);
// Return true if the given node is an index operation into a split variable.
const auto indexesSplit = [this](const TIntermTyped* node) -> bool {
const TIntermBinary* binaryNode = node->getAsBinaryNode();
if (binaryNode == nullptr)
return false;
return (binaryNode->getOp() == EOpIndexDirect || binaryNode->getOp() == EOpIndexIndirect) &&
wasSplit(binaryNode->getLeft());
};
const bool isSplitLeft = wasSplit(left) || indexesSplit(left);
const bool isSplitRight = wasSplit(right) || indexesSplit(right);
const bool isFlattenLeft = wasFlattened(left);
const bool isFlattenRight = wasFlattened(right);
// OK to do a single assign if both are split, or both are unsplit. But if one is and the other
// isn't, we fall back to a member-wise copy.
// OK to do a single assign if neither side is split or flattened. Otherwise,
// fall through to a member-wise copy.
if (!isFlattenLeft && !isFlattenRight && !isSplitLeft && !isSplitRight) {
// Clip and cull distance requires more processing. See comment above assignClipCullDistance.
if (isClipOrCullDistance(left->getType()) || isClipOrCullDistance(right->getType())) {
......@@ -2803,8 +2819,25 @@ TIntermTyped* HlslParseContext::handleAssign(const TSourceLoc& loc, TOperator op
// If either left or right was a split structure, we must read or write it, but still have to
// parallel-recurse through the unsplit structure to identify the built-in IO vars.
if (isSplitLeft)
splitLeft = intermediate.addSymbol(*getSplitNonIoVar(left->getAsSymbolNode()->getId()), loc);
// The left can be either a symbol, or an index into a symbol (e.g, array reference)
if (isSplitLeft) {
if (indexesSplit(left)) {
// Index case: Refer to the indexed symbol, if the left is an index operator.
const TIntermSymbol* symNode = left->getAsBinaryNode()->getLeft()->getAsSymbolNode();
TIntermTyped* splitLeftNonIo = intermediate.addSymbol(*getSplitNonIoVar(symNode->getId()), loc);
splitLeft = intermediate.addIndex(left->getAsBinaryNode()->getOp(), splitLeftNonIo,
left->getAsBinaryNode()->getRight(), loc);
const TType derefType(splitLeftNonIo->getType(), 0);
splitLeft->setType(derefType);
} else {
// Symbol case: otherwise, if not indexed, we have the symbol directly.
const TIntermSymbol* symNode = left->getAsSymbolNode();
splitLeft = intermediate.addSymbol(*getSplitNonIoVar(symNode->getId()), loc);
}
}
if (isSplitRight)
splitRight = intermediate.addSymbol(*getSplitNonIoVar(right->getAsSymbolNode()->getId()), loc);
......@@ -9035,19 +9068,12 @@ TIntermSymbol* HlslParseContext::findTessLinkageSymbol(TBuiltInVariable biType)
return intermediate.addSymbol(*it->second->getAsVariable());
}
// Finalization step: Add patch constant function invocation
void HlslParseContext::addPatchConstantInvocation()
// Find the patch constant function (issues error, returns nullptr if not found)
const TFunction* HlslParseContext::findPatchConstantFunction(const TSourceLoc& loc)
{
TSourceLoc loc;
loc.init();
// If there's no patch constant function, or we're not a HS, do nothing.
if (patchConstantFunctionName.empty() || language != EShLangTessControl)
return;
if (symbolTable.isFunctionNameVariable(patchConstantFunctionName)) {
error(loc, "can't use variable in patch constant function", patchConstantFunctionName.c_str(), "");
return;
return nullptr;
}
const TString mangledName = patchConstantFunctionName + "(";
......@@ -9061,7 +9087,7 @@ void HlslParseContext::addPatchConstantInvocation()
// allow any disambiguation of overloads.
if (candidateList.empty()) {
error(loc, "patch constant function not found", patchConstantFunctionName.c_str(), "");
return;
return nullptr;
}
// Based on directed experiments, it appears that if there are overloaded patchconstantfunctions,
......@@ -9069,9 +9095,22 @@ void HlslParseContext::addPatchConstantInvocation()
// out if there is more than one candidate.
if (candidateList.size() > 1) {
error(loc, "ambiguous patch constant function", patchConstantFunctionName.c_str(), "");
return;
return nullptr;
}
return candidateList[0];
}
// Finalization step: Add patch constant function invocation
void HlslParseContext::addPatchConstantInvocation()
{
TSourceLoc loc;
loc.init();
// If there's no patch constant function, or we're not a HS, do nothing.
if (patchConstantFunctionName.empty() || language != EShLangTessControl)
return;
// Look for built-in variables in a function's parameter list.
const auto findBuiltIns = [&](const TFunction& function, std::set<tInterstageIoData>& builtIns) {
for (int p=0; p<function.getParamCount(); ++p) {
......@@ -9136,7 +9175,13 @@ void HlslParseContext::addPatchConstantInvocation()
//
// 5/5B. Call the PCF inside an if test for (invocation id == 0).
TFunction& patchConstantFunction = const_cast<TFunction&>(*candidateList[0]);
TFunction* patchConstantFunctionPtr = const_cast<TFunction*>(findPatchConstantFunction(loc));
if (patchConstantFunctionPtr == nullptr)
return;
TFunction& patchConstantFunction = *patchConstantFunctionPtr;
const int pcfParamCount = patchConstantFunction.getParamCount();
TIntermSymbol* invocationIdSym = findTessLinkageSymbol(EbvInvocationId);
TIntermSequence& epBodySeq = entryPointFunctionBody->getAsAggregate()->getSequence();
......@@ -9217,10 +9262,9 @@ void HlslParseContext::addPatchConstantInvocation()
// ================ Step 1B: Argument synthesis ================
// Create pcfArguments for synthesis of patchconstantfunction invocation
// TODO: handle struct or array inputs
{
for (int p=0; p<pcfParamCount; ++p) {
TIntermSymbol* inputArg = nullptr;
TIntermTyped* inputArg = nullptr;
if (p == outPatchParam) {
if (perCtrlPtVar == nullptr) {
......@@ -9234,6 +9278,11 @@ void HlslParseContext::addPatchConstantInvocation()
// find which built-in it is
const TBuiltInVariable biType = patchConstantFunction[p].getDeclaredBuiltIn();
if (biType == EbvInputPatch && inputPatch == nullptr) {
error(loc, "unimplemented: PCF input patch without entry point input patch parameter", "", "");
return;
}
inputArg = findTessLinkageSymbol(biType);
if (inputArg == nullptr) {
......
......@@ -316,6 +316,9 @@ protected:
static bool isClipOrCullDistance(const TQualifier& qual) { return isClipOrCullDistance(qual.builtIn); }
static bool isClipOrCullDistance(const TType& type) { return isClipOrCullDistance(type.getQualifier()); }
// Find the patch constant function (issues error, returns nullptr if not found)
const TFunction* findPatchConstantFunction(const TSourceLoc& loc);
// Pass through to base class after remembering built-in mappings.
using TParseContextBase::trackLinkage;
void trackLinkage(TSymbol& variable) override;
......@@ -415,7 +418,8 @@ protected:
};
TMap<tInterstageIoData, TVariable*> splitBuiltIns; // split built-ins, indexed by built-in type.
TVariable* inputPatch;
TVariable* inputPatch; // input patch is special for PCF: it's the only non-builtin PCF input,
// and is handled as a pseudo-builtin.
unsigned int nextInLocation;
unsigned int nextOutLocation;
......
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