Fix pixel shader input aliases

This commit is contained in:
nmzik
2026-09-15 20:46:51 +04:00
parent 629ae1ac05
commit 441367b1a1
5 changed files with 174 additions and 10 deletions
@@ -388,6 +388,19 @@ void DefineInputs(EmitterState& state) {
}
}
for (auto& input: state.inputs) {
if (state.program.stage == ShaderType::Pixel &&
input.kind == IR::StageInputKind::Parameter) {
const auto location = PixelParameterLocation(state, input.location);
const auto alias = std::ranges::find_if(state.inputs, [&](const InputBinding& other) {
return other.kind == IR::StageInputKind::Parameter && other.variable_id != 0 &&
PixelParameterLocation(state, other.location) == location;
});
if (alias != state.inputs.end()) {
EXIT_IF(alias->per_vertex != input.per_vertex);
input.variable_id = alias->variable_id;
continue;
}
}
uint32_t type = TypeU32(state);
switch (input.kind) {
case IR::StageInputKind::VertexIndex:
@@ -226,6 +226,18 @@ void CollectPixelInputs(const Program& program, const ShaderPixelInputInfo* pixe
}
}
}
// Aliases of a vertex output share one SPIR-V interface variable. If any
// alias reads raw vertices, interpolate the other aliases from those too.
for (uint32_t input = 0; input < pixel->input_num; input++) {
for (uint32_t alias = 0; alias < pixel->input_num; alias++) {
if (ShaderPixelParameterMappedLocation(*pixel, input) ==
ShaderPixelParameterMappedLocation(*pixel, alias) &&
ShaderPixelParameterIsFlat(*pixel, input) ==
ShaderPixelParameterIsFlat(*pixel, alias)) {
per_vertex[input] = per_vertex[input] || per_vertex[alias];
}
}
}
for (uint32_t input = 0; input < pixel->input_num; input++) {
AddInput(info, StageInputKind::Parameter, input, 4, fmt::format("in_param_{}", input),
per_vertex[input]);