mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-02 10:24:12 +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) {
|
: m_stage(stage), m_code(code), m_interface(iface) {
|
||||||
for (uint32_t i = 0; i < slotCount; i++)
|
for (uint32_t i = 0; i < slotCount; i++)
|
||||||
m_slots.push_back(slotInfos[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(
|
Rc<DxvkShaderModule> DxvkShader::createShaderModule(
|
||||||
const Rc<vk::DeviceFn>& vkd,
|
const Rc<vk::DeviceFn>& vkd,
|
||||||
const DxvkDescriptorSlotMapping& mapping) const {
|
const DxvkDescriptorSlotMapping& mapping) const {
|
||||||
// Iterate over the code and replace every resource slot
|
|
||||||
// index with the corresponding mapped binding index.
|
|
||||||
SpirvCodeBuffer spirvCode = m_code;
|
SpirvCodeBuffer spirvCode = m_code;
|
||||||
|
|
||||||
for (auto ins : spirvCode) {
|
// Remap resource binding IDs
|
||||||
if (ins.opCode() == spv::OpDecorate
|
uint32_t* code = spirvCode.data();
|
||||||
&& ((ins.arg(2) == spv::DecorationBinding)
|
for (uint32_t ofs : m_idOffsets)
|
||||||
|| (ins.arg(2) == spv::DecorationSpecId))) {
|
code[ofs] = mapping.getBindingId(code[ofs]);
|
||||||
|
|
||||||
const uint32_t oldBinding = ins.arg(3);
|
|
||||||
const uint32_t newBinding = mapping.getBindingId(oldBinding);
|
|
||||||
ins.setArg(3, newBinding);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new DxvkShaderModule(vkd, m_stage, spirvCode, m_debugName);
|
return new DxvkShaderModule(vkd, m_stage, spirvCode, m_debugName);
|
||||||
}
|
}
|
||||||
|
@ -176,6 +176,7 @@ namespace dxvk {
|
|||||||
SpirvCodeBuffer m_code;
|
SpirvCodeBuffer m_code;
|
||||||
|
|
||||||
std::vector<DxvkResourceSlot> m_slots;
|
std::vector<DxvkResourceSlot> m_slots;
|
||||||
|
std::vector<size_t> m_idOffsets;
|
||||||
DxvkInterfaceSlots m_interface;
|
DxvkInterfaceSlots m_interface;
|
||||||
std::string m_debugName;
|
std::string m_debugName;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user