diff options
Diffstat (limited to '')
-rw-r--r-- | src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp | 70 |
1 files changed, 27 insertions, 43 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp index 6f60c6574..d3a93d5f4 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp @@ -43,23 +43,12 @@ Id AttrPointer(EmitContext& ctx, Id pointer_type, Id vertex, Id base, Args&&... } } -bool IsFixedFncTexture(IR::Attribute attribute) { - return attribute >= IR::Attribute::FixedFncTexture0S && - attribute <= IR::Attribute::FixedFncTexture9Q; -} - -u32 FixedFncTextureAttributeIndex(IR::Attribute attribute) { - if (!IsFixedFncTexture(attribute)) { - throw InvalidArgument("Attribute {} is not a FixedFncTexture", attribute); - } - return (static_cast<u32>(attribute) - static_cast<u32>(IR::Attribute::FixedFncTexture0S)) / 4u; -} - -u32 FixedFncTextureAttributeElement(IR::Attribute attribute) { - if (!IsFixedFncTexture(attribute)) { - throw InvalidArgument("Attribute {} is not a FixedFncTexture", attribute); - } - return static_cast<u32>(attribute) % 4u; +bool IsLegacyAttribute(IR::Attribute attribute) { + return (attribute >= IR::Attribute::ColorFrontDiffuseR && + attribute <= IR::Attribute::ColorBackSpecularA) || + attribute == IR::Attribute::FogCoordinate || + (attribute >= IR::Attribute::FixedFncTexture0S && + attribute <= IR::Attribute::FixedFncTexture9Q); } template <typename... Args> @@ -93,12 +82,16 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) { return OutputAccessChain(ctx, ctx.output_f32, info.id, index_id); } } - if (IsFixedFncTexture(attr)) { - const u32 index{FixedFncTextureAttributeIndex(attr)}; - const u32 element{FixedFncTextureAttributeElement(attr)}; - const Id element_id{ctx.Const(element)}; - return OutputAccessChain(ctx, ctx.output_f32, ctx.output_fixed_fnc_textures[index], - element_id); + if (IsLegacyAttribute(attr)) { + if (attr == IR::Attribute::FogCoordinate) { + return OutputAccessChain(ctx, ctx.output_f32, ctx.OutputLegacyAttribute(attr), + ctx.Const(0u)); + } else { + const u32 element{static_cast<u32>(attr) % 4}; + const Id element_id{ctx.Const(element)}; + return OutputAccessChain(ctx, ctx.output_f32, ctx.OutputLegacyAttribute(attr), + element_id); + } } switch (attr) { case IR::Attribute::PointSize: @@ -111,14 +104,6 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) { const Id element_id{ctx.Const(element)}; return OutputAccessChain(ctx, ctx.output_f32, ctx.output_position, element_id); } - case IR::Attribute::ColorFrontDiffuseR: - case IR::Attribute::ColorFrontDiffuseG: - case IR::Attribute::ColorFrontDiffuseB: - case IR::Attribute::ColorFrontDiffuseA: { - const u32 element{static_cast<u32>(attr) % 4}; - const Id element_id{ctx.Const(element)}; - return OutputAccessChain(ctx, ctx.output_f32, ctx.output_front_color, element_id); - } case IR::Attribute::ClipDistance0: case IR::Attribute::ClipDistance1: case IR::Attribute::ClipDistance2: @@ -341,11 +326,17 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) { const Id value{ctx.OpLoad(type->id, pointer)}; return type->needs_cast ? ctx.OpBitcast(ctx.F32[1], value) : value; } - if (IsFixedFncTexture(attr)) { - const u32 index{FixedFncTextureAttributeIndex(attr)}; - const Id attr_id{ctx.input_fixed_fnc_textures[index]}; - const Id attr_ptr{AttrPointer(ctx, ctx.input_f32, vertex, attr_id, ctx.Const(element))}; - return ctx.OpLoad(ctx.F32[1], attr_ptr); + if (IsLegacyAttribute(attr)) { + if (attr == IR::Attribute::FogCoordinate) { + const Id attr_ptr{AttrPointer(ctx, ctx.input_f32, vertex, + ctx.InputLegacyAttribute(attr), ctx.Const(0u))}; + return ctx.OpLoad(ctx.F32[1], attr_ptr); + } else { + const Id element_id{ctx.Const(element)}; + const Id attr_ptr{AttrPointer(ctx, ctx.input_f32, vertex, + ctx.InputLegacyAttribute(attr), element_id)}; + return ctx.OpLoad(ctx.F32[1], attr_ptr); + } } switch (attr) { case IR::Attribute::PrimitiveId: @@ -356,13 +347,6 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) { case IR::Attribute::PositionW: return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_position, ctx.Const(element))); - case IR::Attribute::ColorFrontDiffuseR: - case IR::Attribute::ColorFrontDiffuseG: - case IR::Attribute::ColorFrontDiffuseB: - case IR::Attribute::ColorFrontDiffuseA: { - return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_front_color, - ctx.Const(element))); - } case IR::Attribute::InstanceId: if (ctx.profile.support_vertex_instance_id) { return ctx.OpBitcast(ctx.F32[1], ctx.OpLoad(ctx.U32[1], ctx.instance_id)); |