Skip to content

Commit d2255e9

Browse files
committed
better solution for patch attr locations. Trees still broken
1 parent 3ce8976 commit d2255e9

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/shader_recompiler/backend/spirv/spirv_emit_context.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -379,16 +379,12 @@ void EmitContext::DefineInputs() {
379379
input_params[i] = {id, input_f32, F32[1], 4};
380380
}
381381

382+
u32 patch_base_location = runtime_info.vs_info.hs_output_cp_stride >> 4;
382383
for (size_t index = 0; index < 30; ++index) {
383384
if (!(info.uses_patches & (1U << index))) {
384385
continue;
385386
}
386-
const Id id{
387-
DefineInput(F32[4], 31 - index)}; // TODO: this should usually work, but might
388-
// overlap with per-vertex outputs.
389-
// Safer solution might require recompiling for every hull/domain permutation to make
390-
// sure patch variables match in location
391-
Decorate(id, spv::Decoration::Patch);
387+
const Id id{DefineInput(F32[4], patch_base_location + index)};
392388
Name(id, fmt::format("patch_in{}", index));
393389
patches[index] = id;
394390
}
@@ -456,14 +452,12 @@ void EmitContext::DefineOutputs() {
456452
output_params[i] = {id, output_f32, F32[1], 4};
457453
}
458454

459-
// TODO is it ok to share output locations between patch consts and
460-
// per-vertex output attrs?
461-
// spirv-val doesn't complain so idk
455+
u32 patch_base_location = runtime_info.hs_info.hs_output_cp_stride >> 4;
462456
for (size_t index = 0; index < 30; ++index) {
463457
if (!(info.uses_patches & (1U << index))) {
464458
continue;
465459
}
466-
const Id id{DefineOutput(F32[4], 31 - index)};
460+
const Id id{DefineOutput(F32[4], patch_base_location + index)};
467461
Decorate(id, spv::Decoration::Patch);
468462
Name(id, fmt::format("patch_out{}", index));
469463
patches[index] = id;

src/shader_recompiler/runtime_info.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct HullRuntimeInfo {
101101

102102
// from tess constants buffer
103103
u32 ls_stride;
104-
u32 hs_cp_stride;
104+
u32 hs_output_cp_stride;
105105
u32 hs_num_patch;
106106
u32 hs_output_base;
107107
u32 patch_const_size;
@@ -117,7 +117,7 @@ struct HullRuntimeInfo {
117117

118118
void InitFromTessConstants(Shader::TessellationDataConstantBuffer& tess_constants) {
119119
ls_stride = tess_constants.m_lsStride;
120-
hs_cp_stride = tess_constants.m_hsCpStride;
120+
hs_output_cp_stride = tess_constants.m_hsCpStride;
121121
hs_num_patch = tess_constants.m_hsNumPatch;
122122
hs_output_base = tess_constants.m_hsOutputBase;
123123
patch_const_size = tess_constants.m_patchConstSize;

0 commit comments

Comments
 (0)