VERY experimental Nintendo Switch 2 emulator
C++
glsl: Implement TXQ and other misc changes
ameerj0b8e65125a52
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl.cpp b/src/shader_recompiler/backend/glsl/emit_glsl.cppindex 800de58b7a..8705daeee3 100644--- a/src/shader_recompiler/backend/glsl/emit_glsl.cpp+++ b/src/shader_recompiler/backend/glsl/emit_glsl.cpp@@ -190,7 +190,7 @@ std::string EmitGLSL(const Profile& profile, const RuntimeInfo& runtime_info, IR}ctx.code.insert(0, ctx.header);ctx.code += "}";- fmt::print("\n{}\n", ctx.code);+ // fmt::print("\n{}\n", ctx.code);return ctx.code;}diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cppindex dc0e9ef951..ab7628a5a3 100644--- a/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp+++ b/src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp@@ -118,6 +118,9 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,case IR::Attribute::VertexId:ctx.AddS32("{}=gl_VertexID;", inst);break;+ case IR::Attribute::FrontFace:+ ctx.AddS32("{}=gl_FrontFacing?-1:0;", inst);+ break;default:fmt::print("Get attribute {}", attr);throw NotImplementedException("Get attribute {}", attr);diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_image.cppindex e12d7b8507..9213375b43 100644--- a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp+++ b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp@@ -351,7 +351,29 @@ void EmitImageFetch([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Instvoid EmitImageQueryDimensions([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,[[maybe_unused]] const IR::Value& index,[[maybe_unused]] std::string_view lod) {- throw NotImplementedException("GLSL Instruction");+ const auto info{inst.Flags<IR::TextureInstInfo>()};+ const auto texture{Texture(ctx, info, index)};+ switch (info.type) {+ case TextureType::Color1D:+ return ctx.AddU32x4(+ "{}=uvec4(uint(textureSize({},int({}))),0u,0u,uint(textureQueryLevels({})));", inst,+ texture, lod, texture);+ case TextureType::ColorArray1D:+ case TextureType::Color2D:+ case TextureType::ColorCube:+ return ctx.AddU32x4(+ "{}=uvec4(uvec2(textureSize({},int({}))),0u,uint(textureQueryLevels({})));", inst,+ texture, lod, texture);+ case TextureType::ColorArray2D:+ case TextureType::Color3D:+ case TextureType::ColorArrayCube:+ return ctx.AddU32x4(+ "{}=uvec4(uvec3(textureSize({},int({}))),uint(textureQueryLevels({})));", inst, texture,+ lod, texture);+ case TextureType::Buffer:+ throw NotImplementedException("Texture buffers");+ }+ throw LogicError("Unspecified image type {}", info.type.Value());}void EmitImageQueryLod([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cppindex fd3140dd28..b8f95bd368 100644--- a/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp+++ b/src/shader_recompiler/backend/glsl/emit_glsl_not_implemented.cpp@@ -168,7 +168,7 @@ void EmitSetSampleMask(EmitContext& ctx, std::string_view value) {}void EmitSetFragDepth(EmitContext& ctx, std::string_view value) {- NotImplemented();+ ctx.Add("gl_FragDepth={};", value);}void EmitGetZFlag(EmitContext& ctx) {diff --git a/src/shader_recompiler/backend/glsl/reg_alloc.cpp b/src/shader_recompiler/backend/glsl/reg_alloc.cppindex ecb550095d..b1de022d4e 100644--- a/src/shader_recompiler/backend/glsl/reg_alloc.cpp+++ b/src/shader_recompiler/backend/glsl/reg_alloc.cpp@@ -37,9 +37,14 @@ std::string FormatFloat(std::string_view value, IR::Type type) {return "uintBitsToFloat(0xff800000)";}}- const bool needs_dot = value.find_first_of('.') == std::string_view::npos;- const bool needs_suffix = !value.ends_with('f');- const auto suffix = type == IR::Type::F32 ? "f" : "lf";+ if (value.find_first_of('e') != std::string_view::npos) {+ // scientific notation+ const auto cast{type == IR::Type::F32 ? "float" : "double"};+ return fmt::format("{}({})", cast, value);+ }+ const bool needs_dot{value.find_first_of('.') == std::string_view::npos};+ const bool needs_suffix{!value.ends_with('f')};+ const auto suffix{type == IR::Type::F32 ? "f" : "lf"};return fmt::format("{}{}{}", value, needs_dot ? "." : "", needs_suffix ? suffix : "");}