shader compiler: Ensure all clip distances are initialized when used

Thank you to Ryujinx (riperiperi specifically) for the pointer towards clip distances
Huge thanks to crueter for finding where the code works and Camille for giving pointers along the way.
This commit is contained in:
JPikachu 2025-04-21 03:04:31 +01:00 committed by swurl
parent 609f5e48e0
commit fc1a3b6310
4 changed files with 46 additions and 18 deletions

View file

@ -53,6 +53,15 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) {
return OutputAccessChain(ctx, ctx.output_f32, info.id, index_id);
}
}
for (u32 i = 0; i < ctx.profile.max_user_clip_distances; ++i) {
if (!clip_distance_written.test(i)) {
const Id idx = ctx.Const(i);
const Id element = OutputAccessChain(ctx, ctx.output_f32, ctx.clip_distances, idx);
ctx.OpStore(element, ctx.Const(0.0f));
}
}
switch (attr) {
case IR::Attribute::PointSize:
return ctx.output_point_size;
@ -421,6 +430,14 @@ void EmitSetAttribute(EmitContext& ctx, IR::Attribute attr, Id value, [[maybe_un
if (Sirit::ValidId(output->type)) {
value = ctx.OpBitcast(output->type, value);
}
static constexpr IR::Attribute cd0 = IR::Attribute::ClipDistance0;
static constexpr IR::Attribute cd7 = IR::Attribute::ClipDistance7;
if (attr >= cd0 && attr <= cd7) {
const u32 idx = (u32) attr - (u32) cd0;
clip_distance_written.set(idx);
}
ctx.OpStore(output->pointer, value);
}

View file

@ -108,7 +108,7 @@ void EmitPrologue(EmitContext& ctx) {
ctx.OpStore(element_info.id, value);
element += num;
}
}
}
}
if (ctx.stage == Stage::VertexB || ctx.stage == Stage::Geometry) {
SetFixedPipelinePointSize(ctx);

View file

@ -15,6 +15,8 @@
namespace Shader::Backend::SPIRV {
std::bitset<8> clip_distance_written;
using Sirit::Id;
class VectorTypes {