Refactor D3D12: remove ICommandQueue, IFence dependencies
This commit is contained in:
@@ -4,7 +4,6 @@
|
|||||||
#include <wrl/client.h>
|
#include <wrl/client.h>
|
||||||
|
|
||||||
#include "../Enums.h"
|
#include "../Enums.h"
|
||||||
#include "../CommandAllocator.h"
|
|
||||||
|
|
||||||
using Microsoft::WRL::ComPtr;
|
using Microsoft::WRL::ComPtr;
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include <wrl/client.h>
|
#include <wrl/client.h>
|
||||||
|
|
||||||
#include "../Enums.h"
|
#include "../Enums.h"
|
||||||
#include "../CommandQueue.h"
|
|
||||||
#include "D3D12Enum.h"
|
#include "D3D12Enum.h"
|
||||||
|
|
||||||
using Microsoft::WRL::ComPtr;
|
using Microsoft::WRL::ComPtr;
|
||||||
@@ -22,11 +21,10 @@ public:
|
|||||||
bool Initialize(ID3D12Device* device, CommandQueueType type = CommandQueueType::Direct);
|
bool Initialize(ID3D12Device* device, CommandQueueType type = CommandQueueType::Direct);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
void ExecuteCommandLists(uint32_t count, ICommandList** lists);
|
|
||||||
void ExecuteCommandLists(uint32_t count, ID3D12CommandList** lists);
|
void ExecuteCommandLists(uint32_t count, ID3D12CommandList** lists);
|
||||||
void Signal(IFence* fence, uint64_t value);
|
void Signal(D3D12Fence* fence, uint64_t value);
|
||||||
void Signal(ID3D12Fence* fence, uint64_t value);
|
void Signal(ID3D12Fence* fence, uint64_t value);
|
||||||
void Wait(IFence* fence, uint64_t value);
|
void Wait(D3D12Fence* fence, uint64_t value);
|
||||||
void Wait(ID3D12Fence* fence, uint64_t value);
|
void Wait(ID3D12Fence* fence, uint64_t value);
|
||||||
uint64_t GetCompletedValue();
|
uint64_t GetCompletedValue();
|
||||||
void WaitForIdle();
|
void WaitForIdle();
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
#include "../Enums.h"
|
#include "../Enums.h"
|
||||||
#include "../Types.h"
|
#include "../Types.h"
|
||||||
#include "../DescriptorHeap.h"
|
|
||||||
#include "D3D12Enum.h"
|
#include "D3D12Enum.h"
|
||||||
|
|
||||||
using Microsoft::WRL::ComPtr;
|
using Microsoft::WRL::ComPtr;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "../Enums.h"
|
#include "../Enums.h"
|
||||||
#include "../RHIDevice.h"
|
#include "../Types.h"
|
||||||
#include "D3D12Enum.h"
|
#include "D3D12Enum.h"
|
||||||
|
|
||||||
using Microsoft::WRL::ComPtr;
|
using Microsoft::WRL::ComPtr;
|
||||||
@@ -54,7 +54,7 @@ public:
|
|||||||
|
|
||||||
ID3D12Device* GetDevice() const { return m_device.Get(); }
|
ID3D12Device* GetDevice() const { return m_device.Get(); }
|
||||||
IDXGIFactory4* GetFactory() const { return m_factory.Get(); }
|
IDXGIFactory4* GetFactory() const { return m_factory.Get(); }
|
||||||
const ::XCEngine::RHI::DeviceInfo& GetDeviceInfo() const { return m_deviceInfo; }
|
const AdapterInfo& GetAdapterInfo() const { return m_adapterInfo; }
|
||||||
|
|
||||||
std::vector<AdapterInfo> EnumerateAdapters();
|
std::vector<AdapterInfo> EnumerateAdapters();
|
||||||
|
|
||||||
@@ -66,39 +66,38 @@ public:
|
|||||||
bool IsDeviceRemoved() const { return m_isDeviceRemoved; }
|
bool IsDeviceRemoved() const { return m_isDeviceRemoved; }
|
||||||
|
|
||||||
// Factory methods
|
// Factory methods
|
||||||
ICommandQueue* CreateCommandQueue(const CommandQueueDesc& desc);
|
D3D12CommandQueue* CreateCommandQueue(const CommandQueueDesc& desc);
|
||||||
ICommandList* CreateCommandList(const CommandListDesc& desc);
|
D3D12CommandList* CreateCommandList(const CommandListDesc& desc);
|
||||||
ICommandAllocator* CreateCommandAllocator(const CommandAllocatorDesc& desc);
|
D3D12CommandAllocator* CreateCommandAllocator(const CommandAllocatorDesc& desc);
|
||||||
IFence* CreateFence(const FenceDesc& desc);
|
D3D12Fence* CreateFence(const FenceDesc& desc);
|
||||||
IDescriptorHeap* CreateDescriptorHeap(const DescriptorHeapDesc& desc);
|
D3D12DescriptorHeap* CreateDescriptorHeap(const DescriptorHeapDesc& desc);
|
||||||
IQueryHeap* CreateQueryHeap(const QueryHeapDesc& desc);
|
D3D12QueryHeap* CreateQueryHeap(const QueryHeapDesc& desc);
|
||||||
IRootSignature* CreateRootSignature(const RootSignatureDesc& desc);
|
D3D12RootSignature* CreateRootSignature(const RootSignatureDesc& desc);
|
||||||
IPipelineState* CreatePipelineState(const PipelineStateDesc& desc);
|
D3D12PipelineState* CreatePipelineState(const PipelineStateDesc& desc);
|
||||||
ISampler* CreateSampler(const SamplerDesc& desc);
|
D3D12Sampler* CreateSampler(const SamplerDesc& desc);
|
||||||
ITexture* CreateTexture(const TextureDesc& desc);
|
D3D12Texture* CreateTexture(const TextureDesc& desc);
|
||||||
IBuffer* CreateBuffer(const BufferDesc& desc);
|
D3D12Buffer* CreateBuffer(const BufferDesc& desc);
|
||||||
ISwapChain* CreateSwapChain(const SwapChainDesc& desc);
|
D3D12SwapChain* CreateSwapChain(const SwapChainDesc& desc);
|
||||||
IShader* CompileShader(const ShaderCompileDesc& desc);
|
D3D12Shader* CompileShader(const ShaderCompileDesc& desc);
|
||||||
|
|
||||||
IRenderTargetView* CreateRenderTargetView(IBuffer* resource, const RenderTargetViewDesc& desc);
|
D3D12RenderTargetView* CreateRenderTargetView(D3D12Buffer* resource, const RenderTargetViewDesc& desc);
|
||||||
IDepthStencilView* CreateDepthStencilView(IBuffer* resource, const DepthStencilViewDesc& desc);
|
D3D12DepthStencilView* CreateDepthStencilView(D3D12Buffer* resource, const DepthStencilViewDesc& desc);
|
||||||
IShaderResourceView* CreateShaderResourceView(IBuffer* resource, const ShaderResourceViewDesc& desc);
|
D3D12ShaderResourceView* CreateShaderResourceView(D3D12Buffer* resource, const ShaderResourceViewDesc& desc);
|
||||||
IUnorderedAccessView* CreateUnorderedAccessView(IBuffer* resource, const UnorderedAccessViewDesc& desc);
|
D3D12UnorderedAccessView* CreateUnorderedAccessView(D3D12Buffer* resource, const UnorderedAccessViewDesc& desc);
|
||||||
IConstantBufferView* CreateConstantBufferView(IBuffer* resource, const ConstantBufferViewDesc& desc);
|
D3D12ConstantBufferView* CreateConstantBufferView(D3D12Buffer* resource, const ConstantBufferViewDesc& desc);
|
||||||
|
|
||||||
void GetDeviceInfo(DeviceInfo& info) const;
|
|
||||||
void* GetNativeHandle() const;
|
void* GetNativeHandle() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool CreateDXGIFactory(bool enableDebugLayer);
|
bool CreateDXGIFactory(bool enableDebugLayer);
|
||||||
bool CreateDevice(IDXGIAdapter1* adapter);
|
bool CreateDevice(IDXGIAdapter1* adapter);
|
||||||
void QueryDeviceInfo();
|
void QueryAdapterInfo();
|
||||||
|
|
||||||
ComPtr<ID3D12Device> m_device;
|
ComPtr<ID3D12Device> m_device;
|
||||||
ComPtr<IDXGIFactory4> m_factory;
|
ComPtr<IDXGIFactory4> m_factory;
|
||||||
ComPtr<IDXGIAdapter1> m_adapter;
|
ComPtr<IDXGIAdapter1> m_adapter;
|
||||||
|
|
||||||
::XCEngine::RHI::DeviceInfo m_deviceInfo;
|
AdapterInfo m_adapterInfo;
|
||||||
bool m_isDeviceRemoved;
|
bool m_isDeviceRemoved;
|
||||||
bool m_initialized;
|
bool m_initialized;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include <wrl/client.h>
|
#include <wrl/client.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include "../Fence.h"
|
|
||||||
|
|
||||||
using Microsoft::WRL::ComPtr;
|
using Microsoft::WRL::ComPtr;
|
||||||
|
|
||||||
|
|||||||
@@ -36,23 +36,13 @@ void D3D12CommandQueue::Shutdown() {
|
|||||||
m_commandQueue.Reset();
|
m_commandQueue.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3D12CommandQueue::ExecuteCommandLists(uint32_t count, ICommandList** lists) {
|
|
||||||
std::vector<ID3D12CommandList*> d3d12Lists(count);
|
|
||||||
for (uint32_t i = 0; i < count; ++i) {
|
|
||||||
if (lists[i]) {
|
|
||||||
d3d12Lists[i] = reinterpret_cast<D3D12CommandList*>(lists[i])->GetCommandList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_commandQueue->ExecuteCommandLists(count, d3d12Lists.data());
|
|
||||||
}
|
|
||||||
|
|
||||||
void D3D12CommandQueue::ExecuteCommandLists(uint32_t count, ID3D12CommandList** lists) {
|
void D3D12CommandQueue::ExecuteCommandLists(uint32_t count, ID3D12CommandList** lists) {
|
||||||
m_commandQueue->ExecuteCommandLists(count, lists);
|
m_commandQueue->ExecuteCommandLists(count, lists);
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3D12CommandQueue::Signal(IFence* fence, uint64_t value) {
|
void D3D12CommandQueue::Signal(D3D12Fence* fence, uint64_t value) {
|
||||||
if (fence) {
|
if (fence) {
|
||||||
m_commandQueue->Signal(reinterpret_cast<D3D12Fence*>(fence)->GetFence(), value);
|
m_commandQueue->Signal(fence->GetFence(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,9 +52,9 @@ void D3D12CommandQueue::Signal(ID3D12Fence* fence, uint64_t value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3D12CommandQueue::Wait(IFence* fence, uint64_t value) {
|
void D3D12CommandQueue::Wait(D3D12Fence* fence, uint64_t value) {
|
||||||
if (fence) {
|
if (fence) {
|
||||||
m_commandQueue->Wait(reinterpret_cast<D3D12Fence*>(fence)->GetFence(), value);
|
m_commandQueue->Wait(fence->GetFence(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ bool D3D12Device::Initialize(bool enableDebugLayer) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryDeviceInfo();
|
QueryAdapterInfo();
|
||||||
m_initialized = true;
|
m_initialized = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ bool D3D12Device::CreateDevice(IDXGIAdapter1* adapter) {
|
|||||||
return SUCCEEDED(hr);
|
return SUCCEEDED(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3D12Device::QueryDeviceInfo() {
|
void D3D12Device::QueryAdapterInfo() {
|
||||||
if (!m_adapter) {
|
if (!m_adapter) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -126,26 +126,20 @@ void D3D12Device::QueryDeviceInfo() {
|
|||||||
DXGI_ADAPTER_DESC1 desc;
|
DXGI_ADAPTER_DESC1 desc;
|
||||||
m_adapter->GetDesc1(&desc);
|
m_adapter->GetDesc1(&desc);
|
||||||
|
|
||||||
m_deviceInfo.vendorId = desc.VendorId;
|
m_adapterInfo.vendorId = desc.VendorId;
|
||||||
m_deviceInfo.deviceId = desc.DeviceId;
|
m_adapterInfo.deviceId = desc.DeviceId;
|
||||||
m_deviceInfo.dedicatedVideoMemory = desc.DedicatedVideoMemory;
|
m_adapterInfo.dedicatedVideoMemory = desc.DedicatedVideoMemory;
|
||||||
m_deviceInfo.dedicatedSystemMemory = desc.DedicatedSystemMemory;
|
m_adapterInfo.dedicatedSystemMemory = desc.DedicatedSystemMemory;
|
||||||
m_deviceInfo.sharedSystemMemory = desc.SharedSystemMemory;
|
m_adapterInfo.sharedSystemMemory = desc.SharedSystemMemory;
|
||||||
m_deviceInfo.deviceName = desc.Description;
|
m_adapterInfo.description = desc.Description;
|
||||||
|
m_adapterInfo.isSoftware = (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) != 0;
|
||||||
m_deviceInfo.supportsRaytracing = false;
|
|
||||||
m_deviceInfo.supportsMeshShaders = false;
|
|
||||||
m_deviceInfo.supportsSamplerFeedback = false;
|
|
||||||
|
|
||||||
D3D12_FEATURE_DATA_D3D12_OPTIONS5 options5 = {};
|
D3D12_FEATURE_DATA_D3D12_OPTIONS5 options5 = {};
|
||||||
if (SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS5, &options5, sizeof(options5)))) {
|
if (SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS5, &options5, sizeof(options5)))) {
|
||||||
m_deviceInfo.supportsRaytracing = (options5.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
D3D12_FEATURE_DATA_D3D12_OPTIONS7 options7 = {};
|
D3D12_FEATURE_DATA_D3D12_OPTIONS7 options7 = {};
|
||||||
if (SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS7, &options7, sizeof(options7)))) {
|
if (SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS7, &options7, sizeof(options7)))) {
|
||||||
m_deviceInfo.supportsSamplerFeedback = (options7.SamplerFeedbackTier != D3D12_SAMPLER_FEEDBACK_TIER_NOT_SUPPORTED);
|
|
||||||
m_deviceInfo.supportsMeshShaders = (options7.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,10 +181,6 @@ UINT D3D12Device::GetDescriptorHandleIncrementSize(DescriptorHeapType type) cons
|
|||||||
return m_device->GetDescriptorHandleIncrementSize(ToD3D12(type));
|
return m_device->GetDescriptorHandleIncrementSize(ToD3D12(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3D12Device::GetDeviceInfo(DeviceInfo& info) const {
|
|
||||||
info = m_deviceInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* D3D12Device::GetNativeHandle() const {
|
void* D3D12Device::GetNativeHandle() const {
|
||||||
return m_device.Get();
|
return m_device.Get();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user