diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 6e2d45406..f12016087 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -1579,11 +1579,6 @@ namespace dxvk { UINT StartSlot, UINT NumBuffers, ID3D11Buffer* const* ppConstantBuffers) { - const VkPipelineBindPoint bindPoint - = ShaderStage == DxbcProgramType::ComputeShader - ? VK_PIPELINE_BIND_POINT_COMPUTE - : VK_PIPELINE_BIND_POINT_GRAPHICS; - const uint32_t slotId = computeResourceSlotId( ShaderStage, DxbcBindingType::ConstantBuffer, StartSlot); @@ -1596,10 +1591,10 @@ namespace dxvk { if (newBuffer != nullptr) { m_context->bindResourceBuffer( - bindPoint, slotId + i, newBuffer->GetBufferSlice(0)); + slotId + i, newBuffer->GetBufferSlice(0)); } else { m_context->bindResourceBuffer( - bindPoint, slotId + i, DxvkBufferSlice()); + slotId + i, DxvkBufferSlice()); } } } @@ -1612,11 +1607,6 @@ namespace dxvk { UINT StartSlot, UINT NumSamplers, ID3D11SamplerState* const* ppSamplers) { - const VkPipelineBindPoint bindPoint - = ShaderStage == DxbcProgramType::ComputeShader - ? VK_PIPELINE_BIND_POINT_COMPUTE - : VK_PIPELINE_BIND_POINT_GRAPHICS; - const uint32_t slotId = computeResourceSlotId( ShaderStage, DxbcBindingType::ImageSampler, StartSlot); @@ -1629,10 +1619,10 @@ namespace dxvk { if (sampler != nullptr) { m_context->bindResourceSampler( - bindPoint, slotId + i, sampler->GetDXVKSampler()); + slotId + i, sampler->GetDXVKSampler()); } else { m_context->bindResourceSampler( - bindPoint, slotId + i, nullptr); + slotId + i, nullptr); } } } @@ -1645,11 +1635,6 @@ namespace dxvk { UINT StartSlot, UINT NumResources, ID3D11ShaderResourceView* const* ppResources) { - const VkPipelineBindPoint bindPoint - = ShaderStage == DxbcProgramType::ComputeShader - ? VK_PIPELINE_BIND_POINT_COMPUTE - : VK_PIPELINE_BIND_POINT_GRAPHICS; - const uint32_t slotId = computeResourceSlotId( ShaderStage, DxbcBindingType::ShaderResource, StartSlot); @@ -1665,17 +1650,16 @@ namespace dxvk { if (resView->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER) { Logger::warn("D3D11: Texel buffers not yet supported"); m_context->bindResourceTexelBuffer( - bindPoint, slotId + i, nullptr); + slotId + i, nullptr); } else { - m_context->bindResourceImage(bindPoint, + m_context->bindResourceImage( slotId + i, resView->GetDXVKImageView()); } } else { // When unbinding a resource, it doesn't really matter if // the resource type is correct, so we'll just bind a null // image to the given resource slot - m_context->bindResourceImage( - bindPoint, slotId + i, nullptr); + m_context->bindResourceImage(slotId + i, nullptr); } } } diff --git a/src/dxgi/dxgi_presenter.cpp b/src/dxgi/dxgi_presenter.cpp index 493f88217..f9993322a 100644 --- a/src/dxgi/dxgi_presenter.cpp +++ b/src/dxgi/dxgi_presenter.cpp @@ -191,12 +191,8 @@ namespace dxvk { m_context->setViewports(1, &viewport, &scissor); - m_context->bindResourceSampler( - VK_PIPELINE_BIND_POINT_GRAPHICS, - BindingIds::Sampler, m_sampler); - m_context->bindResourceImage( - VK_PIPELINE_BIND_POINT_GRAPHICS, - BindingIds::Texture, m_backBufferView); + m_context->bindResourceSampler(BindingIds::Sampler, m_sampler); + m_context->bindResourceImage (BindingIds::Texture, m_backBufferView); m_context->draw(4, 1, 0, 0); m_device->submitCommandList( diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 3c28fb8fc..6db65a323 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -70,45 +70,53 @@ namespace dxvk { void DxvkContext::bindResourceBuffer( - VkPipelineBindPoint pipe, uint32_t slot, const DxvkBufferSlice& buffer) { if (m_rc[slot].bufferSlice != buffer) { - m_flags.set(getResourceDirtyFlag(pipe)); m_rc[slot].bufferSlice = buffer; + + m_flags.set( + DxvkContextFlag::CpDirtyResources, + DxvkContextFlag::GpDirtyResources); } } void DxvkContext::bindResourceTexelBuffer( - VkPipelineBindPoint pipe, uint32_t slot, const Rc& bufferView) { if (m_rc[slot].bufferView != bufferView) { - m_flags.set(getResourceDirtyFlag(pipe)); m_rc[slot].bufferView = bufferView; + + m_flags.set( + DxvkContextFlag::CpDirtyResources, + DxvkContextFlag::GpDirtyResources); } } void DxvkContext::bindResourceImage( - VkPipelineBindPoint pipe, uint32_t slot, const Rc& image) { if (m_rc[slot].imageView != image) { - m_flags.set(getResourceDirtyFlag(pipe)); m_rc[slot].imageView = image; + + m_flags.set( + DxvkContextFlag::CpDirtyResources, + DxvkContextFlag::GpDirtyResources); } } void DxvkContext::bindResourceSampler( - VkPipelineBindPoint pipe, uint32_t slot, const Rc& sampler) { if (m_rc[slot].sampler != sampler) { - m_flags.set(getResourceDirtyFlag(pipe)); m_rc[slot].sampler = sampler; + + m_flags.set( + DxvkContextFlag::CpDirtyResources, + DxvkContextFlag::GpDirtyResources); } } @@ -818,17 +826,9 @@ namespace dxvk { if (m_flags.test(DxvkContextFlag::CpDirtyResources)) { m_flags.clr(DxvkContextFlag::CpDirtyResources); - auto layout = m_state.cp.pipeline->layout(); - - // TODO refcount used resources - -// m_cmd->bindResourceDescriptors( -// VK_PIPELINE_BIND_POINT_COMPUTE, -// layout->pipelineLayout(), -// layout->descriptorSetLayout(), -// layout->bindingCount(), -// layout->bindings(), -// m_cResources.descriptors()); + this->updateShaderResources( + VK_PIPELINE_BIND_POINT_COMPUTE, + m_state.cp.pipeline->layout()); } } @@ -837,51 +837,56 @@ namespace dxvk { if (m_flags.test(DxvkContextFlag::GpDirtyResources)) { m_flags.clr(DxvkContextFlag::GpDirtyResources); - auto layout = m_state.gp.pipeline->layout(); - - // TODO recreate resource views if the underlying - // resource was marked as dirty after invalidation - // TODO move this into a separate method so that - // compute can use this code as well - for (uint32_t i = 0; i < layout->bindingCount(); i++) { - const uint32_t slot = layout->binding(i).slot; - const auto& res = m_rc[slot]; - - if (res.sampler != nullptr) { - m_descriptors[i].image.sampler = res.sampler->handle(); - m_descriptors[i].image.imageView = VK_NULL_HANDLE; - m_descriptors[i].image.imageLayout = VK_IMAGE_LAYOUT_UNDEFINED; - - m_cmd->trackResource(res.sampler); - } else if (res.imageView != nullptr) { - m_descriptors[i].image.sampler = VK_NULL_HANDLE; - m_descriptors[i].image.imageView = res.imageView->handle(); - m_descriptors[i].image.imageLayout = res.imageView->imageInfo().layout; - - m_cmd->trackResource(res.imageView); - m_cmd->trackResource(res.imageView->image()); - } else if (res.bufferView != nullptr) { - m_descriptors[i].texelBuffer = res.bufferView->handle(); - - m_cmd->trackResource(res.bufferView); - m_cmd->trackResource(res.bufferView->buffer()->resource()); - } else if (res.bufferSlice.handle() != VK_NULL_HANDLE) { - m_descriptors[i].buffer = res.bufferSlice.descriptorInfo(); - m_cmd->trackResource(res.bufferSlice.resource()); - } - } - - m_cmd->bindResourceDescriptors( + this->updateShaderResources( VK_PIPELINE_BIND_POINT_GRAPHICS, - layout->pipelineLayout(), - layout->descriptorSetLayout(), - layout->bindingCount(), - layout->bindings(), - m_descriptors.data()); + m_state.gp.pipeline->layout()); } } + void DxvkContext::updateShaderResources( + VkPipelineBindPoint bindPoint, + const Rc& layout) { + // TODO recreate resource views if the underlying + // resource was marked as dirty after invalidation + for (uint32_t i = 0; i < layout->bindingCount(); i++) { + const uint32_t slot = layout->binding(i).slot; + const auto& res = m_rc[slot]; + + if (res.sampler != nullptr) { + m_descriptors[i].image.sampler = res.sampler->handle(); + m_descriptors[i].image.imageView = VK_NULL_HANDLE; + m_descriptors[i].image.imageLayout = VK_IMAGE_LAYOUT_UNDEFINED; + + m_cmd->trackResource(res.sampler); + } else if (res.imageView != nullptr) { + m_descriptors[i].image.sampler = VK_NULL_HANDLE; + m_descriptors[i].image.imageView = res.imageView->handle(); + m_descriptors[i].image.imageLayout = res.imageView->imageInfo().layout; + + m_cmd->trackResource(res.imageView); + m_cmd->trackResource(res.imageView->image()); + } else if (res.bufferView != nullptr) { + m_descriptors[i].texelBuffer = res.bufferView->handle(); + + m_cmd->trackResource(res.bufferView); + m_cmd->trackResource(res.bufferView->buffer()->resource()); + } else if (res.bufferSlice.handle() != VK_NULL_HANDLE) { + m_descriptors[i].buffer = res.bufferSlice.descriptorInfo(); + m_cmd->trackResource(res.bufferSlice.resource()); + } + } + + m_cmd->bindResourceDescriptors( + bindPoint, + layout->pipelineLayout(), + layout->descriptorSetLayout(), + layout->bindingCount(), + layout->bindings(), + m_descriptors.data()); + } + + void DxvkContext::updateDynamicState() { if (m_flags.test(DxvkContextFlag::GpDirtyDynamicState)) { m_flags.clr(DxvkContextFlag::GpDirtyDynamicState); @@ -1060,13 +1065,4 @@ namespace dxvk { m_barriers.recordCommands(m_cmd); } - - DxvkContextFlag DxvkContext::getResourceDirtyFlag(VkPipelineBindPoint pipe) const { - switch (pipe) { - default: - case VK_PIPELINE_BIND_POINT_GRAPHICS: return DxvkContextFlag::GpDirtyResources; - case VK_PIPELINE_BIND_POINT_COMPUTE : return DxvkContextFlag::CpDirtyResources; - } - } - } \ No newline at end of file diff --git a/src/dxvk/dxvk_context.h b/src/dxvk/dxvk_context.h index 5aa64c71f..32725fd1b 100644 --- a/src/dxvk/dxvk_context.h +++ b/src/dxvk/dxvk_context.h @@ -70,12 +70,10 @@ namespace dxvk { * \brief Binds buffer as a shader resource * * Can be used for uniform and storage buffers. - * \param [in] pipe Target pipeline * \param [in] slot Resource binding slot * \param [in] buffer Buffer to bind */ void bindResourceBuffer( - VkPipelineBindPoint pipe, uint32_t slot, const DxvkBufferSlice& buffer); @@ -84,12 +82,10 @@ namespace dxvk { * * Can be used for both uniform texel * buffers and storage texel buffers. - * \param [in] pipe Target pipeline * \param [in] slot Resource binding slot * \param [in] bufferView Buffer view to bind */ void bindResourceTexelBuffer( - VkPipelineBindPoint pipe, uint32_t slot, const Rc& bufferView); @@ -98,12 +94,10 @@ namespace dxvk { * * Can be used for sampled images with a * dedicated sampler and storage images. - * \param [in] pipe Target pipeline * \param [in] slot Resource binding slot * \param [in] imageView Image view to bind */ void bindResourceImage( - VkPipelineBindPoint pipe, uint32_t slot, const Rc& image); @@ -112,12 +106,10 @@ namespace dxvk { * * Binds a sampler that can be used together with * an image in order to read from a texture. - * \param [in] pipe Target pipeline * \param [in] slot Resource binding slot * \param [in] sampler Sampler view to bind */ void bindResourceSampler( - VkPipelineBindPoint pipe, uint32_t slot, const Rc& sampler); @@ -427,6 +419,10 @@ namespace dxvk { void updateComputeShaderResources(); void updateGraphicsShaderResources(); + void updateShaderResources( + VkPipelineBindPoint bindPoint, + const Rc& layout); + void updateDynamicState(); void updateViewports(); void updateBlendConstants(); @@ -446,9 +442,6 @@ namespace dxvk { void transformLayoutsRenderPassEnd( const DxvkRenderTargets& renderTargets); - DxvkContextFlag getResourceDirtyFlag( - VkPipelineBindPoint pipe) const; - }; } \ No newline at end of file