rescaling_pass: Fix IR errors when unscalable texture types are encountered

This commit is contained in:
ameerj 2021-09-29 20:53:30 -04:00 committed by Fernando Sahmkow
parent ea82bd4b7e
commit 581ea90062
1 changed files with 28 additions and 0 deletions

View File

@ -14,6 +14,22 @@
namespace Shader::Optimization { namespace Shader::Optimization {
namespace { namespace {
[[nodiscard]] bool IsTextureTypeRescalable(TextureType type) {
switch (type) {
case TextureType::Color2D:
case TextureType::ColorArray2D:
return true;
case TextureType::Color1D:
case TextureType::ColorArray1D:
case TextureType::Color3D:
case TextureType::ColorCube:
case TextureType::ColorArrayCube:
case TextureType::Buffer:
break;
}
return false;
}
void VisitMark(const IR::Inst& inst) { void VisitMark(const IR::Inst& inst) {
switch (inst.GetOpcode()) { switch (inst.GetOpcode()) {
case IR::Opcode::ShuffleIndex: case IR::Opcode::ShuffleIndex:
@ -179,6 +195,9 @@ void SubScaleCoord(IR::IREmitter& ir, IR::Inst& inst, const IR::U1& is_scaled) {
void SubScaleImageFetch(IR::Block& block, IR::Inst& inst) { void SubScaleImageFetch(IR::Block& block, IR::Inst& inst) {
IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)};
const auto info{inst.Flags<IR::TextureInstInfo>()}; const auto info{inst.Flags<IR::TextureInstInfo>()};
if (!IsTextureTypeRescalable(info.type)) {
return;
}
const IR::U1 is_scaled{ir.IsTextureScaled(ir.Imm32(info.descriptor_index))}; const IR::U1 is_scaled{ir.IsTextureScaled(ir.Imm32(info.descriptor_index))};
SubScaleCoord(ir, inst, is_scaled); SubScaleCoord(ir, inst, is_scaled);
// Scale ImageFetch offset // Scale ImageFetch offset
@ -188,6 +207,9 @@ void SubScaleImageFetch(IR::Block& block, IR::Inst& inst) {
void SubScaleImageRead(IR::Block& block, IR::Inst& inst) { void SubScaleImageRead(IR::Block& block, IR::Inst& inst) {
IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)};
const auto info{inst.Flags<IR::TextureInstInfo>()}; const auto info{inst.Flags<IR::TextureInstInfo>()};
if (!IsTextureTypeRescalable(info.type)) {
return;
}
const IR::U1 is_scaled{ir.IsImageScaled(ir.Imm32(info.descriptor_index))}; const IR::U1 is_scaled{ir.IsImageScaled(ir.Imm32(info.descriptor_index))};
SubScaleCoord(ir, inst, is_scaled); SubScaleCoord(ir, inst, is_scaled);
} }
@ -195,6 +217,9 @@ void SubScaleImageRead(IR::Block& block, IR::Inst& inst) {
void PatchImageFetch(IR::Block& block, IR::Inst& inst) { void PatchImageFetch(IR::Block& block, IR::Inst& inst) {
IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)};
const auto info{inst.Flags<IR::TextureInstInfo>()}; const auto info{inst.Flags<IR::TextureInstInfo>()};
if (!IsTextureTypeRescalable(info.type)) {
return;
}
const IR::U1 is_scaled{ir.IsTextureScaled(ir.Imm32(info.descriptor_index))}; const IR::U1 is_scaled{ir.IsTextureScaled(ir.Imm32(info.descriptor_index))};
ScaleIntegerComposite(ir, inst, is_scaled, 1); ScaleIntegerComposite(ir, inst, is_scaled, 1);
// Scale ImageFetch offset // Scale ImageFetch offset
@ -204,6 +229,9 @@ void PatchImageFetch(IR::Block& block, IR::Inst& inst) {
void PatchImageRead(IR::Block& block, IR::Inst& inst) { void PatchImageRead(IR::Block& block, IR::Inst& inst) {
IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)};
const auto info{inst.Flags<IR::TextureInstInfo>()}; const auto info{inst.Flags<IR::TextureInstInfo>()};
if (!IsTextureTypeRescalable(info.type)) {
return;
}
const IR::U1 is_scaled{ir.IsImageScaled(ir.Imm32(info.descriptor_index))}; const IR::U1 is_scaled{ir.IsImageScaled(ir.Imm32(info.descriptor_index))};
ScaleIntegerComposite(ir, inst, is_scaled, 1); ScaleIntegerComposite(ir, inst, is_scaled, 1);
} }