diff options
| author | 2021-05-20 19:21:38 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:32 -0400 | |
| commit | 79929be8331fabdb83b5595704241f863a0ae33a (patch) | |
| tree | 88f532c0759862485592069180b064e22c9b87fe /src/shader_recompiler/backend | |
| parent | glasm: Properly declare attributes on geometry programs (diff) | |
| download | yuzu-79929be8331fabdb83b5595704241f863a0ae33a.tar.gz yuzu-79929be8331fabdb83b5595704241f863a0ae33a.tar.xz yuzu-79929be8331fabdb83b5595704241f863a0ae33a.zip | |
glasm: Implement geometry shader attribute reads
Diffstat (limited to 'src/shader_recompiler/backend')
| -rw-r--r-- | src/shader_recompiler/backend/glasm/emit_context.cpp | 3 | ||||
| -rw-r--r-- | src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp | 19 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_context.cpp b/src/shader_recompiler/backend/glasm/emit_context.cpp index a9bbb680f..d8451b41f 100644 --- a/src/shader_recompiler/backend/glasm/emit_context.cpp +++ b/src/shader_recompiler/backend/glasm/emit_context.cpp | |||
| @@ -74,6 +74,9 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile | |||
| 74 | InterpDecorator(generic.interpolation), index, attr_stage, index, index); | 74 | InterpDecorator(generic.interpolation), index, attr_stage, index, index); |
| 75 | } | 75 | } |
| 76 | } | 76 | } |
| 77 | if (stage == Stage::Geometry && info.loads_position) { | ||
| 78 | Add("ATTRIB vertex_position=vertex.position;"); | ||
| 79 | } | ||
| 77 | for (size_t index = 0; index < program.info.stores_frag_color.size(); ++index) { | 80 | for (size_t index = 0; index < program.info.stores_frag_color.size(); ++index) { |
| 78 | if (!program.info.stores_frag_color[index]) { | 81 | if (!program.info.stores_frag_color[index]) { |
| 79 | continue; | 82 | continue; |
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp index a81bd209b..d736775c8 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_context_get_set.cpp | |||
| @@ -19,6 +19,14 @@ void GetCbuf(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, ScalarU | |||
| 19 | const Register ret{ctx.reg_alloc.Define(inst)}; | 19 | const Register ret{ctx.reg_alloc.Define(inst)}; |
| 20 | ctx.Add("LDC.{} {},c{}[{}];", size, ret, binding.U32(), offset); | 20 | ctx.Add("LDC.{} {},c{}[{}];", size, ret, binding.U32(), offset); |
| 21 | } | 21 | } |
| 22 | |||
| 23 | std::string VertexIndex(EmitContext& ctx, ScalarU32 vertex) { | ||
| 24 | if (ctx.stage == Stage::Geometry) { | ||
| 25 | return fmt::format("[{}]", vertex); | ||
| 26 | } else { | ||
| 27 | return ""; | ||
| 28 | } | ||
| 29 | } | ||
| 22 | } // Anonymous namespace | 30 | } // Anonymous namespace |
| 23 | 31 | ||
| 24 | void EmitGetCbufU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, ScalarU32 offset) { | 32 | void EmitGetCbufU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, ScalarU32 offset) { |
| @@ -50,13 +58,12 @@ void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding | |||
| 50 | GetCbuf(ctx, inst, binding, offset, "U32X2"); | 58 | GetCbuf(ctx, inst, binding, offset, "U32X2"); |
| 51 | } | 59 | } |
| 52 | 60 | ||
| 53 | void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, | 61 | void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, ScalarU32 vertex) { |
| 54 | [[maybe_unused]] ScalarU32 vertex) { | ||
| 55 | const u32 element{static_cast<u32>(attr) % 4}; | 62 | const u32 element{static_cast<u32>(attr) % 4}; |
| 56 | const char swizzle{"xyzw"[element]}; | 63 | const char swizzle{"xyzw"[element]}; |
| 57 | if (IR::IsGeneric(attr)) { | 64 | if (IR::IsGeneric(attr)) { |
| 58 | const u32 index{IR::GenericAttributeIndex(attr)}; | 65 | const u32 index{IR::GenericAttributeIndex(attr)}; |
| 59 | ctx.Add("MOV.F {}.x,in_attr{}[0].{};", inst, index, swizzle); | 66 | ctx.Add("MOV.F {}.x,in_attr{}{}[0].{};", inst, index, VertexIndex(ctx, vertex), swizzle); |
| 60 | return; | 67 | return; |
| 61 | } | 68 | } |
| 62 | switch (attr) { | 69 | switch (attr) { |
| @@ -64,7 +71,11 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, | |||
| 64 | case IR::Attribute::PositionY: | 71 | case IR::Attribute::PositionY: |
| 65 | case IR::Attribute::PositionZ: | 72 | case IR::Attribute::PositionZ: |
| 66 | case IR::Attribute::PositionW: | 73 | case IR::Attribute::PositionW: |
| 67 | ctx.Add("MOV.F {}.x,{}.position.{};", inst, ctx.attrib_name, swizzle); | 74 | if (ctx.stage == Stage::Geometry) { |
| 75 | ctx.Add("MOV.F {}.x,vertex_position{}.{};", inst, VertexIndex(ctx, vertex), swizzle); | ||
| 76 | } else { | ||
| 77 | ctx.Add("MOV.F {}.x,{}.position.{};", inst, ctx.attrib_name, swizzle); | ||
| 78 | } | ||
| 68 | break; | 79 | break; |
| 69 | case IR::Attribute::PointSpriteS: | 80 | case IR::Attribute::PointSpriteS: |
| 70 | case IR::Attribute::PointSpriteT: | 81 | case IR::Attribute::PointSpriteT: |