Skip to content

Commit f25b318

Browse files
committed
Fix SPIRV parsing for SpvOpTypeImage
OpTypeImage can be used for sampled or storage images, which is indicated by an extra word we haven't parsed until now. This is not necessary right now but might be if we decide to get rid of combined image/samplers.
1 parent e80f024 commit f25b318

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/shaders.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct Id
3232
uint32_t storageClass;
3333
uint32_t binding;
3434
uint32_t set;
35+
uint32_t imageSampled;
3536
uint32_t constant;
3637
};
3738

@@ -58,14 +59,14 @@ static VkShaderStageFlagBits getShaderStage(SpvExecutionModel executionModel)
5859
}
5960
}
6061

61-
static VkDescriptorType getDescriptorType(SpvOp op)
62+
static VkDescriptorType getDescriptorType(SpvOp op, uint32_t imageSampled = 0)
6263
{
6364
switch (op)
6465
{
6566
case SpvOpTypeStruct:
6667
return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
6768
case SpvOpTypeImage:
68-
return VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
69+
return imageSampled == 1 ? VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE : VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
6970
case SpvOpTypeSampler:
7071
return VK_DESCRIPTOR_TYPE_SAMPLER;
7172
case SpvOpTypeSampledImage:
@@ -158,7 +159,6 @@ static void parseShader(Shader& shader, const uint32_t* code, uint32_t codeSize)
158159
}
159160
break;
160161
case SpvOpTypeStruct:
161-
case SpvOpTypeImage:
162162
case SpvOpTypeSampler:
163163
case SpvOpTypeSampledImage:
164164
case SpvOpTypeAccelerationStructureKHR:
@@ -172,6 +172,18 @@ static void parseShader(Shader& shader, const uint32_t* code, uint32_t codeSize)
172172
ids[id].opcode = opcode;
173173
}
174174
break;
175+
case SpvOpTypeImage:
176+
{
177+
assert(wordCount >= 9);
178+
179+
uint32_t id = insn[1];
180+
assert(id < idBound);
181+
182+
assert(ids[id].opcode == 0);
183+
ids[id].opcode = opcode;
184+
ids[id].imageSampled = insn[7];
185+
}
186+
break;
175187
case SpvOpTypePointer:
176188
{
177189
assert(wordCount == 4);
@@ -225,8 +237,8 @@ static void parseShader(Shader& shader, const uint32_t* code, uint32_t codeSize)
225237
assert(id.binding < 32);
226238
assert(ids[id.typeId].opcode == SpvOpTypePointer);
227239

228-
uint32_t typeKind = ids[ids[id.typeId].typeId].opcode;
229-
VkDescriptorType resourceType = getDescriptorType(SpvOp(typeKind));
240+
const Id& type = ids[ids[id.typeId].typeId];
241+
VkDescriptorType resourceType = getDescriptorType(SpvOp(type.opcode), type.imageSampled);
230242

231243
assert((shader.resourceMask & (1 << id.binding)) == 0 || shader.resourceTypes[id.binding] == resourceType);
232244

0 commit comments

Comments
 (0)