glBufferSubData VBO

This commit is contained in:
Phantom 2017-10-10 03:43:26 +02:00
parent e258faf0f0
commit a1112cb712
5 changed files with 27 additions and 17 deletions

View File

@ -352,10 +352,6 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
shader_engine->SetupBatch(g_state.vs, regs.vs.main_offset);
const bool use_gs = regs.pipeline.use_gs == PipelineRegs::UseGS::Yes;
g_state.geometry_pipeline.Reconfigure();
g_state.geometry_pipeline.Setup(shader_engine);
if (g_state.geometry_pipeline.NeedIndexInput())
ASSERT(is_indexed);
auto VSUnitLoop = [&](u32 thread_id, auto num_threads) {
constexpr bool single_thread = std::is_same_v<std::integral_constant<u32, 1>, decltype(num_threads)>;
@ -436,6 +432,11 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
}
}
g_state.geometry_pipeline.Reconfigure();
g_state.geometry_pipeline.Setup(shader_engine);
if (g_state.geometry_pipeline.NeedIndexInput())
ASSERT(is_indexed);
for (unsigned int index = 0; index < regs.pipeline.num_vertices; ++index) {
unsigned int vertex = VertexIndex(index);
auto& cached_vertex = vs_output[is_indexed ? vertex : index];

View File

@ -15,7 +15,7 @@ PrimitiveAssembler<VertexType>::PrimitiveAssembler(PipelineRegs::TriangleTopolog
template <typename VertexType>
void PrimitiveAssembler<VertexType>::SubmitVertex(const VertexType& vtx,
TriangleHandler triangle_handler) {
const TriangleHandler& triangle_handler) {
switch (topology) {
case PipelineRegs::TriangleTopology::List:
case PipelineRegs::TriangleTopology::Shader:

View File

@ -27,7 +27,7 @@ struct PrimitiveAssembler {
* NOTE: We could specify the triangle handler in the constructor, but this way we can
* keep event and handler code next to each other.
*/
void SubmitVertex(const VertexType& vtx, TriangleHandler triangle_handler);
void SubmitVertex(const VertexType& vtx, const TriangleHandler& triangle_handler);
/**
* Invert the vertex order of the next triangle. Called by geometry shader emitter.

View File

@ -27,7 +27,7 @@ MICROPROFILE_DEFINE(OpenGL_Drawing, "OpenGL", "Drawing", MP_RGB(128, 128, 192));
MICROPROFILE_DEFINE(OpenGL_Blits, "OpenGL", "Blits", MP_RGB(100, 100, 255));
MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Mgmt", MP_RGB(100, 255, 100));
RasterizerOpenGL::RasterizerOpenGL() : shader_dirty(true) {
RasterizerOpenGL::RasterizerOpenGL() : shader_dirty(true), vertex_buffer_size(0) {
// Clipping plane 0 is always enabled for PICA fixed clip plane z <= 0
state.clip_distance[0] = true;
@ -263,6 +263,11 @@ void RasterizerOpenGL::DrawTriangles() {
GLsizei viewport_height =
(GLsizei)Pica::float24::FromRaw(regs.rasterizer.viewport_size_y).ToFloat32() * 2;
const float res_scale_width = color_surface != nullptr ? color_surface->res_scale_width :
(depth_surface == nullptr ? 1.0f : depth_surface->res_scale_width);
const float res_scale_height = color_surface != nullptr ? color_surface->res_scale_height :
(depth_surface == nullptr ? 1.0f : depth_surface->res_scale_height);
glViewport(
(GLint)(rect.left + regs.rasterizer.viewport_corner.x * color_surface->res_scale_width),
(GLint)(rect.bottom + regs.rasterizer.viewport_corner.y * color_surface->res_scale_height),
@ -381,9 +386,14 @@ void RasterizerOpenGL::DrawTriangles() {
state.Apply();
// Draw the vertex batch
glBufferData(GL_ARRAY_BUFFER, vertex_batch.size() * sizeof(HardwareVertex), vertex_batch.data(),
GL_STREAM_DRAW);
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)vertex_batch.size());
GLsizeiptr target_size = vertex_batch.size() * sizeof(HardwareVertex);
if (vertex_buffer_size < target_size) {
vertex_buffer_size = target_size * 2;
glBufferData(GL_ARRAY_BUFFER, vertex_buffer_size, nullptr, GL_STREAM_DRAW);
}
glBufferSubData(GL_ARRAY_BUFFER, 0, target_size, vertex_batch.data());
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(vertex_batch.size()));
vertex_batch.clear();
// Mark framebuffer surfaces as dirty
// TODO: Restrict invalidation area to the viewport
@ -396,8 +406,6 @@ void RasterizerOpenGL::DrawTriangles() {
res_cache.FlushRegion(depth_surface->addr, depth_surface->size, depth_surface, true);
}
vertex_batch.clear();
// Unbind textures for potential future use as framebuffer attachments
for (unsigned texture_index = 0; texture_index < pica_textures.size(); ++texture_index) {
state.texture_units[texture_index].texture_2d = 0;

View File

@ -283,6 +283,7 @@ private:
std::array<SamplerInfo, 3> texture_samplers;
OGLVertexArray vertex_array;
OGLBuffer vertex_buffer;
GLsizeiptr vertex_buffer_size;
OGLBuffer uniform_buffer;
OGLFramebuffer framebuffer;