yuzu-emu
/
yuzu-mainline
Archived
1
0
Fork 0

shader/shader_ir: Track usage in input attribute and of legacy varyings

This commit is contained in:
ReinUsesLisp 2020-03-15 21:00:51 -03:00
parent 8e6e55d6f8
commit 6442e02c5d
3 changed files with 64 additions and 34 deletions

View File

@ -82,6 +82,10 @@ union Attribute {
Position = 7, Position = 7,
Attribute_0 = 8, Attribute_0 = 8,
Attribute_31 = 39, Attribute_31 = 39,
FrontColor = 40,
FrontSecondaryColor = 41,
BackColor = 42,
BackSecondaryColor = 43,
ClipDistances0123 = 44, ClipDistances0123 = 44,
ClipDistances4567 = 45, ClipDistances4567 = 45,
PointCoord = 46, PointCoord = 46,
@ -89,6 +93,8 @@ union Attribute {
// shader, and a tuple of (TessCoord.x, TessCoord.y, TessCoord.z, ~) when inside a Tess Eval // shader, and a tuple of (TessCoord.x, TessCoord.y, TessCoord.z, ~) when inside a Tess Eval
// shader. // shader.
TessCoordInstanceIDVertexID = 47, TessCoordInstanceIDVertexID = 47,
TexCoord_0 = 48,
TexCoord_7 = 55,
// This attribute contains a tuple of (Unk, Unk, Unk, gl_FrontFacing) when inside a fragment // This attribute contains a tuple of (Unk, Unk, Unk, gl_FrontFacing) when inside a fragment
// shader. It is unknown what the other values contain. // shader. It is unknown what the other values contain.
FrontFacing = 63, FrontFacing = 63,

View File

@ -96,6 +96,7 @@ Node ShaderIR::GetPredicate(bool immediate) {
} }
Node ShaderIR::GetInputAttribute(Attribute::Index index, u64 element, Node buffer) { Node ShaderIR::GetInputAttribute(Attribute::Index index, u64 element, Node buffer) {
MarkAttributeUsage(index, element);
used_input_attributes.emplace(index); used_input_attributes.emplace(index);
return MakeNode<AbufNode>(index, static_cast<u32>(element), std::move(buffer)); return MakeNode<AbufNode>(index, static_cast<u32>(element), std::move(buffer));
} }
@ -106,40 +107,7 @@ Node ShaderIR::GetPhysicalInputAttribute(Tegra::Shader::Register physical_addres
} }
Node ShaderIR::GetOutputAttribute(Attribute::Index index, u64 element, Node buffer) { Node ShaderIR::GetOutputAttribute(Attribute::Index index, u64 element, Node buffer) {
switch (index) { MarkAttributeUsage(index, element);
case Attribute::Index::LayerViewportPointSize:
switch (element) {
case 0:
UNIMPLEMENTED();
break;
case 1:
uses_layer = true;
break;
case 2:
uses_viewport_index = true;
break;
case 3:
uses_point_size = true;
break;
}
break;
case Attribute::Index::TessCoordInstanceIDVertexID:
switch (element) {
case 2:
uses_instance_id = true;
break;
case 3:
uses_vertex_id = true;
break;
}
break;
case Attribute::Index::ClipDistances0123:
case Attribute::Index::ClipDistances4567: {
const u64 clip_index = (index == Attribute::Index::ClipDistances4567 ? 4 : 0) + element;
used_clip_distances.at(clip_index) = true;
break;
}
}
used_output_attributes.insert(index); used_output_attributes.insert(index);
return MakeNode<AbufNode>(index, static_cast<u32>(element), std::move(buffer)); return MakeNode<AbufNode>(index, static_cast<u32>(element), std::move(buffer));
} }
@ -451,6 +419,54 @@ Node ShaderIR::BitfieldInsert(Node base, Node insert, u32 offset, u32 bits) {
Immediate(bits)); Immediate(bits));
} }
void ShaderIR::MarkAttributeUsage(Attribute::Index index, u64 element) {
switch (index) {
case Attribute::Index::LayerViewportPointSize:
switch (element) {
case 0:
UNIMPLEMENTED();
break;
case 1:
uses_layer = true;
break;
case 2:
uses_viewport_index = true;
break;
case 3:
uses_point_size = true;
break;
}
break;
case Attribute::Index::TessCoordInstanceIDVertexID:
switch (element) {
case 2:
uses_instance_id = true;
break;
case 3:
uses_vertex_id = true;
break;
}
break;
case Attribute::Index::ClipDistances0123:
case Attribute::Index::ClipDistances4567: {
const u64 clip_index = (index == Attribute::Index::ClipDistances4567 ? 4 : 0) + element;
used_clip_distances.at(clip_index) = true;
break;
}
case Attribute::Index::FrontColor:
case Attribute::Index::FrontSecondaryColor:
case Attribute::Index::BackColor:
case Attribute::Index::BackSecondaryColor:
uses_legacy_varyings = true;
break;
default:
if (index >= Attribute::Index::TexCoord_0 && index <= Attribute::Index::TexCoord_7) {
uses_legacy_varyings = true;
}
break;
}
}
std::size_t ShaderIR::DeclareAmend(Node new_amend) { std::size_t ShaderIR::DeclareAmend(Node new_amend) {
const std::size_t id = amend_code.size(); const std::size_t id = amend_code.size();
amend_code.push_back(new_amend); amend_code.push_back(new_amend);

View File

@ -137,6 +137,10 @@ public:
return uses_vertex_id; return uses_vertex_id;
} }
bool UsesLegacyVaryings() const {
return uses_legacy_varyings;
}
bool UsesWarps() const { bool UsesWarps() const {
return uses_warps; return uses_warps;
} }
@ -343,6 +347,9 @@ private:
/// Inserts a sequence of bits from a node /// Inserts a sequence of bits from a node
Node BitfieldInsert(Node base, Node insert, u32 offset, u32 bits); Node BitfieldInsert(Node base, Node insert, u32 offset, u32 bits);
/// Marks the usage of a input or output attribute.
void MarkAttributeUsage(Tegra::Shader::Attribute::Index index, u64 element);
void WriteTexInstructionFloat(NodeBlock& bb, Tegra::Shader::Instruction instr, void WriteTexInstructionFloat(NodeBlock& bb, Tegra::Shader::Instruction instr,
const Node4& components); const Node4& components);
@ -443,6 +450,7 @@ private:
bool uses_physical_attributes{}; // Shader uses AL2P or physical attribute read/writes bool uses_physical_attributes{}; // Shader uses AL2P or physical attribute read/writes
bool uses_instance_id{}; bool uses_instance_id{};
bool uses_vertex_id{}; bool uses_vertex_id{};
bool uses_legacy_varyings{};
bool uses_warps{}; bool uses_warps{};
bool uses_indexed_samplers{}; bool uses_indexed_samplers{};