[spirv] do not set result type for OpImageWrite (#3757)

Based on the spec https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpImageWrite,
`OpImageWrite` does not have result type nor result id.
If we set the result type, the RelaxedPrecisionVisitor can set the `RelaxedPrecision` decoration for it.
It results in the invalid SPIR-V code.
This commit is contained in:
Jaebaek Seo 2021-05-12 13:35:00 -04:00 коммит произвёл GitHub
Родитель a8036844fa
Коммит aa4f5176eb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 22 добавлений и 25 удалений

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

@ -314,9 +314,8 @@ public:
SourceLocation loc);
/// \brief Creates SPIR-V instructions for writing to the given image.
void createImageWrite(QualType imageType, SpirvInstruction *image,
SpirvInstruction *coord, SpirvInstruction *texel,
SourceLocation loc);
void createImageWrite(SpirvInstruction *image, SpirvInstruction *coord,
SpirvInstruction *texel, SourceLocation loc);
/// \brief Creates SPIR-V instructions for gathering the given image.
///

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

@ -305,22 +305,22 @@ void EmitVisitor::initInstruction(SpirvInstruction *inst) {
if (inst->hasResultType()) {
const uint32_t resultTypeId = typeHandler.emitType(inst->getResultType());
inst->setResultTypeId(resultTypeId);
}
// Emit NonUniformEXT decoration (if any).
if (inst->isNonUniform()) {
typeHandler.emitDecoration(getOrAssignResultId<SpirvInstruction>(inst),
spv::Decoration::NonUniformEXT, {});
}
// Emit RelaxedPrecision decoration (if any).
if (inst->isRelaxedPrecision()) {
typeHandler.emitDecoration(getOrAssignResultId<SpirvInstruction>(inst),
spv::Decoration::RelaxedPrecision, {});
}
// Emit NoContraction decoration (if any).
if (inst->isPrecise() && inst->isArithmeticInstruction()) {
typeHandler.emitDecoration(getOrAssignResultId<SpirvInstruction>(inst),
spv::Decoration::NoContraction, {});
// Emit NonUniformEXT decoration (if any).
if (inst->isNonUniform()) {
typeHandler.emitDecoration(getOrAssignResultId<SpirvInstruction>(inst),
spv::Decoration::NonUniformEXT, {});
}
// Emit RelaxedPrecision decoration (if any).
if (inst->isRelaxedPrecision()) {
typeHandler.emitDecoration(getOrAssignResultId<SpirvInstruction>(inst),
spv::Decoration::RelaxedPrecision, {});
}
// Emit NoContraction decoration (if any).
if (inst->isPrecise() && inst->isArithmeticInstruction()) {
typeHandler.emitDecoration(getOrAssignResultId<SpirvInstruction>(inst),
spv::Decoration::NoContraction, {});
}
}
// According to Section 2.4. Logical Layout of a Module in the SPIR-V spec:

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

@ -562,13 +562,13 @@ SpirvInstruction *SpirvBuilder::createImageFetchOrRead(
return fetchOrReadInst;
}
void SpirvBuilder::createImageWrite(QualType imageType, SpirvInstruction *image,
void SpirvBuilder::createImageWrite(SpirvInstruction *image,
SpirvInstruction *coord,
SpirvInstruction *texel,
SourceLocation loc) {
assert(insertPoint && "null insert point");
auto *writeInst = new (context) SpirvImageOp(
spv::Op::OpImageWrite, imageType, loc, image, coord,
spv::Op::OpImageWrite, /*QualType*/ {}, loc, image, coord,
spv::ImageOperandsMask::MaskNone,
/*dref*/ nullptr, /*bias*/ nullptr, /*lod*/ nullptr, /*gradDx*/ nullptr,
/*gradDy*/ nullptr, /*constOffset*/ nullptr, /*varOffset*/ nullptr,

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

@ -6377,7 +6377,7 @@ SpirvEmitter::tryToAssignToRWBufferRWTexture(const Expr *lhs,
auto *baseInfo = doExpr(baseExpr);
auto *image =
spvBuilder.createLoad(imageType, baseInfo, baseExpr->getExprLoc());
spvBuilder.createImageWrite(imageType, image, loc, rhs, lhs->getExprLoc());
spvBuilder.createImageWrite(image, loc, rhs, lhs->getExprLoc());
return rhs;
}
return nullptr;

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

@ -1,4 +1,4 @@
// Run: %dxc -T cs_6_0 -E main -Vd
// Run: %dxc -T cs_6_0 -E main
// CHECK: %type_2d_image = OpTypeImage %float 2D 2 0 0 2 Rgba32f
// CHECK: %_ptr_UniformConstant_type_2d_image = OpTypePointer UniformConstant %type_2d_image

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

@ -70,9 +70,7 @@ TEST_F(FileTest, SamplerTypes) { runFileTest("type.sampler.hlsl"); }
TEST_F(FileTest, TextureTypes) { runFileTest("type.texture.hlsl"); }
TEST_F(FileTest, RWTextureTypes) { runFileTest("type.rwtexture.hlsl"); }
TEST_F(FileTest, RWTextureTypesWithMinPrecisionScalarTypes) {
// TODO: Fix the valiation error
runFileTest("type.rwtexture.with.min.precision.scalar.hlsl", Expect::Success,
/* runValidation */ false);
runFileTest("type.rwtexture.with.min.precision.scalar.hlsl");
}
TEST_F(FileTest, BufferType) { runFileTest("type.buffer.hlsl"); }
TEST_F(FileTest, BufferTypeStructError1) {