diff options
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 28 | ||||
| -rw-r--r-- | tests/spirv/depth-replacing-none.slang | 17 |
2 files changed, 27 insertions, 18 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 36c9aa5f8..d32530b90 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -2894,7 +2894,7 @@ struct SPIRVEmitContext } - SpvExecutionMode isDepthOutput(IRInst* builtinVar) + SpvExecutionMode getDepthOutputExecutionMode(IRInst* builtinVar) { SpvExecutionMode result = SpvExecutionModeMax; bool isDepthVar = false; @@ -2943,6 +2943,7 @@ struct SPIRVEmitContext { case kIROp_SwizzledStore: case kIROp_Store: + case kIROp_Call: return result; } } @@ -2956,34 +2957,25 @@ struct SPIRVEmitContext // Check if the entrypoint uses any depth output builtin variables, // if so, we need to emit a DepthReplacing execution mode for the // fragment entrypoint. - bool needDepthReplacingMode = false; SpvExecutionMode mode = SpvExecutionModeMax; for (auto globalInst : referencedBuiltinIRVars) { - if (auto thisMode = isDepthOutput(globalInst)) + auto thisMode = getDepthOutputExecutionMode(globalInst); + if (mode == SpvExecutionModeMax) + mode = thisMode; + else if (mode != thisMode) { - needDepthReplacingMode = true; - if (mode == SpvExecutionModeMax) - mode = thisMode; - else if (mode != thisMode) - mode = SpvExecutionModeDepthReplacing; + mode = SpvExecutionModeDepthReplacing; break; } } - if (!needDepthReplacingMode) + if (mode == SpvExecutionModeMax) return; + emitOpExecutionMode(getSection(SpvLogicalSectionID::ExecutionModes), nullptr, entryPoint, - SpvExecutionModeDepthReplacing); - if (mode != SpvExecutionModeDepthReplacing && - mode != SpvExecutionModeMax) - { - emitOpExecutionMode(getSection(SpvLogicalSectionID::ExecutionModes), - nullptr, - entryPoint, - mode); - } + mode); } // Make user type name conform to `SPV_GOOGLE_user_type` spec. diff --git a/tests/spirv/depth-replacing-none.slang b/tests/spirv/depth-replacing-none.slang new file mode 100644 index 000000000..15932356d --- /dev/null +++ b/tests/spirv/depth-replacing-none.slang @@ -0,0 +1,17 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv -stage fragment -entry main -emit-spirv-directly + +// Test that a fragment shader that does not modify depth does not +// have a DepthReplacing decoration. + +struct PSOut +{ + float4 color : SV_Target; +} +// CHECK-NOT: OpExecutionMode {{.*}} DepthReplacing + +PSOut main() +{ + PSOut psout; + psout.color = float4(1.0f, 0.0f, 0.0f, 1.0f); + return psout; +} |
