From 6beef97cdf22443c480081240941074432a8d7bb Mon Sep 17 00:00:00 2001 From: TobiD7 Date: Sat, 21 Mar 2026 10:11:10 +0100 Subject: [PATCH] Remove Gfx Driver Vertex and IndexBuffer size config --- backends/include/pd_system/gfx_citro3d.hpp | 3 -- backends/include/pd_system/gfx_directx9.hpp | 3 -- backends/include/pd_system/gfx_opengl2.hpp | 3 -- backends/include/pd_system/gfx_opengl3.hpp | 3 -- backends/source/gfx_directx9.cpp | 37 ++++++++++++++++----- include/pd/drivers/gfx.hpp | 21 ++++++------ vendor/spirv-helper | 2 +- 7 files changed, 41 insertions(+), 31 deletions(-) diff --git a/backends/include/pd_system/gfx_citro3d.hpp b/backends/include/pd_system/gfx_citro3d.hpp index 13e08c1..24a65d8 100644 --- a/backends/include/pd_system/gfx_citro3d.hpp +++ b/backends/include/pd_system/gfx_citro3d.hpp @@ -11,9 +11,6 @@ struct GfxCitro3DConfig { // Index Allocator template using IndexAlloc = LinearAllocator; - - static constexpr size_t NumVertices = 32768; // 8192*4 - static constexpr size_t NumIndices = 49152; // 8192*6 }; class GfxCitro3D : public GfxDriverBase { diff --git a/backends/include/pd_system/gfx_directx9.hpp b/backends/include/pd_system/gfx_directx9.hpp index 178eaae..486a76a 100644 --- a/backends/include/pd_system/gfx_directx9.hpp +++ b/backends/include/pd_system/gfx_directx9.hpp @@ -10,9 +10,6 @@ struct GfxDirectX9Config { // Index Allocator template using IndexAlloc = std::allocator; - - static constexpr size_t NumVertices = 32768; // 8192*4 - static constexpr size_t NumIndices = 49152; // 8192*6 }; class GfxDirectX9 : public GfxDriverBase { diff --git a/backends/include/pd_system/gfx_opengl2.hpp b/backends/include/pd_system/gfx_opengl2.hpp index 7423093..da4ccdc 100644 --- a/backends/include/pd_system/gfx_opengl2.hpp +++ b/backends/include/pd_system/gfx_opengl2.hpp @@ -10,9 +10,6 @@ struct GfxOpenGL2Config { // Index Allocator template using IndexAlloc = std::allocator; - - static constexpr size_t NumVertices = 32768; // 8192*4 - static constexpr size_t NumIndices = 49152; // 8192*6 }; class GfxOpenGL2 : public GfxDriverBase { diff --git a/backends/include/pd_system/gfx_opengl3.hpp b/backends/include/pd_system/gfx_opengl3.hpp index 4639972..3f116a0 100644 --- a/backends/include/pd_system/gfx_opengl3.hpp +++ b/backends/include/pd_system/gfx_opengl3.hpp @@ -10,9 +10,6 @@ struct GfxOpenGL3Config { // Index Allocator template using IndexAlloc = std::allocator; - - static constexpr size_t NumVertices = 32768; // 8192*4 - static constexpr size_t NumIndices = 49152; // 8192*6 }; class GfxOpenGL3 : public GfxDriverBase { diff --git a/backends/source/gfx_directx9.cpp b/backends/source/gfx_directx9.cpp index de84273..9e20de8 100644 --- a/backends/source/gfx_directx9.cpp +++ b/backends/source/gfx_directx9.cpp @@ -61,6 +61,8 @@ struct GfxDirectX9::Impl { IDirect3DVertexShader9* VS = nullptr; IDirect3DPixelShader9* FS = nullptr; IDirect3DTexture9* CurrentTex = nullptr; + size_t VertexBufferSize = 0; + size_t IndexBufferSize = 0; }; void GfxDirectX9::SysInit() { @@ -78,14 +80,7 @@ void GfxDirectX9::SysInit() { 0}, D3DDECL_END()}; impl->Device->CreateVertexDeclaration(elements, &impl->Decl); - impl->Device->CreateVertexBuffer( - GfxDirectX9Config::NumVertices * sizeof(PD::Li::Vertex), - D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &impl->VBO, - nullptr); - impl->Device->CreateIndexBuffer(GfxDirectX9Config::NumIndices * sizeof(u16), - D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, - D3DFMT_INDEX16, D3DPOOL_DEFAULT, &impl->IBO, - nullptr); + ID3DBlob* vsBlob = nullptr; ID3DBlob* errBlob = nullptr; HRESULT hr = D3DCompile(g_vsCode, strlen(g_vsCode), nullptr, nullptr, @@ -140,6 +135,32 @@ void GfxDirectX9::Submit(size_t count, size_t start) { impl->Device->SetVertexShaderConstantF( 0, reinterpret_cast(&Projection), 4); + if (!impl->VBO || impl->VertexBufferSize != GetVertexPoolSize()) { + if (impl->VBO) { + impl->VBO->Release(); + impl->VBO = nullptr; + impl->VertexBufferSize = 0; + } + if (impl->Device->CreateVertexBuffer( + GetVertexPoolSize() * sizeof(Li::Vertex), + D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, + &impl->VBO, nullptr) < 0) + return; + impl->VertexBufferSize = GetVertexPoolSize(); + } + if (!impl->IBO || impl->IndexBufferSize != GetIndexPoolSize()) { + if (impl->IBO) { + impl->IBO->Release(); + impl->IBO = nullptr; + impl->IndexBufferSize = 0; + } + if (impl->Device->CreateIndexBuffer(GetVertexPoolSize() * sizeof(u16), + D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, + D3DFMT_INDEX16, D3DPOOL_DEFAULT, + &impl->IBO, nullptr) < 0) + return; + impl->IndexBufferSize = GetIndexPoolSize(); + } void* vptr; impl->VBO->Lock(0, 0, &vptr, D3DLOCK_DISCARD); memcpy(vptr, GetVertexBufPtr(0), CurrentVertex * sizeof(PD::Li::Vertex)); diff --git a/include/pd/drivers/gfx.hpp b/include/pd/drivers/gfx.hpp index 080fb4a..9252543 100755 --- a/include/pd/drivers/gfx.hpp +++ b/include/pd/drivers/gfx.hpp @@ -5,10 +5,11 @@ #include #include -using LiBackendFlags = PD::u32; -enum LiBackendFlags_ { - LiBackendFlags_None = 0, - LiBackendFlags_FlipUV_Y = 1 << 0, // Essential for font loading +using PDBackendFlags = PD::u32; +enum PDBackendFlags_ { + PDBackendFlags_None = 0, + PDBackendFlags_FlipUV_Y = 1 << 0, // Essential for font loading + PDBackendFlags_WindingCW = 1 << 0, // Use CW instead of CCW winding }; namespace PD { @@ -20,7 +21,10 @@ class PD_API GfxDriver : public DriverInterface { virtual ~GfxDriver(); virtual void Init() {} - virtual void Deinit() { SysDeinit(); } + virtual void Deinit() { + DeleteTexture(pWhite); + SysDeinit(); + } void SetViewPort(const ivec2& size); void SetViewPort(int x, int y); @@ -66,9 +70,6 @@ struct DefaultGfxConfig { // Index Allocator template using IndexAlloc = std::allocator; - - static constexpr size_t NumVertices = 32768; // 8192*4 - static constexpr size_t NumIndices = 49152; // 8192*6 }; template @@ -81,8 +82,6 @@ class GfxDriverBase : public GfxDriver { virtual ~GfxDriverBase() {} void Init() override { - // pVtxPool.Init(Config::NumVertices); - // pIdxPool.Init(Config::NumIndices); SysInit(); std::vector img(16 * 16 * 4, 0xff); pWhite = LoadTexture(img, 16, 16); @@ -122,6 +121,8 @@ class GfxDriverBase : public GfxDriver { protected: u16* GetIndexBufPtr(size_t start) { return &pIdxPool[start]; } Li::Vertex* GetVertexBufPtr(size_t start) { return &pVtxPool[start]; } + size_t GetVertexPoolSize() const { return pVtxPool.size(); } + size_t GetIndexPoolSize() const { return pIdxPool.size(); } void ResetPools() override { pVtxPool.Reset(); pIdxPool.Reset(); diff --git a/vendor/spirv-helper b/vendor/spirv-helper index e05a0a4..91f57a5 160000 --- a/vendor/spirv-helper +++ b/vendor/spirv-helper @@ -1 +1 @@ -Subproject commit e05a0a45c21b65f7f4daf0dd64f0ae60c155d86a +Subproject commit 91f57a510129bd29c62677810e450ae5f1d6f85a