Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xrRender: static geometry buffers code unification (#489) #490

Merged
merged 23 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f47a8b2
xrRender: added index staging buffer abstraction
vTurbine Oct 10, 2019
2df13e1
xrRender: Backend: top file cleanup
vTurbine Oct 10, 2019
c9653e6
xrRender: added vertex staging buffer abstraction
vTurbine Oct 10, 2019
64d9691
xrRender: Details: detail manager switched to staging buffers
vTurbine Oct 10, 2019
3804d24
xrRender: vertex format helpers interface unified
vTurbine Oct 10, 2019
6f436ae
xrRender: Utils: geometry switched to staging buffers
vTurbine Oct 10, 2019
3057e28
xrRender: BufferUtils: staging buffer validation added
vTurbine Oct 11, 2019
97b0b8e
xrRender: BufferUtils: staging buffer is reusable now
vTurbine Oct 11, 2019
31056ec
xrRender: renderers were switched to common `BufferUtils.h`
vTurbine Oct 12, 2019
097463e
xrRender: BufferUtils: added ref counting into staging buffer
vTurbine Oct 13, 2019
df0d27a
xrRenderR2: RT switched to staging buffers
vTurbine Oct 13, 2019
3d38723
xrRenderR2: loader switched to staging geometry buffers
vTurbine Oct 13, 2019
42d1d22
xrRenderR1: loader switched to staging geometry buffers
vTurbine Oct 13, 2019
b1cacab
xrRenderR3: loader switched to staging geometry buffers
vTurbine Oct 13, 2019
a837eb6
xrRenderR4: loader switched to staging buffers
vTurbine Oct 14, 2019
861de26
Review iteration
vTurbine Oct 14, 2019
f84a3d0
Review iteration #2
vTurbine Oct 26, 2019
7c5b1c7
Assert statement simplified
vTurbine Oct 26, 2019
3b3a6a3
Merge branch 'xd_dev' into renderer/staging_buffers
vTurbine Oct 26, 2019
f17ab22
Merge issue resolved
vTurbine Oct 27, 2019
3732d5a
Review iteration #3
vTurbine Oct 28, 2019
1ebd608
Coding style fixed
vTurbine Nov 3, 2019
794696d
`r_restore_quad_ib_data` removed
vTurbine Nov 4, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/Layers/xrRenderDX10/dx10BufferUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,37 @@ void ConvertVertexDeclaration(const xr_vector<D3DVERTEXELEMENT9>& declIn, xr_vec
ZeroMemory(&declOut[iDeclSize], sizeof(declOut[iDeclSize]));
}
};

void IndexStagingBuffer::Create(size_t size)
{
m_HostData = xr_alloc<u8>(size);
m_Size = size;
}

void* IndexStagingBuffer::GetHostPointer() const
{
return m_HostData;
}

void IndexStagingBuffer::Flush()
{
// Upload data to device
dx10BufferUtils::CreateIndexBuffer(&m_DeviceBuffer, m_HostData, m_Size, false);
HW.stats_manager.increment_stats_ib(m_DeviceBuffer);
// Free host memory
xr_delete(m_HostData);
m_HostData = nullptr;
vTurbine marked this conversation as resolved.
Show resolved Hide resolved
}

ID3DIndexBuffer* IndexStagingBuffer::GetBufferHandle() const
{
return m_DeviceBuffer;
}

void IndexStagingBuffer::Destroy()
{
if (m_HostData)
xr_delete(m_HostData);
HW.stats_manager.decrement_stats_ib(m_DeviceBuffer);
_RELEASE(m_DeviceBuffer);
}
31 changes: 31 additions & 0 deletions src/Layers/xrRenderDX10/dx10BufferUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,36 @@ HRESULT CreateConstantBuffer(ID3DBuffer** ppBuffer, UINT DataSize);
void ConvertVertexDeclaration(const xr_vector<D3DVERTEXELEMENT9>& declIn, xr_vector<D3D_INPUT_ELEMENT_DESC>& declOut);
};


class IndexStagingBuffer
{
public:
void Create(size_t size);
void Destroy();

void* GetHostPointer() const;
ID3DIndexBuffer* GetBufferHandle() const;
void Flush();

operator ID3DIndexBuffer*() const
{
return m_DeviceBuffer;
}

bool IndexStagingBuffer::operator==(ID3DIndexBuffer* other) const
{
return other == m_DeviceBuffer;
}
bool IndexStagingBuffer::operator==(const IndexStagingBuffer& other) const
{
return other.m_DeviceBuffer == m_DeviceBuffer;
}

private:
ID3DIndexBuffer* m_DeviceBuffer{ nullptr };
void* m_HostData{ nullptr };
size_t m_Size{ 0 };
};

