From 65c1e58bd9abcf808d018ef366c901f9fee9203f Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 30 Jul 2019 19:51:26 +0200 Subject: [PATCH] [dxvk] Use DxvkObjects to create and pass around common objects --- src/dxvk/dxvk_context.cpp | 64 +++++++++++++--------------------- src/dxvk/dxvk_context.h | 31 +++-------------- src/dxvk/dxvk_device.cpp | 38 ++++++-------------- src/dxvk/dxvk_device.h | 69 ++----------------------------------- src/dxvk/dxvk_gpu_query.cpp | 5 ++- src/dxvk/dxvk_gpu_query.h | 5 ++- src/dxvk/dxvk_pipemanager.h | 1 + src/dxvk/dxvk_unbound.h | 2 ++ 8 files changed, 47 insertions(+), 168 deletions(-) diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index c15e5c546..96d29375d 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -6,30 +6,15 @@ namespace dxvk { - DxvkContext::DxvkContext( - const Rc& device, - const Rc& pipelineManager, - const Rc& gpuEventPool, - const Rc& gpuQueryPool, - const Rc& metaClearObjects, - const Rc& metaCopyObjects, - const Rc& metaResolveObjects, - const Rc& metaMipGenObjects, - const Rc& metaPackObjects) + DxvkContext::DxvkContext(const Rc& device) : m_device (device), - m_pipeMgr (pipelineManager), - m_gpuEvents (gpuEventPool), - m_metaClear (metaClearObjects), - m_metaCopy (metaCopyObjects), - m_metaResolve (metaResolveObjects), - m_metaMipGen (metaMipGenObjects), - m_metaPack (metaPackObjects), + m_common (&device->m_objects), m_sdmaAcquires(DxvkCmdBuffer::SdmaBuffer), m_sdmaBarriers(DxvkCmdBuffer::SdmaBuffer), m_initBarriers(DxvkCmdBuffer::InitBuffer), m_execAcquires(DxvkCmdBuffer::ExecBuffer), m_execBarriers(DxvkCmdBuffer::ExecBuffer), - m_queryManager(gpuQueryPool), + m_queryManager(m_common->queryPool()), m_staging (device) { } @@ -422,7 +407,7 @@ namespace dxvk { m_execBarriers.recordCommands(m_cmd); // Query pipeline objects to use for this clear operation - DxvkMetaClearPipeline pipeInfo = m_metaClear->getClearBufferPipeline( + DxvkMetaClearPipeline pipeInfo = m_common->metaClear().getClearBufferPipeline( imageFormatInfo(bufferView->info().format)->flags); // Create a descriptor set pointing to the view @@ -1109,7 +1094,7 @@ namespace dxvk { this->unbindComputePipeline(); // Retrieve compute pipeline for the given format - auto pipeInfo = m_metaPack->getPackPipeline(format); + auto pipeInfo = m_common->metaPack().getPackPipeline(format); if (!pipeInfo.pipeHandle) return; @@ -1222,8 +1207,7 @@ namespace dxvk { m_execBarriers.recordCommands(m_cmd); // Retrieve compute pipeline for the given format - auto pipeInfo = m_metaPack->getUnpackPipeline( - dstImage->info().format, format); + auto pipeInfo = m_common->metaPack().getUnpackPipeline(dstImage->info().format, format); if (!pipeInfo.pipeHandle) { Logger::err(str::format( @@ -1684,7 +1668,7 @@ namespace dxvk { passInfo.pClearValues = nullptr; // Retrieve a compatible pipeline to use for rendering - DxvkMetaMipGenPipeline pipeInfo = m_metaMipGen->getPipeline( + DxvkMetaMipGenPipeline pipeInfo = m_common->metaMipGen().getPipeline( mipGenerator->viewType(), imageView->info().format); for (uint32_t i = 0; i < mipGenerator->passCount(); i++) { @@ -2342,7 +2326,7 @@ namespace dxvk { void DxvkContext::signalGpuEvent(const Rc& event) { this->spillRenderPass(); - DxvkGpuEventHandle handle = m_gpuEvents->allocEvent(); + DxvkGpuEventHandle handle = m_common->eventPool().allocEvent(); m_cmd->cmdSetEvent(handle.event, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT); @@ -2501,7 +2485,7 @@ namespace dxvk { m_execBarriers.recordCommands(m_cmd); // Query pipeline objects to use for this clear operation - DxvkMetaClearPipeline pipeInfo = m_metaClear->getClearImagePipeline( + DxvkMetaClearPipeline pipeInfo = m_common->metaClear().getClearImagePipeline( imageView->type(), imageFormatInfo(imageView->info().format)->flags); // Create a descriptor set pointing to the view @@ -2666,7 +2650,7 @@ namespace dxvk { } // Render target format to use for this copy - VkFormat viewFormat = m_metaCopy->getCopyDestinationFormat( + VkFormat viewFormat = m_common->metaCopy().getCopyDestinationFormat( dstSubresource.aspectMask, srcSubresource.aspectMask, srcImage->info().format); @@ -2769,7 +2753,7 @@ namespace dxvk { m_device->vkd(), tgtImageView, srcImageView, srcStencilView, tgtImage->isFullSubresource(tgtSubresource, extent)); - auto pipeInfo = m_metaCopy->getPipeline( + auto pipeInfo = m_common->metaCopy().getPipeline( viewType, viewFormat, tgtImage->info().sampleCount); VkDescriptorImageInfo descriptorImage; @@ -2997,7 +2981,7 @@ namespace dxvk { m_device->vkd(), dstImageView, srcImageView, dstImage->isFullSubresource(region.dstSubresource, region.extent)); - auto pipeInfo = m_metaResolve->getPipeline( + auto pipeInfo = m_common->metaResolve().getPipeline( format, srcImage->info().sampleCount); VkDescriptorImageInfo descriptorImage; @@ -3411,7 +3395,7 @@ namespace dxvk { m_flags.clr(DxvkContextFlag::CpDirtyPipeline); m_state.cp.state.bsBindingMask.clear(); - m_state.cp.pipeline = m_pipeMgr->createComputePipeline(m_state.cp.shaders); + m_state.cp.pipeline = m_common->pipelineManager().createComputePipeline(m_state.cp.shaders); if (m_state.cp.pipeline != nullptr && m_state.cp.pipeline->layout()->pushConstRange().size) @@ -3461,8 +3445,8 @@ namespace dxvk { m_flags.clr(DxvkContextFlag::GpDirtyPipeline); m_state.gp.state.bsBindingMask.clear(); - m_state.gp.pipeline = m_pipeMgr->createGraphicsPipeline(m_state.gp.shaders); - m_state.gp.flags = DxvkGraphicsPipelineFlags(); + m_state.gp.pipeline = m_common->pipelineManager().createGraphicsPipeline(m_state.gp.shaders); + m_state.gp.flags = DxvkGraphicsPipelineFlags(); if (m_state.gp.pipeline != nullptr) { m_state.gp.flags = m_state.gp.pipeline->flags(); @@ -3645,7 +3629,7 @@ namespace dxvk { m_cmd->trackResource(res.sampler); } else { bindMask.clr(i); - m_descInfos[i].image = m_device->dummySamplerDescriptor(); + m_descInfos[i].image = m_common->dummyResources().samplerDescriptor(); } break; case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: @@ -3664,7 +3648,7 @@ namespace dxvk { } } else { bindMask.clr(i); - m_descInfos[i].image = m_device->dummyImageViewDescriptor(binding.view); + m_descInfos[i].image = m_common->dummyResources().imageViewDescriptor(binding.view); } break; case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: @@ -3684,7 +3668,7 @@ namespace dxvk { } } else { bindMask.clr(i); - m_descInfos[i].image = m_device->dummyImageSamplerDescriptor(binding.view); + m_descInfos[i].image = m_common->dummyResources().imageSamplerDescriptor(binding.view); } break; case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: @@ -3699,7 +3683,7 @@ namespace dxvk { } } else { bindMask.clr(i); - m_descInfos[i].texelBuffer = m_device->dummyBufferViewDescriptor(); + m_descInfos[i].texelBuffer = m_common->dummyResources().bufferViewDescriptor(); } break; case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: @@ -3711,7 +3695,7 @@ namespace dxvk { m_cmd->trackResource(res.bufferSlice.buffer()); } else { bindMask.clr(i); - m_descInfos[i].buffer = m_device->dummyBufferDescriptor(); + m_descInfos[i].buffer = m_common->dummyResources().bufferDescriptor(); } break; case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: @@ -3724,7 +3708,7 @@ namespace dxvk { m_cmd->trackResource(res.bufferSlice.buffer()); } else { bindMask.clr(i); - m_descInfos[i].buffer = m_device->dummyBufferDescriptor(); + m_descInfos[i].buffer = m_common->dummyResources().bufferDescriptor(); } break; default: @@ -3822,7 +3806,7 @@ namespace dxvk { m_cmd->trackResource(m_state.vi.indexBuffer.buffer()); } else { m_cmd->cmdBindIndexBuffer( - m_device->dummyBufferHandle(), + m_common->dummyResources().bufferHandle(), 0, VK_INDEX_TYPE_UINT32); } } @@ -3852,7 +3836,7 @@ namespace dxvk { if (m_vbTracked.set(binding)) m_cmd->trackResource(m_state.vi.vertexBuffers[binding].buffer()); } else { - buffers[i] = m_device->dummyBufferHandle(); + buffers[i] = m_common->dummyResources().bufferHandle(); offsets[i] = 0; } } @@ -3881,7 +3865,7 @@ namespace dxvk { xfbLengths[i] = physSlice.length; if (physSlice.handle == VK_NULL_HANDLE) - xfbBuffers[i] = m_device->dummyBufferHandle(); + xfbBuffers[i] = m_common->dummyResources().bufferHandle(); if (physSlice.handle != VK_NULL_HANDLE) { auto buffer = m_state.xfb.buffers[i].buffer(); diff --git a/src/dxvk/dxvk_context.h b/src/dxvk/dxvk_context.h index 79a818e9a..bb5b8a6fc 100644 --- a/src/dxvk/dxvk_context.h +++ b/src/dxvk/dxvk_context.h @@ -5,15 +5,7 @@ #include "dxvk_cmdlist.h" #include "dxvk_context_state.h" #include "dxvk_data.h" -#include "dxvk_gpu_event.h" -#include "dxvk_gpu_query.h" -#include "dxvk_meta_clear.h" -#include "dxvk_meta_copy.h" -#include "dxvk_meta_mipgen.h" -#include "dxvk_meta_pack.h" -#include "dxvk_meta_resolve.h" -#include "dxvk_pipecache.h" -#include "dxvk_pipemanager.h" +#include "dxvk_objects.h" #include "dxvk_util.h" namespace dxvk { @@ -29,16 +21,7 @@ namespace dxvk { public: - DxvkContext( - const Rc& device, - const Rc& pipelineManager, - const Rc& gpuEventPool, - const Rc& gpuQueryPool, - const Rc& metaClearObjects, - const Rc& metaCopyObjects, - const Rc& metaResolveObjects, - const Rc& metaMipGenObjects, - const Rc& metaPackObjects); + DxvkContext(const Rc& device); ~DxvkContext(); /** @@ -996,14 +979,8 @@ namespace dxvk { private: - const Rc m_device; - const Rc m_pipeMgr; - const Rc m_gpuEvents; - const Rc m_metaClear; - const Rc m_metaCopy; - const Rc m_metaResolve; - const Rc m_metaMipGen; - const Rc m_metaPack; + Rc m_device; + DxvkObjects* m_common; Rc m_cmd; Rc m_descPool; diff --git a/src/dxvk/dxvk_device.cpp b/src/dxvk/dxvk_device.cpp index 2b84190ad..8c6428788 100644 --- a/src/dxvk/dxvk_device.cpp +++ b/src/dxvk/dxvk_device.cpp @@ -17,17 +17,7 @@ namespace dxvk { m_features (features), m_properties (adapter->deviceProperties()), m_perfHints (getPerfHints()), - m_memory (new DxvkMemoryAllocator (this)), - m_renderPassPool (new DxvkRenderPassPool (this)), - m_pipelineManager (new DxvkPipelineManager (this, m_renderPassPool.ptr())), - m_gpuEventPool (new DxvkGpuEventPool (this)), - m_gpuQueryPool (new DxvkGpuQueryPool (this)), - m_metaClearObjects (new DxvkMetaClearObjects (this)), - m_metaCopyObjects (new DxvkMetaCopyObjects (this)), - m_metaResolveObjects(new DxvkMetaResolveObjects (this)), - m_metaMipGenObjects (new DxvkMetaMipGenObjects (this)), - m_metaPackObjects (new DxvkMetaPackObjects (this)), - m_unboundResources (this), + m_objects (this), m_submissionQueue (this) { auto queueFamilies = m_adapter->findQueueFamilies(); m_queues.graphics = getQueue(queueFamilies.graphics, 0); @@ -88,15 +78,7 @@ namespace dxvk { Rc DxvkDevice::createContext() { - return new DxvkContext(this, - m_pipelineManager, - m_gpuEventPool, - m_gpuQueryPool, - m_metaClearObjects, - m_metaCopyObjects, - m_metaResolveObjects, - m_metaMipGenObjects, - m_metaPackObjects); + return new DxvkContext(this); } @@ -121,7 +103,7 @@ namespace dxvk { m_properties.limits.maxFramebufferLayers }; auto renderPassFormat = DxvkFramebuffer::getRenderPassFormat(renderTargets); - auto renderPassObject = m_renderPassPool->getRenderPass(renderPassFormat); + auto renderPassObject = m_objects.renderPassPool().getRenderPass(renderPassFormat); return new DxvkFramebuffer(m_vkd, renderPassObject, renderTargets, defaultSize); @@ -131,7 +113,7 @@ namespace dxvk { Rc DxvkDevice::createBuffer( const DxvkBufferCreateInfo& createInfo, VkMemoryPropertyFlags memoryType) { - return new DxvkBuffer(this, createInfo, *m_memory, memoryType); + return new DxvkBuffer(this, createInfo, m_objects.memoryManager(), memoryType); } @@ -145,7 +127,7 @@ namespace dxvk { Rc DxvkDevice::createImage( const DxvkImageCreateInfo& createInfo, VkMemoryPropertyFlags memoryType) { - return new DxvkImage(m_vkd, createInfo, *m_memory, memoryType); + return new DxvkImage(m_vkd, createInfo, m_objects.memoryManager(), memoryType); } @@ -176,15 +158,15 @@ namespace dxvk { DxvkStatCounters DxvkDevice::getStatCounters() { - DxvkMemoryStats mem = m_memory->getMemoryStats(); - DxvkPipelineCount pipe = m_pipelineManager->getPipelineCount(); + DxvkMemoryStats mem = m_objects.memoryManager().getMemoryStats(); + DxvkPipelineCount pipe = m_objects.pipelineManager().getPipelineCount(); DxvkStatCounters result; result.setCtr(DxvkStatCounter::MemoryAllocated, mem.memoryAllocated); result.setCtr(DxvkStatCounter::MemoryUsed, mem.memoryUsed); result.setCtr(DxvkStatCounter::PipeCountGraphics, pipe.numGraphicsPipelines); result.setCtr(DxvkStatCounter::PipeCountCompute, pipe.numComputePipelines); - result.setCtr(DxvkStatCounter::PipeCompilerBusy, m_pipelineManager->isCompilingShaders()); + result.setCtr(DxvkStatCounter::PipeCompilerBusy, m_objects.pipelineManager().isCompilingShaders()); result.setCtr(DxvkStatCounter::GpuIdleTicks, m_submissionQueue.gpuIdleTicks()); std::lock_guard lock(m_statLock); @@ -199,12 +181,12 @@ namespace dxvk { void DxvkDevice::initResources() { - m_unboundResources.clearResources(this); + m_objects.dummyResources().clearResources(this); } void DxvkDevice::registerShader(const Rc& shader) { - m_pipelineManager->registerShader(shader); + m_objects.pipelineManager().registerShader(shader); } diff --git a/src/dxvk/dxvk_device.h b/src/dxvk/dxvk_device.h index 6e62222b3..2d45a1b17 100644 --- a/src/dxvk/dxvk_device.h +++ b/src/dxvk/dxvk_device.h @@ -10,6 +10,7 @@ #include "dxvk_image.h" #include "dxvk_memory.h" #include "dxvk_meta_clear.h" +#include "dxvk_objects.h" #include "dxvk_options.h" #include "dxvk_pipecache.h" #include "dxvk_pipemanager.h" @@ -433,22 +434,8 @@ namespace dxvk { VkPhysicalDeviceProperties m_properties; DxvkDevicePerfHints m_perfHints; - - Rc m_memory; - Rc m_renderPassPool; - Rc m_pipelineManager; + DxvkObjects m_objects; - Rc m_gpuEventPool; - Rc m_gpuQueryPool; - - Rc m_metaClearObjects; - Rc m_metaCopyObjects; - Rc m_metaResolveObjects; - Rc m_metaMipGenObjects; - Rc m_metaPackObjects; - - DxvkUnboundResources m_unboundResources; - sync::Spinlock m_statLock; DxvkStatCounters m_statCounters; @@ -471,58 +458,6 @@ namespace dxvk { uint32_t family, uint32_t index) const; - /** - * \brief Dummy buffer handle - * \returns Use for unbound vertex buffers. - */ - VkBuffer dummyBufferHandle() const { - return m_unboundResources.bufferHandle(); - } - - /** - * \brief Dummy buffer descriptor - * \returns Descriptor that points to a dummy buffer - */ - VkDescriptorBufferInfo dummyBufferDescriptor() const { - return m_unboundResources.bufferDescriptor(); - } - - /** - * \brief Dummy buffer view descriptor - * \returns Dummy buffer view handle - */ - VkBufferView dummyBufferViewDescriptor() const { - return m_unboundResources.bufferViewDescriptor(); - } - - /** - * \brief Dummy sampler descriptor - * \returns Descriptor that points to a dummy sampler - */ - VkDescriptorImageInfo dummySamplerDescriptor() const { - return m_unboundResources.samplerDescriptor(); - } - - /** - * \brief Dummy image view descriptor - * - * \param [in] type Required view type - * \returns Descriptor that points to a dummy image - */ - VkDescriptorImageInfo dummyImageViewDescriptor(VkImageViewType type) const { - return m_unboundResources.imageViewDescriptor(type); - } - - /** - * \brief Dummy combined image sampler descriptor - * - * \param [in] type Required view type - * \returns Descriptor that points to a dummy image - */ - VkDescriptorImageInfo dummyImageSamplerDescriptor(VkImageViewType type) const { - return m_unboundResources.imageSamplerDescriptor(type); - } - }; } \ No newline at end of file diff --git a/src/dxvk/dxvk_gpu_query.cpp b/src/dxvk/dxvk_gpu_query.cpp index 058ad036e..4a3b5c9dd 100644 --- a/src/dxvk/dxvk_gpu_query.cpp +++ b/src/dxvk/dxvk_gpu_query.cpp @@ -287,9 +287,8 @@ namespace dxvk { - DxvkGpuQueryManager::DxvkGpuQueryManager( - const Rc& pool) - : m_pool(pool), m_activeTypes(0) { + DxvkGpuQueryManager::DxvkGpuQueryManager(DxvkGpuQueryPool& pool) + : m_pool(&pool), m_activeTypes(0) { } diff --git a/src/dxvk/dxvk_gpu_query.h b/src/dxvk/dxvk_gpu_query.h index e466fad1a..1810f3bdc 100644 --- a/src/dxvk/dxvk_gpu_query.h +++ b/src/dxvk/dxvk_gpu_query.h @@ -331,8 +331,7 @@ namespace dxvk { public: - DxvkGpuQueryManager( - const Rc& pool); + DxvkGpuQueryManager(DxvkGpuQueryPool& pool); ~DxvkGpuQueryManager(); @@ -397,7 +396,7 @@ namespace dxvk { private: - Rc m_pool; + DxvkGpuQueryPool* m_pool; uint32_t m_activeTypes; std::vector> m_activeQueries; diff --git a/src/dxvk/dxvk_pipemanager.h b/src/dxvk/dxvk_pipemanager.h index c5f570193..cf524bdfb 100644 --- a/src/dxvk/dxvk_pipemanager.h +++ b/src/dxvk/dxvk_pipemanager.h @@ -1,3 +1,4 @@ + #pragma once #include diff --git a/src/dxvk/dxvk_unbound.h b/src/dxvk/dxvk_unbound.h index 92d00e85a..c9a5cf63f 100644 --- a/src/dxvk/dxvk_unbound.h +++ b/src/dxvk/dxvk_unbound.h @@ -5,6 +5,8 @@ #include "dxvk_sampler.h" namespace dxvk { + + class DxvkContext; /** * \brief Unbound resources