summaryrefslogtreecommitdiffstats
path: root/src/shader_recompiler/backend/spirv/emit_context.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_context.cpp')
-rw-r--r--src/shader_recompiler/backend/spirv/emit_context.cpp143
1 files changed, 115 insertions, 28 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp
index 2885e6799..3c84e6466 100644
--- a/src/shader_recompiler/backend/spirv/emit_context.cpp
+++ b/src/shader_recompiler/backend/spirv/emit_context.cpp
@@ -430,15 +430,33 @@ Id DescType(EmitContext& ctx, Id sampled_type, Id pointer_type, u32 count) {
}
}
-size_t FindNextUnusedLocation(const std::bitset<IR::NUM_GENERICS>& used_locations,
- size_t start_offset) {
+size_t FindAndSetNextUnusedLocation(std::bitset<IR::NUM_GENERICS>& used_locations,
+ size_t& start_offset) {
for (size_t location = start_offset; location < used_locations.size(); ++location) {
if (!used_locations.test(location)) {
+ start_offset = location;
+ used_locations.set(location);
return location;
}
}
throw RuntimeError("Unable to get an unused location for legacy attribute");
}
+
+Id DefineLegacyInput(EmitContext& ctx, std::bitset<IR::NUM_GENERICS>& used_locations,
+ size_t& start_offset) {
+ const Id id{DefineInput(ctx, ctx.F32[4], true)};
+ const size_t location = FindAndSetNextUnusedLocation(used_locations, start_offset);
+ ctx.Decorate(id, spv::Decoration::Location, location);
+ return id;
+}
+
+Id DefineLegacyOutput(EmitContext& ctx, std::bitset<IR::NUM_GENERICS>& used_locations,
+ size_t& start_offset, std::optional<u32> invocations) {
+ const Id id{DefineOutput(ctx, ctx.F32[4], invocations)};
+ const size_t location = FindAndSetNextUnusedLocation(used_locations, start_offset);
+ ctx.Decorate(id, spv::Decoration::Location, location);
+ return id;
+}
} // Anonymous namespace
void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) {
@@ -520,6 +538,64 @@ Id EmitContext::BitOffset16(const IR::Value& offset) {
return OpBitwiseAnd(U32[1], OpShiftLeftLogical(U32[1], Def(offset), Const(3u)), Const(16u));
}
+Id EmitContext::InputLegacyAttribute(IR::Attribute attribute) {
+ if (attribute >= IR::Attribute::ColorFrontDiffuseR &&
+ attribute <= IR::Attribute::ColorFrontDiffuseA) {
+ return input_front_color;
+ }
+ if (attribute >= IR::Attribute::ColorFrontSpecularR &&
+ attribute <= IR::Attribute::ColorFrontSpecularA) {
+ return input_front_secondary_color;
+ }
+ if (attribute >= IR::Attribute::ColorBackDiffuseR &&
+ attribute <= IR::Attribute::ColorBackDiffuseA) {
+ return input_back_color;
+ }
+ if (attribute >= IR::Attribute::ColorBackSpecularR &&
+ attribute <= IR::Attribute::ColorBackSpecularA) {
+ return input_back_secondary_color;
+ }
+ if (attribute == IR::Attribute::FogCoordinate) {
+ return input_fog_frag_coord;
+ }
+ if (attribute >= IR::Attribute::FixedFncTexture0S &&
+ attribute <= IR::Attribute::FixedFncTexture9Q) {
+ u32 index =
+ (static_cast<u32>(attribute) - static_cast<u32>(IR::Attribute::FixedFncTexture0S)) / 4;
+ return input_fixed_fnc_textures[index];
+ }
+ throw InvalidArgument("Attribute is not legacy attribute {}", attribute);
+}
+
+Id EmitContext::OutputLegacyAttribute(IR::Attribute attribute) {
+ if (attribute >= IR::Attribute::ColorFrontDiffuseR &&
+ attribute <= IR::Attribute::ColorFrontDiffuseA) {
+ return output_front_color;
+ }
+ if (attribute >= IR::Attribute::ColorFrontSpecularR &&
+ attribute <= IR::Attribute::ColorFrontSpecularA) {
+ return output_front_secondary_color;
+ }
+ if (attribute >= IR::Attribute::ColorBackDiffuseR &&
+ attribute <= IR::Attribute::ColorBackDiffuseA) {
+ return output_back_color;
+ }
+ if (attribute >= IR::Attribute::ColorBackSpecularR &&
+ attribute <= IR::Attribute::ColorBackSpecularA) {
+ return output_back_secondary_color;
+ }
+ if (attribute == IR::Attribute::FogCoordinate) {
+ return output_fog_frag_coord;
+ }
+ if (attribute >= IR::Attribute::FixedFncTexture0S &&
+ attribute <= IR::Attribute::FixedFncTexture9Q) {
+ u32 index =
+ (static_cast<u32>(attribute) - static_cast<u32>(IR::Attribute::FixedFncTexture0S)) / 4;
+ return output_fixed_fnc_textures[index];
+ }
+ throw InvalidArgument("Attribute is not legacy attribute {}", attribute);
+}
+
void EmitContext::DefineCommonTypes(const Info& info) {
void_id = TypeVoid();
@@ -1279,22 +1355,26 @@ void EmitContext::DefineInputs(const IR::Program& program) {
}
size_t previous_unused_location = 0;
if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
- const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location);
- previous_unused_location = location;
- used_locations.set(location);
- const Id id{DefineInput(*this, F32[4], true)};
- Decorate(id, spv::Decoration::Location, location);
- input_front_color = id;
+ input_front_color = DefineLegacyInput(*this, used_locations, previous_unused_location);
+ }
+ if (loads.AnyComponent(IR::Attribute::ColorFrontSpecularR)) {
+ input_front_secondary_color =
+ DefineLegacyInput(*this, used_locations, previous_unused_location);
+ }
+ if (loads.AnyComponent(IR::Attribute::ColorBackDiffuseR)) {
+ input_back_color = DefineLegacyInput(*this, used_locations, previous_unused_location);
+ }
+ if (loads.AnyComponent(IR::Attribute::ColorBackSpecularR)) {
+ input_back_secondary_color =
+ DefineLegacyInput(*this, used_locations, previous_unused_location);
+ }
+ if (loads.AnyComponent(IR::Attribute::FogCoordinate)) {
+ input_fog_frag_coord = DefineLegacyInput(*this, used_locations, previous_unused_location);
}
for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) {
if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {
- const size_t location =
- FindNextUnusedLocation(used_locations, previous_unused_location);
- previous_unused_location = location;
- used_locations.set(location);
- const Id id{DefineInput(*this, F32[4], true)};
- Decorate(id, spv::Decoration::Location, location);
- input_fixed_fnc_textures[index] = id;
+ input_fixed_fnc_textures[index] =
+ DefineLegacyInput(*this, used_locations, previous_unused_location);
}
}
if (stage == Stage::TessellationEval) {
@@ -1356,22 +1436,29 @@ void EmitContext::DefineOutputs(const IR::Program& program) {
}
size_t previous_unused_location = 0;
if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
- const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location);
- previous_unused_location = location;
- used_locations.set(location);
- const Id id{DefineOutput(*this, F32[4], invocations)};
- Decorate(id, spv::Decoration::Location, static_cast<u32>(location));
- output_front_color = id;
+ output_front_color =
+ DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations);
+ }
+ if (info.stores.AnyComponent(IR::Attribute::ColorFrontSpecularR)) {
+ output_front_secondary_color =
+ DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations);
+ }
+ if (info.stores.AnyComponent(IR::Attribute::ColorBackDiffuseR)) {
+ output_back_color =
+ DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations);
+ }
+ if (info.stores.AnyComponent(IR::Attribute::ColorBackSpecularR)) {
+ output_back_secondary_color =
+ DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations);
+ }
+ if (info.stores.AnyComponent(IR::Attribute::FogCoordinate)) {
+ output_fog_frag_coord =
+ DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations);
}
for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) {
if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {
- const size_t location =
- FindNextUnusedLocation(used_locations, previous_unused_location);
- previous_unused_location = location;
- used_locations.set(location);
- const Id id{DefineOutput(*this, F32[4], invocations)};
- Decorate(id, spv::Decoration::Location, location);
- output_fixed_fnc_textures[index] = id;
+ output_fixed_fnc_textures[index] =
+ DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations);
}
}
switch (stage) {