summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend
diff options
context:
space:
mode:
authorGravatar Feng Chen2021-09-07 12:34:35 +0800
committerGravatar Feng Chen2021-09-07 12:34:35 +0800
commit9cdf2383e99fac2110d788da070f16b2b5c678e7 (patch)
treea4857abbacebf3659e6b5c647eceb5a64146a26b /src/shader_recompiler/backend
parentDynamic get unused location (diff)
downloadyuzu-9cdf2383e99fac2110d788da070f16b2b5c678e7.tar.gz
yuzu-9cdf2383e99fac2110d788da070f16b2b5c678e7.tar.xz
yuzu-9cdf2383e99fac2110d788da070f16b2b5c678e7.zip
Move attribute related definitions to spirv anonymous namespace
Diffstat (limited to 'src/shader_recompiler/backend')
-rw-r--r--src/shader_recompiler/backend/spirv/emit_context.cpp6
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp25
2 files changed, 26 insertions, 5 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp
index 2809f9281..f048174cb 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) {
428 return pointer_type; 428 return pointer_type;
429 } 429 }
430} 430}
431
432constexpr size_t NUM_FIXEDFNCTEXTURE = 10;
431} // Anonymous namespace 433} // Anonymous namespace
432 434
433void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) { 435void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) {
@@ -1272,7 +1274,7 @@ void EmitContext::DefineInputs(const IR::Program& program) {
1272 Decorate(id, spv::Decoration::Location, location); 1274 Decorate(id, spv::Decoration::Location, location);
1273 input_front_color = id; 1275 input_front_color = id;
1274 } 1276 }
1275 for (size_t index = 0; index < IR::NUM_FIXEDFNCTEXTURE; ++index) { 1277 for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) {
1276 if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { 1278 if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {
1277 if (ununsed_location.empty()) { 1279 if (ununsed_location.empty()) {
1278 throw RuntimeError("Unable to get an unused location"); 1280 throw RuntimeError("Unable to get an unused location");
@@ -1352,7 +1354,7 @@ void EmitContext::DefineOutputs(const IR::Program& program) {
1352 Decorate(id, spv::Decoration::Location, location); 1354 Decorate(id, spv::Decoration::Location, location);
1353 output_front_color = id; 1355 output_front_color = id;
1354 } 1356 }
1355 for (size_t index = 0; index < IR::NUM_FIXEDFNCTEXTURE; ++index) { 1357 for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) {
1356 if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { 1358 if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {
1357 if (ununsed_location.empty()) { 1359 if (ununsed_location.empty()) {
1358 throw RuntimeError("Unable to get an unused location"); 1360 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.cpp
index c3ebd3e6a..dd0d01b2a 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&&...
43 } 43 }
44} 44}
45 45
46bool IsFixedFncTexture(IR::Attribute attribute) {
47 return attribute >= IR::Attribute::FixedFncTexture0S &&
48 attribute <= IR::Attribute::FixedFncTexture9Q;
49}
50
51u32 FixedFncTextureAttributeIndex(IR::Attribute attribute) {
52 if (!IsFixedFncTexture(attribute)) {
53 throw InvalidArgument("Attribute is not fixedfnctexture {}", attribute);
54 }
55 return (static_cast<u32>(attribute) - static_cast<u32>(IR::Attribute::FixedFncTexture0S)) / 4u;
56}
57
58u32 FixedFncTextureAttributeElement(IR::Attribute attribute) {
59 if (!IsFixedFncTexture(attribute)) {
60 throw InvalidArgument("Attribute is not fixedfnctexture {}", attribute);
61 }
62 return static_cast<u32>(attribute) % 4;
63}
64
46template <typename... Args> 65template <typename... Args>
47Id OutputAccessChain(EmitContext& ctx, Id result_type, Id base, Args&&... args) { 66Id OutputAccessChain(EmitContext& ctx, Id result_type, Id base, Args&&... args) {
48 if (ctx.stage == Stage::TessellationControl) { 67 if (ctx.stage == Stage::TessellationControl) {
@@ -75,8 +94,8 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) {
75 } 94 }
76 } 95 }
77 if (attr >= IR::Attribute::FixedFncTexture0S && attr <= IR::Attribute::FixedFncTexture9Q) { 96 if (attr >= IR::Attribute::FixedFncTexture0S && attr <= IR::Attribute::FixedFncTexture9Q) {
78 const u32 index{IR::FixedFncTextureAttributeIndex(attr)}; 97 const u32 index{FixedFncTextureAttributeIndex(attr)};
79 const u32 element{IR::FixedFncTextureAttributeElement(attr)}; 98 const u32 element{FixedFncTextureAttributeElement(attr)};
80 const Id element_id{ctx.Const(element)}; 99 const Id element_id{ctx.Const(element)};
81 return OutputAccessChain(ctx, ctx.output_f32, ctx.output_fixed_fnc_textures[index], 100 return OutputAccessChain(ctx, ctx.output_f32, ctx.output_fixed_fnc_textures[index],
82 element_id); 101 element_id);
@@ -323,7 +342,7 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) {
323 return type->needs_cast ? ctx.OpBitcast(ctx.F32[1], value) : value; 342 return type->needs_cast ? ctx.OpBitcast(ctx.F32[1], value) : value;
324 } 343 }
325 if (attr >= IR::Attribute::FixedFncTexture0S && attr <= IR::Attribute::FixedFncTexture9Q) { 344 if (attr >= IR::Attribute::FixedFncTexture0S && attr <= IR::Attribute::FixedFncTexture9Q) {
326 const u32 index{IR::FixedFncTextureAttributeIndex(attr)}; 345 const u32 index{FixedFncTextureAttributeIndex(attr)};
327 return ctx.OpLoad(ctx.F32[1], 346 return ctx.OpLoad(ctx.F32[1],
328 AttrPointer(ctx, ctx.input_f32, vertex, 347 AttrPointer(ctx, ctx.input_f32, vertex,
329 ctx.input_fixed_fnc_textures[index], ctx.Const(element))); 348 ctx.input_fixed_fnc_textures[index], ctx.Const(element)));