#endif // USE_DX10
#endif // dx10BufferUtils_included
42 changes: 42 additions & 0 deletions src/Layers/xrRenderDX9/BufferUtils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "stdafx.h"

void IndexStagingBuffer::Create(size_t size)
{
m_HostData = xr_alloc<u8>(size);
m_Size = size;

u32 dwUsage = D3DUSAGE_WRITEONLY;
if (HW.Caps.geometry.bSoftware)
dwUsage |= D3DUSAGE_SOFTWAREPROCESSING;
R_CHK(HW.pDevice->CreateIndexBuffer(size, dwUsage, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &m_DeviceBuffer, NULL));
}

void* IndexStagingBuffer::GetHostPointer() const
{
VERIFY(m_DeviceBuffer);
R_CHK(m_DeviceBuffer->Lock(0, 0, const_cast<void**>(&m_HostData), 0));
return m_HostData;
}

void IndexStagingBuffer::Flush()
{
// Upload data to device
R_CHK(m_DeviceBuffer->Unlock());
HW.stats_manager.increment_stats_ib(m_DeviceBuffer);
// Free host memory
xr_delete(m_HostData);
m_HostData = nullptr;
}

ID3DIndexBuffer* IndexStagingBuffer::GetBufferHandle() const
{
return m_DeviceBuffer;
}

void IndexStagingBuffer::Destroy()
{
if (m_HostData)
xr_delete(m_HostData);
HW.stats_manager.decrement_stats_ib(m_DeviceBuffer);
_RELEASE(m_DeviceBuffer);
}
31 changes: 31 additions & 0 deletions src/Layers/xrRenderDX9/BufferUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

class IndexStagingBuffer
{
public:
void Create(size_t size);
void Destroy();

void* GetHostPointer() const;
ID3DIndexBuffer* GetBufferHandle() const;
void Flush();

operator ID3DIndexBuffer*() const
{
return m_DeviceBuffer;
}

bool IndexStagingBuffer::operator==(ID3DIndexBuffer* other) const
{
return other == m_DeviceBuffer;
}
bool IndexStagingBuffer::operator==(const IndexStagingBuffer& other) const
{
return other.m_DeviceBuffer == m_DeviceBuffer;
}

private:
ID3DIndexBuffer* m_DeviceBuffer{ nullptr };
void* m_HostData{ nullptr };
size_t m_Size{ 0 };
};
32 changes: 32 additions & 0 deletions src/Layers/xrRenderGL/glBufferUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,35 @@ u32 GetDeclLength(const D3DVERTEXELEMENT9* decl)
return element - decl;
}
} // namespace glBufferUtils

void IndexStagingBuffer::Create(size_t size)
{
m_HostData = xr_alloc<u8>(size);
m_Size = size;
}

void* IndexStagingBuffer::GetHostPointer() const
{
return m_HostData;
}

void IndexStagingBuffer::Flush()
{
// Upload data to device
glBufferUtils::CreateIndexBuffer(&m_DeviceBuffer, m_HostData, m_Size, true);
// Free host memory
xr_delete(m_HostData);
m_HostData = nullptr;
}

GLuint IndexStagingBuffer::GetBufferHandle() const
{
return m_DeviceBuffer;
}

void IndexStagingBuffer::Destroy()
{
if (m_HostData)
xr_delete(m_HostData);
glDeleteBuffers(1, &m_DeviceBuffer);
}
32 changes: 32 additions & 0 deletions src/Layers/xrRenderGL/glBufferUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#ifdef USE_OGL

struct SDeclaration;

namespace glBufferUtils
{
void CreateVertexBuffer(GLuint* pBuffer, const void* pData, UINT DataSize, bool bImmutable = true);
Expand All @@ -13,4 +15,34 @@ void ConvertVertexDeclaration(u32 FVF, SDeclaration* decl);
void ConvertVertexDeclaration(const D3DVERTEXELEMENT9* dxdecl, SDeclaration* decl);
};

class IndexStagingBuffer
{
public:
void Create(size_t size);
void Destroy();

void* GetHostPointer() const;
GLuint GetBufferHandle() const;
void Flush();

operator GLuint() const
{
return m_DeviceBuffer;
}

bool IndexStagingBuffer::operator==(GLuint other) const
{
return other == m_DeviceBuffer;
}
bool IndexStagingBuffer::operator==(const IndexStagingBuffer& other) const
{
return other.m_DeviceBuffer == m_DeviceBuffer;
}

private:
GLuint m_DeviceBuffer{ 0 };
void* m_HostData{ nullptr };
size_t m_Size{ 0 };
};

