From e2d0a63b98be4cacb90ebc6725904af652db29f5 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Wed, 11 Nov 2015 00:19:27 +0100 Subject: [PATCH] gl: Use factored scale offset function call --- rpcs3/Emu/RSX/GL/GLGSRender.cpp | 36 ++++++---------------------- rpcs3/Emu/RSX/GL/GLGSRender.h | 2 ++ rpcs3/Emu/RSX/GL/GLProcTable.h | 3 +++ rpcs3/Emu/RSX/GL/GLVertexProgram.cpp | 7 ++++-- rpcs3/Emu/RSX/RSXThread.cpp | 9 ++++--- rpcs3/Emu/RSX/RSXThread.h | 3 ++- 6 files changed, 25 insertions(+), 35 deletions(-) diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.cpp b/rpcs3/Emu/RSX/GL/GLGSRender.cpp index 5e7c2deee3..7352d6671a 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.cpp +++ b/rpcs3/Emu/RSX/GL/GLGSRender.cpp @@ -1063,6 +1063,9 @@ void GLGSRender::oninit_thread() m_vao.create(); m_vbo.create(); m_ebo.create(); + m_scale_offset_buffer.create(16 * sizeof(float)); + + glBindBufferBase(GL_UNIFORM_BUFFER, 0, m_scale_offset_buffer.id()); m_vao.array_buffer = m_vbo; m_vao.element_array_buffer = m_ebo; @@ -1259,37 +1262,12 @@ bool GLGSRender::load_program() (m_program.recreate() += { fp.compile(), vp.compile() }).make(); #endif + glBindBuffer(GL_UNIFORM_BUFFER, m_scale_offset_buffer.id()); - int viewport_x = int(rsx::method_registers[NV4097_SET_VIEWPORT_HORIZONTAL] & 0xffff); - int viewport_y = int(rsx::method_registers[NV4097_SET_VIEWPORT_VERTICAL] & 0xffff); - int viewport_w = int(rsx::method_registers[NV4097_SET_VIEWPORT_HORIZONTAL] >> 16); - int viewport_h = int(rsx::method_registers[NV4097_SET_VIEWPORT_VERTICAL] >> 16); + void *buffer = glMapBuffer(GL_UNIFORM_BUFFER, GL_WRITE_ONLY); + fill_scale_offset_data(buffer, false); + glUnmapBuffer(GL_UNIFORM_BUFFER); - f32 viewport_offset_x = (f32&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + 0]; - f32 viewport_offset_y = (f32&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + 1]; - f32 viewport_offset_z = (f32&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + 2]; - f32 viewport_offset_w = (f32&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + 3]; - - f32 viewport_scale_x = (f32&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + 0]; - f32 viewport_scale_y = (f32&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + 1]; - f32 viewport_scale_z = (f32&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + 2]; - f32 viewport_scale_w = (f32&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + 3]; - - f32 width = f32(rsx::method_registers[NV4097_SET_SURFACE_CLIP_HORIZONTAL] >> 16); - f32 height = f32(rsx::method_registers[NV4097_SET_SURFACE_CLIP_VERTICAL] >> 16); - glm::mat4 scaleOffsetMat(1.f); - - //Scale - scaleOffsetMat[0][0] = viewport_scale_x * 2.f / width; - scaleOffsetMat[1][1] = viewport_scale_y * 2.f / height; - scaleOffsetMat[2][2] = viewport_scale_z; - - // Offset - scaleOffsetMat[0][3] = viewport_offset_x * 2.f / width - 1.f; - scaleOffsetMat[1][3] = viewport_offset_y * 2.f / height - 1.f; - scaleOffsetMat[2][3] = viewport_offset_z - .5f; - - __glcheck m_program->uniforms["scaleOffsetMat"] = scaleOffsetMat; for (auto &constant : transform_constants) { diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.h b/rpcs3/Emu/RSX/GL/GLGSRender.h index 71f0c08ac0..c583da5c65 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.h +++ b/rpcs3/Emu/RSX/GL/GLGSRender.h @@ -75,6 +75,8 @@ private: gl::fbo m_flip_fbo; gl::texture m_flip_tex_color; + gl::buffer m_scale_offset_buffer; + gl::buffer m_vbo; gl::buffer m_ebo; gl::vao m_vao; diff --git a/rpcs3/Emu/RSX/GL/GLProcTable.h b/rpcs3/Emu/RSX/GL/GLProcTable.h index 83cd07262d..eca05e3bc6 100644 --- a/rpcs3/Emu/RSX/GL/GLProcTable.h +++ b/rpcs3/Emu/RSX/GL/GLProcTable.h @@ -163,6 +163,9 @@ OPENGL_PROC(PFNGLGETINTEGER64VPROC, GetInteger64v); OPENGL_PROC(PFNGLCHECKFRAMEBUFFERSTATUSPROC, CheckFramebufferStatus); + +OPENGL_PROC(PFNGLBINDBUFFERBASEPROC, BindBufferBase); + //KHR_debug OPENGL_PROC(PFNGLDEBUGMESSAGECONTROLARBPROC, DebugMessageControlARB); OPENGL_PROC(PFNGLDEBUGMESSAGEINSERTARBPROC, DebugMessageInsertARB); diff --git a/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp b/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp index 3abc3a78ef..e0da701409 100644 --- a/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp +++ b/rpcs3/Emu/RSX/GL/GLVertexProgram.cpp @@ -28,8 +28,11 @@ std::string GLVertexDecompilerThread::compareFunction(COMPARE f, const std::stri void GLVertexDecompilerThread::insertHeader(std::stringstream &OS) { - OS << "#version 140" << std::endl << std::endl; - OS << "uniform mat4 scaleOffsetMat = mat4(1.0);" << std::endl; + OS << "#version 420" << std::endl << std::endl; + OS << "layout(std140, binding = 0) uniform ScaleOffsetBuffer" << std::endl; + OS << "{" << std::endl; + OS << " mat4 scaleOffsetMat;" << std::endl; + OS << "};" << std::endl; } void GLVertexDecompilerThread::insertInputs(std::stringstream & OS, const std::vector& inputs) diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index f0a4cd6ef1..f766137a56 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -1100,7 +1100,7 @@ namespace rsx onexit_thread(); } - void thread::fill_scale_offset_data(void *buffer) const noexcept + void thread::fill_scale_offset_data(void *buffer, bool is_d3d) const noexcept { int clip_w = rsx::method_registers[NV4097_SET_SURFACE_CLIP_HORIZONTAL] >> 16; int clip_h = rsx::method_registers[NV4097_SET_SURFACE_CLIP_VERTICAL] >> 16; @@ -1109,12 +1109,15 @@ namespace rsx float offset_x = (float&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET] - (clip_w / 2.f); offset_x /= clip_w / 2.f; - float scale_y = -(float&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + 1] / (clip_h / 2.f); - float offset_y = -((float&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + 1] - (clip_h / 2.f)); + float scale_y = (float&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + 1] / (clip_h / 2.f); + float offset_y = ((float&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + 1] - (clip_h / 2.f)); offset_y /= clip_h / 2.f; + if (is_d3d) scale_y *= -1; + if (is_d3d) offset_y *= -1; float scale_z = (float&)rsx::method_registers[NV4097_SET_VIEWPORT_SCALE + 2]; float offset_z = (float&)rsx::method_registers[NV4097_SET_VIEWPORT_OFFSET + 2]; + if (!is_d3d) offset_z -= .5; float one = 1.f; diff --git a/rpcs3/Emu/RSX/RSXThread.h b/rpcs3/Emu/RSX/RSXThread.h index e9f1770701..44e92d96a1 100644 --- a/rpcs3/Emu/RSX/RSXThread.h +++ b/rpcs3/Emu/RSX/RSXThread.h @@ -256,8 +256,9 @@ namespace rsx /** * Fill buffer with 4x4 scale offset matrix. * Vertex shader's position is to be multiplied by this matrix. + * if is_d3d is set, the matrix is modified to use d3d convention. */ - void fill_scale_offset_data(void *buffer) const noexcept; + void fill_scale_offset_data(void *buffer, bool is_d3d = true) const noexcept; /** * Fill buffer with vertex program constants.