mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-25 15:15:40 +00:00
GPU: Use max vertex count based on buffer size
This commit is contained in:
parent
a58b687352
commit
1bb794dd39
|
@ -379,7 +379,9 @@ void GPU_HW::DispatchRenderCommand(RenderCommand rc, u32 num_vertices)
|
|||
// flush when the command changes
|
||||
if (!m_batch_vertices.empty())
|
||||
{
|
||||
if (m_batch_vertices.size() >= MAX_BATCH_VERTEX_COUNT || m_batch_command.bits != rc.bits)
|
||||
// including the degenerate triangles for strips
|
||||
const u32 max_added_vertices = num_vertices + 2;
|
||||
if ((m_batch_vertices.size() + max_added_vertices) >= MAX_BATCH_VERTEX_COUNT || m_batch_command.bits != rc.bits)
|
||||
FlushRender();
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,6 @@ public:
|
|||
virtual ~GPU_HW();
|
||||
|
||||
protected:
|
||||
static constexpr u32 MAX_BATCH_VERTEX_COUNT = 1024;
|
||||
|
||||
struct HWVertex
|
||||
{
|
||||
s32 x;
|
||||
|
@ -28,6 +26,9 @@ protected:
|
|||
static constexpr u16 EncodeTexcoord(u8 x, u8 y) { return ZeroExtend16(x) | (ZeroExtend16(y) << 8); }
|
||||
};
|
||||
|
||||
static constexpr u32 VERTEX_BUFFER_SIZE = 1 * 1024 * 1024;
|
||||
static constexpr u32 MAX_BATCH_VERTEX_COUNT = VERTEX_BUFFER_SIZE / sizeof(HWVertex);
|
||||
|
||||
static constexpr std::tuple<float, float, float, float> RGBA8ToFloat(u32 rgba)
|
||||
{
|
||||
return std::make_tuple(static_cast<float>(rgba & UINT32_C(0xFF)) * (1.0f / 255.0f),
|
||||
|
|
|
@ -81,7 +81,7 @@ void GPU_HW_OpenGL::CreateVertexBuffer()
|
|||
{
|
||||
glGenBuffers(1, &m_vertex_buffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vertex_buffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, 128, nullptr, GL_STREAM_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, VERTEX_BUFFER_SIZE, nullptr, GL_STREAM_DRAW);
|
||||
|
||||
glGenVertexArrays(1, &m_vao_id);
|
||||
glBindVertexArray(m_vao_id);
|
||||
|
@ -339,14 +339,10 @@ void GPU_HW_OpenGL::FlushRender()
|
|||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer_fbo_id);
|
||||
glBindVertexArray(m_vao_id);
|
||||
|
||||
Assert((m_batch_vertices.size() * sizeof(HWVertex)) <= VERTEX_BUFFER_SIZE);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vertex_buffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, static_cast<GLsizei>(sizeof(HWVertex) * m_batch_vertices.size()),
|
||||
m_batch_vertices.data(), GL_STREAM_DRAW);
|
||||
glVertexAttribIPointer(0, 2, GL_INT, sizeof(HWVertex), reinterpret_cast<void*>(offsetof(HWVertex, x)));
|
||||
glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, true, sizeof(HWVertex),
|
||||
reinterpret_cast<void*>(offsetof(HWVertex, color)));
|
||||
glVertexAttribPointer(2, 2, GL_UNSIGNED_BYTE, true, sizeof(HWVertex),
|
||||
reinterpret_cast<void*>(offsetof(HWVertex, texcoord)));
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, static_cast<GLsizei>(sizeof(HWVertex) * m_batch_vertices.size()),
|
||||
m_batch_vertices.data());
|
||||
|
||||
const bool is_strip = ((m_batch_command.primitive == Primitive::Polygon && m_batch_command.quad_polygon) ||
|
||||
m_batch_command.primitive == Primitive::Rectangle);
|
||||
|
|
Loading…
Reference in a new issue