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

[dxvk] Use DxvkObjects to create and pass around common objects

This commit is contained in:
Philip Rebohle 2019-07-30 19:51:26 +02:00
parent 35679d2ba7
commit 65c1e58bd9
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
8 changed files with 47 additions and 168 deletions

View File

@ -6,30 +6,15 @@
namespace dxvk {
DxvkContext::DxvkContext(
const Rc<DxvkDevice>& device,
const Rc<DxvkPipelineManager>& pipelineManager,
const Rc<DxvkGpuEventPool>& gpuEventPool,
const Rc<DxvkGpuQueryPool>& gpuQueryPool,
const Rc<DxvkMetaClearObjects>& metaClearObjects,
const Rc<DxvkMetaCopyObjects>& metaCopyObjects,
const Rc<DxvkMetaResolveObjects>& metaResolveObjects,
const Rc<DxvkMetaMipGenObjects>& metaMipGenObjects,
const Rc<DxvkMetaPackObjects>& metaPackObjects)
DxvkContext::DxvkContext(const Rc<DxvkDevice>& 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<DxvkGpuEvent>& 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();

View File

@ -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<DxvkDevice>& device,
const Rc<DxvkPipelineManager>& pipelineManager,
const Rc<DxvkGpuEventPool>& gpuEventPool,
const Rc<DxvkGpuQueryPool>& gpuQueryPool,
const Rc<DxvkMetaClearObjects>& metaClearObjects,
const Rc<DxvkMetaCopyObjects>& metaCopyObjects,
const Rc<DxvkMetaResolveObjects>& metaResolveObjects,
const Rc<DxvkMetaMipGenObjects>& metaMipGenObjects,
const Rc<DxvkMetaPackObjects>& metaPackObjects);
DxvkContext(const Rc<DxvkDevice>& device);
~DxvkContext();
/**
@ -996,14 +979,8 @@ namespace dxvk {
private:
const Rc<DxvkDevice> m_device;
const Rc<DxvkPipelineManager> m_pipeMgr;
const Rc<DxvkGpuEventPool> m_gpuEvents;
const Rc<DxvkMetaClearObjects> m_metaClear;
const Rc<DxvkMetaCopyObjects> m_metaCopy;
const Rc<DxvkMetaResolveObjects> m_metaResolve;
const Rc<DxvkMetaMipGenObjects> m_metaMipGen;
const Rc<DxvkMetaPackObjects> m_metaPack;
Rc<DxvkDevice> m_device;
DxvkObjects* m_common;
Rc<DxvkCommandList> m_cmd;
Rc<DxvkDescriptorPool> m_descPool;

View File

@ -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<DxvkContext> 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<DxvkBuffer> 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<DxvkImage> 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<sync::Spinlock> 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<DxvkShader>& shader) {
m_pipelineManager->registerShader(shader);
m_objects.pipelineManager().registerShader(shader);
}

View File

@ -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<DxvkMemoryAllocator> m_memory;
Rc<DxvkRenderPassPool> m_renderPassPool;
Rc<DxvkPipelineManager> m_pipelineManager;
DxvkObjects m_objects;
Rc<DxvkGpuEventPool> m_gpuEventPool;
Rc<DxvkGpuQueryPool> m_gpuQueryPool;
Rc<DxvkMetaClearObjects> m_metaClearObjects;
Rc<DxvkMetaCopyObjects> m_metaCopyObjects;
Rc<DxvkMetaResolveObjects> m_metaResolveObjects;
Rc<DxvkMetaMipGenObjects> m_metaMipGenObjects;
Rc<DxvkMetaPackObjects> 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);
}
};
}

View File

@ -287,9 +287,8 @@ namespace dxvk {
DxvkGpuQueryManager::DxvkGpuQueryManager(
const Rc<DxvkGpuQueryPool>& pool)
: m_pool(pool), m_activeTypes(0) {
DxvkGpuQueryManager::DxvkGpuQueryManager(DxvkGpuQueryPool& pool)
: m_pool(&pool), m_activeTypes(0) {
}

View File

@ -331,8 +331,7 @@ namespace dxvk {
public:
DxvkGpuQueryManager(
const Rc<DxvkGpuQueryPool>& pool);
DxvkGpuQueryManager(DxvkGpuQueryPool& pool);
~DxvkGpuQueryManager();
@ -397,7 +396,7 @@ namespace dxvk {
private:
Rc<DxvkGpuQueryPool> m_pool;
DxvkGpuQueryPool* m_pool;
uint32_t m_activeTypes;
std::vector<Rc<DxvkGpuQuery>> m_activeQueries;

View File

@ -1,3 +1,4 @@
#pragma once
#include <mutex>

View File

@ -5,6 +5,8 @@
#include "dxvk_sampler.h"
namespace dxvk {
class DxvkContext;
/**
* \brief Unbound resources