summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glsl
diff options
context:
space:
mode:
authorGravatar ameerj2021-12-24 20:00:28 -0500
committerGravatar ameerj2021-12-29 19:03:49 -0500
commit14ac0c2923c41df9c6fc4833d2a8e46a6efe5b59 (patch)
tree6d9cb0ebd7d8d7b75d88a0d598c659b06d45004c /src/shader_recompiler/backend/glsl
parentemit_glsl_floating_point: Fix FPNeg on newer Nvidia drivers (diff)
downloadyuzu-14ac0c2923c41df9c6fc4833d2a8e46a6efe5b59.tar.gz
yuzu-14ac0c2923c41df9c6fc4833d2a8e46a6efe5b59.tar.xz
yuzu-14ac0c2923c41df9c6fc4833d2a8e46a6efe5b59.zip
shader: Add integer attribute get optimization pass
Works around an nvidia driver bug, where casting the integer attributes to float and back to an integer always returned 0.
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_context_get_set.cpp16
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_instructions.h2
2 files changed, 18 insertions, 0 deletions
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 6477bd192..5ef46d634 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
@@ -221,6 +221,22 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,
221 } 221 }
222} 222}
223 223
224void EmitGetAttributeU32(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, std::string_view) {
225 switch (attr) {
226 case IR::Attribute::PrimitiveId:
227 ctx.AddU32("{}=uint(gl_PrimitiveID);", inst);
228 break;
229 case IR::Attribute::InstanceId:
230 ctx.AddU32("{}=uint(gl_InstanceID);", inst);
231 break;
232 case IR::Attribute::VertexId:
233 ctx.AddU32("{}=uint(gl_VertexID);", inst);
234 break;
235 default:
236 throw NotImplementedException("Get U32 attribute {}", attr);
237 }
238}
239
224void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view value, 240void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view value,
225 [[maybe_unused]] std::string_view vertex) { 241 [[maybe_unused]] std::string_view vertex) {
226 if (IR::IsGeneric(attr)) { 242 if (IR::IsGeneric(attr)) {
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h
index f86502e4c..6cabbc717 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h
@@ -60,6 +60,8 @@ void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding
60 const IR::Value& offset); 60 const IR::Value& offset);
61void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, 61void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,
62 std::string_view vertex); 62 std::string_view vertex);
63void EmitGetAttributeU32(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,
64 std::string_view vertex);
63void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view value, 65void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, std::string_view value,
64 std::string_view vertex); 66 std::string_view vertex);
65void EmitGetAttributeIndexed(EmitContext& ctx, IR::Inst& inst, std::string_view offset, 67void EmitGetAttributeIndexed(EmitContext& ctx, IR::Inst& inst, std::string_view offset,