diff options
| author | 2021-05-29 18:08:19 -0400 | |
|---|---|---|
| committer | 2021-07-22 21:51:36 -0400 | |
| commit | 3047eb66889a9782fadfbe479c33e6a8bfc5bf53 (patch) | |
| tree | 9491643b07576e354844b39d5dffb321491aadf9 /src/shader_recompiler/backend/glsl | |
| parent | glsl: TLD4 implementation (diff) | |
| download | yuzu-3047eb66889a9782fadfbe479c33e6a8bfc5bf53.tar.gz yuzu-3047eb66889a9782fadfbe479c33e6a8bfc5bf53.tar.xz yuzu-3047eb66889a9782fadfbe479c33e6a8bfc5bf53.zip | |
glsl: Implement TXQ and other misc changes
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
5 files changed, 36 insertions, 6 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl.cpp b/src/shader_recompiler/backend/glsl/emit_glsl.cpp index 800de58b7..8705daeee 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 | |||
| 190 | } | 190 | } |
| 191 | ctx.code.insert(0, ctx.header); | 191 | ctx.code.insert(0, ctx.header); |
| 192 | ctx.code += "}"; | 192 | ctx.code += "}"; |
| 193 | fmt::print("\n{}\n", ctx.code); | 193 | // fmt::print("\n{}\n", ctx.code); |
| 194 | return ctx.code; | 194 | return ctx.code; |
| 195 | } | 195 | } |
| 196 | 196 | ||
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.cpp index dc0e9ef95..ab7628a5a 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, | |||
| 118 | case IR::Attribute::VertexId: | 118 | case IR::Attribute::VertexId: |
| 119 | ctx.AddS32("{}=gl_VertexID;", inst); | 119 | ctx.AddS32("{}=gl_VertexID;", inst); |
| 120 | break; | 120 | break; |
| 121 | case IR::Attribute::FrontFace: | ||
| 122 | ctx.AddS32("{}=gl_FrontFacing?-1:0;", inst); | ||
| 123 | break; | ||
| 121 | default: | 124 | default: |
| 122 | fmt::print("Get attribute {}", attr); | 125 | fmt::print("Get attribute {}", attr); |
| 123 | throw NotImplementedException("Get attribute {}", attr); | 126 | 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.cpp index e12d7b850..9213375b4 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::Inst | |||
| 351 | void EmitImageQueryDimensions([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 351 | void EmitImageQueryDimensions([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 352 | [[maybe_unused]] const IR::Value& index, | 352 | [[maybe_unused]] const IR::Value& index, |
| 353 | [[maybe_unused]] std::string_view lod) { | 353 | [[maybe_unused]] std::string_view lod) { |
| 354 | throw NotImplementedException("GLSL Instruction"); | 354 | const auto info{inst.Flags<IR::TextureInstInfo>()}; |
| 355 | const auto texture{Texture(ctx, info, index)}; | ||
| 356 | switch (info.type) { | ||
| 357 | case TextureType::Color1D: | ||
| 358 | return ctx.AddU32x4( | ||
| 359 | "{}=uvec4(uint(textureSize({},int({}))),0u,0u,uint(textureQueryLevels({})));", inst, | ||
| 360 | texture, lod, texture); | ||
| 361 | case TextureType::ColorArray1D: | ||
| 362 | case TextureType::Color2D: | ||
| 363 | case TextureType::ColorCube: | ||
| 364 | return ctx.AddU32x4( | ||
| 365 | "{}=uvec4(uvec2(textureSize({},int({}))),0u,uint(textureQueryLevels({})));", inst, | ||
| 366 | texture, lod, texture); | ||
| 367 | case TextureType::ColorArray2D: | ||
| 368 | case TextureType::Color3D: | ||
| 369 | case TextureType::ColorArrayCube: | ||
| 370 | return ctx.AddU32x4( | ||
| 371 | "{}=uvec4(uvec3(textureSize({},int({}))),uint(textureQueryLevels({})));", inst, texture, | ||
| 372 | lod, texture); | ||
| 373 | case TextureType::Buffer: | ||
| 374 | throw NotImplementedException("Texture buffers"); | ||
| 375 | } | ||
| 376 | throw LogicError("Unspecified image type {}", info.type.Value()); | ||
| 355 | } | 377 | } |
| 356 | 378 | ||
| 357 | void EmitImageQueryLod([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 379 | 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.cpp index fd3140dd2..b8f95bd36 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) { | |||
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | void EmitSetFragDepth(EmitContext& ctx, std::string_view value) { | 170 | void EmitSetFragDepth(EmitContext& ctx, std::string_view value) { |
| 171 | NotImplemented(); | 171 | ctx.Add("gl_FragDepth={};", value); |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | void EmitGetZFlag(EmitContext& ctx) { | 174 | void EmitGetZFlag(EmitContext& ctx) { |
diff --git a/src/shader_recompiler/backend/glsl/reg_alloc.cpp b/src/shader_recompiler/backend/glsl/reg_alloc.cpp index ecb550095..b1de022d4 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) { | |||
| 37 | return "uintBitsToFloat(0xff800000)"; | 37 | return "uintBitsToFloat(0xff800000)"; |
| 38 | } | 38 | } |
| 39 | } | 39 | } |
| 40 | const bool needs_dot = value.find_first_of('.') == std::string_view::npos; | 40 | if (value.find_first_of('e') != std::string_view::npos) { |
| 41 | const bool needs_suffix = !value.ends_with('f'); | 41 | // scientific notation |
| 42 | const auto suffix = type == IR::Type::F32 ? "f" : "lf"; | 42 | const auto cast{type == IR::Type::F32 ? "float" : "double"}; |
| 43 | return fmt::format("{}({})", cast, value); | ||
| 44 | } | ||
| 45 | const bool needs_dot{value.find_first_of('.') == std::string_view::npos}; | ||
| 46 | const bool needs_suffix{!value.ends_with('f')}; | ||
| 47 | const auto suffix{type == IR::Type::F32 ? "f" : "lf"}; | ||
| 43 | return fmt::format("{}{}{}", value, needs_dot ? "." : "", needs_suffix ? suffix : ""); | 48 | return fmt::format("{}{}{}", value, needs_dot ? "." : "", needs_suffix ? suffix : ""); |
| 44 | } | 49 | } |
| 45 | 50 | ||