1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-29 17:52:18 +01:00

[dxvk] Moved descriptor set updates into DxvkContext

This commit is contained in:
Philip Rebohle 2018-01-11 20:31:18 +01:00
parent 30eb43a284
commit a875e045c5
3 changed files with 49 additions and 61 deletions

View File

@ -88,52 +88,6 @@ namespace dxvk {
}
void DxvkCommandList::bindResourceDescriptors(
VkPipelineBindPoint pipeline,
VkPipelineLayout pipelineLayout,
VkDescriptorSetLayout descriptorLayout,
uint32_t descriptorCount,
const DxvkDescriptorSlot* descriptorSlots,
const DxvkDescriptorInfo* descriptorInfos,
const DxvkBindingState& bindingState) {
// Allocate a new descriptor set
VkDescriptorSet dset = m_descAlloc.alloc(descriptorLayout);
// Write data to the descriptor set
std::array<VkWriteDescriptorSet, MaxNumResourceSlots> descriptorWrites;
uint32_t writeId = 0;
for (uint32_t i = 0; i < descriptorCount; i++) {
if (bindingState.isBound(i)) {
auto& curr = descriptorWrites[writeId++];
auto& binding = descriptorSlots[i];
curr.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
curr.pNext = nullptr;
curr.dstSet = dset;
curr.dstBinding = i;
curr.dstArrayElement = 0;
curr.descriptorCount = 1;
curr.descriptorType = binding.type;
curr.pImageInfo = &descriptorInfos[i].image;
curr.pBufferInfo = &descriptorInfos[i].buffer;
curr.pTexelBufferView = &descriptorInfos[i].texelBuffer;
}
}
m_vkd->vkUpdateDescriptorSets(
m_vkd->device(), writeId,
descriptorWrites.data(),
0, nullptr);
// Bind descriptor set to the pipeline
m_vkd->vkCmdBindDescriptorSets(m_buffer,
pipeline, pipelineLayout, 0, 1,
&dset, 0, nullptr);
}
DxvkStagingBufferSlice DxvkCommandList::stagedAlloc(VkDeviceSize size) {
return m_stagingAlloc.alloc(size);
}

View File

@ -82,14 +82,19 @@ namespace dxvk {
*/
void reset();
void bindResourceDescriptors(
VkPipelineBindPoint pipeline,
VkPipelineLayout pipelineLayout,
VkDescriptorSetLayout descriptorLayout,
VkDescriptorSet allocateDescriptorSet(
VkDescriptorSetLayout descriptorLayout) {
return m_descAlloc.alloc(descriptorLayout);
}
void updateDescriptorSet(
uint32_t descriptorCount,
const DxvkDescriptorSlot* descriptorSlots,
const DxvkDescriptorInfo* descriptorInfos,
const DxvkBindingState& bindingState);
const VkWriteDescriptorSet* descriptorWrites) {
m_vkd->vkUpdateDescriptorSets(m_vkd->device(),
descriptorCount, descriptorWrites, 0, nullptr);
}
void cmdBeginRenderPass(
const VkRenderPassBeginInfo* pRenderPassBegin,
@ -99,6 +104,16 @@ namespace dxvk {
}
void cmdBindDescriptorSet(
VkPipelineBindPoint pipeline,
VkPipelineLayout pipelineLayout,
VkDescriptorSet descriptorSet) {
m_vkd->vkCmdBindDescriptorSets(m_buffer,
pipeline, pipelineLayout, 0, 1,
&descriptorSet, 0, nullptr);
}
void cmdBindIndexBuffer(
VkBuffer buffer,
VkDeviceSize offset,

View File

@ -1130,14 +1130,33 @@ namespace dxvk {
VkPipelineBindPoint bindPoint,
const DxvkBindingState& bindingState,
const Rc<DxvkBindingLayout>& layout) {
m_cmd->bindResourceDescriptors(
bindPoint,
layout->pipelineLayout(),
layout->descriptorSetLayout(),
layout->bindingCount(),
layout->bindings(),
m_descriptors.data(),
bindingState);
std::array<VkWriteDescriptorSet, MaxNumResourceSlots> writes;
const VkDescriptorSet dset =
m_cmd->allocateDescriptorSet(
layout->descriptorSetLayout());
size_t writeId = 0;
for (uint32_t i = 0; i < layout->bindingCount(); i++) {
if (bindingState.isBound(i)) {
writes[writeId].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writes[writeId].pNext = nullptr;
writes[writeId].dstSet = dset;
writes[writeId].dstBinding = i;
writes[writeId].dstArrayElement = 0;
writes[writeId].descriptorCount = 1;
writes[writeId].descriptorType = layout->binding(i).type;
writes[writeId].pImageInfo = &m_descriptors[i].image;
writes[writeId].pBufferInfo = &m_descriptors[i].buffer;
writes[writeId].pTexelBufferView = &m_descriptors[i].texelBuffer;
writeId++;
}
}
m_cmd->updateDescriptorSet(writeId, writes.data());
m_cmd->cmdBindDescriptorSet(bindPoint,
layout->pipelineLayout(), dset);
}