1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-13 07:08:50 +01:00

[dxvk] Change descriptor info to take only one shader stage

And fix the binding index -> descriptor mapping.
This affects D3D9 since the spec constant change.
This commit is contained in:
Philip Rebohle 2022-08-17 22:39:52 +02:00
parent 3c2fc41e4c
commit 3806bd44d8
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
9 changed files with 60 additions and 35 deletions

View File

@ -329,10 +329,10 @@ namespace dxvk {
SpirvCodeBuffer fsCode(d3d11_video_blit_frag);
const std::array<DxvkBindingInfo, 4> fsBindings = {{
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, VK_IMAGE_VIEW_TYPE_MAX_ENUM, 0, VK_ACCESS_UNIFORM_READ_BIT },
{ VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_IMAGE_VIEW_TYPE_MAX_ENUM, 0, 0 },
{ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 2, VK_IMAGE_VIEW_TYPE_2D, 0, VK_ACCESS_SHADER_READ_BIT },
{ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 3, VK_IMAGE_VIEW_TYPE_2D, 0, VK_ACCESS_SHADER_READ_BIT },
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, VK_IMAGE_VIEW_TYPE_MAX_ENUM, VK_SHADER_STAGE_FRAGMENT_BIT, VK_ACCESS_UNIFORM_READ_BIT },
{ VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_IMAGE_VIEW_TYPE_MAX_ENUM, VK_SHADER_STAGE_FRAGMENT_BIT, 0 },
{ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 2, VK_IMAGE_VIEW_TYPE_2D, VK_SHADER_STAGE_FRAGMENT_BIT, VK_ACCESS_SHADER_READ_BIT },
{ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 3, VK_IMAGE_VIEW_TYPE_2D, VK_SHADER_STAGE_FRAGMENT_BIT, VK_ACCESS_SHADER_READ_BIT },
}};
DxvkShaderCreateInfo vsInfo;

View File

