From e7707ea1ca71fca19b4bd91a93ec78057c1d7529 Mon Sep 17 00:00:00 2001 From: lizzie Date: Sun, 25 Jan 2026 02:59:43 +0000 Subject: [PATCH] partial revert --- .../spirv/emit_spirv_context_get_set.cpp | 4 +- .../backend/spirv/spirv_emit_context.cpp | 23 +++++--- src/shader_recompiler/runtime_info.h | 4 +- .../renderer_vulkan/fixed_pipeline_state.cpp | 12 ++-- .../renderer_vulkan/vk_pipeline_cache.cpp | 58 +++++++++++++------ 5 files changed, 63 insertions(+), 38 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 36ddeffb16..db11def7b2 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 @@ -327,9 +327,9 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) { return ctx.OpConvertSToF(ctx.F32[1], value); case InputGenericLoadOp::UToF: return ctx.OpConvertUToF(ctx.F32[1], value); - case InputGenericLoadOp::None: + default: return value; - } + }; }(); } switch (attr) { diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp index 9337e294fc..c70f9ae934 100644 --- a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp @@ -204,7 +204,8 @@ Id GetAttributeType(EmitContext& ctx, AttributeType type) { case AttributeType::UnsignedInt: return ctx.U32[4]; case AttributeType::SignedScaled: - return ctx.profile.support_scaled_attributes ? ctx.F32[4] : ctx.TypeVector(ctx.TypeInt(32, true), 4); + return ctx.profile.support_scaled_attributes ? ctx.F32[4] + : ctx.TypeVector(ctx.TypeInt(32, true), 4); case AttributeType::UnsignedScaled: return ctx.profile.support_scaled_attributes ? ctx.F32[4] : ctx.U32[4]; case AttributeType::Disabled: @@ -220,15 +221,17 @@ InputGenericInfo GetAttributeInfo(EmitContext& ctx, AttributeType type, Id id) { case AttributeType::UnsignedInt: return InputGenericInfo{id, ctx.input_u32, ctx.U32[1], InputGenericLoadOp::Bitcast}; case AttributeType::SignedInt: - return InputGenericInfo{id, ctx.input_s32, ctx.TypeInt(32, true), InputGenericLoadOp::Bitcast}; + return InputGenericInfo{id, ctx.input_s32, ctx.TypeInt(32, true), + InputGenericLoadOp::Bitcast}; case AttributeType::SignedScaled: return ctx.profile.support_scaled_attributes - ? InputGenericInfo{id, ctx.input_f32, ctx.F32[1], InputGenericLoadOp::None} - : InputGenericInfo{id, ctx.input_s32, ctx.TypeInt(32, true), InputGenericLoadOp::SToF}; + ? InputGenericInfo{id, ctx.input_f32, ctx.F32[1], InputGenericLoadOp::None} + : InputGenericInfo{id, ctx.input_s32, ctx.TypeInt(32, true), + InputGenericLoadOp::SToF}; case AttributeType::UnsignedScaled: return ctx.profile.support_scaled_attributes - ? InputGenericInfo{id, ctx.input_f32, ctx.F32[1], InputGenericLoadOp::None} - : InputGenericInfo{id, ctx.input_u32, ctx.U32[1], InputGenericLoadOp::UToF}; + ? InputGenericInfo{id, ctx.input_f32, ctx.F32[1], InputGenericLoadOp::None} + : InputGenericInfo{id, ctx.input_u32, ctx.U32[1], InputGenericLoadOp::UToF}; case AttributeType::Disabled: return InputGenericInfo{}; } @@ -774,9 +777,9 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) { return OpConvertSToF(F32[1], value); case InputGenericLoadOp::UToF: return OpConvertUToF(F32[1], value); - case InputGenericLoadOp::None: + default: return value; - } + }; }()}; OpReturnValue(result); ++label_index; @@ -1564,7 +1567,9 @@ void EmitContext::DefineInputs(const IR::Program& program) { if (stage != Stage::Fragment) { continue; } - if (input_type == AttributeType::SignedInt || input_type == AttributeType::UnsignedInt) { + const bool is_integer = input_type == AttributeType::SignedInt || + input_type == AttributeType::UnsignedInt; + if (is_integer) { Decorate(id, spv::Decoration::Flat); } else { switch (info.interpolation[index]) { diff --git a/src/shader_recompiler/runtime_info.h b/src/shader_recompiler/runtime_info.h index 09169358a8..613c598d0c 100644 --- a/src/shader_recompiler/runtime_info.h +++ b/src/shader_recompiler/runtime_info.h @@ -17,12 +17,12 @@ namespace Shader { enum class AttributeType : u8 { - Disabled, + Float, SignedInt, UnsignedInt, SignedScaled, UnsignedScaled, - Float, + Disabled, }; enum class InputTopology { diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp index 5c36c9a9ea..4da986415e 100644 --- a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp +++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp @@ -111,16 +111,14 @@ void FixedPipelineState::Refresh(Tegra::Engines::Maxwell3D& maxwell3d, DynamicFe attribute_types = {0, 0, 0}; static_assert(Maxwell::NumVertexAttributes == 32); for (size_t i = 0; i < Maxwell::NumVertexAttributes; ++i) { - u32 const mask = attrs[i].constant != 0 ? 0 : 1; // non-constant equates invalid - u32 const type = u32(attrs[i].type.Value()); - attribute_types[0] |= u32((type >> 0) & mask) << i; - attribute_types[1] |= u32((type >> 1) & mask) << i; - attribute_types[2] |= u32((type >> 2) & mask) << i; + u32 const type = attrs[i].constant != 0 ? 0 : u32(attrs[i].type.Value()); // non-constant equates invalid + attribute_types[0] |= u32((type >> 0) & 1) << i; + attribute_types[1] |= u32((type >> 1) & 1) << i; + attribute_types[2] |= u32((type >> 2) & 1) << i; } } else { maxwell3d.dirty.flags[Dirty::VertexInput] = false; - enabled_divisors[0] = 0; - enabled_divisors[1] = 0; + enabled_divisors = {0, 0}; for (size_t index = 0; index < Maxwell::NumVertexArrays; ++index) { const bool is_enabled = regs.vertex_stream_instances.IsInstancingEnabled(index); binding_divisors[index] = is_enabled ? regs.vertex_streams[index].frequency : 0; diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 3b621d7509..40b8160cf5 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp @@ -104,23 +104,45 @@ Shader::CompareFunction MaxwellToCompareFunction(Maxwell::ComparisonOp compariso case Maxwell::ComparisonOp::Always_GL: return Shader::CompareFunction::Always; } - UNIMPLEMENTED_MSG("op={}", comparison); + UNIMPLEMENTED_MSG("Unimplemented comparison op={}", comparison); return {}; } -Shader::AttributeType MaxwellToAttributeType(Maxwell::VertexAttribute::Type type) noexcept { - switch (type) { - case Maxwell::VertexAttribute::Type::UnusedEnumDoNotUseBecauseItWillGoAway: return Shader::AttributeType::Disabled; - case Maxwell::VertexAttribute::Type::UInt: return Shader::AttributeType::UnsignedInt; - case Maxwell::VertexAttribute::Type::SInt: return Shader::AttributeType::SignedInt; - case Maxwell::VertexAttribute::Type::UScaled: return Shader::AttributeType::UnsignedScaled; - case Maxwell::VertexAttribute::Type::SScaled: return Shader::AttributeType::SignedScaled; - case Maxwell::VertexAttribute::Type::Float: return Shader::AttributeType::Float; - case Maxwell::VertexAttribute::Type::UNorm: return Shader::AttributeType::Float; - case Maxwell::VertexAttribute::Type::SNorm: return Shader::AttributeType::Float; +Shader::AttributeType CastAttributeType(const FixedPipelineState::VertexAttribute& attr) { + if (attr.enabled == 0) { + return Shader::AttributeType::Disabled; + } + switch (attr.Type()) { + case Maxwell::VertexAttribute::Type::UnusedEnumDoNotUseBecauseItWillGoAway: + ASSERT_MSG(false, "Invalid vertex attribute type!"); + return Shader::AttributeType::Disabled; + case Maxwell::VertexAttribute::Type::SNorm: + case Maxwell::VertexAttribute::Type::UNorm: + case Maxwell::VertexAttribute::Type::Float: + return Shader::AttributeType::Float; + case Maxwell::VertexAttribute::Type::SInt: + return Shader::AttributeType::SignedInt; + case Maxwell::VertexAttribute::Type::UInt: + return Shader::AttributeType::UnsignedInt; + case Maxwell::VertexAttribute::Type::UScaled: + return Shader::AttributeType::UnsignedScaled; + case Maxwell::VertexAttribute::Type::SScaled: + return Shader::AttributeType::SignedScaled; + } + return Shader::AttributeType::Float; } - UNIMPLEMENTED_MSG("op={}", index); - return Shader::AttributeType::Disabled; + +Shader::AttributeType AttributeType(const FixedPipelineState& state, size_t index) { + switch (state.DynamicAttributeType(index)) { + case Maxwell::VertexAttribute::Type::Float: + return Shader::AttributeType::Float; + case Maxwell::VertexAttribute::Type::SInt: + return Shader::AttributeType::SignedInt; + case Maxwell::VertexAttribute::Type::UInt: + return Shader::AttributeType::UnsignedInt; + default: + return Shader::AttributeType::Disabled; + } } Shader::RuntimeInfo MakeRuntimeInfo(std::span programs, @@ -161,12 +183,12 @@ Shader::RuntimeInfo MakeRuntimeInfo(std::span program info.convert_depth_mode = gl_ndc; } if (key.state.dynamic_vertex_input) { - for (size_t i = 0; i < Maxwell::NumVertexAttributes; ++i) - info.generic_input_types[i] = MaxwellToAttributeType(key.state.DynamicAttributeType(i)); + for (size_t index = 0; index < Maxwell::NumVertexAttributes; ++index) { + info.generic_input_types[index] = AttributeType(key.state, index); + } } else { - std::ranges::transform(key.state.attributes, info.generic_input_types.begin(), [](auto const attr) { - return attr.enabled ? MaxwellToAttributeType(attr.Type()) : Shader::AttributeType::Disabled; - }); + std::ranges::transform(key.state.attributes, info.generic_input_types.begin(), + &CastAttributeType); } break; case Shader::Stage::TessellationEval: