summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
-rw-r--r--src/shader_recompiler/frontend/ir/attribute.cpp18
-rw-r--r--src/shader_recompiler/frontend/ir/attribute.h7
4 files changed, 26 insertions, 30 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)));
diff --git a/src/shader_recompiler/frontend/ir/attribute.cpp b/src/shader_recompiler/frontend/ir/attribute.cpp
index 5b3694f65..4d0b8b8e5 100644
--- a/src/shader_recompiler/frontend/ir/attribute.cpp
+++ b/src/shader_recompiler/frontend/ir/attribute.cpp
@@ -9,24 +9,6 @@
9 9
10namespace Shader::IR { 10namespace Shader::IR {
11 11
12bool IsFixedFncTexture(Attribute attribute) {
13 return attribute >= Attribute::FixedFncTexture0S && attribute <= Attribute::FixedFncTexture9Q;
14}
15
16u32 FixedFncTextureAttributeIndex(Attribute attribute) {
17 if (!IsFixedFncTexture(attribute)) {
18 throw InvalidArgument("Attribute is not fixedfnctexture {}", attribute);
19 }
20 return (static_cast<u32>(attribute) - static_cast<u32>(Attribute::FixedFncTexture0S)) / 4u;
21}
22
23u32 FixedFncTextureAttributeElement(Attribute attribute) {
24 if (!IsFixedFncTexture(attribute)) {
25 throw InvalidArgument("Attribute is not fixedfnctexture {}", attribute);
26 }
27 return static_cast<u32>(attribute) % 4;
28}
29
30bool IsGeneric(Attribute attribute) noexcept { 12bool IsGeneric(Attribute attribute) noexcept {
31 return attribute >= Attribute::Generic0X && attribute <= Attribute::Generic31X; 13 return attribute >= Attribute::Generic0X && attribute <= Attribute::Generic31X;
32} 14}
diff --git a/src/shader_recompiler/frontend/ir/attribute.h b/src/shader_recompiler/frontend/ir/attribute.h
index 9ca4dd76e..ca1199494 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 {
222 FrontFace = 255, 222 FrontFace = 255,
223}; 223};
224 224
225constexpr size_t NUM_FIXEDFNCTEXTURE = 10;
226constexpr size_t NUM_GENERICS = 32; 225constexpr size_t NUM_GENERICS = 32;
227 226
228[[nodiscard]] bool IsFixedFncTexture(Attribute attribute);
229
230[[nodiscard]] u32 FixedFncTextureAttributeIndex(Attribute attribute);
231
232[[nodiscard]] u32 FixedFncTextureAttributeElement(Attribute attribute);
233
234[[nodiscard]] bool IsGeneric(Attribute attribute) noexcept; 227[[nodiscard]] bool IsGeneric(Attribute attribute) noexcept;
235 228
236[[nodiscard]] u32 GenericAttributeIndex(Attribute attribute); 229[[nodiscard]] u32 GenericAttributeIndex(Attribute attribute);