feat: 实现 D3D12Texture 和 D3D12Buffer 资源类
- 添加 D3D12Texture.h/cpp - 纹理资源封装 - 添加 D3D12Buffer.h/cpp - 缓冲区资源封装 - 支持 CreateCommittedResource 创建资源 - 测试通过
This commit is contained in:
@@ -89,7 +89,9 @@ add_library(XCEngine STATIC
|
||||
include/XCEngine/RHI/D3D12/D3D12CommandAllocator.h
|
||||
include/XCEngine/RHI/D3D12/D3D12CommandList.h
|
||||
include/XCEngine/RHI/D3D12/D3D12DescriptorHeap.h
|
||||
include/XCEngine/RHI/D3D12/D3D12Buffer.h
|
||||
include/XCEngine/RHI/D3D12/D3D12PipelineState.h
|
||||
include/XCEngine/RHI/D3D12/D3D12Texture.h
|
||||
include/XCEngine/RHI/D3D12/D3D12RootSignature.h
|
||||
include/XCEngine/RHI/D3D12/D3D12SwapChain.h
|
||||
include/XCEngine/RHI/D3D12/D3D12Fence.h
|
||||
@@ -99,7 +101,9 @@ add_library(XCEngine STATIC
|
||||
src/RHI/D3D12CommandAllocator.cpp
|
||||
src/RHI/D3D12CommandList.cpp
|
||||
src/RHI/D3D12DescriptorHeap.cpp
|
||||
src/RHI/D3D12Buffer.cpp
|
||||
src/RHI/D3D12PipelineState.cpp
|
||||
src/RHI/D3D12Texture.cpp
|
||||
src/RHI/D3D12RootSignature.cpp
|
||||
src/RHI/D3D12SwapChain.cpp
|
||||
src/RHI/D3D12Fence.cpp
|
||||
|
||||
33
engine/include/XCEngine/RHI/D3D12/D3D12Buffer.h
Normal file
33
engine/include/XCEngine/RHI/D3D12/D3D12Buffer.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <d3d12.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
#include "D3D12Enum.h"
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
class D3D12Buffer {
|
||||
public:
|
||||
D3D12Buffer();
|
||||
~D3D12Buffer();
|
||||
|
||||
bool Initialize(ID3D12Device* device, uint64_t size, D3D12_RESOURCE_STATES initialState = D3D12_RESOURCE_STATE_COMMON);
|
||||
bool InitializeFromExisting(ID3D12Resource* resource);
|
||||
void Shutdown();
|
||||
|
||||
ID3D12Resource* GetResource() const { return m_resource.Get(); }
|
||||
D3D12_RESOURCE_DESC GetDesc() const { return m_resource->GetDesc(); }
|
||||
|
||||
uint64_t GetSize() const { return GetDesc().Width; }
|
||||
D3D12_GPU_VIRTUAL_ADDRESS GetGPUVirtualAddress() const { return m_resource->GetGPUVirtualAddress(); }
|
||||
|
||||
private:
|
||||
ComPtr<ID3D12Resource> m_resource;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
36
engine/include/XCEngine/RHI/D3D12/D3D12Texture.h
Normal file
36
engine/include/XCEngine/RHI/D3D12/D3D12Texture.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <d3d12.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
#include "D3D12Enum.h"
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
class D3D12Texture {
|
||||
public:
|
||||
D3D12Texture();
|
||||
~D3D12Texture();
|
||||
|
||||
bool Initialize(ID3D12Device* device, const D3D12_RESOURCE_DESC& desc, D3D12_RESOURCE_STATES initialState = D3D12_RESOURCE_STATE_COMMON);
|
||||
bool InitializeFromExisting(ID3D12Resource* resource);
|
||||
void Shutdown();
|
||||
|
||||
ID3D12Resource* GetResource() const { return m_resource.Get(); }
|
||||
D3D12_RESOURCE_DESC GetDesc() const { return m_resource->GetDesc(); }
|
||||
|
||||
uint32_t GetWidth() const { return static_cast<uint32_t>(GetDesc().Width); }
|
||||
uint32_t GetHeight() const { return GetDesc().Height; }
|
||||
uint32_t GetDepth() const { return GetDesc().DepthOrArraySize; }
|
||||
uint32_t GetMipLevels() const { return GetDesc().MipLevels; }
|
||||
DXGI_FORMAT GetFormat() const { return GetDesc().Format; }
|
||||
|
||||
private:
|
||||
ComPtr<ID3D12Resource> m_resource;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
60
engine/src/RHI/D3D12Buffer.cpp
Normal file
60
engine/src/RHI/D3D12Buffer.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#include "XCEngine/RHI/D3D12/D3D12Buffer.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
D3D12Buffer::D3D12Buffer() {
|
||||
}
|
||||
|
||||
D3D12Buffer::~D3D12Buffer() {
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
bool D3D12Buffer::Initialize(ID3D12Device* device, uint64_t size, D3D12_RESOURCE_STATES initialState) {
|
||||
D3D12_HEAP_PROPERTIES heapProperties = {};
|
||||
heapProperties.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
heapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
||||
heapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
||||
heapProperties.CreationNodeMask = 0;
|
||||
heapProperties.VisibleNodeMask = 0;
|
||||
|
||||
D3D12_RESOURCE_DESC bufferDesc = {};
|
||||
bufferDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
||||
bufferDesc.Alignment = 0;
|
||||
bufferDesc.Width = size;
|
||||
bufferDesc.Height = 1;
|
||||
bufferDesc.DepthOrArraySize = 1;
|
||||
bufferDesc.MipLevels = 1;
|
||||
bufferDesc.Format = DXGI_FORMAT_UNKNOWN;
|
||||
bufferDesc.SampleDesc.Count = 1;
|
||||
bufferDesc.SampleDesc.Quality = 0;
|
||||
bufferDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
|
||||
bufferDesc.Flags = D3D12_RESOURCE_FLAG_NONE;
|
||||
|
||||
HRESULT hResult = device->CreateCommittedResource(
|
||||
&heapProperties,
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
&bufferDesc,
|
||||
initialState,
|
||||
nullptr,
|
||||
IID_PPV_ARGS(&m_resource)
|
||||
);
|
||||
|
||||
if (FAILED(hResult)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool D3D12Buffer::InitializeFromExisting(ID3D12Resource* resource) {
|
||||
m_resource = resource;
|
||||
return true;
|
||||
}
|
||||
|
||||
void D3D12Buffer::Shutdown() {
|
||||
m_resource.Reset();
|
||||
}
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
49
engine/src/RHI/D3D12Texture.cpp
Normal file
49
engine/src/RHI/D3D12Texture.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "XCEngine/RHI/D3D12/D3D12Texture.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
D3D12Texture::D3D12Texture() {
|
||||
}
|
||||
|
||||
D3D12Texture::~D3D12Texture() {
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
bool D3D12Texture::Initialize(ID3D12Device* device, const D3D12_RESOURCE_DESC& desc, D3D12_RESOURCE_STATES initialState) {
|
||||
D3D12_HEAP_PROPERTIES heapProperties = {};
|
||||
heapProperties.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
heapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
||||
heapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
||||
heapProperties.CreationNodeMask = 0;
|
||||
heapProperties.VisibleNodeMask = 0;
|
||||
|
||||
D3D12_CLEAR_VALUE* pOptimizedClearValue = nullptr;
|
||||
|
||||
HRESULT hResult = device->CreateCommittedResource(
|
||||
&heapProperties,
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
&desc,
|
||||
initialState,
|
||||
pOptimizedClearValue,
|
||||
IID_PPV_ARGS(&m_resource)
|
||||
);
|
||||
|
||||
if (FAILED(hResult)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool D3D12Texture::InitializeFromExisting(ID3D12Resource* resource) {
|
||||
m_resource = resource;
|
||||
return true;
|
||||
}
|
||||
|
||||
void D3D12Texture::Shutdown() {
|
||||
m_resource.Reset();
|
||||
}
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user