Allow DepthUnchanged and DepthReplaced Modes in same SPIR-V module.

Fixes #2555
This commit is contained in:
Greg Fischer 2021-03-01 17:45:03 -07:00
parent 0eca413092
commit b479ce0bfa
4 changed files with 58 additions and 4 deletions

View File

@ -1551,15 +1551,16 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion,
builder.addExtension(spv::E_SPV_KHR_post_depth_coverage);
}
if (glslangIntermediate->getDepth() != glslang::EldUnchanged && glslangIntermediate->isDepthReplacing())
if (glslangIntermediate->isDepthReplacing())
builder.addExecutionMode(shaderEntry, spv::ExecutionModeDepthReplacing);
#ifndef GLSLANG_WEB
switch(glslangIntermediate->getDepth()) {
case glslang::EldGreater: mode = spv::ExecutionModeDepthGreater; break;
case glslang::EldLess: mode = spv::ExecutionModeDepthLess; break;
default: mode = spv::ExecutionModeMax; break;
case glslang::EldGreater: mode = spv::ExecutionModeDepthGreater; break;
case glslang::EldLess: mode = spv::ExecutionModeDepthLess; break;
case glslang::EldUnchanged: mode = spv::ExecutionModeDepthUnchanged; break;
default: mode = spv::ExecutionModeMax; break;
}
if (mode != spv::ExecutionModeMax)
builder.addExecutionMode(shaderEntry, (spv::ExecutionMode)mode);

View File

@ -0,0 +1,44 @@
spv.depthUnchanged.frag
// Module Version 10000
// Generated by (magic number): 8000a
// Id's are bound by 22
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 9 14 16
ExecutionMode 4 OriginUpperLeft
ExecutionMode 4 DepthReplacing
ExecutionMode 4 DepthUnchanged
Source GLSL 430
Name 4 "main"
Name 9 "outColor"
Name 14 "gl_FragDepth"
Name 16 "gl_FragCoord"
Decorate 9(outColor) Location 0
Decorate 14(gl_FragDepth) BuiltIn FragDepth
Decorate 16(gl_FragCoord) BuiltIn FragCoord
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer Output 7(fvec4)
9(outColor): 8(ptr) Variable Output
10: 6(float) Constant 1065353216
11: 6(float) Constant 0
12: 7(fvec4) ConstantComposite 10 11 11 10
13: TypePointer Output 6(float)
14(gl_FragDepth): 13(ptr) Variable Output
15: TypePointer Input 7(fvec4)
16(gl_FragCoord): 15(ptr) Variable Input
17: TypeInt 32 0
18: 17(int) Constant 1
19: TypePointer Input 6(float)
4(main): 2 Function None 3
5: Label
Store 9(outColor) 12
20: 19(ptr) AccessChain 16(gl_FragCoord) 18
21: 6(float) Load 20
Store 14(gl_FragDepth) 21
Return
FunctionEnd

View File

@ -0,0 +1,8 @@
#version 430
layout(location = 0) out vec4 outColor;
layout(depth_unchanged) out float gl_FragDepth;
void main() {
outColor = vec4(1.0, 0.0, 0.0, 1.0);
gl_FragDepth = gl_FragCoord.y;
}

View File

@ -328,6 +328,7 @@ INSTANTIATE_TEST_SUITE_P(
"spv.demoteDisabled.frag",
"spv.deepRvalue.frag",
"spv.depthOut.frag",
"spv.depthUnchanged.frag",
"spv.discard-dce.frag",
"spv.doWhileLoop.frag",
"spv.earlyReturnDiscard.frag",