Skip to content

Commit fcbd2a1

Browse files
authored
[SPIRV] Add the vk::image_format to runtime arrays (microsoft#7128)
A case was missed when adding the `vk::image_format` to the image types. We did not handle runtime arrays. We fix that oversight. Fixes microsoft#6880
1 parent d2f2aae commit fcbd2a1

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

tools/clang/lib/SPIRV/LowerTypeVisitor.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,17 @@ bool LowerTypeVisitor::visitInstruction(SpirvInstruction *instr) {
214214
arrayType->getStride());
215215
instr->setResultType(resultType);
216216
}
217+
} else if (const auto *runtimeArrayType =
218+
dyn_cast<RuntimeArrayType>(resultType)) {
219+
if (const auto *imageType =
220+
dyn_cast<ImageType>(runtimeArrayType->getElementType())) {
221+
auto newImgType = spvContext.getImageType(
222+
imageType,
223+
vkImgFeatures.format.value_or(spv::ImageFormat::Unknown));
224+
resultType = spvContext.getRuntimeArrayType(
225+
newImgType, runtimeArrayType->getStride());
226+
instr->setResultType(resultType);
227+
}
217228
}
218229
}
219230
}

tools/clang/test/CodeGenSPIRV/vk.attribute.image-format.hlsl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ RWBuffer<int64_t> Buf_r64i;
6060
[[vk::image_format("r64ui")]]
6161
RWBuffer<uint64_t> Buf_r64ui;
6262

63+
[[vk::image_format("r16f")]]
64+
// CHECK: [[ImgType:%[0-9a-zA-Z_]+]] = OpTypeImage %float 2D 2 0 0 2 R16f
65+
// CHECK: [[ArrayType:%[0-9a-zA-Z_]+]] = OpTypeRuntimeArray [[ImgType]]
66+
// CHECK: [[PtrType:%[0-9a-zA-Z_]+]] = OpTypePointer UniformConstant [[ArrayType]]
67+
RWTexture2D<float> Buf_r16f_bindless[];
68+
6369
struct S {
6470
RWBuffer<float4> b;
6571
};

0 commit comments

Comments
 (0)