shader_recompiler: Use functions for indirect const buffer accesses
This commit is contained in:
parent
3ac522ba41
commit
e228a40db8
5 changed files with 94 additions and 39 deletions
|
@ -464,6 +464,7 @@ EmitContext::EmitContext(const Profile& profile_, const RuntimeInfo& runtime_inf
|
|||
DefineSharedMemory(program);
|
||||
DefineSharedMemoryFunctions(program);
|
||||
DefineConstantBuffers(program.info, uniform_binding);
|
||||
DefineConstantBufferIndirectFunctions(program.info);
|
||||
DefineStorageBuffers(program.info, storage_binding);
|
||||
DefineTextureBuffers(program.info, texture_binding);
|
||||
DefineImageBuffers(program.info, image_binding);
|
||||
|
@ -1027,6 +1028,69 @@ void EmitContext::DefineConstantBuffers(const Info& info, u32& binding) {
|
|||
binding += static_cast<u32>(info.constant_buffer_descriptors.size());
|
||||
}
|
||||
|
||||
void EmitContext::DefineConstantBufferIndirectFunctions(const Info& info) {
|
||||
if (!info.uses_cbuf_indirect) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto make_accessor{[&](Id buffer_type, Id UniformDefinitions::*member_ptr) {
|
||||
const Id func_type{TypeFunction(buffer_type, U32[1], U32[1])};
|
||||
const Id func{OpFunction(buffer_type, spv::FunctionControlMask::MaskNone, func_type)};
|
||||
const Id binding{OpFunctionParameter(U32[1])};
|
||||
const Id offset{OpFunctionParameter(U32[1])};
|
||||
|
||||
AddLabel();
|
||||
|
||||
const Id merge_label{OpLabel()};
|
||||
const Id uniform_type{uniform_types.*member_ptr};
|
||||
|
||||
std::array<Id, Info::MAX_CBUFS> buf_labels;
|
||||
std::array<Sirit::Literal, Info::MAX_CBUFS> buf_literals;
|
||||
for (u32 i = 0; i < Info::MAX_CBUFS; i++) {
|
||||
buf_labels[i] = OpLabel();
|
||||
buf_literals[i] = Sirit::Literal{i};
|
||||
}
|
||||
|
||||
OpSelectionMerge(merge_label, spv::SelectionControlMask::MaskNone);
|
||||
OpSwitch(binding, buf_labels[0], buf_literals, buf_labels);
|
||||
|
||||
for (u32 i = 0; i < Info::MAX_CBUFS; i++) {
|
||||
AddLabel(buf_labels[i]);
|
||||
const Id cbuf{cbufs[i].*member_ptr};
|
||||
const Id access_chain{OpAccessChain(uniform_type, cbuf, u32_zero_value, offset)};
|
||||
const Id result{OpLoad(buffer_type, access_chain)};
|
||||
OpReturnValue(result);
|
||||
}
|
||||
|
||||
AddLabel(merge_label);
|
||||
OpUnreachable();
|
||||
OpFunctionEnd();
|
||||
|
||||
return func;
|
||||
}};
|
||||
|
||||
IR::Type types{info.used_constant_buffer_types};
|
||||
|
||||
if (True(types & IR::Type::U8)) {
|
||||
load_const_func_u8 = make_accessor(U8, &UniformDefinitions::U8);
|
||||
}
|
||||
if (True(types & IR::Type::U16)) {
|
||||
load_const_func_u16 = make_accessor(U16, &UniformDefinitions::U16);
|
||||
}
|
||||
if (True(types & IR::Type::F32)) {
|
||||
load_const_func_f32 = make_accessor(F32[1], &UniformDefinitions::F32);
|
||||
}
|
||||
if (True(types & IR::Type::U32)) {
|
||||
load_const_func_u32 = make_accessor(U32[1], &UniformDefinitions::U32);
|
||||
}
|
||||
if (True(types & IR::Type::U32x2)) {
|
||||
load_const_func_u32x2 = make_accessor(U32[2], &UniformDefinitions::U32x2);
|
||||
}
|
||||
if (True(types & IR::Type::U32x4)) {
|
||||
load_const_func_u32x4 = make_accessor(U32[4], &UniformDefinitions::U32x4);
|
||||
}
|
||||
}
|
||||
|
||||
void EmitContext::DefineStorageBuffers(const Info& info, u32& binding) {
|
||||
if (info.storage_buffers_descriptors.empty()) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue