Implement IShader and ISwapChain interfaces for D3D12 backend

- D3D12Shader now implements IShader interface with GetBytecode, GetBytecodeSize, GetType, GetInputLayout
- D3D12SwapChain now implements ISwapChain interface with GetBackBuffer returning IResource*
- Added D3D12Texture back buffer storage to SwapChain
- Fixed ISwapChain const correctness (GetCurrentBackBufferIndex, GetBackBuffer)
- main.cpp: use GetD3D12Bytecode() instead of GetBytecode() for PSO creation
This commit is contained in:
2026-03-16 12:38:17 +08:00
parent f4d94bda3d
commit 554c48448b
10 changed files with 84 additions and 46 deletions

View File

@@ -28,11 +28,7 @@ public:
uint32_t GetDescriptorCount() const override;
DescriptorType GetType() const override;
D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorHandle(uint32_t index) const;
D3D12_GPU_DESCRIPTOR_HANDLE GetGPUDescriptorHandle(uint32_t index) const;
uint32_t GetDescriptorSize() const { return m_descriptorSize; }
D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorHandleForHeapStart() const;
D3D12_GPU_DESCRIPTOR_HANDLE GetGPUDescriptorHandleForHeapStart() const;

View File

@@ -1,9 +1,11 @@
#pragma once
#include <d3d12.h>
#include <dxgi1_4.h>
#include <wrl/client.h>
#include <string>
#include "../SwapChain.h"
#include "D3D12Enum.h"
using Microsoft::WRL::ComPtr;
@@ -11,7 +13,7 @@ using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12Shader {
class D3D12Shader : public IShader {
public:
D3D12Shader();
~D3D12Shader();
@@ -20,13 +22,17 @@ public:
bool Compile(const void* sourceData, size_t sourceSize, const char* entryPoint, const char* target);
void Shutdown();
const D3D12_SHADER_BYTECODE GetBytecode() const;
ShaderType GetType() const { return m_type; }
const D3D12_SHADER_BYTECODE GetD3D12Bytecode() const;
virtual const void* GetBytecode() const override;
virtual size_t GetBytecodeSize() const override;
virtual ShaderType GetType() const override;
virtual const InputLayoutDesc& GetInputLayout() const override;
private:
ComPtr<ID3DBlob> m_bytecode;
ComPtr<ID3DBlob> m_error;
ShaderType m_type;
InputLayoutDesc m_inputLayout;
};
} // namespace RHI

View File

@@ -4,15 +4,16 @@
#include <dxgi1_4.h>
#include <wrl/client.h>
#include "../Enums.h"
#include "../SwapChain.h"
#include "D3D12Enum.h"
#include "D3D12Texture.h"
using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12SwapChain {
class D3D12SwapChain : public ISwapChain {
public:
D3D12SwapChain();
~D3D12SwapChain();
@@ -21,10 +22,13 @@ public:
bool Initialize(IDXGISwapChain* swapChain, uint32_t width, uint32_t height);
void Shutdown();
uint32_t GetCurrentBackBufferIndex() const;
ID3D12Resource* GetBackBuffer(uint32_t index) const;
void Present(uint32_t syncInterval, uint32_t flags);
void Resize(uint32_t width, uint32_t height);
uint32_t GetCurrentBackBufferIndex() const override;
IResource* GetBackBuffer(uint32_t index) const override;
void Present(uint32_t syncInterval, uint32_t flags) override;
void Resize(uint32_t width, uint32_t height) override;
void SetFullscreen(bool fullscreen) override;
bool IsFullscreen() const override;
void* GetNativeHandle() const override;
IDXGISwapChain3* GetSwapChain() const { return m_swapChain.Get(); }
@@ -35,6 +39,7 @@ private:
uint32_t m_width;
uint32_t m_height;
uint32_t m_bufferCount;
std::vector<D3D12Texture> m_backBuffers;
};
} // namespace RHI

View File

@@ -11,8 +11,8 @@ class ISwapChain {
public:
virtual ~ISwapChain() = default;
virtual uint32_t GetCurrentBackBufferIndex() = 0;
virtual IResource* GetBackBuffer(uint32_t index) = 0;
virtual uint32_t GetCurrentBackBufferIndex() const = 0;
virtual IResource* GetBackBuffer(uint32_t index) const = 0;
virtual void Present(uint32_t syncInterval, uint32_t flags) = 0;
virtual void Resize(uint32_t width, uint32_t height) = 0;
virtual void SetFullscreen(bool fullscreen) = 0;