mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-29 23:06:23 -05:00
glasm: Implement ImageFetch
This commit is contained in:
parent
3777592ada
commit
4a22942f45
4 changed files with 38 additions and 13 deletions
|
@ -80,11 +80,14 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings) : info{progra
|
||||||
Add("OUTPUT out_attr{}[]={{result.attrib[{}..{}]}};", index, index, index);
|
Add("OUTPUT out_attr{}[]={{result.attrib[{}..{}]}};", index, index, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const size_t num_textures{program.info.texture_descriptors.size()};
|
texture_buffer_bindings.reserve(program.info.texture_buffer_descriptors.size());
|
||||||
texture_bindings.resize(num_textures);
|
for (const auto& desc : program.info.texture_buffer_descriptors) {
|
||||||
for (size_t index = 0; index < num_textures; ++index) {
|
texture_buffer_bindings.push_back(bindings.texture);
|
||||||
const auto& desc{program.info.texture_descriptors[index]};
|
bindings.texture += desc.count;
|
||||||
texture_bindings[index] = bindings.texture;
|
}
|
||||||
|
texture_bindings.reserve(program.info.texture_descriptors.size());
|
||||||
|
for (const auto& desc : program.info.texture_descriptors) {
|
||||||
|
texture_bindings.push_back(bindings.texture);
|
||||||
bindings.texture += desc.count;
|
bindings.texture += desc.count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@ public:
|
||||||
RegAlloc reg_alloc{*this};
|
RegAlloc reg_alloc{*this};
|
||||||
const Info& info;
|
const Info& info;
|
||||||
|
|
||||||
|
std::vector<u32> texture_buffer_bindings;
|
||||||
std::vector<u32> texture_bindings;
|
std::vector<u32> texture_bindings;
|
||||||
|
|
||||||
std::string_view stage_name = "invalid";
|
std::string_view stage_name = "invalid";
|
||||||
|
|
|
@ -43,7 +43,11 @@ struct ScopedRegister {
|
||||||
std::string Texture(EmitContext& ctx, IR::TextureInstInfo info,
|
std::string Texture(EmitContext& ctx, IR::TextureInstInfo info,
|
||||||
[[maybe_unused]] const IR::Value& index) {
|
[[maybe_unused]] const IR::Value& index) {
|
||||||
// FIXME: indexed reads
|
// FIXME: indexed reads
|
||||||
return fmt::format("texture[{}]", ctx.texture_bindings.at(info.descriptor_index));
|
if (info.type == TextureType::Buffer) {
|
||||||
|
return fmt::format("texture[{}]", ctx.texture_buffer_bindings.at(info.descriptor_index));
|
||||||
|
} else {
|
||||||
|
return fmt::format("texture[{}]", ctx.texture_bindings.at(info.descriptor_index));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view TextureType(IR::TextureInstInfo info) {
|
std::string_view TextureType(IR::TextureInstInfo info) {
|
||||||
|
@ -421,11 +425,28 @@ void EmitImageGatherDref(EmitContext& ctx, IR::Inst& inst, const IR::Value& inde
|
||||||
StoreSparse(ctx, sparse_inst);
|
StoreSparse(ctx, sparse_inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitImageFetch([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||||
[[maybe_unused]] const IR::Value& index, [[maybe_unused]] Register coord,
|
const IR::Value& coord, const IR::Value& offset, ScalarS32 lod, ScalarS32 ms) {
|
||||||
[[maybe_unused]] Register offset, [[maybe_unused]] Register lod,
|
const auto info{inst.Flags<IR::TextureInstInfo>()};
|
||||||
[[maybe_unused]] Register ms) {
|
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::Buffer) {
|
||||||
|
ctx.Add("TXF.F{} {},{},{},{}{};", sparse_mod, ret, coord_vec, texture, type, offset_vec);
|
||||||
|
} else if (ms.type != Type::Void) {
|
||||||
|
ctx.Add("MOV.S {}.w,{};"
|
||||||
|
"TXFMS.F{} {},{},{},{}{};",
|
||||||
|
coord_vec, ms, sparse_mod, ret, coord_vec, texture, type, offset_vec);
|
||||||
|
} else {
|
||||||
|
ctx.Add("MOV.S {}.w,{};"
|
||||||
|
"TXF.F{} {},{},{},{}{};",
|
||||||
|
coord_vec, lod, sparse_mod, ret, coord_vec, texture, type, offset_vec);
|
||||||
|
}
|
||||||
|
StoreSparse(ctx, sparse_inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||||
|
|
|
@ -541,8 +541,8 @@ void EmitImageGather(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||||
void EmitImageGatherDref(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
void EmitImageGatherDref(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||||
const IR::Value& coord, const IR::Value& offset, const IR::Value& offset2,
|
const IR::Value& coord, const IR::Value& offset, const IR::Value& offset2,
|
||||||
const IR::Value& dref);
|
const IR::Value& dref);
|
||||||
void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord,
|
void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||||
Register offset, Register lod, Register ms);
|
const IR::Value& coord, const IR::Value& offset, ScalarS32 lod, ScalarS32 ms);
|
||||||
void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index,
|
||||||
ScalarF32 lod);
|
ScalarF32 lod);
|
||||||
void EmitImageQueryLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord);
|
void EmitImageQueryLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord);
|
||||||
|
|
Loading…
Reference in a new issue