Add D3D12 view wrapper classes: RTV, DSV, SRV, CBV
This commit is contained in:
@@ -98,6 +98,10 @@ add_library(XCEngine STATIC
|
|||||||
include/XCEngine/RHI/D3D12/D3D12SwapChain.h
|
include/XCEngine/RHI/D3D12/D3D12SwapChain.h
|
||||||
include/XCEngine/RHI/D3D12/D3D12Fence.h
|
include/XCEngine/RHI/D3D12/D3D12Fence.h
|
||||||
include/XCEngine/RHI/D3D12/D3D12Screenshot.h
|
include/XCEngine/RHI/D3D12/D3D12Screenshot.h
|
||||||
|
include/XCEngine/RHI/D3D12/D3D12RenderTargetView.h
|
||||||
|
include/XCEngine/RHI/D3D12/D3D12DepthStencilView.h
|
||||||
|
include/XCEngine/RHI/D3D12/D3D12ShaderResourceView.h
|
||||||
|
include/XCEngine/RHI/D3D12/D3D12ConstantBufferView.h
|
||||||
src/RHI/D3D12Device.cpp
|
src/RHI/D3D12Device.cpp
|
||||||
src/RHI/D3D12CommandQueue.cpp
|
src/RHI/D3D12CommandQueue.cpp
|
||||||
src/RHI/D3D12CommandAllocator.cpp
|
src/RHI/D3D12CommandAllocator.cpp
|
||||||
@@ -112,6 +116,10 @@ add_library(XCEngine STATIC
|
|||||||
src/RHI/D3D12SwapChain.cpp
|
src/RHI/D3D12SwapChain.cpp
|
||||||
src/RHI/D3D12Fence.cpp
|
src/RHI/D3D12Fence.cpp
|
||||||
src/RHI/D3D12Screenshot.cpp
|
src/RHI/D3D12Screenshot.cpp
|
||||||
|
src/RHI/D3D12RenderTargetView.cpp
|
||||||
|
src/RHI/D3D12DepthStencilView.cpp
|
||||||
|
src/RHI/D3D12ShaderResourceView.cpp
|
||||||
|
src/RHI/D3D12ConstantBufferView.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(XCEngine PUBLIC
|
target_include_directories(XCEngine PUBLIC
|
||||||
|
|||||||
27
engine/include/XCEngine/RHI/D3D12/D3D12ConstantBufferView.h
Normal file
27
engine/include/XCEngine/RHI/D3D12/D3D12ConstantBufferView.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <d3d12.h>
|
||||||
|
#include <wrl/client.h>
|
||||||
|
|
||||||
|
using Microsoft::WRL::ComPtr;
|
||||||
|
|
||||||
|
namespace XCEngine {
|
||||||
|
namespace RHI {
|
||||||
|
|
||||||
|
class D3D12ConstantBufferView {
|
||||||
|
public:
|
||||||
|
D3D12ConstantBufferView();
|
||||||
|
~D3D12ConstantBufferView();
|
||||||
|
|
||||||
|
void Initialize(ID3D12Device* device, ID3D12Resource* buffer, const D3D12_CONSTANT_BUFFER_VIEW_DESC* desc = nullptr);
|
||||||
|
void Shutdown();
|
||||||
|
|
||||||
|
D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorHandle() const { return m_handle; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
D3D12_CPU_DESCRIPTOR_HANDLE m_handle;
|
||||||
|
ID3D12Resource* m_resource;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace RHI
|
||||||
|
} // namespace XCEngine
|
||||||
27
engine/include/XCEngine/RHI/D3D12/D3D12DepthStencilView.h
Normal file
27
engine/include/XCEngine/RHI/D3D12/D3D12DepthStencilView.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <d3d12.h>
|
||||||
|
#include <wrl/client.h>
|
||||||
|
|
||||||
|
using Microsoft::WRL::ComPtr;
|
||||||
|
|
||||||
|
namespace XCEngine {
|
||||||
|
namespace RHI {
|
||||||
|
|
||||||
|
class D3D12DepthStencilView {
|
||||||
|
public:
|
||||||
|
D3D12DepthStencilView();
|
||||||
|
~D3D12DepthStencilView();
|
||||||
|
|
||||||
|
void Initialize(ID3D12Device* device, ID3D12Resource* resource, const D3D12_DEPTH_STENCIL_VIEW_DESC* desc = nullptr);
|
||||||
|
void Shutdown();
|
||||||
|
|
||||||
|
D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorHandle() const { return m_handle; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
D3D12_CPU_DESCRIPTOR_HANDLE m_handle;
|
||||||
|
ID3D12Resource* m_resource;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace RHI
|
||||||
|
} // namespace XCEngine
|
||||||
27
engine/include/XCEngine/RHI/D3D12/D3D12RenderTargetView.h
Normal file
27
engine/include/XCEngine/RHI/D3D12/D3D12RenderTargetView.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <d3d12.h>
|
||||||
|
#include <wrl/client.h>
|
||||||
|
|
||||||
|
using Microsoft::WRL::ComPtr;
|
||||||
|
|
||||||
|
namespace XCEngine {
|
||||||
|
namespace RHI {
|
||||||
|
|
||||||
|
class D3D12RenderTargetView {
|
||||||
|
public:
|
||||||
|
D3D12RenderTargetView();
|
||||||
|
~D3D12RenderTargetView();
|
||||||
|
|
||||||
|
void Initialize(ID3D12Device* device, ID3D12Resource* resource, const D3D12_RENDER_TARGET_VIEW_DESC* desc = nullptr);
|
||||||
|
void Shutdown();
|
||||||
|
|
||||||
|
D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorHandle() const { return m_handle; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
D3D12_CPU_DESCRIPTOR_HANDLE m_handle;
|
||||||
|
ID3D12Resource* m_resource;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace RHI
|
||||||
|
} // namespace XCEngine
|
||||||
27
engine/include/XCEngine/RHI/D3D12/D3D12ShaderResourceView.h
Normal file
27
engine/include/XCEngine/RHI/D3D12/D3D12ShaderResourceView.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <d3d12.h>
|
||||||
|
#include <wrl/client.h>
|
||||||
|
|
||||||
|
using Microsoft::WRL::ComPtr;
|
||||||
|
|
||||||
|
namespace XCEngine {
|
||||||
|
namespace RHI {
|
||||||
|
|
||||||
|
class D3D12ShaderResourceView {
|
||||||
|
public:
|
||||||
|
D3D12ShaderResourceView();
|
||||||
|
~D3D12ShaderResourceView();
|
||||||
|
|
||||||
|
void Initialize(ID3D12Device* device, ID3D12Resource* resource, const D3D12_SHADER_RESOURCE_VIEW_DESC* desc = nullptr);
|
||||||
|
void Shutdown();
|
||||||
|
|
||||||
|
D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorHandle() const { return m_handle; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
D3D12_CPU_DESCRIPTOR_HANDLE m_handle;
|
||||||
|
ID3D12Resource* m_resource;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace RHI
|
||||||
|
} // namespace XCEngine
|
||||||
35
engine/src/RHI/D3D12ConstantBufferView.cpp
Normal file
35
engine/src/RHI/D3D12ConstantBufferView.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#include "XCEngine/RHI/D3D12/D3D12ConstantBufferView.h"
|
||||||
|
|
||||||
|
namespace XCEngine {
|
||||||
|
namespace RHI {
|
||||||
|
|
||||||
|
D3D12ConstantBufferView::D3D12ConstantBufferView()
|
||||||
|
: m_handle({0})
|
||||||
|
, m_resource(nullptr) {
|
||||||
|
}
|
||||||
|
|
||||||
|
D3D12ConstantBufferView::~D3D12ConstantBufferView() {
|
||||||
|
Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void D3D12ConstantBufferView::Initialize(ID3D12Device* device, ID3D12Resource* buffer, const D3D12_CONSTANT_BUFFER_VIEW_DESC* desc) {
|
||||||
|
m_resource = buffer;
|
||||||
|
m_handle = {};
|
||||||
|
|
||||||
|
if (desc) {
|
||||||
|
device->CreateConstantBufferView(desc, m_handle);
|
||||||
|
} else {
|
||||||
|
D3D12_CONSTANT_BUFFER_VIEW_DESC cbvDesc = {};
|
||||||
|
cbvDesc.BufferLocation = buffer->GetGPUVirtualAddress();
|
||||||
|
cbvDesc.SizeInBytes = static_cast<UINT>(buffer->GetDesc().Width);
|
||||||
|
device->CreateConstantBufferView(&cbvDesc, m_handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void D3D12ConstantBufferView::Shutdown() {
|
||||||
|
m_handle = {};
|
||||||
|
m_resource = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace RHI
|
||||||
|
} // namespace XCEngine
|
||||||
27
engine/src/RHI/D3D12DepthStencilView.cpp
Normal file
27
engine/src/RHI/D3D12DepthStencilView.cpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#include "XCEngine/RHI/D3D12/D3D12DepthStencilView.h"
|
||||||
|
|
||||||
|
namespace XCEngine {
|
||||||
|
namespace RHI {
|
||||||
|
|
||||||
|
D3D12DepthStencilView::D3D12DepthStencilView()
|
||||||
|
: m_handle({0})
|
||||||
|
, m_resource(nullptr) {
|
||||||
|
}
|
||||||
|
|
||||||
|
D3D12DepthStencilView::~D3D12DepthStencilView() {
|
||||||
|
Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void D3D12DepthStencilView::Initialize(ID3D12Device* device, ID3D12Resource* resource, const D3D12_DEPTH_STENCIL_VIEW_DESC* desc) {
|
||||||
|
m_resource = resource;
|
||||||
|
m_handle = {};
|
||||||
|
device->CreateDepthStencilView(resource, desc, m_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void D3D12DepthStencilView::Shutdown() {
|
||||||
|
m_handle = {};
|
||||||
|
m_resource = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace RHI
|
||||||
|
} // namespace XCEngine
|
||||||
27
engine/src/RHI/D3D12RenderTargetView.cpp
Normal file
27
engine/src/RHI/D3D12RenderTargetView.cpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#include "XCEngine/RHI/D3D12/D3D12RenderTargetView.h"
|
||||||
|
|
||||||
|
namespace XCEngine {
|
||||||
|
namespace RHI {
|
||||||
|
|
||||||
|
D3D12RenderTargetView::D3D12RenderTargetView()
|
||||||
|
: m_handle({0})
|
||||||
|
, m_resource(nullptr) {
|
||||||
|
}
|
||||||
|
|
||||||
|
D3D12RenderTargetView::~D3D12RenderTargetView() {
|
||||||
|
Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void D3D12RenderTargetView::Initialize(ID3D12Device* device, ID3D12Resource* resource, const D3D12_RENDER_TARGET_VIEW_DESC* desc) {
|
||||||
|
m_resource = resource;
|
||||||
|
m_handle = {};
|
||||||
|
device->CreateRenderTargetView(resource, desc, m_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void D3D12RenderTargetView::Shutdown() {
|
||||||
|
m_handle = {};
|
||||||
|
m_resource = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace RHI
|
||||||
|
} // namespace XCEngine
|
||||||
27
engine/src/RHI/D3D12ShaderResourceView.cpp
Normal file
27
engine/src/RHI/D3D12ShaderResourceView.cpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#include "XCEngine/RHI/D3D12/D3D12ShaderResourceView.h"
|
||||||
|
|
||||||
|
namespace XCEngine {
|
||||||
|
namespace RHI {
|
||||||
|
|
||||||
|
D3D12ShaderResourceView::D3D12ShaderResourceView()
|
||||||
|
: m_handle({0})
|
||||||
|
, m_resource(nullptr) {
|
||||||
|
}
|
||||||
|
|
||||||
|
D3D12ShaderResourceView::~D3D12ShaderResourceView() {
|
||||||
|
Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void D3D12ShaderResourceView::Initialize(ID3D12Device* device, ID3D12Resource* resource, const D3D12_SHADER_RESOURCE_VIEW_DESC* desc) {
|
||||||
|
m_resource = resource;
|
||||||
|
m_handle = {};
|
||||||
|
device->CreateShaderResourceView(resource, desc, m_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void D3D12ShaderResourceView::Shutdown() {
|
||||||
|
m_handle = {};
|
||||||
|
m_resource = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace RHI
|
||||||
|
} // namespace XCEngine
|
||||||
Reference in New Issue
Block a user