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.
This commit is contained in:
parent
2712d643b1
commit
7c3c50ea94
6 changed files with 180 additions and 1 deletions
21
Test/spv.sampledImageBlock.frag
Normal file
21
Test/spv.sampledImageBlock.frag
Normal file
|
|
@ -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);
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue