glasm: Implement TEX and TEXS instructions
Remove lod clamp from texture instructions with lod, as this is not needed (nor supported).
This commit is contained in:
parent
c42a6143a5
commit
ec6fc5fe78
10 changed files with 276 additions and 70 deletions
|
@ -283,6 +283,9 @@ void SetupOptions(std::string& header, Info info) {
|
||||||
if (info.uses_subgroup_shuffles) {
|
if (info.uses_subgroup_shuffles) {
|
||||||
header += "OPTION NV_shader_thread_shuffle;";
|
header += "OPTION NV_shader_thread_shuffle;";
|
||||||
}
|
}
|
||||||
|
if (info.uses_sparse_residency) {
|
||||||
|
header += "OPTION EXT_sparse_texture2;";
|
||||||
|
}
|
||||||
const auto non_zero_frag_colors{info.stores_frag_color | std::views::drop(1)};
|
const auto non_zero_frag_colors{info.stores_frag_color | std::views::drop(1)};
|
||||||
if (std::ranges::find(non_zero_frag_colors, true) != non_zero_frag_colors.end()) {
|
if (std::ranges::find(non_zero_frag_colors, true) != non_zero_frag_colors.end()) {
|
||||||
header += "OPTION ARB_draw_buffers;";
|
header += "OPTION ARB_draw_buffers;";
|
||||||
|
|
|
@ -9,6 +9,34 @@
|
||||||
|
|
||||||
namespace Shader::Backend::GLASM {
|
namespace Shader::Backend::GLASM {
|
||||||
namespace {
|
namespace {
|
||||||
|
struct ScopedRegister {
|
||||||
|
ScopedRegister() = default;
|
||||||
|
ScopedRegister(RegAlloc& reg_alloc_) : reg_alloc{®_alloc_}, reg{reg_alloc->AllocReg()} {}
|
||||||
|
|
||||||
|
~ScopedRegister() {
|
||||||
|
if (reg_alloc) {
|
||||||
|
reg_alloc->FreeReg(reg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedRegister& operator=(ScopedRegister&& rhs) noexcept {
|
||||||
|
if (reg_alloc) {
|
||||||
|
reg_alloc->FreeReg(reg);
|
||||||
|
}
|
||||||
|
reg_alloc = std::exchange(rhs.reg_alloc, nullptr);
|
||||||
|
reg = rhs.reg;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedRegister(ScopedRegister&& rhs) noexcept
|
||||||
|
: reg_alloc{std::exchange(rhs.reg_alloc, nullptr)}, reg{rhs.reg} {}
|
||||||
|
|
||||||
|
ScopedRegister& operator=(const ScopedRegister&) = delete;
|
||||||
|
ScopedRegister(const ScopedRegister&) = delete;
|
||||||
|
|
||||||
|
RegAlloc* reg_alloc{};
|
||||||
|
Register reg;
|
||||||
|
};
|
||||||
|
|
||||||
std::string Texture([[maybe_unused]] EmitContext& ctx, IR::TextureInstInfo info,
|
std::string Texture([[maybe_unused]] EmitContext& ctx, IR::TextureInstInfo info,
|
||||||
[[maybe_unused]] const IR::Value& index) {
|
[[maybe_unused]] const IR::Value& index) {
|
||||||
// FIXME
|
// FIXME
|
||||||
|
@ -36,6 +64,61 @@ std::string_view TextureType(IR::TextureInstInfo info) {
|
||||||
}
|
}
|
||||||
throw InvalidArgument("Invalid texture type {}", info.type.Value());
|
throw InvalidArgument("Invalid texture type {}", info.type.Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string_view ShadowTextureType(IR::TextureInstInfo info) {
|
||||||
|
switch (info.type) {
|
||||||
|
case TextureType::Color1D:
|
||||||
|
return "SHADOW1D";
|
||||||
|
case TextureType::ColorArray1D:
|
||||||
|
return "SHADOWARRAY1D";
|
||||||
|
case TextureType::Color2D:
|
||||||
|
return "SHADOW2D";
|
||||||
|
case TextureType::ColorArray2D:
|
||||||
|
return "SHADOWARRAY2D";
|
||||||
|
case TextureType::Color3D:
|
||||||
|
return "SHADOW3D";
|
||||||
|
case TextureType::ColorCube:
|
||||||
|
return "SHADOWCUBE";
|
||||||
|
case TextureType::ColorArrayCube:
|
||||||
|
return "SHADOWARRAYCUBE";
|
||||||
|
case TextureType::Buffer:
|
||||||
|
return "SHADOWBUFFER";
|
||||||
|
}
|
||||||
|
throw InvalidArgument("Invalid texture type {}", info.type.Value());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Offset(EmitContext& ctx, const IR::Value& offset) {
|
||||||
|
if (offset.IsEmpty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return fmt::format(",offset({})", Register{ctx.reg_alloc.Consume(offset)});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<std::string, ScopedRegister> Coord(EmitContext& ctx, const IR::Value& coord) {
|
||||||
|
if (coord.IsImmediate()) {
|
||||||
|
ScopedRegister scoped_reg(ctx.reg_alloc);
|
||||||
|
return {fmt::to_string(scoped_reg.reg), std::move(scoped_reg)};
|
||||||
|
}
|
||||||
|
std::string coord_vec{fmt::to_string(Register{ctx.reg_alloc.Consume(coord)})};
|
||||||
|
if (coord.InstRecursive()->HasUses()) {
|
||||||
|
// Move non-dead coords to a separate register, although this should never happen because
|
||||||
|
// vectors are only assembled for immediate texture instructions
|
||||||
|
ctx.Add("MOV.F RC,{};", coord_vec);
|
||||||
|
coord_vec = "RC";
|
||||||
|
}
|
||||||
|
return {std::move(coord_vec), ScopedRegister{}};
|
||||||
|
}
|
||||||
|
|
||||||
|
void StoreSparse(EmitContext& ctx, IR::Inst* sparse_inst) {
|
||||||
|
if (!sparse_inst) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const Register sparse_ret{ctx.reg_alloc.Define(*sparse_inst)};
|
||||||
|
ctx.Add("MOV.S {},-1;"
|
||||||
|
"MOV.S {}(NONRESIDENT),0;",
|
||||||
|
sparse_ret, sparse_ret);
|
||||||
|
sparse_inst->Invalidate();
|
||||||
|
}
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
||||||
void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||||
|
@ -46,17 +129,8 @@ void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Valu
|
||||||
const std::string_view lod_clamp_mod{info.has_lod_clamp ? ".LODCLAMP" : ""};
|
const std::string_view lod_clamp_mod{info.has_lod_clamp ? ".LODCLAMP" : ""};
|
||||||
const std::string_view type{TextureType(info)};
|
const std::string_view type{TextureType(info)};
|
||||||
const std::string texture{Texture(ctx, info, index)};
|
const std::string texture{Texture(ctx, info, index)};
|
||||||
std::string offset_vec;
|
const std::string offset_vec{Offset(ctx, offset)};
|
||||||
if (!offset.IsEmpty()) {
|
const auto [coord_vec, coord_alloc]{Coord(ctx, coord)};
|
||||||
offset_vec = fmt::format(",offset({})", Register{ctx.reg_alloc.Consume(offset)});
|
|
||||||
}
|
|
||||||
std::string coord_vec{fmt::to_string(Register{ctx.reg_alloc.Consume(coord)})};
|
|
||||||
if (coord.InstRecursive()->HasUses()) {
|
|
||||||
// Move non-dead coords to a separate register, although this should never happen because
|
|
||||||
// vectors are only assembled for immediate texture instructions
|
|
||||||
ctx.Add("MOV.F RC,{};", coord_vec);
|
|
||||||
coord_vec = "RC";
|
|
||||||
}
|
|
||||||
const Register ret{ctx.reg_alloc.Define(inst)};
|
const Register ret{ctx.reg_alloc.Define(inst)};
|
||||||
if (info.has_bias) {
|
if (info.has_bias) {
|
||||||
if (info.type == TextureType::ColorArrayCube) {
|
if (info.type == TextureType::ColorArrayCube) {
|
||||||
|
@ -83,38 +157,172 @@ void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Valu
|
||||||
type, offset_vec);
|
type, offset_vec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sparse_inst) {
|
StoreSparse(ctx, sparse_inst);
|
||||||
const Register sparse_ret{ctx.reg_alloc.Define(*sparse_inst)};
|
|
||||||
ctx.Add("MOV.S {},-1;"
|
|
||||||
"MOV.S {}(NONRESIDENT),0;",
|
|
||||||
sparse_ret, sparse_ret);
|
|
||||||
sparse_inst->Invalidate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitImageSampleExplicitLod([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
void EmitImageSampleExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||||
[[maybe_unused]] const IR::Value& index,
|
const IR::Value& coord, ScalarF32 lod, const IR::Value& offset) {
|
||||||
[[maybe_unused]] Register coord, [[maybe_unused]] Register lod_lc,
|
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||||
[[maybe_unused]] const IR::Value& offset) {
|
const auto sparse_inst{inst.GetAssociatedPseudoOperation(IR::Opcode::GetSparseFromOp)};
|
||||||
throw NotImplementedException("GLASM instruction");
|
const std::string_view sparse_mod{sparse_inst ? ".SPARSE" : ""};
|
||||||
|
const std::string_view type{TextureType(info)};
|
||||||
|
const std::string texture{Texture(ctx, info, index)};
|
||||||
|
const std::string offset_vec{Offset(ctx, offset)};
|
||||||
|
const auto [coord_vec, coord_alloc]{Coord(ctx, coord)};
|
||||||
|
const Register ret{ctx.reg_alloc.Define(inst)};
|
||||||
|
if (info.type == TextureType::ColorArrayCube) {
|
||||||
|
ctx.Add("TXL.F{} {},{},{},{},ARRAYCUBE{};", sparse_mod, ret, coord_vec, lod, texture,
|
||||||
|
offset_vec);
|
||||||
|
} else {
|
||||||
|
ctx.Add("MOV.F {}.w,{};"
|
||||||
|
"TXL.F{} {},{},{},{}{};",
|
||||||
|
coord_vec, lod, sparse_mod, ret, coord_vec, texture, type, offset_vec);
|
||||||
|
}
|
||||||
|
StoreSparse(ctx, sparse_inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitImageSampleDrefImplicitLod([[maybe_unused]] EmitContext& ctx,
|
void EmitImageSampleDrefImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||||
[[maybe_unused]] IR::Inst& inst,
|
const IR::Value& coord, ScalarF32 dref, Register bias_lc,
|
||||||
[[maybe_unused]] const IR::Value& index,
|
const IR::Value& offset) {
|
||||||
[[maybe_unused]] Register coord, [[maybe_unused]] Register dref,
|
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||||
[[maybe_unused]] Register bias_lc,
|
const auto sparse_inst{inst.GetAssociatedPseudoOperation(IR::Opcode::GetSparseFromOp)};
|
||||||
[[maybe_unused]] const IR::Value& offset) {
|
const std::string_view sparse_mod{sparse_inst ? ".SPARSE" : ""};
|
||||||
throw NotImplementedException("GLASM instruction");
|
const std::string_view type{ShadowTextureType(info)};
|
||||||
|
const std::string texture{Texture(ctx, info, index)};
|
||||||
|
const std::string offset_vec{Offset(ctx, offset)};
|
||||||
|
const auto [coord_vec, coord_alloc]{Coord(ctx, coord)};
|
||||||
|
const Register ret{ctx.reg_alloc.Define(inst)};
|
||||||
|
if (info.has_bias) {
|
||||||
|
if (info.has_lod_clamp) {
|
||||||
|
switch (info.type) {
|
||||||
|
case TextureType::Color1D:
|
||||||
|
case TextureType::ColorArray1D:
|
||||||
|
case TextureType::Color2D:
|
||||||
|
ctx.Add("MOV.F {}.z,{};"
|
||||||
|
"MOV.F {}.w,{}.x;"
|
||||||
|
"TXB.F.LODCLAMP{} {},{},{}.y,{},{}{};",
|
||||||
|
coord_vec, dref, coord_vec, bias_lc, sparse_mod, ret, coord_vec, bias_lc,
|
||||||
|
texture, type, offset_vec);
|
||||||
|
break;
|
||||||
|
case TextureType::ColorArray2D:
|
||||||
|
case TextureType::ColorCube:
|
||||||
|
ctx.Add("MOV.F {}.w,{};"
|
||||||
|
"TXB.F.LODCLAMP{} {},{},{},{},{}{};",
|
||||||
|
coord_vec, dref, sparse_mod, ret, coord_vec, bias_lc, texture, type,
|
||||||
|
offset_vec);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw NotImplementedException("Invalid type {} with bias and lod clamp",
|
||||||
|
info.type.Value());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (info.type) {
|
||||||
|
case TextureType::Color1D:
|
||||||
|
case TextureType::ColorArray1D:
|
||||||
|
case TextureType::Color2D:
|
||||||
|
ctx.Add("MOV.F {}.z,{};"
|
||||||
|
"MOV.F {}.w,{}.x;"
|
||||||
|
"TXB.F{} {},{},{},{}{};",
|
||||||
|
coord_vec, dref, coord_vec, bias_lc, sparse_mod, ret, coord_vec, texture,
|
||||||
|
type, offset_vec);
|
||||||
|
break;
|
||||||
|
case TextureType::ColorArray2D:
|
||||||
|
case TextureType::ColorCube:
|
||||||
|
ctx.Add("MOV.F {}.w,{};"
|
||||||
|
"TXB.F{} {},{},{},{},{}{};",
|
||||||
|
coord_vec, dref, sparse_mod, ret, coord_vec, bias_lc, texture, type,
|
||||||
|
offset_vec);
|
||||||
|
break;
|
||||||
|
case TextureType::ColorArrayCube: {
|
||||||
|
const ScopedRegister pair{ctx.reg_alloc};
|
||||||
|
ctx.Add("MOV.F {}.x,{};"
|
||||||
|
"MOV.F {}.y,{}.x;"
|
||||||
|
"TXB.F{} {},{},{},{},{}{};",
|
||||||
|
pair.reg, dref, pair.reg, bias_lc, sparse_mod, ret, coord_vec, pair.reg,
|
||||||
|
texture, type, offset_vec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw NotImplementedException("Invalid type {}", info.type.Value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (info.has_lod_clamp) {
|
||||||
|
if (info.type != TextureType::ColorArrayCube) {
|
||||||
|
const bool w_swizzle{info.type == TextureType::ColorArray2D ||
|
||||||
|
info.type == TextureType::ColorCube};
|
||||||
|
const char dref_swizzle{w_swizzle ? 'w' : 'z'};
|
||||||
|
ctx.Add("MOV.F {}.{},{};"
|
||||||
|
"TEX.F.LODCLAMP{} {},{},{},{},{}{};",
|
||||||
|
coord_vec, dref_swizzle, dref, sparse_mod, ret, coord_vec, bias_lc, texture,
|
||||||
|
type, offset_vec);
|
||||||
|
} else {
|
||||||
|
const ScopedRegister pair{ctx.reg_alloc};
|
||||||
|
ctx.Add("MOV.F {}.x,{};"
|
||||||
|
"MOV.F {}.y,{};"
|
||||||
|
"TEX.F.LODCLAMP{} {},{},{},{},{}{};",
|
||||||
|
pair.reg, dref, pair.reg, bias_lc, sparse_mod, ret, coord_vec, pair.reg,
|
||||||
|
texture, type, offset_vec);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (info.type != TextureType::ColorArrayCube) {
|
||||||
|
const bool w_swizzle{info.type == TextureType::ColorArray2D ||
|
||||||
|
info.type == TextureType::ColorCube};
|
||||||
|
const char dref_swizzle{w_swizzle ? 'w' : 'z'};
|
||||||
|
ctx.Add("MOV.F {}.{},{};"
|
||||||
|
"TEX.F{} {},{},{},{}{};",
|
||||||
|
coord_vec, dref_swizzle, dref, sparse_mod, ret, coord_vec, texture, type,
|
||||||
|
offset_vec);
|
||||||
|
} else {
|
||||||
|
const ScopedRegister pair{ctx.reg_alloc};
|
||||||
|
ctx.Add("TEX.F{} {},{},{},{},{}{};", sparse_mod, ret, coord_vec, dref, texture,
|
||||||
|
type, offset_vec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StoreSparse(ctx, sparse_inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitImageSampleDrefExplicitLod([[maybe_unused]] EmitContext& ctx,
|
void EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||||
[[maybe_unused]] IR::Inst& inst,
|
const IR::Value& coord, ScalarF32 dref, ScalarF32 lod,
|
||||||
[[maybe_unused]] const IR::Value& index,
|
const IR::Value& offset) {
|
||||||
[[maybe_unused]] Register coord, [[maybe_unused]] Register dref,
|
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||||
[[maybe_unused]] Register lod_lc,
|
const auto sparse_inst{inst.GetAssociatedPseudoOperation(IR::Opcode::GetSparseFromOp)};
|
||||||
[[maybe_unused]] const IR::Value& offset) {
|
const std::string_view sparse_mod{sparse_inst ? ".SPARSE" : ""};
|
||||||
throw NotImplementedException("GLASM instruction");
|
const std::string_view type{ShadowTextureType(info)};
|
||||||
|
const std::string texture{Texture(ctx, info, index)};
|
||||||
|
const std::string offset_vec{Offset(ctx, offset)};
|
||||||
|
const auto [coord_vec, coord_alloc]{Coord(ctx, coord)};
|
||||||
|
const Register ret{ctx.reg_alloc.Define(inst)};
|
||||||
|
switch (info.type) {
|
||||||
|
case TextureType::Color1D:
|
||||||
|
case TextureType::ColorArray1D:
|
||||||
|
case TextureType::Color2D:
|
||||||
|
ctx.Add("MOV.F {}.z,{};"
|
||||||
|
"MOV.F {}.w,{};"
|
||||||
|
"TXL.F{} {},{},{},{}{};",
|
||||||
|
coord_vec, dref, coord_vec, lod, sparse_mod, ret, coord_vec, texture, type,
|
||||||
|
offset_vec);
|
||||||
|
break;
|
||||||
|
case TextureType::ColorArray2D:
|
||||||
|
case TextureType::ColorCube:
|
||||||
|
ctx.Add("MOV.F {}.w,{};"
|
||||||
|
"TXL.F{} {},{},{},{},{}{};",
|
||||||
|
coord_vec, dref, sparse_mod, ret, coord_vec, lod, texture, type, offset_vec);
|
||||||
|
break;
|
||||||
|
case TextureType::ColorArrayCube: {
|
||||||
|
const ScopedRegister pair{ctx.reg_alloc};
|
||||||
|
ctx.Add("MOV.F {}.x,{};"
|
||||||
|
"MOV.F {}.y,{};"
|
||||||
|
"TXL.F{} {},{},{},{},{}{};",
|
||||||
|
pair.reg, dref, pair.reg, lod, sparse_mod, ret, coord_vec, pair.reg, texture, type,
|
||||||
|
offset_vec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw NotImplementedException("Invalid type {}", info.type.Value());
|
||||||
|
}
|
||||||
|
StoreSparse(ctx, sparse_inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitImageGather([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
void EmitImageGather([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||||
|
|
|
@ -527,12 +527,12 @@ void EmitBoundImageWrite(EmitContext&);
|
||||||
void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
void EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||||
const IR::Value& coord, Register bias_lc, const IR::Value& offset);
|
const IR::Value& coord, Register bias_lc, const IR::Value& offset);
|
||||||
void EmitImageSampleExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
void EmitImageSampleExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||||
Register coord, Register lod_lc, const IR::Value& offset);
|
const IR::Value& coord, ScalarF32 lod, const IR::Value& offset);
|
||||||
void EmitImageSampleDrefImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
void EmitImageSampleDrefImplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||||
Register coord, Register dref, Register bias_lc,
|
const IR::Value& coord, ScalarF32 dref, Register bias_lc,
|
||||||
const IR::Value& offset);
|
const IR::Value& offset);
|
||||||
void EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
void EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||||
Register coord, Register dref, Register lod_lc,
|
const IR::Value& coord, ScalarF32 dref, ScalarF32 lod,
|
||||||
const IR::Value& offset);
|
const IR::Value& offset);
|
||||||
void EmitImageGather(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
|
void EmitImageGather(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
|
||||||
const IR::Value& offset, const IR::Value& offset2);
|
const IR::Value& offset, const IR::Value& offset2);
|
||||||
|
|
|
@ -38,7 +38,7 @@ void Store(EmitContext& ctx, const IR::Value& binding, ScalarU32 offset, ValueTy
|
||||||
void Load(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, ScalarU32 offset,
|
void Load(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, ScalarU32 offset,
|
||||||
std::string_view size) {
|
std::string_view size) {
|
||||||
const Register ret{ctx.reg_alloc.Define(inst)};
|
const Register ret{ctx.reg_alloc.Define(inst)};
|
||||||
StorageOp(ctx, binding, offset, fmt::format("STORE.{} {},DC.x;", size, ret),
|
StorageOp(ctx, binding, offset, fmt::format("LOAD.{} {},DC.x;", size, ret),
|
||||||
fmt::format("MOV.U {},{{0,0,0,0}};", ret));
|
fmt::format("MOV.U {},{{0,0,0,0}};", ret));
|
||||||
}
|
}
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
|
@ -337,9 +337,9 @@ Id EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value&
|
||||||
}
|
}
|
||||||
|
|
||||||
Id EmitImageSampleExplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
|
Id EmitImageSampleExplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
|
||||||
Id lod_lc, const IR::Value& offset) {
|
Id lod, const IR::Value& offset) {
|
||||||
const auto info{inst->Flags<IR::TextureInstInfo>()};
|
const auto info{inst->Flags<IR::TextureInstInfo>()};
|
||||||
const ImageOperands operands(ctx, false, true, info.has_lod_clamp != 0, lod_lc, offset);
|
const ImageOperands operands(ctx, false, true, false, lod, offset);
|
||||||
return Emit(&EmitContext::OpImageSparseSampleExplicitLod,
|
return Emit(&EmitContext::OpImageSparseSampleExplicitLod,
|
||||||
&EmitContext::OpImageSampleExplicitLod, ctx, inst, ctx.F32[4],
|
&EmitContext::OpImageSampleExplicitLod, ctx, inst, ctx.F32[4],
|
||||||
Texture(ctx, info, index), coords, operands.Mask(), operands.Span());
|
Texture(ctx, info, index), coords, operands.Mask(), operands.Span());
|
||||||
|
@ -356,9 +356,9 @@ Id EmitImageSampleDrefImplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Va
|
||||||
}
|
}
|
||||||
|
|
||||||
Id EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index,
|
Id EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index,
|
||||||
Id coords, Id dref, Id lod_lc, const IR::Value& offset) {
|
Id coords, Id dref, Id lod, const IR::Value& offset) {
|
||||||
const auto info{inst->Flags<IR::TextureInstInfo>()};
|
const auto info{inst->Flags<IR::TextureInstInfo>()};
|
||||||
const ImageOperands operands(ctx, false, true, info.has_lod_clamp != 0, lod_lc, offset);
|
const ImageOperands operands(ctx, false, true, false, lod, offset);
|
||||||
return Emit(&EmitContext::OpImageSparseSampleDrefExplicitLod,
|
return Emit(&EmitContext::OpImageSparseSampleDrefExplicitLod,
|
||||||
&EmitContext::OpImageSampleDrefExplicitLod, ctx, inst, ctx.F32[1],
|
&EmitContext::OpImageSampleDrefExplicitLod, ctx, inst, ctx.F32[1],
|
||||||
Texture(ctx, info, index), coords, dref, operands.Mask(), operands.Span());
|
Texture(ctx, info, index), coords, dref, operands.Mask(), operands.Span());
|
||||||
|
|
|
@ -491,11 +491,11 @@ Id EmitBoundImageWrite(EmitContext&);
|
||||||
Id EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
|
Id EmitImageSampleImplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
|
||||||
Id bias_lc, const IR::Value& offset);
|
Id bias_lc, const IR::Value& offset);
|
||||||
Id EmitImageSampleExplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
|
Id EmitImageSampleExplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
|
||||||
Id lod_lc, const IR::Value& offset);
|
Id lod, const IR::Value& offset);
|
||||||
Id EmitImageSampleDrefImplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index,
|
Id EmitImageSampleDrefImplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index,
|
||||||
Id coords, Id dref, Id bias_lc, const IR::Value& offset);
|
Id coords, Id dref, Id bias_lc, const IR::Value& offset);
|
||||||
Id EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index,
|
Id EmitImageSampleDrefExplicitLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index,
|
||||||
Id coords, Id dref, Id lod_lc, const IR::Value& offset);
|
Id coords, Id dref, Id lod, const IR::Value& offset);
|
||||||
Id EmitImageGather(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
|
Id EmitImageGather(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
|
||||||
const IR::Value& offset, const IR::Value& offset2);
|
const IR::Value& offset, const IR::Value& offset2);
|
||||||
Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
|
Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords,
|
||||||
|
|
|
@ -1778,12 +1778,10 @@ Value IREmitter::ImageSampleImplicitLod(const Value& handle, const Value& coords
|
||||||
}
|
}
|
||||||
|
|
||||||
Value IREmitter::ImageSampleExplicitLod(const Value& handle, const Value& coords, const F32& lod,
|
Value IREmitter::ImageSampleExplicitLod(const Value& handle, const Value& coords, const F32& lod,
|
||||||
const Value& offset, const F32& lod_clamp,
|
const Value& offset, TextureInstInfo info) {
|
||||||
TextureInstInfo info) {
|
|
||||||
const Value lod_lc{MakeLodClampPair(*this, lod, lod_clamp)};
|
|
||||||
const Opcode op{handle.IsImmediate() ? Opcode::BoundImageSampleExplicitLod
|
const Opcode op{handle.IsImmediate() ? Opcode::BoundImageSampleExplicitLod
|
||||||
: Opcode::BindlessImageSampleExplicitLod};
|
: Opcode::BindlessImageSampleExplicitLod};
|
||||||
return Inst(op, Flags{info}, handle, coords, lod_lc, offset);
|
return Inst(op, Flags{info}, handle, coords, lod, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
F32 IREmitter::ImageSampleDrefImplicitLod(const Value& handle, const Value& coords, const F32& dref,
|
F32 IREmitter::ImageSampleDrefImplicitLod(const Value& handle, const Value& coords, const F32& dref,
|
||||||
|
@ -1796,12 +1794,11 @@ F32 IREmitter::ImageSampleDrefImplicitLod(const Value& handle, const Value& coor
|
||||||
}
|
}
|
||||||
|
|
||||||
F32 IREmitter::ImageSampleDrefExplicitLod(const Value& handle, const Value& coords, const F32& dref,
|
F32 IREmitter::ImageSampleDrefExplicitLod(const Value& handle, const Value& coords, const F32& dref,
|
||||||
const F32& lod, const Value& offset, const F32& lod_clamp,
|
const F32& lod, const Value& offset,
|
||||||
TextureInstInfo info) {
|
TextureInstInfo info) {
|
||||||
const Value lod_lc{MakeLodClampPair(*this, lod, lod_clamp)};
|
|
||||||
const Opcode op{handle.IsImmediate() ? Opcode::BoundImageSampleDrefExplicitLod
|
const Opcode op{handle.IsImmediate() ? Opcode::BoundImageSampleDrefExplicitLod
|
||||||
: Opcode::BindlessImageSampleDrefExplicitLod};
|
: Opcode::BindlessImageSampleDrefExplicitLod};
|
||||||
return Inst<F32>(op, Flags{info}, handle, coords, dref, lod_lc, offset);
|
return Inst<F32>(op, Flags{info}, handle, coords, dref, lod, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value IREmitter::ImageGather(const Value& handle, const Value& coords, const Value& offset,
|
Value IREmitter::ImageGather(const Value& handle, const Value& coords, const Value& offset,
|
||||||
|
|
|
@ -302,15 +302,14 @@ public:
|
||||||
const F32& lod_clamp, TextureInstInfo info);
|
const F32& lod_clamp, TextureInstInfo info);
|
||||||
[[nodiscard]] Value ImageSampleExplicitLod(const Value& handle, const Value& coords,
|
[[nodiscard]] Value ImageSampleExplicitLod(const Value& handle, const Value& coords,
|
||||||
const F32& lod, const Value& offset,
|
const F32& lod, const Value& offset,
|
||||||
const F32& lod_clamp, TextureInstInfo info);
|
TextureInstInfo info);
|
||||||
[[nodiscard]] F32 ImageSampleDrefImplicitLod(const Value& handle, const Value& coords,
|
[[nodiscard]] F32 ImageSampleDrefImplicitLod(const Value& handle, const Value& coords,
|
||||||
const F32& dref, const F32& bias,
|
const F32& dref, const F32& bias,
|
||||||
const Value& offset, const F32& lod_clamp,
|
const Value& offset, const F32& lod_clamp,
|
||||||
TextureInstInfo info);
|
TextureInstInfo info);
|
||||||
[[nodiscard]] F32 ImageSampleDrefExplicitLod(const Value& handle, const Value& coords,
|
[[nodiscard]] F32 ImageSampleDrefExplicitLod(const Value& handle, const Value& coords,
|
||||||
const F32& dref, const F32& lod,
|
const F32& dref, const F32& lod,
|
||||||
const Value& offset, const F32& lod_clamp,
|
const Value& offset, TextureInstInfo info);
|
||||||
TextureInstInfo info);
|
|
||||||
[[nodiscard]] Value ImageQueryDimension(const Value& handle, const IR::U32& lod);
|
[[nodiscard]] Value ImageQueryDimension(const Value& handle, const IR::U32& lod);
|
||||||
|
|
||||||
[[nodiscard]] Value ImageQueryLod(const Value& handle, const Value& coords,
|
[[nodiscard]] Value ImageQueryLod(const Value& handle, const Value& coords,
|
||||||
|
|
|
@ -177,14 +177,13 @@ void Impl(TranslatorVisitor& v, u64 insn, bool aoffi, Blod blod, bool lc,
|
||||||
const IR::Value sample{[&]() -> IR::Value {
|
const IR::Value sample{[&]() -> IR::Value {
|
||||||
if (tex.dc == 0) {
|
if (tex.dc == 0) {
|
||||||
if (HasExplicitLod(blod)) {
|
if (HasExplicitLod(blod)) {
|
||||||
return v.ir.ImageSampleExplicitLod(handle, coords, lod, offset, lod_clamp, info);
|
return v.ir.ImageSampleExplicitLod(handle, coords, lod, offset, info);
|
||||||
} else {
|
} else {
|
||||||
return v.ir.ImageSampleImplicitLod(handle, coords, lod, offset, lod_clamp, info);
|
return v.ir.ImageSampleImplicitLod(handle, coords, lod, offset, lod_clamp, info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (HasExplicitLod(blod)) {
|
if (HasExplicitLod(blod)) {
|
||||||
return v.ir.ImageSampleDrefExplicitLod(handle, coords, dref, lod, offset, lod_clamp,
|
return v.ir.ImageSampleDrefExplicitLod(handle, coords, dref, lod, offset, info);
|
||||||
info);
|
|
||||||
} else {
|
} else {
|
||||||
return v.ir.ImageSampleDrefImplicitLod(handle, coords, dref, lod, offset, lod_clamp,
|
return v.ir.ImageSampleDrefImplicitLod(handle, coords, dref, lod, offset, lod_clamp,
|
||||||
info);
|
info);
|
||||||
|
|
|
@ -81,18 +81,18 @@ IR::Value Sample(TranslatorVisitor& v, u64 insn) {
|
||||||
switch (texs.encoding) {
|
switch (texs.encoding) {
|
||||||
case 0: // 1D.LZ
|
case 0: // 1D.LZ
|
||||||
info.type.Assign(TextureType::Color1D);
|
info.type.Assign(TextureType::Color1D);
|
||||||
return v.ir.ImageSampleExplicitLod(handle, v.F(reg_a), zero, {}, {}, info);
|
return v.ir.ImageSampleExplicitLod(handle, v.F(reg_a), zero, {}, info);
|
||||||
case 1: // 2D
|
case 1: // 2D
|
||||||
info.type.Assign(TextureType::Color2D);
|
info.type.Assign(TextureType::Color2D);
|
||||||
return v.ir.ImageSampleImplicitLod(handle, Composite(v, reg_a, reg_b), {}, {}, {}, info);
|
return v.ir.ImageSampleImplicitLod(handle, Composite(v, reg_a, reg_b), {}, {}, {}, info);
|
||||||
case 2: // 2D.LZ
|
case 2: // 2D.LZ
|
||||||
info.type.Assign(TextureType::Color2D);
|
info.type.Assign(TextureType::Color2D);
|
||||||
return v.ir.ImageSampleExplicitLod(handle, Composite(v, reg_a, reg_b), zero, {}, {}, info);
|
return v.ir.ImageSampleExplicitLod(handle, Composite(v, reg_a, reg_b), zero, {}, info);
|
||||||
case 3: // 2D.LL
|
case 3: // 2D.LL
|
||||||
CheckAlignment(reg_a, 2);
|
CheckAlignment(reg_a, 2);
|
||||||
info.type.Assign(TextureType::Color2D);
|
info.type.Assign(TextureType::Color2D);
|
||||||
return v.ir.ImageSampleExplicitLod(handle, Composite(v, reg_a, reg_a + 1), v.F(reg_b), {},
|
return v.ir.ImageSampleExplicitLod(handle, Composite(v, reg_a, reg_a + 1), v.F(reg_b), {},
|
||||||
{}, info);
|
info);
|
||||||
case 4: // 2D.DC
|
case 4: // 2D.DC
|
||||||
CheckAlignment(reg_a, 2);
|
CheckAlignment(reg_a, 2);
|
||||||
info.type.Assign(TextureType::Color2D);
|
info.type.Assign(TextureType::Color2D);
|
||||||
|
@ -105,13 +105,13 @@ IR::Value Sample(TranslatorVisitor& v, u64 insn) {
|
||||||
info.type.Assign(TextureType::Color2D);
|
info.type.Assign(TextureType::Color2D);
|
||||||
info.is_depth.Assign(1);
|
info.is_depth.Assign(1);
|
||||||
return v.ir.ImageSampleDrefExplicitLod(handle, Composite(v, reg_a, reg_a + 1),
|
return v.ir.ImageSampleDrefExplicitLod(handle, Composite(v, reg_a, reg_a + 1),
|
||||||
v.F(reg_b + 1), v.F(reg_b), {}, {}, info);
|
v.F(reg_b + 1), v.F(reg_b), {}, info);
|
||||||
case 6: // 2D.LZ.DC
|
case 6: // 2D.LZ.DC
|
||||||
CheckAlignment(reg_a, 2);
|
CheckAlignment(reg_a, 2);
|
||||||
info.type.Assign(TextureType::Color2D);
|
info.type.Assign(TextureType::Color2D);
|
||||||
info.is_depth.Assign(1);
|
info.is_depth.Assign(1);
|
||||||
return v.ir.ImageSampleDrefExplicitLod(handle, Composite(v, reg_a, reg_a + 1), v.F(reg_b),
|
return v.ir.ImageSampleDrefExplicitLod(handle, Composite(v, reg_a, reg_a + 1), v.F(reg_b),
|
||||||
zero, {}, {}, info);
|
zero, {}, info);
|
||||||
case 7: // ARRAY_2D
|
case 7: // ARRAY_2D
|
||||||
CheckAlignment(reg_a, 2);
|
CheckAlignment(reg_a, 2);
|
||||||
info.type.Assign(TextureType::ColorArray2D);
|
info.type.Assign(TextureType::ColorArray2D);
|
||||||
|
@ -123,7 +123,7 @@ IR::Value Sample(TranslatorVisitor& v, u64 insn) {
|
||||||
info.type.Assign(TextureType::ColorArray2D);
|
info.type.Assign(TextureType::ColorArray2D);
|
||||||
return v.ir.ImageSampleExplicitLod(
|
return v.ir.ImageSampleExplicitLod(
|
||||||
handle, v.ir.CompositeConstruct(v.F(reg_a + 1), v.F(reg_b), ReadArray(v, v.X(reg_a))),
|
handle, v.ir.CompositeConstruct(v.F(reg_a + 1), v.F(reg_b), ReadArray(v, v.X(reg_a))),
|
||||||
zero, {}, {}, info);
|
zero, {}, info);
|
||||||
case 9: // ARRAY_2D.LZ.DC
|
case 9: // ARRAY_2D.LZ.DC
|
||||||
CheckAlignment(reg_a, 2);
|
CheckAlignment(reg_a, 2);
|
||||||
CheckAlignment(reg_b, 2);
|
CheckAlignment(reg_b, 2);
|
||||||
|
@ -131,7 +131,7 @@ IR::Value Sample(TranslatorVisitor& v, u64 insn) {
|
||||||
info.is_depth.Assign(1);
|
info.is_depth.Assign(1);
|
||||||
return v.ir.ImageSampleDrefExplicitLod(
|
return v.ir.ImageSampleDrefExplicitLod(
|
||||||
handle, v.ir.CompositeConstruct(v.F(reg_a + 1), v.F(reg_b), ReadArray(v, v.X(reg_a))),
|
handle, v.ir.CompositeConstruct(v.F(reg_a + 1), v.F(reg_b), ReadArray(v, v.X(reg_a))),
|
||||||
v.F(reg_b + 1), zero, {}, {}, info);
|
v.F(reg_b + 1), zero, {}, info);
|
||||||
case 10: // 3D
|
case 10: // 3D
|
||||||
CheckAlignment(reg_a, 2);
|
CheckAlignment(reg_a, 2);
|
||||||
info.type.Assign(TextureType::Color3D);
|
info.type.Assign(TextureType::Color3D);
|
||||||
|
@ -141,7 +141,7 @@ IR::Value Sample(TranslatorVisitor& v, u64 insn) {
|
||||||
CheckAlignment(reg_a, 2);
|
CheckAlignment(reg_a, 2);
|
||||||
info.type.Assign(TextureType::Color3D);
|
info.type.Assign(TextureType::Color3D);
|
||||||
return v.ir.ImageSampleExplicitLod(handle, Composite(v, reg_a, reg_a + 1, reg_b), zero, {},
|
return v.ir.ImageSampleExplicitLod(handle, Composite(v, reg_a, reg_a + 1, reg_b), zero, {},
|
||||||
{}, info);
|
info);
|
||||||
case 12: // CUBE
|
case 12: // CUBE
|
||||||
CheckAlignment(reg_a, 2);
|
CheckAlignment(reg_a, 2);
|
||||||
info.type.Assign(TextureType::ColorCube);
|
info.type.Assign(TextureType::ColorCube);
|
||||||
|
@ -152,7 +152,7 @@ IR::Value Sample(TranslatorVisitor& v, u64 insn) {
|
||||||
CheckAlignment(reg_b, 2);
|
CheckAlignment(reg_b, 2);
|
||||||
info.type.Assign(TextureType::ColorCube);
|
info.type.Assign(TextureType::ColorCube);
|
||||||
return v.ir.ImageSampleExplicitLod(handle, Composite(v, reg_a, reg_a + 1, reg_b),
|
return v.ir.ImageSampleExplicitLod(handle, Composite(v, reg_a, reg_a + 1, reg_b),
|
||||||
v.F(reg_b + 1), {}, {}, info);
|
v.F(reg_b + 1), {}, info);
|
||||||
default:
|
default:
|
||||||
throw NotImplementedException("Illegal encoding {}", texs.encoding.Value());
|
throw NotImplementedException("Illegal encoding {}", texs.encoding.Value());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue