2021-05-20 23:38:38 -04:00
|
|
|
// Copyright 2021 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
#include "shader_recompiler/backend/glsl/emit_context.h"
|
2021-05-29 02:09:29 -04:00
|
|
|
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
|
2021-05-20 23:38:38 -04:00
|
|
|
#include "shader_recompiler/frontend/ir/value.h"
|
|
|
|
|
|
|
|
namespace Shader::Backend::GLSL {
|
2021-05-28 21:24:52 -04:00
|
|
|
void EmitLoadStorageU8([[maybe_unused]] EmitContext& ctx, IR::Inst& inst,
|
|
|
|
[[maybe_unused]] const IR::Value& binding,
|
2021-05-20 23:38:38 -04:00
|
|
|
[[maybe_unused]] const IR::Value& offset) {
|
2021-05-30 17:27:00 -04:00
|
|
|
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
2021-05-30 20:02:44 -04:00
|
|
|
ctx.AddU32("{}=bitfieldExtract({}_ssbo{}[{}/4],int({}%4)*8,8);", inst, ctx.stage_name,
|
|
|
|
binding.U32(), offset_var, offset_var);
|
2021-05-20 23:38:38 -04:00
|
|
|
}
|
|
|
|
|
2021-05-28 21:24:52 -04:00
|
|
|
void EmitLoadStorageS8([[maybe_unused]] EmitContext& ctx, IR::Inst& inst,
|
|
|
|
[[maybe_unused]] const IR::Value& binding,
|
2021-05-20 23:38:38 -04:00
|
|
|
[[maybe_unused]] const IR::Value& offset) {
|
2021-05-30 17:27:00 -04:00
|
|
|
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
2021-05-30 20:02:44 -04:00
|
|
|
ctx.AddS32("{}=bitfieldExtract(int({}_ssbo{}[{}/4]),int({}%4)*8,8);", inst, ctx.stage_name,
|
|
|
|
binding.U32(), offset_var, offset_var);
|
2021-05-20 23:38:38 -04:00
|
|
|
}
|
|
|
|
|
2021-05-28 21:24:52 -04:00
|
|
|
void EmitLoadStorageU16([[maybe_unused]] EmitContext& ctx, IR::Inst& inst,
|
2021-05-20 23:38:38 -04:00
|
|
|
[[maybe_unused]] const IR::Value& binding,
|
|
|
|
[[maybe_unused]] const IR::Value& offset) {
|
2021-05-30 17:27:00 -04:00
|
|
|
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
2021-05-30 20:02:44 -04:00
|
|
|
ctx.AddU32("{}=bitfieldExtract({}_ssbo{}[{}/4],int(({}/2)%2)*16,16);", inst, ctx.stage_name,
|
|
|
|
binding.U32(), offset_var, offset_var);
|
2021-05-20 23:38:38 -04:00
|
|
|
}
|
|
|
|
|
2021-05-28 21:24:52 -04:00
|
|
|
void EmitLoadStorageS16([[maybe_unused]] EmitContext& ctx, IR::Inst& inst,
|
2021-05-20 23:38:38 -04:00
|
|
|
[[maybe_unused]] const IR::Value& binding,
|
|
|
|
[[maybe_unused]] const IR::Value& offset) {
|
2021-05-30 17:27:00 -04:00
|
|
|
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
2021-05-30 20:02:44 -04:00
|
|
|
ctx.AddS32("{}=bitfieldExtract(int({}_ssbo{}[{}/4]),int(({}/2)%2)*16,16);", inst,
|
|
|
|
ctx.stage_name, binding.U32(), offset_var, offset_var);
|
2021-05-20 23:38:38 -04:00
|
|
|
}
|
|
|
|
|
2021-05-24 18:35:37 -04:00
|
|
|
void EmitLoadStorage32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
|
|
|
const IR::Value& offset) {
|
2021-05-30 17:27:00 -04:00
|
|
|
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
2021-05-30 20:02:44 -04:00
|
|
|
ctx.AddU32("{}={}_ssbo{}[{}/4];", inst, ctx.stage_name, binding.U32(), offset_var);
|
2021-05-20 23:38:38 -04:00
|
|
|
}
|
|
|
|
|
2021-05-25 01:35:30 -04:00
|
|
|
void EmitLoadStorage64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
|
|
|
const IR::Value& offset) {
|
2021-05-30 17:27:00 -04:00
|
|
|
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
2021-05-30 20:02:44 -04:00
|
|
|
ctx.AddU32x2("{}=uvec2({}_ssbo{}[{}/4],{}_ssbo{}[({}+4)/4]);", inst, ctx.stage_name,
|
|
|
|
binding.U32(), offset_var, ctx.stage_name, binding.U32(), offset_var);
|
2021-05-20 23:38:38 -04:00
|
|
|
}
|
|
|
|
|
2021-05-27 00:26:16 -04:00
|
|
|
void EmitLoadStorage128(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
|
|
|
|
const IR::Value& offset) {
|
2021-05-30 17:27:00 -04:00
|
|
|
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
2021-05-30 20:02:44 -04:00
|
|
|
ctx.AddU32x4(
|
|
|
|
"{}=uvec4({}_ssbo{}[{}/4],{}_ssbo{}[({}+4)/4],{}_ssbo{}[({}+8)/4],{}_ssbo{}[({}+12)/4]);",
|
|
|
|
inst, ctx.stage_name, binding.U32(), offset_var, ctx.stage_name, binding.U32(), offset_var,
|
|
|
|
ctx.stage_name, binding.U32(), offset_var, ctx.stage_name, binding.U32(), offset_var);
|
2021-05-20 23:38:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmitWriteStorageU8([[maybe_unused]] EmitContext& ctx,
|
|
|
|
[[maybe_unused]] const IR::Value& binding,
|
|
|
|
[[maybe_unused]] const IR::Value& offset,
|
2021-05-21 19:55:58 -04:00
|
|
|
[[maybe_unused]] std::string_view value) {
|
2021-05-30 17:27:00 -04:00
|
|
|
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
2021-05-30 20:02:44 -04:00
|
|
|
ctx.Add("{}_ssbo{}[{}/4]=bitfieldInsert({}_ssbo{}[{}/4],{},int({}%4)*8,8);", ctx.stage_name,
|
|
|
|
binding.U32(), offset_var, ctx.stage_name, binding.U32(), offset_var, value,
|
|
|
|
offset_var);
|
2021-05-20 23:38:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmitWriteStorageS8([[maybe_unused]] EmitContext& ctx,
|
|
|
|
[[maybe_unused]] const IR::Value& binding,
|
|
|
|
[[maybe_unused]] const IR::Value& offset,
|
2021-05-21 19:55:58 -04:00
|
|
|
[[maybe_unused]] std::string_view value) {
|
2021-05-30 17:27:00 -04:00
|
|
|
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
2021-05-30 20:02:44 -04:00
|
|
|
ctx.Add("{}_ssbo{}[{}/4]=bitfieldInsert({}_ssbo{}[{}/4],{},int({}%4)*8,8);", ctx.stage_name,
|
|
|
|
binding.U32(), offset_var, ctx.stage_name, binding.U32(), offset_var, value,
|
|
|
|
offset_var);
|
2021-05-20 23:38:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmitWriteStorageU16([[maybe_unused]] EmitContext& ctx,
|
|
|
|
[[maybe_unused]] const IR::Value& binding,
|
|
|
|
[[maybe_unused]] const IR::Value& offset,
|
2021-05-21 19:55:58 -04:00
|
|
|
[[maybe_unused]] std::string_view value) {
|
2021-05-30 17:27:00 -04:00
|
|
|
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
2021-05-30 20:02:44 -04:00
|
|
|
ctx.Add("{}_ssbo{}[{}/4]=bitfieldInsert({}_ssbo{}[{}/4],{},int(({}/2)%2)*16,16);",
|
|
|
|
ctx.stage_name, binding.U32(), offset_var, ctx.stage_name, binding.U32(), offset_var,
|
|
|
|
value, offset_var);
|
2021-05-20 23:38:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmitWriteStorageS16([[maybe_unused]] EmitContext& ctx,
|
|
|
|
[[maybe_unused]] const IR::Value& binding,
|
|
|
|
[[maybe_unused]] const IR::Value& offset,
|
2021-05-21 19:55:58 -04:00
|
|
|
[[maybe_unused]] std::string_view value) {
|
2021-05-30 17:27:00 -04:00
|
|
|
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
2021-05-30 20:02:44 -04:00
|
|
|
ctx.Add("{}_ssbo{}[{}/4]=bitfieldInsert({}_ssbo{}[{}/4],{},int(({}/2)%2)*16,16);",
|
|
|
|
ctx.stage_name, binding.U32(), offset_var, ctx.stage_name, binding.U32(), offset_var,
|
|
|
|
value, offset_var);
|
2021-05-20 23:38:38 -04:00
|
|
|
}
|
|
|
|
|
2021-05-22 01:52:03 -04:00
|
|
|
void EmitWriteStorage32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
|
|
|
std::string_view value) {
|
2021-05-30 17:27:00 -04:00
|
|
|
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
2021-05-30 20:02:44 -04:00
|
|
|
ctx.Add("{}_ssbo{}[{}/4]={};", ctx.stage_name, binding.U32(), offset_var, value);
|
2021-05-20 23:38:38 -04:00
|
|
|
}
|
|
|
|
|
2021-05-22 01:52:03 -04:00
|
|
|
void EmitWriteStorage64(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
|
|
|
|
std::string_view value) {
|
2021-05-30 17:27:00 -04:00
|
|
|
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
2021-05-30 20:02:44 -04:00
|
|
|
ctx.Add("{}_ssbo{}[{}/4]={}.x;", ctx.stage_name, binding.U32(), offset_var, value);
|
|
|
|
ctx.Add("{}_ssbo{}[({}+4)/4]={}.y;", ctx.stage_name, binding.U32(), offset_var, value);
|
2021-05-20 23:38:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmitWriteStorage128([[maybe_unused]] EmitContext& ctx,
|
|
|
|
[[maybe_unused]] const IR::Value& binding,
|
|
|
|
[[maybe_unused]] const IR::Value& offset,
|
2021-05-21 19:55:58 -04:00
|
|
|
[[maybe_unused]] std::string_view value) {
|
2021-05-30 17:27:00 -04:00
|
|
|
const auto offset_var{ctx.var_alloc.Consume(offset)};
|
2021-05-30 20:02:44 -04:00
|
|
|
ctx.Add("{}_ssbo{}[{}/4]={}.x;", ctx.stage_name, binding.U32(), offset_var, value);
|
|
|
|
ctx.Add("{}_ssbo{}[({}+4)/4]={}.y;", ctx.stage_name, binding.U32(), offset_var, value);
|
|
|
|
ctx.Add("{}_ssbo{}[({}+8)/4]={}.z;", ctx.stage_name, binding.U32(), offset_var, value);
|
|
|
|
ctx.Add("{}_ssbo{}[({}+12)/4]={}.w;", ctx.stage_name, binding.U32(), offset_var, value);
|
2021-05-20 23:38:38 -04:00
|
|
|
}
|
|
|
|
} // namespace Shader::Backend::GLSL
|