yuzu-emu
/
yuzu-mainline
Archived
1
0
Fork 0

glsl: FP function fixes

This commit is contained in:
ameerj 2021-05-22 15:06:14 -04:00
parent 65c6f73e43
commit 3064bde415
7 changed files with 25 additions and 17 deletions

View File

@ -48,8 +48,11 @@ void EmitContext::DefineStorageBuffers() {
} }
u32 binding{}; u32 binding{};
for (const auto& desc : info.storage_buffers_descriptors) { for (const auto& desc : info.storage_buffers_descriptors) {
Add("layout(std430,binding={}) buffer buff_{}{{uint buff{}[];}};", binding, binding, Add("layout(std430,binding={}) buffer ssbo_{}_u32{{uint ssbo{}_u32[];}};", binding, binding,
desc.cbuf_index, desc.count); desc.cbuf_index, desc.count);
// TODO: Track ssbo data type usage
Add("layout(std430,binding={}) buffer ssbo_{}_u64{{uvec2 ssbo{}_u64[];}};", binding,
binding, desc.cbuf_index, desc.count);
++binding; ++binding;
} }
} }

View File

@ -10,6 +10,8 @@
#include "shader_recompiler/profile.h" #include "shader_recompiler/profile.h"
namespace Shader::Backend::GLSL { namespace Shader::Backend::GLSL {
static constexpr std::string_view SWIZZLE{"xyzw"};
void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1, void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
std::string_view e2) { std::string_view e2) {
ctx.AddU32x2("{}=uvec2({},{});", inst, e1, e2); ctx.AddU32x2("{}=uvec2({},{});", inst, e1, e2);
@ -32,7 +34,7 @@ void EmitCompositeConstructU32x4([[maybe_unused]] EmitContext& ctx,
void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
u32 index) { u32 index) {
ctx.AddU32("{}={}[{}];", inst, composite, index); ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
} }
void EmitCompositeExtractU32x3([[maybe_unused]] EmitContext& ctx, void EmitCompositeExtractU32x3([[maybe_unused]] EmitContext& ctx,
@ -130,7 +132,7 @@ void EmitCompositeInsertF16x4([[maybe_unused]] EmitContext& ctx,
void EmitCompositeConstructF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1, void EmitCompositeConstructF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
std::string_view e2) { std::string_view e2) {
ctx.AddF32x2("{}=uvec2({},{});", inst, e1, e2); ctx.AddF32x2("{}=vec2({},{});", inst, e1, e2);
} }
void EmitCompositeConstructF32x3([[maybe_unused]] EmitContext& ctx, void EmitCompositeConstructF32x3([[maybe_unused]] EmitContext& ctx,
@ -150,7 +152,7 @@ void EmitCompositeConstructF32x4([[maybe_unused]] EmitContext& ctx,
void EmitCompositeExtractF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite, void EmitCompositeExtractF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
u32 index) { u32 index) {
ctx.AddF32("{}={}[{}];", inst, composite, index); ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
} }
void EmitCompositeExtractF32x3([[maybe_unused]] EmitContext& ctx, void EmitCompositeExtractF32x3([[maybe_unused]] EmitContext& ctx,

View File

@ -10,6 +10,8 @@
#include "shader_recompiler/profile.h" #include "shader_recompiler/profile.h"
namespace Shader::Backend::GLSL { namespace Shader::Backend::GLSL {
static constexpr std::string_view SWIZZLE{"xyzw"};
void EmitGetCbufU8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR::Value& binding, void EmitGetCbufU8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR::Value& binding,
[[maybe_unused]] const IR::Value& offset) { [[maybe_unused]] const IR::Value& offset) {
throw NotImplementedException("GLSL"); throw NotImplementedException("GLSL");
@ -33,14 +35,16 @@ void EmitGetCbufS16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR
void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, void EmitGetCbufU32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
const IR::Value& offset) { const IR::Value& offset) {
const auto u32_offset{offset.U32()}; const auto u32_offset{offset.U32()};
ctx.AddU32("{}=floatBitsToUint(cbuf{}[{}][{}]);", inst, binding.U32(), u32_offset / 16, const auto index{(u32_offset / 4) % 4};
(u32_offset / 4) % 4); ctx.AddU32("{}=floatBitsToUint(cbuf{}[{}].{});", inst, binding.U32(), u32_offset / 16,
SWIZZLE[index]);
} }
void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, void EmitGetCbufF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
const IR::Value& offset) { const IR::Value& offset) {
const auto u32_offset{offset.U32()}; const auto u32_offset{offset.U32()};
ctx.AddF32("{}=cbuf{}[{}][{}];", inst, binding.U32(), u32_offset / 16, (u32_offset / 4) % 4); const auto index{(u32_offset / 4) % 4};
ctx.AddF32("{}=cbuf{}[{}].{};", inst, binding.U32(), u32_offset / 16, SWIZZLE[index]);
} }
void EmitGetCbufU32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR::Value& binding, void EmitGetCbufU32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] const IR::Value& binding,

View File

@ -47,7 +47,7 @@ void EmitConvertS64F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::I
void EmitConvertS64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitConvertS64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
[[maybe_unused]] std::string_view value) { [[maybe_unused]] std::string_view value) {
ctx.AddS64("{}=int64_t({});", inst, value); ctx.AddS64("{}=int64_t(double({}));", inst, value);
} }
void EmitConvertS64F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitConvertS64F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
@ -92,7 +92,7 @@ void EmitConvertU64F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::I
void EmitConvertU64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitConvertU64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
[[maybe_unused]] std::string_view value) { [[maybe_unused]] std::string_view value) {
ctx.AddU64("{}=uint64_t({});", inst, value); ctx.AddU64("{}=uint64_t(double({}));", inst, value);
} }
void EmitConvertU64F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitConvertU64F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,

