mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-05 19:46:15 +01:00
[dxvk] Rework binding ID patching
This commit is contained in:
parent
955e0cca62
commit
d65ceb82cf
@ -100,15 +100,32 @@ namespace dxvk {
|
|||||||
|
|
||||||
// Run an analysis pass over the SPIR-V code to gather some
|
// Run an analysis pass over the SPIR-V code to gather some
|
||||||
// info that we may need during pipeline compilation.
|
// info that we may need during pipeline compilation.
|
||||||
|
std::vector<BindingOffsets> bindingOffsets;
|
||||||
|
std::vector<ConstOffsets> constIdOffsets;
|
||||||
|
std::vector<uint32_t> varIds;
|
||||||
|
|
||||||
SpirvCodeBuffer code = std::move(spirv);
|
SpirvCodeBuffer code = std::move(spirv);
|
||||||
uint32_t o1VarId = 0;
|
uint32_t o1VarId = 0;
|
||||||
|
|
||||||
for (auto ins : code) {
|
for (auto ins : code) {
|
||||||
if (ins.opCode() == spv::OpDecorate) {
|
if (ins.opCode() == spv::OpDecorate) {
|
||||||
if (ins.arg(2) == spv::DecorationBinding
|
if (ins.arg(2) == spv::DecorationBinding) {
|
||||||
|| ins.arg(2) == spv::DecorationSpecId)
|
uint32_t varId = ins.arg(1);
|
||||||
m_idOffsets.push_back(ins.offset() + 3);
|
bindingOffsets.resize(std::max(bindingOffsets.size(), size_t(varId + 1)));
|
||||||
|
bindingOffsets[varId].bindingId = ins.arg(3);
|
||||||
|
bindingOffsets[varId].bindingOffset = ins.offset() + 3;
|
||||||
|
varIds.push_back(varId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ins.arg(2) == spv::DecorationDescriptorSet) {
|
||||||
|
uint32_t varId = ins.arg(1);
|
||||||
|
bindingOffsets.resize(std::max(bindingOffsets.size(), size_t(varId + 1)));
|
||||||
|
bindingOffsets[varId].setOffset = ins.offset() + 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ins.arg(2) == spv::DecorationSpecId)
|
||||||
|
constIdOffsets.push_back({ ins.arg(3), ins.offset() + 3 });
|
||||||
|
|
||||||
if (ins.arg(2) == spv::DecorationLocation && ins.arg(3) == 1) {
|
if (ins.arg(2) == spv::DecorationLocation && ins.arg(3) == 1) {
|
||||||
m_o1LocOffset = ins.offset() + 3;
|
m_o1LocOffset = ins.offset() + 3;
|
||||||
o1VarId = ins.arg(1);
|
o1VarId = ins.arg(1);
|
||||||
@ -133,6 +150,25 @@ namespace dxvk {
|
|||||||
if (ins.arg(1) == spv::CapabilityShaderViewportIndexLayerEXT)
|
if (ins.arg(1) == spv::CapabilityShaderViewportIndexLayerEXT)
|
||||||
m_flags.set(DxvkShaderFlag::ExportsViewportIndexLayerFromVertexStage);
|
m_flags.set(DxvkShaderFlag::ExportsViewportIndexLayerFromVertexStage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ignore the actual shader code, there's nothing interesting for us in there.
|
||||||
|
if (ins.opCode() == spv::OpFunction)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combine spec constant IDs with other binding info
|
||||||
|
for (auto varId : varIds) {
|
||||||
|
BindingOffsets info = bindingOffsets[varId];
|
||||||
|
|
||||||
|
for (const auto& specOfs : constIdOffsets) {
|
||||||
|
if (info.bindingId == specOfs.bindingId) {
|
||||||
|
info.constIdOffset = specOfs.constIdOffset;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info.bindingOffset)
|
||||||
|
m_bindingOffsets.push_back(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,9 +199,15 @@ namespace dxvk {
|
|||||||
uint32_t* code = spirvCode.data();
|
uint32_t* code = spirvCode.data();
|
||||||
|
|
||||||
// Remap resource binding IDs
|
// Remap resource binding IDs
|
||||||
for (uint32_t ofs : m_idOffsets) {
|
for (const auto& info : m_bindingOffsets) {
|
||||||
if (code[ofs] < MaxNumResourceSlots)
|
uint32_t mappedBinding = mapping.getBindingId(info.bindingId);
|
||||||
code[ofs] = mapping.getBindingId(code[ofs]);
|
code[info.bindingOffset] = mappedBinding;
|
||||||
|
|
||||||
|
if (info.constIdOffset)
|
||||||
|
code[info.constIdOffset] = mappedBinding;
|
||||||
|
|
||||||
|
if (code[info.setOffset])
|
||||||
|
code[info.setOffset] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For dual-source blending we need to re-map
|
// For dual-source blending we need to re-map
|
||||||
|
@ -209,7 +209,19 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
struct ConstOffsets {
|
||||||
|
uint32_t bindingId;
|
||||||
|
uint32_t constIdOffset;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BindingOffsets {
|
||||||
|
uint32_t bindingId;
|
||||||
|
uint32_t constIdOffset;
|
||||||
|
uint32_t bindingOffset;
|
||||||
|
uint32_t setOffset;
|
||||||
|
};
|
||||||
|
|
||||||
DxvkShaderCreateInfo m_info;
|
DxvkShaderCreateInfo m_info;
|
||||||
SpirvCompressedBuffer m_code;
|
SpirvCompressedBuffer m_code;
|
||||||
|
|
||||||
@ -222,7 +234,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
std::vector<DxvkResourceSlot> m_slots;
|
std::vector<DxvkResourceSlot> m_slots;
|
||||||
std::vector<char> m_uniformData;
|
std::vector<char> m_uniformData;
|
||||||
std::vector<size_t> m_idOffsets;
|
std::vector<BindingOffsets> m_bindingOffsets;
|
||||||
|
|
||||||
DxvkBindingLayout m_bindings;
|
DxvkBindingLayout m_bindings;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user