diff options
3 files changed, 58 insertions, 48 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp index d60ad139d..386c14ce5 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/emit_context.cpp @@ -430,10 +430,12 @@ Id DescType(EmitContext& ctx, Id sampled_type, Id pointer_type, u32 count) { } } -size_t FindNextUnusedLocation(const std::bitset<IR::NUM_GENERICS>& used_locations, - size_t start_offset) { +size_t FindAndSetNextUnusedLocation(std::bitset<IR::NUM_GENERICS>& used_locations, + size_t& start_offset) { for (size_t location = start_offset; location < used_locations.size(); ++location) { if (!used_locations.test(location)) { + start_offset = location; + used_locations.set(location); return location; } } @@ -1279,45 +1281,40 @@ void EmitContext::DefineInputs(const IR::Program& program) { } size_t previous_unused_location = 0; if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { - const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); - previous_unused_location = location; - used_locations.set(location); const Id id{DefineInput(*this, F32[4], true)}; - Decorate(id, spv::Decoration::Location, location); + Decorate(id, spv::Decoration::Location, + FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); input_front_color = id; } if (loads.AnyComponent(IR::Attribute::ColorFrontSpecularR)) { - const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); - previous_unused_location = location; - used_locations.set(location); const Id id{DefineInput(*this, F32[4], true)}; - Decorate(id, spv::Decoration::Location, location); + Decorate(id, spv::Decoration::Location, + FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); input_front_secondary_color = id; } if (loads.AnyComponent(IR::Attribute::ColorBackDiffuseR)) { - const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); - previous_unused_location = location; - used_locations.set(location); const Id id{DefineInput(*this, F32[4], true)}; - Decorate(id, spv::Decoration::Location, location); + Decorate(id, spv::Decoration::Location, + FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); input_back_color = id; } if (loads.AnyComponent(IR::Attribute::ColorBackSpecularR)) { - const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); - previous_unused_location = location; - used_locations.set(location); const Id id{DefineInput(*this, F32[4], true)}; - Decorate(id, spv::Decoration::Location, location); + Decorate(id, spv::Decoration::Location, + FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); input_back_secondary_color = id; } + if (loads.AnyComponent(IR::Attribute::FogCoordinate)) { + const Id id{DefineInput(*this, F32[4], true)}; + Decorate(id, spv::Decoration::Location, + FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); + input_fog_frag_coord = id; + } for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { - const size_t location = - FindNextUnusedLocation(used_locations, previous_unused_location); - previous_unused_location = location; - used_locations.set(location); const Id id{DefineInput(*this, F32[4], true)}; - Decorate(id, spv::Decoration::Location, location); + Decorate(id, spv::Decoration::Location, + FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); input_fixed_fnc_textures[index] = id; } } @@ -1380,45 +1377,45 @@ void EmitContext::DefineOutputs(const IR::Program& program) { } size_t previous_unused_location = 0; if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { - const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); - previous_unused_location = location; - used_locations.set(location); const Id id{DefineOutput(*this, F32[4], invocations)}; - Decorate(id, spv::Decoration::Location, static_cast<u32>(location)); + Decorate(id, spv::Decoration::Location, + static_cast<u32>( + FindAndSetNextUnusedLocation(used_locations, previous_unused_location))); output_front_color = id; } if (info.stores.AnyComponent(IR::Attribute::ColorFrontSpecularR)) { - const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); - previous_unused_location = location; - used_locations.set(location); const Id id{DefineOutput(*this, F32[4], invocations)}; - Decorate(id, spv::Decoration::Location, static_cast<u32>(location)); + Decorate(id, spv::Decoration::Location, + static_cast<u32>( + FindAndSetNextUnusedLocation(used_locations, previous_unused_location))); output_front_secondary_color = id; } if (info.stores.AnyComponent(IR::Attribute::ColorBackDiffuseR)) { - const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); - previous_unused_location = location; - used_locations.set(location); const Id id{DefineOutput(*this, F32[4], invocations)}; - Decorate(id, spv::Decoration::Location, static_cast<u32>(location)); + Decorate(id, spv::Decoration::Location, + static_cast<u32>( + FindAndSetNextUnusedLocation(used_locations, previous_unused_location))); output_back_color = id; } if (info.stores.AnyComponent(IR::Attribute::ColorBackSpecularR)) { - const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); - previous_unused_location = location; - used_locations.set(location); const Id id{DefineOutput(*this, F32[4], invocations)}; - Decorate(id, spv::Decoration::Location, static_cast<u32>(location)); + Decorate(id, spv::Decoration::Location, + static_cast<u32>( + FindAndSetNextUnusedLocation(used_locations, previous_unused_location))); output_back_secondary_color = id; } + if (info.stores.AnyComponent(IR::Attribute::FogCoordinate)) { + const Id id{DefineOutput(*this, F32[4], invocations)}; + Decorate(id, spv::Decoration::Location, + static_cast<u32>( + FindAndSetNextUnusedLocation(used_locations, previous_unused_location))); + output_fog_frag_coord = id; + } for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { - const size_t location = - FindNextUnusedLocation(used_locations, previous_unused_location); - previous_unused_location = location; - used_locations.set(location); const Id id{DefineOutput(*this, F32[4], invocations)}; - Decorate(id, spv::Decoration::Location, location); + Decorate(id, spv::Decoration::Location, + FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); output_fixed_fnc_textures[index] = id; } } diff --git a/src/shader_recompiler/backend/spirv/emit_context.h b/src/shader_recompiler/backend/spirv/emit_context.h index a08622099..e1af12a38 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.h +++ b/src/shader_recompiler/backend/spirv/emit_context.h @@ -272,6 +272,7 @@ public: Id input_front_secondary_color{}; Id input_back_color{}; Id input_back_secondary_color{}; + Id input_fog_frag_coord{}; std::array<Id, 10> input_fixed_fnc_textures{}; std::array<Id, 32> input_generics{}; @@ -281,6 +282,7 @@ public: Id output_front_secondary_color{}; Id output_back_color{}; Id output_back_secondary_color{}; + Id output_fog_frag_coord{}; std::array<Id, 10> output_fixed_fnc_textures{}; std::array<std::array<GenericElementInfo, 4>, 32> output_generics{}; 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 2d1545851..6fa99cc1a 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 @@ -143,6 +143,11 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) { const Id element_id{ctx.Const(element)}; return OutputAccessChain(ctx, ctx.output_f32, ctx.output_back_secondary_color, element_id); } + case IR::Attribute::FogCoordinate: { + const u32 element{static_cast<u32>(attr) % 4}; + const Id element_id{ctx.Const(element)}; + return OutputAccessChain(ctx, ctx.output_f32, ctx.output_fog_frag_coord, element_id); + } case IR::Attribute::ClipDistance0: case IR::Attribute::ClipDistance1: case IR::Attribute::ClipDistance2: @@ -391,8 +396,9 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) { case IR::Attribute::ColorFrontSpecularG: case IR::Attribute::ColorFrontSpecularB: case IR::Attribute::ColorFrontSpecularA: { - return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_front_secondary_color, - ctx.Const(element))); + return ctx.OpLoad(ctx.F32[1], + AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_front_secondary_color, + ctx.Const(element))); } case IR::Attribute::ColorBackDiffuseR: case IR::Attribute::ColorBackDiffuseG: @@ -405,8 +411,13 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) { case IR::Attribute::ColorBackSpecularG: case IR::Attribute::ColorBackSpecularB: case IR::Attribute::ColorBackSpecularA: { - return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_back_secondary_color, - ctx.Const(element))); + return ctx.OpLoad(ctx.F32[1], + AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_back_secondary_color, + ctx.Const(element))); + } + case IR::Attribute::FogCoordinate: { + return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex, + ctx.input_fog_frag_coord, ctx.Const(element))); } case IR::Attribute::InstanceId: if (ctx.profile.support_vertex_instance_id) { |