Files
XCEngine/engine/include/XCEngine/RHI/D3D12/D3D12Buffer.h
ssdfasd 0ce312e648 Remove RHI interface inheritance from all D3D12 backend classes
- D3D12Device, D3D12CommandQueue, D3D12CommandAllocator, D3D12Fence
- D3D12DescriptorHeap, D3D12QueryHeap, D3D12RootSignature
- D3D12PipelineState, D3D12Sampler, D3D12Shader
- D3D12Buffer, D3D12Texture, D3D12SwapChain

All D3D12 backend classes now directly use D3D12 APIs without
going through RHI interface abstraction. This decouples the
D3D12 backend from the RHI abstraction layer.

Test: D3D12 rendering test passed (screenshot comparison 100% match)
2026-03-16 15:48:14 +08:00

58 lines
1.9 KiB
C++

#pragma once
#include <d3d12.h>
#include <wrl/client.h>
#include "D3D12Enum.h"
#include "../SwapChain.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, D3D12_HEAP_TYPE heapType = D3D12_HEAP_TYPE_DEFAULT);
bool InitializeFromExisting(ID3D12Resource* resource);
bool InitializeWithData(ID3D12Device* device, ID3D12GraphicsCommandList* commandList,
const void* data, uint64_t size, D3D12_RESOURCE_STATES finalState);
void Shutdown();
ID3D12Resource* GetResource() const { return m_resource.Get(); }
D3D12_RESOURCE_DESC GetDesc() const { return m_resource->GetDesc(); }
D3D12_GPU_VIRTUAL_ADDRESS GetGPUVirtualAddress() const { return m_resource->GetGPUVirtualAddress(); }
void UpdateData(const void* data, uint64_t size);
void* GetNativeHandle() const { return m_resource.Get(); }
ResourceStates GetState() const { return m_state; }
void SetState(ResourceStates state) { m_state = state; }
uint64_t GetGPUAddress() const { return m_resource->GetGPUVirtualAddress(); }
size_t GetSize() const { return GetDesc().Width; }
const std::string& GetName() const { return m_name; }
void SetName(const std::string& name) { m_name = name; }
uint32_t GetStride() const { return m_stride; }
BufferType GetBufferType() const { return m_bufferType; }
void SetStride(uint32_t stride) { m_stride = stride; }
void SetBufferType(BufferType type) { m_bufferType = type; }
private:
ComPtr<ID3D12Resource> m_resource;
ResourceStates m_state = ResourceStates::Common;
std::string m_name;
uint32_t m_stride = 0;
BufferType m_bufferType = BufferType::Vertex;
};
} // namespace RHI
} // namespace XCEngine