From 271695f020b226e7594f58bf8dedbd0b2fe4b7e8 Mon Sep 17 00:00:00 2001 From: lizzie Date: Sun, 25 Jan 2026 01:28:00 +0000 Subject: [PATCH] fuck you 2 times --- .../backend/spirv/spirv_emit_context.cpp | 21 +++++++++++++------ .../backend/spirv/spirv_emit_context.h | 2 ++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp index c8727e3d06..a89344b0f3 100644 --- a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp @@ -200,12 +200,13 @@ Id GetAttributeType(EmitContext& ctx, AttributeType type) { case AttributeType::Float: return ctx.F32[4]; case AttributeType::SignedInt: + case AttributeType::SignedNorm: return ctx.TypeVector(ctx.TypeInt(32, true), 4); case AttributeType::UnsignedInt: + case AttributeType::UnsignedNorm: 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: @@ -218,12 +219,10 @@ InputGenericInfo GetAttributeInfo(EmitContext& ctx, AttributeType type, Id id) { switch (type) { case AttributeType::Float: return InputGenericInfo{id, ctx.input_f32, ctx.F32[1], InputGenericLoadOp::None}; - // TODO: properly impl this? case AttributeType::UnsignedNorm: - return InputGenericInfo{id, ctx.input_u32, ctx.U32[1], InputGenericLoadOp::Bitcast}; + return InputGenericInfo{id, ctx.input_u32, ctx.U32[1], InputGenericLoadOp::UNorm}; case AttributeType::SignedNorm: - return InputGenericInfo{id, ctx.input_s32, ctx.TypeInt(32, true), InputGenericLoadOp::Bitcast}; - // + return InputGenericInfo{id, ctx.input_s32, ctx.TypeInt(32, true), InputGenericLoadOp::SNorm}; case AttributeType::UnsignedInt: return InputGenericInfo{id, ctx.input_u32, ctx.U32[1], InputGenericLoadOp::Bitcast}; case AttributeType::SignedInt: @@ -781,6 +780,16 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) { return OpConvertSToF(F32[1], value); case InputGenericLoadOp::UToF: return OpConvertUToF(F32[1], value); + case InputGenericLoadOp::SNorm: { + Id const fp16_value = OpShiftRightArithmetic(U32[1], value, Const(16U)); + Id const max_value = Const(unsigned(std::numeric_limits::max())); + return OpFDiv(F32[1], OpConvertSToF(F32[1], fp16_value), max_value); + } + case InputGenericLoadOp::UNorm: { + Id const fp16_value = OpShiftRightLogical(U32[1], value, Const(16U)); + Id const max_value = Const(unsigned(std::numeric_limits::max())); + return OpFDiv(F32[1], OpConvertSToF(F32[1], fp16_value), max_value); + } default: return value; }; diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.h b/src/shader_recompiler/backend/spirv/spirv_emit_context.h index 80ac79f2d6..fd4277300d 100644 --- a/src/shader_recompiler/backend/spirv/spirv_emit_context.h +++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.h @@ -143,6 +143,8 @@ enum class InputGenericLoadOp { Bitcast, SToF, UToF, + SNorm, + UNorm, }; struct InputGenericInfo {