mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-11-30 04:24:11 +01:00
[dxvk] Optimize binding ID remapping
We don't need to iterate over the full shader code when creating a new shader module. This optimization may slightly reduce the initial pipeline creation time.
This commit is contained in:
parent
5d1642af1f
commit
a28303c4bd
@ -49,6 +49,15 @@ namespace dxvk {
|
||||
: m_stage(stage), m_code(code), m_interface(iface) {
|
||||
for (uint32_t i = 0; i < slotCount; i++)
|
||||
m_slots.push_back(slotInfos[i]);
|
||||
|
||||
// Gather the offsets where the binding IDs
|
||||
// are stored so we can quickly remap them.
|
||||
for (auto ins : m_code) {
|
||||
if (ins.opCode() == spv::OpDecorate
|
||||
&& ((ins.arg(2) == spv::DecorationBinding)
|
||||
|| (ins.arg(2) == spv::DecorationSpecId)))
|
||||
m_idOffsets.push_back(ins.offset() + 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -81,20 +90,12 @@ namespace dxvk {
|
||||
Rc<DxvkShaderModule> DxvkShader::createShaderModule(
|
||||
const Rc<vk::DeviceFn>& vkd,
|
||||
const DxvkDescriptorSlotMapping& mapping) const {
|
||||
// Iterate over the code and replace every resource slot
|
||||
// index with the corresponding mapped binding index.
|
||||
SpirvCodeBuffer spirvCode = m_code;
|
||||
|
||||
for (auto ins : spirvCode) {
|
||||
if (ins.opCode() == spv::OpDecorate
|
||||
&& ((ins.arg(2) == spv::DecorationBinding)
|
||||
|| (ins.arg(2) == spv::DecorationSpecId))) {
|
||||
|
||||
const uint32_t oldBinding = ins.arg(3);
|
||||
const uint32_t newBinding = mapping.getBindingId(oldBinding);
|
||||
ins.setArg(3, newBinding);
|
||||
}
|
||||
}
|
||||
// Remap resource binding IDs
|
||||
uint32_t* code = spirvCode.data();
|
||||
for (uint32_t ofs : m_idOffsets)
|
||||
code[ofs] = mapping.getBindingId(code[ofs]);
|
||||
|
||||
return new DxvkShaderModule(vkd, m_stage, spirvCode, m_debugName);
|
||||
}
|
||||
|
@ -176,6 +176,7 @@ namespace dxvk {
|
||||
SpirvCodeBuffer m_code;
|
||||
|
||||
std::vector<DxvkResourceSlot> m_slots;
|
||||
std::vector<size_t> m_idOffsets;
|
||||
DxvkInterfaceSlots m_interface;
|
||||
std::string m_debugName;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user