VERY experimental Nintendo Switch 2 emulator
C++
Move attribute related definitions to spirv anonymous namespace
Feng Chenbd94ea2f5abb
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cppindex 2809f9281e..f048174cb5 100644--- a/src/shader_recompiler/backend/spirv/emit_context.cpp+++ b/src/shader_recompiler/backend/spirv/emit_context.cpp@@ -428,6 +428,8 @@ Id DescType(EmitContext& ctx, Id sampled_type, Id pointer_type, u32 count) {return pointer_type;}}++constexpr size_t NUM_FIXEDFNCTEXTURE = 10;} // Anonymous namespacevoid VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) {@@ -1272,7 +1274,7 @@ void EmitContext::DefineInputs(const IR::Program& program) {Decorate(id, spv::Decoration::Location, location);input_front_color = id;}- for (size_t index = 0; index < IR::NUM_FIXEDFNCTEXTURE; ++index) {+ for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) {if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {if (ununsed_location.empty()) {throw RuntimeError("Unable to get an unused location");@@ -1352,7 +1354,7 @@ void EmitContext::DefineOutputs(const IR::Program& program) {Decorate(id, spv::Decoration::Location, location);output_front_color = id;}- for (size_t index = 0; index < IR::NUM_FIXEDFNCTEXTURE; ++index) {+ for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) {if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {if (ununsed_location.empty()) {throw RuntimeError("Unable to get an unused location");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.cppindex c3ebd3e6a7..dd0d01b2ad 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,6 +43,25 @@ 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 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 fixedfnctexture {}", attribute);+ }+ return static_cast<u32>(attribute) % 4;+}+template <typename... Args>Id OutputAccessChain(EmitContext& ctx, Id result_type, Id base, Args&&... args) {if (ctx.stage == Stage::TessellationControl) {@@ -75,8 +94,8 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) {}}if (attr >= IR::Attribute::FixedFncTexture0S && attr <= IR::Attribute::FixedFncTexture9Q) {- const u32 index{IR::FixedFncTextureAttributeIndex(attr)};- const u32 element{IR::FixedFncTextureAttributeElement(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);@@ -323,7 +342,7 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) {return type->needs_cast ? ctx.OpBitcast(ctx.F32[1], value) : value;}if (attr >= IR::Attribute::FixedFncTexture0S && attr <= IR::Attribute::FixedFncTexture9Q) {- const u32 index{IR::FixedFncTextureAttributeIndex(attr)};+ const u32 index{FixedFncTextureAttributeIndex(attr)};return ctx.OpLoad(ctx.F32[1],AttrPointer(ctx, ctx.input_f32, vertex,ctx.input_fixed_fnc_textures[index], ctx.Const(element)));diff --git a/src/shader_recompiler/frontend/ir/attribute.cpp b/src/shader_recompiler/frontend/ir/attribute.cppindex 5b3694f652..4d0b8b8e5c 100644--- a/src/shader_recompiler/frontend/ir/attribute.cpp+++ b/src/shader_recompiler/frontend/ir/attribute.cpp@@ -9,24 +9,6 @@namespace Shader::IR {-bool IsFixedFncTexture(Attribute attribute) {- return attribute >= Attribute::FixedFncTexture0S && attribute <= Attribute::FixedFncTexture9Q;-}--u32 FixedFncTextureAttributeIndex(Attribute attribute) {- if (!IsFixedFncTexture(attribute)) {- throw InvalidArgument("Attribute is not fixedfnctexture {}", attribute);- }- return (static_cast<u32>(attribute) - static_cast<u32>(Attribute::FixedFncTexture0S)) / 4u;-}--u32 FixedFncTextureAttributeElement(Attribute attribute) {- if (!IsFixedFncTexture(attribute)) {- throw InvalidArgument("Attribute is not fixedfnctexture {}", attribute);- }- return static_cast<u32>(attribute) % 4;-}-bool IsGeneric(Attribute attribute) noexcept {return attribute >= Attribute::Generic0X && attribute <= Attribute::Generic31X;}diff --git a/src/shader_recompiler/frontend/ir/attribute.h b/src/shader_recompiler/frontend/ir/attribute.hindex 9ca4dd76ec..ca11994943 100644--- a/src/shader_recompiler/frontend/ir/attribute.h+++ b/src/shader_recompiler/frontend/ir/attribute.h@@ -222,15 +222,8 @@ enum class Attribute : u64 {FrontFace = 255,};-constexpr size_t NUM_FIXEDFNCTEXTURE = 10;constexpr size_t NUM_GENERICS = 32;-[[nodiscard]] bool IsFixedFncTexture(Attribute attribute);--[[nodiscard]] u32 FixedFncTextureAttributeIndex(Attribute attribute);--[[nodiscard]] u32 FixedFncTextureAttributeElement(Attribute attribute);-[[nodiscard]] bool IsGeneric(Attribute attribute) noexcept;[[nodiscard]] u32 GenericAttributeIndex(Attribute attribute);