@ -120,8 +120,8 @@ namespace dxvk {
Rc<DxvkShader> D3D9FormatHelper::InitShader(SpirvCodeBuffer code) {
const std::array<DxvkBindingInfo, 2> bindings = { {
{ VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, BindingIds::Image, VK_IMAGE_VIEW_TYPE_2D, 0, VK_ACCESS_SHADER_WRITE_BIT },
{ VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, BindingIds::Buffer, VK_IMAGE_VIEW_TYPE_1D, 0, VK_ACCESS_SHADER_READ_BIT },
{ VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, BindingIds::Image, VK_IMAGE_VIEW_TYPE_2D, VK_SHADER_STAGE_COMPUTE_BIT, VK_ACCESS_SHADER_WRITE_BIT },
{ VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, BindingIds::Buffer, VK_IMAGE_VIEW_TYPE_1D, VK_SHADER_STAGE_COMPUTE_BIT, VK_ACCESS_SHADER_READ_BIT },
} };
DxvkShaderCreateInfo info;

View File

@ -133,8 +133,8 @@ namespace dxvk {
m_bufferBinding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
m_bufferBinding.viewType = VK_IMAGE_VIEW_TYPE_MAX_ENUM;
m_bufferBinding.resourceBinding = bufferSlot;
m_bufferBinding.stage = VK_SHADER_STAGE_GEOMETRY_BIT;
m_bufferBinding.access = VK_ACCESS_SHADER_WRITE_BIT;
m_bufferBinding.stages = 0;
// Load our builtins
uint32_t primitiveIdPtr = m_module.newVar(m_module.defPointerType(uint_t, spv::StorageClassInput), spv::StorageClassInput);

View File

@ -5581,7 +5581,7 @@ namespace dxvk {
if ((slot.bufferSlice.length())
&& (slot.bufferSlice.bufferInfo().access & storageBufferAccess)) {
requiresBarrier = this->checkBufferBarrier<DoEmit>(slot.bufferSlice,
util::pipelineStages(binding.stages), binding.access);
util::pipelineStages(binding.stage), binding.access);
}
break;
@ -5591,7 +5591,7 @@ namespace dxvk {
&& (slot.bufferView->bufferInfo().access & storageBufferAccess)) {
slot.bufferView->updateView();
requiresBarrier = this->checkBufferViewBarrier<DoEmit>(slot.bufferView,
util::pipelineStages(binding.stages), binding.access);
util::pipelineStages(binding.stage), binding.access);
}
break;
@ -5601,7 +5601,7 @@ namespace dxvk {
if ((slot.imageView != nullptr)
&& (slot.imageView->imageInfo().access & storageImageAccess)) {
requiresBarrier = this->checkImageViewBarrier<DoEmit>(slot.imageView,
util::pipelineStages(binding.stages), binding.access);
util::pipelineStages(binding.stage), binding.access);
}
break;

View File

@ -9,10 +9,10 @@
namespace dxvk {
uint32_t DxvkBindingInfo::computeSetIndex() const {
if (stages & VK_SHADER_STAGE_COMPUTE_BIT) {
if (stage == VK_SHADER_STAGE_COMPUTE_BIT) {
// Use one single set for compute shaders
return DxvkDescriptorSets::CsAll;
} else if (stages & VK_SHADER_STAGE_FRAGMENT_BIT) {
} else if (stage == VK_SHADER_STAGE_FRAGMENT_BIT) {
// For fragment shaders, create a separate set for UBOs
if (descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
|| descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)
@ -37,17 +37,17 @@ namespace dxvk {
return descriptorType == other.descriptorType
&& resourceBinding == other.resourceBinding
&& viewType == other.viewType
&& stages == other.stages
&& stage == other.stage
&& access == other.access;
}
size_t DxvkBindingInfo::hash() const {
DxvkHashState hash;
hash.add(descriptorType);
hash.add(uint32_t(descriptorType));
hash.add(resourceBinding);
hash.add(viewType);
hash.add(stages);
hash.add(uint32_t(viewType));
hash.add(uint32_t(stage));
hash.add(access);
return hash;
}
@ -107,7 +107,7 @@ namespace dxvk {
for (uint32_t i = 0; i < list.getBindingCount(); i++) {
m_bindings[i].descriptorType = list.getBinding(i).descriptorType;
m_bindings[i].stages = list.getBinding(i).stages;
m_bindings[i].stages = list.getBinding(i).stage;
}
}
@ -315,11 +315,15 @@ namespace dxvk {
for (uint32_t j = 0; j < bindingCount; j++) {
const DxvkBindingInfo& binding = m_layout.getBinding(i, j);
DxvkBindingKey key;
key.stage = binding.stage;
key.binding = binding.resourceBinding;
DxvkBindingMapping mapping;
mapping.set = i;
mapping.binding = j;
m_mapping.insert({ binding.resourceBinding, mapping });
m_mapping.insert({ key, mapping });
}
if (bindingCount) {
@ -372,7 +376,7 @@ namespace dxvk {
for (uint32_t i = 0; i < DxvkDescriptorSets::SetCount; i++) {
for (uint32_t j = 0; j < m_layout.getBindingCount(i); j++) {
const auto& binding = m_layout.getBinding(i, j);
barrier.stages |= util::pipelineStages(binding.stages);
barrier.stages |= util::pipelineStages(binding.stage);
barrier.access |= binding.access;
}
}

View File

@ -31,11 +31,11 @@ namespace dxvk {
* a given shader, or for the whole pipeline.
*/
struct DxvkBindingInfo {
VkDescriptorType descriptorType; ///< Vulkan descriptor type
uint32_t resourceBinding; ///< API binding slot for the resource
VkImageViewType viewType; ///< Image view type
VkShaderStageFlags stages; ///< Shader stage mask
VkAccessFlags access; ///< Access mask for the resource
VkDescriptorType descriptorType; ///< Vulkan descriptor type
uint32_t resourceBinding; ///< API binding slot for the resource
VkImageViewType viewType; ///< Image view type
VkShaderStageFlagBits stage; ///< Shader stage
VkAccessFlags access; ///< Access mask for the resource
/**
* \brief Computes descriptor set index for the given binding
@ -364,6 +364,25 @@ namespace dxvk {
uint32_t binding;
};
/**
* \brief Key for binding lookups
*/
struct DxvkBindingKey {
VkShaderStageFlagBits stage;
uint32_t binding;
size_t hash() const {
DxvkHashState hash;
hash.add(uint32_t(stage));
hash.add(binding);
return hash;
}
bool eq(const DxvkBindingKey& other) const {
return stage == other.stage && binding == other.binding;
}
};
/**
* \brief Global resource barrier
*
@ -453,11 +472,13 @@ namespace dxvk {
/**
* \brief Looks up set and binding number by resource binding
*
* \param [in] stage Shader stage
* \param [in] index Resource binding index
* \returns Descriptor set and binding number
*/
std::optional<DxvkBindingMapping> lookupBinding(uint32_t index) const {
auto entry = m_mapping.find(index);
std::optional<DxvkBindingMapping> lookupBinding(VkShaderStageFlagBits stage, uint32_t index) const {
DxvkBindingKey key = { stage, index };
auto entry = m_mapping.find(key);
if (entry != m_mapping.end())
return entry->second;
@ -487,7 +508,7 @@ namespace dxvk {
std::array<const DxvkBindingSetLayout*, DxvkDescriptorSets::SetCount> m_bindingObjects = { };
std::unordered_map<uint32_t, DxvkBindingMapping> m_mapping;
std::unordered_map<DxvkBindingKey, DxvkBindingMapping, DxvkHash, DxvkEq> m_mapping;
};

View File

@ -53,7 +53,7 @@ namespace dxvk {
// Copy resource binding slot infos
for (uint32_t i = 0; i < info.bindingCount; i++) {
DxvkBindingInfo binding = info.bindings[i];
binding.stages = info.stage;
binding.stage = info.stage;
m_bindings.addBinding(binding);
}
@ -172,7 +172,7 @@ namespace dxvk {
// Remap resource binding IDs
for (const auto& info : m_bindingOffsets) {
auto mappedBinding = layout->lookupBinding(info.bindingId);
auto mappedBinding = layout->lookupBinding(m_info.stage, info.bindingId);
if (mappedBinding) {
code[info.bindingOffset] = mappedBinding->binding;

View File

@ -321,8 +321,8 @@ namespace dxvk {
SpirvCodeBuffer fsCodeResolveAmd(dxvk_present_frag_ms_amd);
const std::array<DxvkBindingInfo, 2> fsBindings = {{
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, BindingIds::Image, VK_IMAGE_VIEW_TYPE_2D, 0, VK_ACCESS_SHADER_READ_BIT },
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, BindingIds::Gamma, VK_IMAGE_VIEW_TYPE_1D, 0, VK_ACCESS_SHADER_READ_BIT },
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, BindingIds::Image, VK_IMAGE_VIEW_TYPE_2D, VK_SHADER_STAGE_FRAGMENT_BIT, VK_ACCESS_SHADER_READ_BIT },
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, BindingIds::Gamma, VK_IMAGE_VIEW_TYPE_1D, VK_SHADER_STAGE_FRAGMENT_BIT, VK_ACCESS_SHADER_READ_BIT },
}};
DxvkShaderCreateInfo vsInfo;

View File

@ -160,12 +160,12 @@ namespace dxvk::hud {
SpirvCodeBuffer fsCode(hud_text_frag);
const std::array<DxvkBindingInfo, 2> vsBindings = {{
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 0, VK_IMAGE_VIEW_TYPE_MAX_ENUM, 0, VK_ACCESS_SHADER_READ_BIT },
{ VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1, VK_IMAGE_VIEW_TYPE_MAX_ENUM, 0, VK_ACCESS_SHADER_READ_BIT },
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 0, VK_IMAGE_VIEW_TYPE_MAX_ENUM, VK_SHADER_STAGE_VERTEX_BIT, VK_ACCESS_SHADER_READ_BIT },
{ VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1, VK_IMAGE_VIEW_TYPE_MAX_ENUM, VK_SHADER_STAGE_VERTEX_BIT, VK_ACCESS_SHADER_READ_BIT },
}};
const std::array<DxvkBindingInfo, 1> fsBindings = {{
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2, VK_IMAGE_VIEW_TYPE_MAX_ENUM, 0, VK_ACCESS_SHADER_READ_BIT },
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2, VK_IMAGE_VIEW_TYPE_MAX_ENUM, VK_SHADER_STAGE_FRAGMENT_BIT, VK_ACCESS_SHADER_READ_BIT },
}};
DxvkShaderCreateInfo vsInfo;
@ -195,7 +195,7 @@ namespace dxvk::hud {
SpirvCodeBuffer fsCode(hud_graph_frag);
const std::array<DxvkBindingInfo, 1> fsBindings = {{
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 0, VK_IMAGE_VIEW_TYPE_MAX_ENUM, 0, VK_ACCESS_SHADER_READ_BIT },
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 0, VK_IMAGE_VIEW_TYPE_MAX_ENUM, VK_SHADER_STAGE_FRAGMENT_BIT, VK_ACCESS_SHADER_READ_BIT },
}};
DxvkShaderCreateInfo vsInfo;