View File

@ -156,12 +156,12 @@ void EmitFPSqrt([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& in
void EmitFPSaturate16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitFPSaturate16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
[[maybe_unused]] std::string_view value) { [[maybe_unused]] std::string_view value) {
ctx.AddF64("{}=sqrt({});", inst, value); throw NotImplementedException("GLSL");
} }
void EmitFPSaturate32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitFPSaturate32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
[[maybe_unused]] std::string_view value) { [[maybe_unused]] std::string_view value) {
ctx.AddF32("{}=clamp({},0.0f,1.0f);", inst, value); ctx.AddF32("{}=clamp({},0.0,1.0);", inst, value);
} }
void EmitFPSaturate64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitFPSaturate64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
@ -197,12 +197,12 @@ void EmitFPRoundEven16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::I
void EmitFPRoundEven32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitFPRoundEven32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
[[maybe_unused]] std::string_view value) { [[maybe_unused]] std::string_view value) {
ctx.AddF32("{}=round({});", inst, value); ctx.AddF32("{}=roundEven({});", inst, value);
} }
void EmitFPRoundEven64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitFPRoundEven64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
[[maybe_unused]] std::string_view value) { [[maybe_unused]] std::string_view value) {
ctx.AddF64("{}=round({});", inst, value); ctx.AddF64("{}=roundEven({});", inst, value);
} }
void EmitFPFloor16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitFPFloor16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,

View File

@ -78,13 +78,12 @@ void EmitWriteStorageS16([[maybe_unused]] EmitContext& ctx,
void EmitWriteStorage32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, void EmitWriteStorage32(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
std::string_view value) { std::string_view value) {
ctx.Add("buff{}[{}]={};", binding.U32(), offset.U32(), value); ctx.Add("ssbo{}_u32[{}]={};", binding.U32(), offset.U32(), value);
} }
void EmitWriteStorage64(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset, void EmitWriteStorage64(EmitContext& ctx, const IR::Value& binding, const IR::Value& offset,
std::string_view value) { std::string_view value) {
ctx.Add("buff{}[{}]={}.x;", binding.U32(), offset.U32(), value); ctx.Add("ssbo{}_u64[{}]={};", binding.U32(), offset.U32(), value);
ctx.Add("buff{}[{}]={}.y;", binding.U32(), offset.U32() + 1, value);
} }
void EmitWriteStorage128([[maybe_unused]] EmitContext& ctx, void EmitWriteStorage128([[maybe_unused]] EmitContext& ctx,

View File

@ -36,7 +36,7 @@ std::string MakeImm(const IR::Value& value) {
case IR::Type::U64: case IR::Type::U64:
return fmt::format("{}ul", value.U64()); return fmt::format("{}ul", value.U64());
case IR::Type::F64: case IR::Type::F64:
return fmt::format("{}", value.F64()); return fmt::format("{}lf", value.F64());
default: default:
throw NotImplementedException("Immediate type {}", value.Type()); throw NotImplementedException("Immediate type {}", value.Type());
} }