-
Notifications
You must be signed in to change notification settings - Fork 854
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spirv: Add a postprocessing pass to fix up uses of OpSampledImage
SPIR-V requires that any instruction using the result of an OpSampledImage instruction be in the same block as the OpSampledImage. This is hard to guarantee in code generation but easy to fix after the fact, by simply inserting a new OpSampledImage before the user of its result if needed, with the new instruction having the same operands as the original OpSampledImage. This change adds a new pass to spv::Builder::postProcess that does this. This might leave the original OpSampledImage instructions "orphaned" with no users of their result ID, but dead code elimination would take care of those further down the line.
- Loading branch information
1 parent
2712d64
commit 7c3c50e
Showing
6 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
spv.sampledImageBlock.frag | ||
// Module Version 10000 | ||
// Generated by (magic number): 8000b | ||
// Id's are bound by 55 | ||
|
||
Capability Shader | ||
1: ExtInstImport "GLSL.std.450" | ||
MemoryModel Logical GLSL450 | ||
EntryPoint Fragment 4 "main" 36 45 | ||
ExecutionMode 4 OriginUpperLeft | ||
Source GLSL 450 | ||
Name 4 "main" | ||
Name 9 "texel" | ||
Name 12 "tex0" | ||
Name 16 "samp0" | ||
Name 21 "ParamBuffer" | ||
MemberName 21(ParamBuffer) 0 "cond" | ||
Name 23 "paramBuffer" | ||
Name 36 "texCoord" | ||
Name 45 "fragColor" | ||
Decorate 12(tex0) DescriptorSet 0 | ||
Decorate 12(tex0) Binding 0 | ||
Decorate 16(samp0) DescriptorSet 0 | ||
Decorate 16(samp0) Binding 1 | ||
MemberDecorate 21(ParamBuffer) 0 Offset 0 | ||
Decorate 21(ParamBuffer) Block | ||
Decorate 23(paramBuffer) DescriptorSet 0 | ||
Decorate 23(paramBuffer) Binding 2 | ||
Decorate 36(texCoord) Flat | ||
Decorate 36(texCoord) Location 0 | ||
Decorate 45(fragColor) Location 0 | ||
2: TypeVoid | ||
3: TypeFunction 2 | ||
6: TypeFloat 32 | ||
7: TypeVector 6(float) 4 | ||
8: TypePointer Function 7(fvec4) | ||
10: TypeImage 6(float) 2D sampled format:Unknown | ||
11: TypePointer UniformConstant 10 | ||
12(tex0): 11(ptr) Variable UniformConstant | ||
14: TypeSampler | ||
15: TypePointer UniformConstant 14 | ||
16(samp0): 15(ptr) Variable UniformConstant | ||
18: TypeSampledImage 10 | ||
20: TypeInt 32 1 | ||
21(ParamBuffer): TypeStruct 20(int) | ||
22: TypePointer Uniform 21(ParamBuffer) | ||
23(paramBuffer): 22(ptr) Variable Uniform | ||
24: 20(int) Constant 0 | ||
25: TypePointer Uniform 20(int) | ||
28: TypeBool | ||
30: TypeVector 20(int) 2 | ||
31: TypePointer Function 30(ivec2) | ||
35: TypePointer Input 30(ivec2) | ||
36(texCoord): 35(ptr) Variable Input | ||
44: TypePointer Output 7(fvec4) | ||
45(fragColor): 44(ptr) Variable Output | ||
46: TypeVector 6(float) 3 | ||
49: 6(float) Constant 1065353216 | ||
4(main): 2 Function None 3 | ||
5: Label | ||
9(texel): 8(ptr) Variable Function | ||
32: 31(ptr) Variable Function | ||
13: 10 Load 12(tex0) | ||
17: 14 Load 16(samp0) | ||
19: 18 SampledImage 13 17 | ||
26: 25(ptr) AccessChain 23(paramBuffer) 24 | ||
27: 20(int) Load 26 | ||
29: 28(bool) IEqual 27 24 | ||
SelectionMerge 34 None | ||
BranchConditional 29 33 38 | ||
33: Label | ||
37: 30(ivec2) Load 36(texCoord) | ||
Store 32 37 | ||
Branch 34 | ||
38: Label | ||
39: 30(ivec2) Load 36(texCoord) | ||
40: 30(ivec2) VectorShuffle 39 39 1 0 | ||
Store 32 40 | ||
Branch 34 | ||
34: Label | ||
41: 30(ivec2) Load 32 | ||
54: 18 SampledImage 13 17 | ||
42: 10 Image 54 | ||
43: 7(fvec4) ImageFetch 42 41 Lod 24 | ||
Store 9(texel) 43 | ||
47: 7(fvec4) Load 9(texel) | ||
48: 46(fvec3) VectorShuffle 47 47 0 1 2 | ||
50: 6(float) CompositeExtract 48 0 | ||
51: 6(float) CompositeExtract 48 1 | ||
52: 6(float) CompositeExtract 48 2 | ||
53: 7(fvec4) CompositeConstruct 50 51 52 49 | ||
Store 45(fragColor) 53 | ||
Return | ||
FunctionEnd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#version 450 | ||
|
||
layout(set = 0, binding = 0) uniform texture2D tex0; | ||
layout(set = 0, binding = 1) uniform sampler samp0; | ||
layout(set = 0, binding = 2) uniform ParamBuffer { | ||
int cond; | ||
} paramBuffer; | ||
|
||
layout(location = 0) out vec4 fragColor; | ||
layout(location = 0) in flat ivec2 texCoord; | ||
|
||
void main() { | ||
// get input | ||
|
||
const vec4 texel = texelFetch(sampler2D(tex0, samp0), | ||
paramBuffer.cond == 0 ? texCoord.xy : texCoord.yx, | ||
0); | ||
|
||
fragColor = vec4(texel.xyz, 1.0); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters