shader_recompiler: Increase push constants user data to full capacity. (#1032)

This commit is contained in:
squidbus 2024-09-23 03:40:33 -07:00 committed by GitHub
parent ee38eec7fe
commit a5001d11a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 4 deletions

View File

@ -333,8 +333,8 @@ void EmitContext::DefineOutputs() {
void EmitContext::DefinePushDataBlock() { void EmitContext::DefinePushDataBlock() {
// Create push constants block for instance steps rates // Create push constants block for instance steps rates
const Id struct_type{ const Id struct_type{Name(
Name(TypeStruct(U32[1], U32[1], U32[4], U32[4], U32[4], U32[4]), "AuxData")}; TypeStruct(U32[1], U32[1], U32[4], U32[4], U32[4], U32[4], U32[4], U32[4]), "AuxData")};
Decorate(struct_type, spv::Decoration::Block); Decorate(struct_type, spv::Decoration::Block);
MemberName(struct_type, 0, "sr0"); MemberName(struct_type, 0, "sr0");
MemberName(struct_type, 1, "sr1"); MemberName(struct_type, 1, "sr1");
@ -342,12 +342,16 @@ void EmitContext::DefinePushDataBlock() {
MemberName(struct_type, 3, "buf_offsets1"); MemberName(struct_type, 3, "buf_offsets1");
MemberName(struct_type, 4, "ud_regs0"); MemberName(struct_type, 4, "ud_regs0");
MemberName(struct_type, 5, "ud_regs1"); MemberName(struct_type, 5, "ud_regs1");
MemberName(struct_type, 6, "ud_regs2");
MemberName(struct_type, 7, "ud_regs3");
MemberDecorate(struct_type, 0, spv::Decoration::Offset, 0U); MemberDecorate(struct_type, 0, spv::Decoration::Offset, 0U);
MemberDecorate(struct_type, 1, spv::Decoration::Offset, 4U); MemberDecorate(struct_type, 1, spv::Decoration::Offset, 4U);
MemberDecorate(struct_type, 2, spv::Decoration::Offset, 8U); MemberDecorate(struct_type, 2, spv::Decoration::Offset, 8U);
MemberDecorate(struct_type, 3, spv::Decoration::Offset, 24U); MemberDecorate(struct_type, 3, spv::Decoration::Offset, 24U);
MemberDecorate(struct_type, 4, spv::Decoration::Offset, 40U); MemberDecorate(struct_type, 4, spv::Decoration::Offset, 40U);
MemberDecorate(struct_type, 5, spv::Decoration::Offset, 56U); MemberDecorate(struct_type, 5, spv::Decoration::Offset, 56U);
MemberDecorate(struct_type, 6, spv::Decoration::Offset, 72U);
MemberDecorate(struct_type, 7, spv::Decoration::Offset, 88U);
push_data_block = DefineVar(struct_type, spv::StorageClass::PushConstant); push_data_block = DefineVar(struct_type, spv::StorageClass::PushConstant);
Name(push_data_block, "push_data"); Name(push_data_block, "push_data");
interfaces.push_back(push_data_block); interfaces.push_back(push_data_block);

View File

@ -88,18 +88,19 @@ using SamplerResourceList = boost::container::small_vector<SamplerResource, 16>;
struct PushData { struct PushData {
static constexpr u32 BufOffsetIndex = 2; static constexpr u32 BufOffsetIndex = 2;
static constexpr u32 UdRegsIndex = 4; static constexpr u32 UdRegsIndex = 4;
static constexpr u32 MaxUdRegs = 8;
u32 step0; u32 step0;
u32 step1; u32 step1;
std::array<u8, 32> buf_offsets; std::array<u8, 32> buf_offsets;
std::array<u32, MaxUdRegs> ud_regs; std::array<u32, NumUserDataRegs> ud_regs;
void AddOffset(u32 binding, u32 offset) { void AddOffset(u32 binding, u32 offset) {
ASSERT(offset < 256 && binding < buf_offsets.size()); ASSERT(offset < 256 && binding < buf_offsets.size());
buf_offsets[binding] = offset; buf_offsets[binding] = offset;
} }
}; };
static_assert(sizeof(PushData) <= 128,
"PushData size is greater than minimum size guaranteed by Vulkan spec");
/** /**
* Contains general information generated by the shader recompiler for an input program. * Contains general information generated by the shader recompiler for an input program.
@ -216,6 +217,7 @@ struct Info {
u32 mask = ud_mask.mask; u32 mask = ud_mask.mask;
while (mask) { while (mask) {
const u32 index = std::countr_zero(mask); const u32 index = std::countr_zero(mask);
ASSERT(bnd.user_data < NumUserDataRegs && index < NumUserDataRegs);
mask &= ~(1U << index); mask &= ~(1U << index);
push.ud_regs[bnd.user_data++] = user_data[index]; push.ud_regs[bnd.user_data++] = user_data[index];
} }