mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-11-01 12:57:52 +00:00
gl_shader_decompiler: Skip physical unused attributes
This commit is contained in:
parent
28bffb1ffa
commit
5321cdd276
1 changed files with 27 additions and 18 deletions
|
@ -310,30 +310,28 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetInputFlags(AttributeUse attribute) {
|
std::string GetInputFlags(AttributeUse attribute) {
|
||||||
std::string out;
|
|
||||||
|
|
||||||
switch (attribute) {
|
switch (attribute) {
|
||||||
case AttributeUse::Constant:
|
|
||||||
out += "flat ";
|
|
||||||
break;
|
|
||||||
case AttributeUse::ScreenLinear:
|
|
||||||
out += "noperspective ";
|
|
||||||
break;
|
|
||||||
case AttributeUse::Perspective:
|
case AttributeUse::Perspective:
|
||||||
// Default, Smooth
|
// Default, Smooth
|
||||||
break;
|
return {};
|
||||||
|
case AttributeUse::Constant:
|
||||||
|
return "flat ";
|
||||||
|
case AttributeUse::ScreenLinear:
|
||||||
|
return "noperspective ";
|
||||||
default:
|
default:
|
||||||
LOG_CRITICAL(HW_GPU, "Unused attribute being fetched");
|
case AttributeUse::Unused:
|
||||||
UNREACHABLE();
|
UNREACHABLE_MSG("Unused attribute being fetched");
|
||||||
|
return {};
|
||||||
|
UNIMPLEMENTED_MSG("Unknown attribute usage index={}", static_cast<u32>(attribute));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeclareInputAttributes() {
|
void DeclareInputAttributes() {
|
||||||
if (ir.HasPhysicalAttributes()) {
|
if (ir.HasPhysicalAttributes()) {
|
||||||
const u32 num_inputs{GetNumPhysicalInputAttributes()};
|
const u32 num_inputs{GetNumPhysicalInputAttributes()};
|
||||||
for (u32 i = 0; i < num_inputs; ++i) {
|
for (u32 i = 0; i < num_inputs; ++i) {
|
||||||
DeclareInputAttribute(ToGenericAttribute(i));
|
DeclareInputAttribute(ToGenericAttribute(i), true);
|
||||||
}
|
}
|
||||||
code.AddNewLine();
|
code.AddNewLine();
|
||||||
return;
|
return;
|
||||||
|
@ -342,14 +340,14 @@ private:
|
||||||
const auto& attributes = ir.GetInputAttributes();
|
const auto& attributes = ir.GetInputAttributes();
|
||||||
for (const auto index : attributes) {
|
for (const auto index : attributes) {
|
||||||
if (IsGenericAttribute(index)) {
|
if (IsGenericAttribute(index)) {
|
||||||
DeclareInputAttribute(index);
|
DeclareInputAttribute(index, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!attributes.empty())
|
if (!attributes.empty())
|
||||||
code.AddNewLine();
|
code.AddNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeclareInputAttribute(Attribute::Index index) {
|
void DeclareInputAttribute(Attribute::Index index, bool skip_unused) {
|
||||||
const u32 generic_index{GetGenericAttributeIndex(index)};
|
const u32 generic_index{GetGenericAttributeIndex(index)};
|
||||||
|
|
||||||
std::string name{GetInputAttribute(index)};
|
std::string name{GetInputAttribute(index)};
|
||||||
|
@ -360,6 +358,9 @@ private:
|
||||||
std::string suffix;
|
std::string suffix;
|
||||||
if (stage == ShaderStage::Fragment) {
|
if (stage == ShaderStage::Fragment) {
|
||||||
const auto input_mode{header.ps.GetAttributeUse(generic_index)};
|
const auto input_mode{header.ps.GetAttributeUse(generic_index)};
|
||||||
|
if (skip_unused && input_mode == AttributeUse::Unused) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
suffix = GetInputFlags(input_mode);
|
suffix = GetInputFlags(input_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,11 +471,19 @@ private:
|
||||||
code.AddLine("switch (physical_address) {");
|
code.AddLine("switch (physical_address) {");
|
||||||
|
|
||||||
// Just declare generic attributes for now.
|
// Just declare generic attributes for now.
|
||||||
const auto num_attributes{static_cast<u32>(GetNumPhysicalAttributes())};
|
const auto num_attributes{static_cast<u32>(GetNumPhysicalInputAttributes())};
|
||||||
for (u32 index = 0; index < num_attributes; ++index) {
|
for (u32 index = 0; index < num_attributes; ++index) {
|
||||||
|
const auto attribute{ToGenericAttribute(index)};
|
||||||
for (u32 element = 0; element < 4; ++element) {
|
for (u32 element = 0; element < 4; ++element) {
|
||||||
code.AddLine(fmt::format("case 0x{:x}: return {};", 0x80 + index * 16 + element * 4,
|
constexpr u32 generic_base{0x80};
|
||||||
ReadAttribute(ToGenericAttribute(index), element)));
|
constexpr u32 generic_stride{16};
|
||||||
|
constexpr u32 element_stride{4};
|
||||||
|
const u32 address{generic_base + index * generic_stride + element * element_stride};
|
||||||
|
|
||||||
|
const bool declared{stage != ShaderStage::Fragment ||
|
||||||
|
header.ps.GetAttributeUse(index) != AttributeUse::Unused};
|
||||||
|
const std::string value{declared ? ReadAttribute(attribute, element) : "0"};
|
||||||
|
code.AddLine(fmt::format("case 0x{:x}: return {};", address, value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue