fix(RHI): 修复 OpenGL/D3D12 后端编译问题

- 修复 OpenGLCommandList 方法签名匹配 RHI 抽象接口
- 修复 OpenGLSwapChain Present/Resize 方法签名
- 添加 OpenGL 特有方法重载支持后端测试(底层逃逸)
- 暂时禁用不兼容的 Resources 模块
- 更新 OpenGL 测试 CMakeLists
This commit is contained in:
2026-03-17 19:35:51 +08:00
parent a257ff2d8b
commit e138fb2075
15 changed files with 188 additions and 308 deletions

View File

@@ -31,9 +31,12 @@ public:
void TransitionBarrier(void* resource, ResourceStates stateBefore, ResourceStates stateAfter) override;
void TransitionBarrierInternal(ID3D12Resource* resource, ResourceStates stateBefore, ResourceStates stateAfter, uint32_t subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES);
void UAVBarrier(void* resource = nullptr);
void UAVBarrierInternal(ID3D12Resource* resource);
void AliasBarrier(void* beforeResource = nullptr, void* afterResource = nullptr);
void AliasBarrierInternal(ID3D12Resource* beforeResource, ID3D12Resource* afterResource);
void SetPipelineState(void* pso) override;
void SetPipelineStateInternal(ID3D12PipelineState* pso);
void SetRootSignature(ID3D12RootSignature* signature);
void SetViewport(const Viewport& viewport) override;
void SetViewports(uint32_t count, const Viewport* viewports) override;
@@ -68,7 +71,9 @@ public:
void Draw(uint32_t vertexCount, uint32_t instanceCount = 1, uint32_t startVertex = 0, uint32_t startInstance = 0) override;
void DrawIndexed(uint32_t indexCount, uint32_t instanceCount = 1, uint32_t startIndex = 0, int32_t baseVertex = 0, uint32_t startInstance = 0) override;
void DrawInstancedIndirect(void* argBuffer, uint64_t alignedByteOffset);
void DrawInstancedIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset);
void DrawIndexedInstancedIndirect(void* argBuffer, uint64_t alignedByteOffset);
void DrawIndexedInstancedIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset);
void Clear(float r, float g, float b, float a, uint32_t buffers) override;
void ClearRenderTarget(void* renderTarget, const float color[4]) override;
@@ -90,6 +95,7 @@ public:
void Dispatch(uint32_t x, uint32_t y, uint32_t z) override;
void DispatchIndirect(void* argBuffer, uint64_t alignedByteOffset);
void DispatchIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset);
void ExecuteBundle(ID3D12GraphicsCommandList* bundle);

View File

@@ -80,7 +80,7 @@ public:
const RHIDeviceInfo& GetDeviceInfo() const override;
void* GetNativeDevice() override;
void* GetNativeHandle() const override;
void* GetNativeHandle() const;
bool PollEvents() override;
void SwapBuffers() override;

View File

@@ -57,6 +57,12 @@ public:
void SetVertexBuffers(uint32_t startSlot, uint32_t count, const uint64_t* buffers, const uint64_t* offsets, const uint32_t* strides) override;
void SetIndexBuffer(void* buffer, uint64_t offset, Format format) override;
// OpenGL 特有版本(底层逃逸)
void SetVertexBuffer(unsigned int buffer, size_t offset, size_t stride);
void SetVertexBuffers(unsigned int startSlot, unsigned int count, const unsigned int* buffers, const size_t* offsets, const size_t* strides);
void SetIndexBuffer(unsigned int buffer, unsigned int type);
void SetIndexBuffer(unsigned int buffer, unsigned int type, size_t offset);
void BindVertexArray(unsigned int vao);
void BindVertexArray(unsigned int vao, unsigned int indexBuffer, unsigned int indexType);
void UseShader(unsigned int program);

View File

@@ -21,7 +21,7 @@ public:
bool InitializeWithExistingWindow(GLFWwindow* window);
GLFWwindow* GetWindow() const { return m_window; }
const OpenGLDeviceInfo& GetDeviceInfoImpl() const { return m_deviceInfo; }
const RHIDeviceInfo& GetDeviceInfoImpl() const { return m_deviceInfo; }
void SwapBuffers() override;
bool PollEvents() override;
@@ -42,13 +42,12 @@ public:
const RHIDeviceInfo& GetDeviceInfo() const override;
void* GetNativeDevice() override;
void* GetNativeHandle() const override;
void* GetNativeHandle() const;
private:
GLFWwindow* m_window;
OpenGLDeviceInfo m_deviceInfo;
RHIDeviceInfo m_deviceInfo;
RHICapabilities m_capabilities;
RHIDeviceInfo m_deviceInfoBase;
bool m_initialized;
bool m_ownsWindow;
};

View File

@@ -5,43 +5,20 @@
#include <string>
#include "../RHIPipelineState.h"
#include "../RHIEnums.h"
namespace XCEngine {
namespace RHI {
enum class ComparisonFunc {
Never,
Less,
Equal,
LessEqual,
Greater,
NotEqual,
GreaterEqual,
Always
enum class OpenGLPrimitiveTopology {
Points,
Lines,
LineStrip,
Triangles,
TriangleStrip
};
enum class BlendFactor {
Zero,
One,
SrcColor,
OneMinusSrcColor,
DstColor,
OneMinusDstColor,
SrcAlpha,
OneMinusSrcAlpha,
DstAlpha,
OneMinusDstAlpha,
ConstantColor,
OneMinusConstantColor,
ConstantAlpha,
OneMinusConstantAlpha,
Src1Color,
InvSrc1Color,
Src1Alpha,
InvSrc1Alpha
};
enum class BlendOp {
enum class OpenGLBlendOp {
Add,
Subtract,
ReverseSubtract,
@@ -66,17 +43,6 @@ enum class PolygonMode {
Fill
};
enum class StencilOp {
Keep,
Zero,
Replace,
Incr,
IncrWrap,
Decr,
DecrWrap,
Invert
};
struct DepthStencilState {
bool depthTestEnable = true;
bool depthWriteEnable = true;
@@ -94,7 +60,7 @@ struct DepthStencilState {
struct BlendState {
bool blendEnable = false;
BlendFactor srcBlend = BlendFactor::SrcAlpha;
BlendFactor dstBlend = BlendFactor::OneMinusSrcAlpha;
BlendFactor dstBlend = BlendFactor::InvSrcAlpha;
BlendFactor srcBlendAlpha = BlendFactor::One;
BlendFactor dstBlendAlpha = BlendFactor::Zero;
BlendOp blendOp = BlendOp::Add;