#endif // USE_OGL
4 changes: 3 additions & 1 deletion src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
<ClInclude Include="..\..\Include\xrRender\UIShader.h" />
<ClInclude Include="..\..\Include\xrRender\WallMarkArray.h" />
<ClInclude Include="..\xrRenderDX9\CommonTypes.h" />
<ClInclude Include="..\xrRenderDX9\BufferUtils.h" />
<ClInclude Include="..\xrRenderDX9\dx9HW.h" />
<ClInclude Include="..\xrRenderDX9\dx9R_Backend_Runtime.h" />
<ClInclude Include="..\xrRenderDX9\dx9r_constants_cache.h" />
Expand Down Expand Up @@ -306,6 +307,7 @@
<ClInclude Include="stdafx.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\xrRenderDX9\BufferUtils.cpp" />
<ClCompile Include="..\xrRenderDX9\dx9HW.cpp" />
<ClCompile Include="..\xrRenderDX9\dx9HWCaps.cpp" />
<ClCompile Include="..\xrRenderDX9\dx9r_constants_cache.cpp" />
Expand Down Expand Up @@ -500,4 +502,4 @@
<Error Condition="!Exists('..\..\packages\sdl2.redist.2.0.5\build\native\sdl2.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\sdl2.redist.2.0.5\build\native\sdl2.redist.targets'))" />
<Error Condition="!Exists('..\..\packages\sdl2.2.0.5\build\native\sdl2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\sdl2.2.0.5\build\native\sdl2.targets'))" />
</Target>
</Project>
</Project>
8 changes: 7 additions & 1 deletion src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,9 @@
<ClInclude Include="..\xrRenderDX9\CommonTypes.h">
<Filter>Kernel</Filter>
</ClInclude>
<ClInclude Include="..\xrRenderDX9\BufferUtils.h">
<Filter>Refactored\HW</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
Expand Down Expand Up @@ -962,6 +965,9 @@
<ClCompile Include="..\xrRenderDX9\dx9SH_RT.cpp">
<Filter>Refactored\Execution &amp; 3D\Shaders\Resources</Filter>
</ClCompile>
<ClCompile Include="..\xrRenderDX9\BufferUtils.cpp">
<Filter>Refactored\HW</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="Pipeline.txt" />
Expand All @@ -972,4 +978,4 @@
<ItemGroup>
<Natvis Include="..\..\OpenXRay.natvis" />
</ItemGroup>
</Project>
</Project>
4 changes: 3 additions & 1 deletion src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
<ClInclude Include="..\..\Include\xrRender\UIShader.h" />
<ClInclude Include="..\..\Include\xrRender\WallMarkArray.h" />
<ClInclude Include="..\xrRenderDX9\CommonTypes.h" />
<ClInclude Include="..\xrRenderDX9\BufferUtils.h" />
<ClInclude Include="..\xrRenderDX9\dx9HW.h" />
<ClInclude Include="..\xrRenderDX9\dx9R_Backend_Runtime.h" />
<ClInclude Include="..\xrRenderDX9\dx9r_constants_cache.h" />
Expand Down Expand Up @@ -319,6 +320,7 @@
<ClInclude Include="stdafx.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\xrRenderDX9\BufferUtils.cpp" />
<ClCompile Include="..\xrRenderDX9\dx9HW.cpp" />
<ClCompile Include="..\xrRenderDX9\dx9HWCaps.cpp" />
<ClCompile Include="..\xrRenderDX9\dx9r_constants_cache.cpp" />
Expand Down Expand Up @@ -543,4 +545,4 @@
<Error Condition="!Exists('..\..\packages\sdl2.redist.2.0.5\build\native\sdl2.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\sdl2.redist.2.0.5\build\native\sdl2.redist.targets'))" />
<Error Condition="!Exists('..\..\packages\sdl2.2.0.5\build\native\sdl2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\sdl2.2.0.5\build\native\sdl2.targets'))" />
</Target>
</Project>
</Project>
8 changes: 7 additions & 1 deletion src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,9 @@
<ClInclude Include="..\xrRenderDX9\dx9HW.h">
<Filter>Refactored\HW</Filter>
</ClInclude>
<ClInclude Include="..\xrRenderDX9\BufferUtils.h">
<Filter>Refactored\HW</Filter>
</ClInclude>
<ClInclude Include="..\xrRenderDX9\CommonTypes.h">
<Filter>Kernel</Filter>
</ClInclude>
Expand Down Expand Up @@ -1109,6 +1112,9 @@
<ClCompile Include="..\xrRenderDX9\dx9SH_RT.cpp">
<Filter>Refactored\Execution &amp; 3D\Shaders\Resources</Filter>
</ClCompile>
<ClCompile Include="..\xrRenderDX9\BufferUtils.cpp">
<Filter>Refactored\HW</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="todo.txt" />
Expand All @@ -1119,4 +1125,4 @@
<ItemGroup>
<Natvis Include="..\..\OpenXRay.natvis" />
</ItemGroup>
</Project>
</Project>