Enable legalization when the vk::image_format attribute is used (#4048)

- Legalization is required to propagate the correct type of the OpLoad even when
the resource variables are not being passed or assigned
- This fixes a validation error in simple shaders using image_format, where legalization
would not be needed otherwise

Co-authored-by: Atte Seppälä <atte.seppala@ul.com>
This commit is contained in:
Atte Seppälä 2021-10-29 21:46:27 +03:00 коммит произвёл GitHub
Родитель 1629096dc4
Коммит b930b5fa43
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 23 добавлений и 0 удалений

Просмотреть файл

@ -1013,6 +1013,12 @@ SpirvVariable *DeclResultIdMapper::createExternVar(const VarDecl *var) {
VkImageFeatures vkImgFeatures = {
var->getAttr<VKCombinedImageSamplerAttr>() != nullptr,
getSpvImageFormat(var->getAttr<VKImageFormatAttr>())};
if (vkImgFeatures.format != spv::ImageFormat::Unknown) {
// Legalization is needed to propagate the correct image type for
// instructions in addition to cases where the resource is assigned to
// another variable or function parameter
needsLegalization = true;
}
if (vkImgFeatures.isCombinedImageSampler ||
vkImgFeatures.format != spv::ImageFormat::Unknown) {
spvContext.registerVkImageFeaturesForSpvVariable(varInstr, vkImgFeatures);

Просмотреть файл

@ -0,0 +1,14 @@
// Run: %dxc -T cs_6_0 -E main -O3
//CHECK: OpTypeImage %float Buffer 2 0 0 2 Rgba16f
[[vk::image_format("rgba16f")]]
RWBuffer<float4> Buf;
//CHECK: OpTypeImage %float 2D 2 0 0 2 Rgba16f
[[vk::image_format("rgba16f")]]
RWTexture2D<float4> Tex;
[numthreads(1, 1, 1)]
void main() {
Buf[0] = Tex[uint2(0, 0)];
Tex[uint2(1, 0)] = Buf[1];
}

Просмотреть файл

@ -1820,6 +1820,9 @@ TEST_F(FileTest, VulkanAttributeImageFormat) {
TEST_F(FileTest, VulkanAttributeImageFormatO3) {
runFileTest("vk.attribute.image-format.o3.hlsl");
}
TEST_F(FileTest, VulkanAttributeImageFormatSimple) {
runFileTest("vk.attribute.image-format.simple.hlsl", Expect::Success);
}
TEST_F(FileTest, VulkanCLOptionInvertYVS) {
runFileTest("vk.cloption.invert-y.vs.hlsl");