From deec03cfca7f4d7a63797a65a665faf623740eb9 Mon Sep 17 00:00:00 2001 From: Dan Baker Date: Thu, 25 Aug 2016 11:59:17 -0400 Subject: [PATCH 1/3] First stab at system value interpretation --- hlsl/hlslParseHelper.cpp | 139 +++++++++++++++++++++++++++++++++------ 1 file changed, 118 insertions(+), 21 deletions(-) diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index 720cb230..42edf7bc 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -755,8 +755,24 @@ TIntermAggregate* HlslParseContext::handleFunctionDefinition(const TSourceLoc& l inEntrypoint = (function.getName() == intermediate.getEntryPoint().c_str()); if (inEntrypoint) { // parameters are actually shader-level inputs + unsigned int inCount = 0, outCount = 0; for (int i = 0; i < function.getParamCount(); i++) - function[i].type->getQualifier().storage = EvqVaryingIn; + { + // Fragment programs do not use ordering for the output layout position, rather it is + // embedded in the semantic + if (function[i].type->getQualifier().isParamOutput() && language != EShLangFragment) + { + if (function[i].type->getQualifier().builtIn == EbvNone) + function[i].type->getQualifier().layoutLocation = outCount++; + function[i].type->getQualifier().storage = EvqVaryingOut; + } + else + { + if (function[i].type->getQualifier().builtIn == EbvNone) + function[i].type->getQualifier().layoutLocation = inCount++; + function[i].type->getQualifier().storage = EvqVaryingIn; + } + } } // @@ -2260,27 +2276,108 @@ void HlslParseContext::handleSemantic(TType& type, const TString& semantic) // TODO: need to know if it's an input or an output // The following sketches what needs to be done, but can't be right // without taking into account stage and input/output. + + // in DX9, all outputs had to have a semantic associated with them, that was either consumed + // by the system or was a specific register assignment + // in DX10+, only semantics with the SV_ prefix have any meaning beyond decoration + // Fxc will only accept DX9 style semantics in compat mode + // Also, in DX10 if a SV value is present as the input of a stage, but isn't appropriate for that + // stage, it would just be ignored as it is likely there as part of an output struct from one stage + // to the next + bool bParseDX9 = false; - if (semantic == "PSIZE") - type.getQualifier().builtIn = EbvPointSize; - else if (semantic == "POSITION") - type.getQualifier().builtIn = EbvPosition; - else if (semantic == "FOG") - type.getQualifier().builtIn = EbvFogFragCoord; - else if (semantic == "DEPTH" || semantic == "SV_Depth") - type.getQualifier().builtIn = EbvFragDepth; - else if (semantic == "VFACE" || semantic == "SV_IsFrontFace") - type.getQualifier().builtIn = EbvFace; - else if (semantic == "VPOS" || semantic == "SV_Position") - type.getQualifier().builtIn = EbvFragCoord; - else if (semantic == "SV_ClipDistance") - type.getQualifier().builtIn = EbvClipDistance; - else if (semantic == "SV_CullDistance") - type.getQualifier().builtIn = EbvCullDistance; - else if (semantic == "SV_VertexID") - type.getQualifier().builtIn = EbvVertexId; - else if (semantic == "SV_ViewportArrayIndex") - type.getQualifier().builtIn = EbvViewportIndex; + if (bParseDX9) + { + if (semantic == "PSIZE") + type.getQualifier().builtIn = EbvPointSize; + else if (semantic == "FOG") + type.getQualifier().builtIn = EbvFogFragCoord; + else if (semantic == "DEPTH" || semantic == "SV_Depth") + type.getQualifier().builtIn = EbvFragDepth; + else if (semantic == "VFACE" || semantic == "SV_IsFrontFace") + type.getQualifier().builtIn = EbvFace; + else if (semantic == "VPOS" || semantic == "SV_Position") + type.getQualifier().builtIn = EbvFragCoord; + } + + TString semanticUpperCase = semantic; + std::transform(semanticUpperCase.begin(), semanticUpperCase.end(), semanticUpperCase.begin(), ::toupper); + { + //SV Position has a different meaning in vertex vs fragment + if (semanticUpperCase == "SV_POSITION" && language != EShLangFragment) + type.getQualifier().builtIn = EbvPosition; + else if (semanticUpperCase == "SV_POSITION" && language == EShLangFragment) + type.getQualifier().builtIn = EbvFragCoord; + else if (semanticUpperCase == "SV_CLIPDISTANCE") + type.getQualifier().builtIn = EbvClipDistance; + else if (semanticUpperCase == "SV_CULLDISTANCE") + type.getQualifier().builtIn = EbvCullDistance; + else if (semanticUpperCase == "SV_VERTEXID") + type.getQualifier().builtIn = EbvVertexIndex; + else if (semanticUpperCase == "SV_VIEWPORTARRAYINDEX") + type.getQualifier().builtIn = EbvViewportIndex; + else if (semanticUpperCase == "SV_TESSFACTOR") + type.getQualifier().builtIn = EbvTessLevelOuter; + + //Targets are defined 0-7 + else if (semanticUpperCase == "SV_TARGET") { + type.getQualifier().builtIn = EbvNone; type.getQualifier().layoutLocation = 0; } + else if (semanticUpperCase == "SV_TARGET0") { + type.getQualifier().builtIn = EbvNone; type.getQualifier().layoutLocation = 0; } + else if (semanticUpperCase == "SV_TARGET1") { + type.getQualifier().builtIn = EbvNone; type.getQualifier().layoutLocation = 1; } + else if (semanticUpperCase == "SV_TARGET2") { + type.getQualifier().builtIn = EbvNone; type.getQualifier().layoutLocation = 2; } + else if (semanticUpperCase == "SV_TARGET3") { + type.getQualifier().builtIn = EbvNone; type.getQualifier().layoutLocation = 3; } + else if (semanticUpperCase == "SV_TARGET4") { + type.getQualifier().builtIn = EbvNone; type.getQualifier().layoutLocation = 4; } + else if (semanticUpperCase == "SV_TARGET5") { + type.getQualifier().builtIn = EbvNone; type.getQualifier().layoutLocation = 5; } + else if (semanticUpperCase == "SV_TARGET6") { + type.getQualifier().builtIn = EbvNone; type.getQualifier().layoutLocation = 6; } + else if (semanticUpperCase == "SV_TARGET7") { + type.getQualifier().builtIn = EbvNone; type.getQualifier().layoutLocation = 7; } + else if (semanticUpperCase == "SV_SAMPLEINDEX") + type.getQualifier().builtIn = EbvSampleId; + else if (semanticUpperCase == "SV_RENDERTARGETARRAYINDEX") + type.getQualifier().builtIn = EbvLayer; + else if (semanticUpperCase == "SV_PRIMITIVEID") + type.getQualifier().builtIn = EbvPrimitiveId; + else if (semanticUpperCase == "SV_OUTPUTCONTROLPOINTID") + type.getQualifier().builtIn = EbvInvocationId; + else if (semanticUpperCase == "SV_ISFRONTFACE") + type.getQualifier().builtIn = EbvFace; + else if (semanticUpperCase == "SV_INSTANCEID") + type.getQualifier().builtIn = EbvInstanceIndex; + else if (semanticUpperCase == "SV_INSIDETESSFACTOR") + type.getQualifier().builtIn = EbvTessLevelInner; + else if (semanticUpperCase == "SV_GSINSTANCEID") + type.getQualifier().builtIn = EbvInvocationId; + else if (semanticUpperCase == "SV_GROUPTHREADID") + type.getQualifier().builtIn = EbvLocalInvocationId; + else if (semanticUpperCase == "SV_GROUPID") + type.getQualifier().builtIn = EbvWorkGroupId; + else if (semanticUpperCase == "SV_DOMAINLOCATION") + type.getQualifier().builtIn = EbvTessCoord; + else if (semanticUpperCase == "SV_DEPTH") + type.getQualifier().builtIn = EbvFragDepth; + + + //not supported or not trivial + //else if( semanticUpperCase == "SV_STENCILREF") + // type.getQualifier().builtIn = gl_FragStencilRef + //else if( semanticUpperCase == "SV_DEPTHGREATEREQUAL") + // type.getQualifier().builtIn = ?? + //else if( semanticUpperCase == "SV_DEPTHLESSEQUAL") + // type.getQualifier().builtIn = ?? + //else if( semanticUpperCase == "SV_COVERAGE") + // type.getQualifier().builtIn = ?? + + + } + + } // From 26aa8a4b16ece4106e403db047546f94062fc4ff Mon Sep 17 00:00:00 2001 From: Dan Baker Date: Thu, 25 Aug 2016 17:13:25 -0400 Subject: [PATCH 2/3] HLSL: Format updates and some minor adjustments to SV_ handling --- hlsl/hlslParseHelper.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index 42edf7bc..8e87c6e2 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -756,18 +756,14 @@ TIntermAggregate* HlslParseContext::handleFunctionDefinition(const TSourceLoc& l if (inEntrypoint) { // parameters are actually shader-level inputs unsigned int inCount = 0, outCount = 0; - for (int i = 0; i < function.getParamCount(); i++) - { + for (int i = 0; i < function.getParamCount(); i++) { // Fragment programs do not use ordering for the output layout position, rather it is // embedded in the semantic - if (function[i].type->getQualifier().isParamOutput() && language != EShLangFragment) - { - if (function[i].type->getQualifier().builtIn == EbvNone) + if (function[i].type->getQualifier().isParamOutput() ) { + if (function[i].type->getQualifier().builtIn == EbvNone && language != EShLangFragment) function[i].type->getQualifier().layoutLocation = outCount++; function[i].type->getQualifier().storage = EvqVaryingOut; - } - else - { + } else { if (function[i].type->getQualifier().builtIn == EbvNone) function[i].type->getQualifier().layoutLocation = inCount++; function[i].type->getQualifier().storage = EvqVaryingIn; @@ -2276,7 +2272,9 @@ void HlslParseContext::handleSemantic(TType& type, const TString& semantic) // TODO: need to know if it's an input or an output // The following sketches what needs to be done, but can't be right // without taking into account stage and input/output. - + + TString semanticUpperCase = semantic; + std::transform(semanticUpperCase.begin(), semanticUpperCase.end(), semanticUpperCase.begin(), ::toupper); // in DX9, all outputs had to have a semantic associated with them, that was either consumed // by the system or was a specific register assignment // in DX10+, only semantics with the SV_ prefix have any meaning beyond decoration @@ -2284,24 +2282,23 @@ void HlslParseContext::handleSemantic(TType& type, const TString& semantic) // Also, in DX10 if a SV value is present as the input of a stage, but isn't appropriate for that // stage, it would just be ignored as it is likely there as part of an output struct from one stage // to the next - bool bParseDX9 = false; + + bool bParseDX9 = false; if (bParseDX9) { - if (semantic == "PSIZE") + if (semanticUpperCase == "PSIZE") type.getQualifier().builtIn = EbvPointSize; else if (semantic == "FOG") type.getQualifier().builtIn = EbvFogFragCoord; - else if (semantic == "DEPTH" || semantic == "SV_Depth") + else if (semanticUpperCase == "DEPTH") type.getQualifier().builtIn = EbvFragDepth; - else if (semantic == "VFACE" || semantic == "SV_IsFrontFace") + else if (semanticUpperCase == "VFACE") type.getQualifier().builtIn = EbvFace; - else if (semantic == "VPOS" || semantic == "SV_Position") + else if (semanticUpperCase == "VPOS") type.getQualifier().builtIn = EbvFragCoord; } - TString semanticUpperCase = semantic; - std::transform(semanticUpperCase.begin(), semanticUpperCase.end(), semanticUpperCase.begin(), ::toupper); { //SV Position has a different meaning in vertex vs fragment if (semanticUpperCase == "SV_POSITION" && language != EShLangFragment) From 6f220c0fd18f597d0319f91e42abd4df7e785037 Mon Sep 17 00:00:00 2001 From: Dan Baker Date: Mon, 29 Aug 2016 15:56:55 -0400 Subject: [PATCH 3/3] HLSL: Setting SV_DEPTHGREATEREQUAL and SV_DEPTHLESSEQUAL to EbvFragDepth for now --- hlsl/hlslParseHelper.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index 8e87c6e2..efa8b2ab 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -2359,14 +2359,14 @@ void HlslParseContext::handleSemantic(TType& type, const TString& semantic) type.getQualifier().builtIn = EbvTessCoord; else if (semanticUpperCase == "SV_DEPTH") type.getQualifier().builtIn = EbvFragDepth; - - + //TODO, these need to get refined to be more specific + else if( semanticUpperCase == "SV_DEPTHGREATEREQUAL") + type.getQualifier().builtIn = EbvFragDepth; + else if( semanticUpperCase == "SV_DEPTHLESSEQUAL") + type.getQualifier().builtIn = EbvFragDepth; //not supported or not trivial //else if( semanticUpperCase == "SV_STENCILREF") - // type.getQualifier().builtIn = gl_FragStencilRef - //else if( semanticUpperCase == "SV_DEPTHGREATEREQUAL") - // type.getQualifier().builtIn = ?? - //else if( semanticUpperCase == "SV_DEPTHLESSEQUAL") + // type.getQualifier().builtIn = gl_FragStencilRef // type.getQualifier().builtIn = ?? //else if( semanticUpperCase == "SV_COVERAGE") // type.getQualifier().builtIn = ??