glasm: Make GLASM aware of types
This commit is contained in:
parent
94ee083286
commit
04ed27a997
12 changed files with 1396 additions and 1260 deletions
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace Shader::Backend::GLASM {
|
||||
namespace {
|
||||
void StorageOp(EmitContext& ctx, const IR::Value& binding, std::string_view offset,
|
||||
void StorageOp(EmitContext& ctx, const IR::Value& binding, ScalarU32 offset,
|
||||
std::string_view then_expr, std::string_view else_expr = {}) {
|
||||
// Operate on bindless SSBO, call the expression with bounds checking
|
||||
// address = c[binding].xy
|
||||
|
@ -23,20 +23,21 @@ void StorageOp(EmitContext& ctx, const IR::Value& binding, std::string_view offs
|
|||
"SLT.U.CC RC.x,{},c[{}].z;", // cc = offset < length
|
||||
sb_binding, offset, offset, sb_binding);
|
||||
if (else_expr.empty()) {
|
||||
ctx.Add("{}", then_expr);
|
||||
ctx.Add("IF NE.x;{}ENDIF;", then_expr);
|
||||
} else {
|
||||
ctx.Add("IF NE.x;{}ELSE;{}ENDIF;", then_expr, else_expr);
|
||||
}
|
||||
}
|
||||
|
||||
void Store(EmitContext& ctx, const IR::Value& binding, std::string_view offset,
|
||||
std::string_view value, std::string_view size) {
|
||||
template <typename ValueType>
|
||||
void Store(EmitContext& ctx, const IR::Value& binding, ScalarU32 offset, ValueType value,
|
||||
std::string_view size) {
|
||||
StorageOp(ctx, binding, offset, fmt::format("STORE.{} {},LC.x;", size, value));
|
||||
}
|
||||
|
||||
void Load(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, std::string_view offset,
|
||||
void Load(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, ScalarU32 offset,
|
||||
std::string_view size) {
|
||||
const std::string ret{ctx.reg_alloc.Define(inst)};
|
||||
const Register ret{ctx.reg_alloc.Define(inst)};
|
||||
StorageOp(ctx, binding, offset, fmt::format("STORE.{} {},LC.x;", size, ret),
|
||||
fmt::format("MOV.U {},{{0,0,0,0}};", ret));
|
||||
}
|
||||
|
@ -58,18 +59,15 @@ void EmitLoadGlobalS16([[maybe_unused]] EmitContext& ctx) {
|
|||
throw NotImplementedException("GLASM instruction");
|
||||
}
|
||||
|
||||
void EmitLoadGlobal32([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view address) {
|
||||
void EmitLoadGlobal32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Register address) {
|
||||
throw NotImplementedException("GLASM instruction");
|
||||
}
|
||||
|
||||
void EmitLoadGlobal64([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view address) {
|
||||
void EmitLoadGlobal64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Register address) {
|
||||
throw NotImplementedException("GLASM instruction");
|
||||
}
|
||||
|
||||
void EmitLoadGlobal128([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view address) {
|
||||
void EmitLoadGlobal128([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Register address) {
|
||||
throw NotImplementedException("GLASM instruction");
|
||||
}
|
||||
|
||||
|
@ -89,89 +87,88 @@ void EmitWriteGlobalS16([[maybe_unused]] EmitContext& ctx) {
|
|||
throw NotImplementedException("GLASM instruction");
|
||||
}
|
||||
|
||||
void EmitWriteGlobal32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view address,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
void EmitWriteGlobal32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Register address,
|
||||
[[maybe_unused]] ScalarU32 value) {
|
||||
throw NotImplementedException("GLASM instruction");
|
||||
}
|
||||
|
||||
void EmitWriteGlobal64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view address,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
void EmitWriteGlobal64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Register address,
|
||||
[[maybe_unused]] Register value) {
|
||||
throw NotImplementedException("GLASM instruction");
|
||||
}
|
||||
|
||||
void EmitWriteGlobal128([[maybe_unused]] EmitContext& ctx,
|
||||
[[maybe_unused]] std::string_view address,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
void EmitWriteGlobal128([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Register address,
|
||||
[[maybe_unused]] Register value) {
|
||||
throw NotImplementedException("GLASM instruction");
|
||||
}
|
||||
|
||||
void EmitLoadStorageU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
std::string_view offset) {
|
||||
ScalarU32 offset) {
|
||||
Load(ctx, inst, binding, offset, "U8");
|
||||
}
|
||||
|
||||
void EmitLoadStorageS8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
std::string_view offset) {
|
||||
ScalarU32 offset) {
|
||||
Load(ctx, inst, binding, offset, "S8");
|
||||
}
|
||||
|
||||
void EmitLoadStorageU16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
std::string_view offset) {
|
||||
ScalarU32 offset) {
|
||||
Load(ctx, inst, binding, offset, "U16");
|
||||
}
|
||||
|
||||
void EmitLoadStorageS16(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
std::string_view offset) {
|
||||
ScalarU32 offset) {
|
||||
Load(ctx, inst, binding, offset, "S16");
|
||||
}
|
||||
|
||||
void EmitLoadStorage32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
std::string_view offset) {
|
||||
ScalarU32 offset) {
|
||||
Load(ctx, inst, binding, offset, "U32");
|
||||
}
|
||||
|
||||
void EmitLoadStorage64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
std::string_view offset) {
|
||||
ScalarU32 offset) {
|
||||
Load(ctx, inst, binding, offset, "U32X2");
|
||||
}
|
||||
|
||||
void EmitLoadStorage128(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
||||
std::string_view offset) {
|
||||
ScalarU32 offset) {
|
||||
Load(ctx, inst, binding, offset, "U32X4");
|
||||
}
|
||||
|
||||
void EmitWriteStorageU8(EmitContext& ctx, const IR::Value& binding, std::string_view offset,
|
||||
std::string_view value) {
|
||||
void EmitWriteStorageU8(EmitContext& ctx, const IR::Value& binding, ScalarU32 offset,
|
||||
ScalarU32 value) {
|
||||
Store(ctx, binding, offset, value, "U8");
|
||||
}
|
||||
|
||||
void EmitWriteStorageS8(EmitContext& ctx, const IR::Value& binding, std::string_view offset,
|
||||
std::string_view value) {
|
||||
void EmitWriteStorageS8(EmitContext& ctx, const IR::Value& binding, ScalarU32 offset,
|
||||
ScalarS32 value) {
|
||||
Store(ctx, binding, offset, value, "S8");
|
||||
}
|
||||
|
||||
void EmitWriteStorageU16(EmitContext& ctx, const IR::Value& binding, std::string_view offset,
|
||||
std::string_view value) {
|
||||
void EmitWriteStorageU16(EmitContext& ctx, const IR::Value& binding, ScalarU32 offset,
|
||||
ScalarU32 value) {
|
||||
Store(ctx, binding, offset, value, "U16");
|
||||
}
|
||||
|
||||
void EmitWriteStorageS16(EmitContext& ctx, const IR::Value& binding, std::string_view offset,
|
||||
std::string_view value) {
|
||||
void EmitWriteStorageS16(EmitContext& ctx, const IR::Value& binding, ScalarU32 offset,
|
||||
ScalarS32 value) {
|
||||
Store(ctx, binding, offset, value, "S16");
|
||||
}
|
||||
|
||||
void EmitWriteStorage32(EmitContext& ctx, const IR::Value& binding, std::string_view offset,
|
||||
std::string_view value) {
|
||||
void EmitWriteStorage32(EmitContext& ctx, const IR::Value& binding, ScalarU32 offset,
|
||||
ScalarU32 value) {
|
||||
Store(ctx, binding, offset, value, "U32");
|
||||
}
|
||||
|
||||
void EmitWriteStorage64(EmitContext& ctx, const IR::Value& binding, std::string_view offset,
|
||||
std::string_view value) {
|
||||
void EmitWriteStorage64(EmitContext& ctx, const IR::Value& binding, ScalarU32 offset,
|
||||
Register value) {
|
||||
Store(ctx, binding, offset, value, "U32X2");
|
||||
}
|
||||
|
||||
void EmitWriteStorage128(EmitContext& ctx, const IR::Value& binding, std::string_view offset,
|
||||
std::string_view value) {
|
||||
void EmitWriteStorage128(EmitContext& ctx, const IR::Value& binding, ScalarU32 offset,
|
||||
Register value) {
|
||||
Store(ctx, binding, offset, value, "U32X4");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue