From 4af31a9d64a03f12a9e47eccb17b8063987c2424 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 22 Oct 2024 15:18:38 +0200 Subject: [PATCH] [dxvk] Remove context type concept We only have a single context per device now. --- src/d3d11/d3d11_context_imm.cpp | 2 +- src/d3d9/d3d9_device.cpp | 2 +- src/dxvk/dxvk_context.cpp | 5 ++-- src/dxvk/dxvk_context.h | 3 +- src/dxvk/dxvk_descriptor.cpp | 52 +++++++++++++-------------------- src/dxvk/dxvk_descriptor.h | 18 ++---------- src/dxvk/dxvk_device.cpp | 4 +-- src/dxvk/dxvk_device.h | 3 +- 8 files changed, 30 insertions(+), 59 deletions(-) diff --git a/src/d3d11/d3d11_context_imm.cpp b/src/d3d11/d3d11_context_imm.cpp index b7c45b8c4..6dc8a832f 100644 --- a/src/d3d11/d3d11_context_imm.cpp +++ b/src/d3d11/d3d11_context_imm.cpp @@ -16,7 +16,7 @@ namespace dxvk { D3D11Device* pParent, const Rc& Device) : D3D11CommonContext(pParent, Device, 0, DxvkCsChunkFlag::SingleUse), - m_csThread(Device, Device->createContext(DxvkContextType::Primary)), + m_csThread(Device, Device->createContext()), m_maxImplicitDiscardSize(pParent->GetOptions()->maxImplicitDiscardSize), m_submissionFence(new sync::CallbackFence()), m_flushTracker(pParent->GetOptions()->reproducibleCommandStream), diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 17dcc7c3a..345e1c856 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -54,7 +54,7 @@ namespace dxvk { , m_d3d9Options ( dxvkDevice, pParent->GetInstance()->config() ) , m_multithread ( BehaviorFlags & D3DCREATE_MULTITHREADED ) , m_isSWVP ( (BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING) ? true : false ) - , m_csThread ( dxvkDevice, dxvkDevice->createContext(DxvkContextType::Primary) ) + , m_csThread ( dxvkDevice, dxvkDevice->createContext() ) , m_csChunk ( AllocCsChunk() ) , m_submissionFence (new sync::Fence()) , m_flushTracker (m_d3d9Options.reproducibleCommandStream) diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index a78c355c1..677985bdc 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -7,9 +7,8 @@ namespace dxvk { - DxvkContext::DxvkContext(const Rc& device, DxvkContextType type) + DxvkContext::DxvkContext(const Rc& device) : m_device (device), - m_type (type), m_common (&device->m_objects), m_sdmaBarriers(DxvkCmdBuffer::SdmaBuffer), m_initBarriers(DxvkCmdBuffer::InitBuffer), @@ -18,7 +17,7 @@ namespace dxvk { // Init framebuffer info with default render pass in case // the app does not explicitly bind any render targets m_state.om.framebufferInfo = makeFramebufferInfo(m_state.om.renderTargets); - m_descriptorManager = new DxvkDescriptorManager(device.ptr(), type); + m_descriptorManager = new DxvkDescriptorManager(device.ptr()); // Default destination barriers for graphics pipelines m_globalRoGraphicsBarrier.stages = m_device->getShaderPipelineStages() diff --git a/src/dxvk/dxvk_context.h b/src/dxvk/dxvk_context.h index c26788493..e6da3de4d 100644 --- a/src/dxvk/dxvk_context.h +++ b/src/dxvk/dxvk_context.h @@ -32,7 +32,7 @@ namespace dxvk { public: - DxvkContext(const Rc& device, DxvkContextType type); + DxvkContext(const Rc& device); ~DxvkContext(); /** @@ -1389,7 +1389,6 @@ namespace dxvk { private: Rc m_device; - DxvkContextType m_type; DxvkObjects* m_common; Rc m_cmd; diff --git a/src/dxvk/dxvk_descriptor.cpp b/src/dxvk/dxvk_descriptor.cpp index c33de22f9..120c9f1f6 100644 --- a/src/dxvk/dxvk_descriptor.cpp +++ b/src/dxvk/dxvk_descriptor.cpp @@ -35,9 +35,8 @@ namespace dxvk { DxvkDescriptorPool::DxvkDescriptorPool( DxvkDevice* device, - DxvkDescriptorManager* manager, - DxvkContextType contextType) - : m_device(device), m_manager(manager), m_contextType(contextType), + DxvkDescriptorManager* manager) + : m_device(device), m_manager(manager), m_cachedEntry(nullptr, nullptr) { } @@ -49,12 +48,10 @@ namespace dxvk { for (auto pool : m_descriptorPools) vk->vkDestroyDescriptorPool(vk->device(), pool, nullptr); - if (m_contextType == DxvkContextType::Primary) { - m_device->addStatCtr(DxvkStatCounter::DescriptorPoolCount, - uint64_t(-int64_t(m_descriptorPools.size()))); - m_device->addStatCtr(DxvkStatCounter::DescriptorSetCount, - uint64_t(-int64_t(m_setsAllocated))); - } + m_device->addStatCtr(DxvkStatCounter::DescriptorPoolCount, + uint64_t(-int64_t(m_descriptorPools.size()))); + m_device->addStatCtr(DxvkStatCounter::DescriptorSetCount, + uint64_t(-int64_t(m_setsAllocated))); } @@ -63,9 +60,10 @@ namespace dxvk { if (!m_setsAllocated) return false; - // No frame tracking for supplementary contexts, so - // always submit those at the end of a command list - if (endFrame || m_contextType != DxvkContextType::Primary) + // Submit at the end of each frame to make it more likely + // to get similar descriptor set layouts the next time the + // pool gets used. + if (endFrame) return true; // Submit very large descriptor pools to prevent extreme @@ -136,10 +134,8 @@ namespace dxvk { void DxvkDescriptorPool::updateStats(DxvkStatCounters& counters) { - if (m_contextType == DxvkContextType::Primary) { - counters.addCtr(DxvkStatCounter::DescriptorSetCount, - uint64_t(int64_t(m_setsAllocated) - int64_t(m_prevSetsAllocated))); - } + counters.addCtr(DxvkStatCounter::DescriptorSetCount, + uint64_t(int64_t(m_setsAllocated) - int64_t(m_prevSetsAllocated))); m_prevSetsAllocated = m_setsAllocated; } @@ -238,15 +234,12 @@ namespace dxvk { DxvkDescriptorManager::DxvkDescriptorManager( - DxvkDevice* device, - DxvkContextType contextType) - : m_device(device), m_contextType(contextType) { + DxvkDevice* device) + : m_device(device) { // Deliberately pick a very high number of descriptor sets so that // we will typically end up using all available pool memory before // the descriptor set limit becomes the limiting factor. - m_maxSets = m_contextType == DxvkContextType::Primary - ? (env::is32BitHostPlatform() ? 24576u : 49152u) - : (512u); + m_maxSets = env::is32BitHostPlatform() ? 24576u : 49152u; } @@ -256,10 +249,8 @@ namespace dxvk { for (size_t i = 0; i < m_vkPoolCount; i++) vk->vkDestroyDescriptorPool(vk->device(), m_vkPools[i], nullptr); - if (m_contextType == DxvkContextType::Primary) { - m_device->addStatCtr(DxvkStatCounter::DescriptorPoolCount, - uint64_t(-int64_t(m_vkPoolCount))); - } + m_device->addStatCtr(DxvkStatCounter::DescriptorPoolCount, + uint64_t(-int64_t(m_vkPoolCount))); } @@ -267,7 +258,7 @@ namespace dxvk { Rc pool = m_pools.retrieveObject(); if (pool == nullptr) - pool = new DxvkDescriptorPool(m_device, this, m_contextType); + pool = new DxvkDescriptorPool(m_device, this); return pool; } @@ -319,8 +310,7 @@ namespace dxvk { if (vk->vkCreateDescriptorPool(vk->device(), &info, nullptr, &pool) != VK_SUCCESS) throw DxvkError("DxvkDescriptorPool: Failed to create descriptor pool"); - if (m_contextType == DxvkContextType::Primary) - m_device->addStatCtr(DxvkStatCounter::DescriptorPoolCount, 1); + m_device->addStatCtr(DxvkStatCounter::DescriptorPoolCount, 1); return pool; } @@ -337,9 +327,7 @@ namespace dxvk { } } - if (m_contextType == DxvkContextType::Primary) - m_device->addStatCtr(DxvkStatCounter::DescriptorPoolCount, uint64_t(-1ll)); - + m_device->addStatCtr(DxvkStatCounter::DescriptorPoolCount, uint64_t(-1ll)); vk->vkDestroyDescriptorPool(vk->device(), pool, nullptr); } diff --git a/src/dxvk/dxvk_descriptor.h b/src/dxvk/dxvk_descriptor.h index 52c088fab..5e88bde96 100644 --- a/src/dxvk/dxvk_descriptor.h +++ b/src/dxvk/dxvk_descriptor.h @@ -12,16 +12,6 @@ namespace dxvk { class DxvkDevice; class DxvkDescriptorManager; - /** - * \brief DXVK context type - * - * Used as a hint to optimize certain usage patterns. - */ - enum class DxvkContextType : uint32_t { - Primary = 0, - Supplementary = 1, - }; - /** * \brief Descriptor info * @@ -85,8 +75,7 @@ namespace dxvk { DxvkDescriptorPool( DxvkDevice* device, - DxvkDescriptorManager* manager, - DxvkContextType contextType); + DxvkDescriptorManager* manager); ~DxvkDescriptorPool(); @@ -134,7 +123,6 @@ namespace dxvk { DxvkDevice* m_device; DxvkDescriptorManager* m_manager; - DxvkContextType m_contextType; std::vector m_descriptorPools; @@ -184,8 +172,7 @@ namespace dxvk { public: DxvkDescriptorManager( - DxvkDevice* device, - DxvkContextType contextType); + DxvkDevice* device); ~DxvkDescriptorManager(); @@ -234,7 +221,6 @@ namespace dxvk { private: DxvkDevice* m_device; - DxvkContextType m_contextType; uint32_t m_maxSets = 0; DxvkRecycler m_pools; diff --git a/src/dxvk/dxvk_device.cpp b/src/dxvk/dxvk_device.cpp index 6a7512aca..2056ef2ac 100644 --- a/src/dxvk/dxvk_device.cpp +++ b/src/dxvk/dxvk_device.cpp @@ -133,8 +133,8 @@ namespace dxvk { } - Rc DxvkDevice::createContext(DxvkContextType type) { - return new DxvkContext(this, type); + Rc DxvkDevice::createContext() { + return new DxvkContext(this); } diff --git a/src/dxvk/dxvk_device.h b/src/dxvk/dxvk_device.h index b98b72229..3e49ac4a9 100644 --- a/src/dxvk/dxvk_device.h +++ b/src/dxvk/dxvk_device.h @@ -278,10 +278,9 @@ namespace dxvk { * * Creates a context object that can * be used to record command buffers. - * \param [in] type Context type * \returns The context object */ - Rc createContext(DxvkContextType type); + Rc createContext(); /** * \brief Creates a GPU event