summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2019-12-26 01:50:38 -0300
committerGravatar ReinUsesLisp2020-02-28 17:25:18 -0300
commitd3e433a38048c5d32c0929446008586e975ccd0e (patch)
tree06ac0719687b366f6c82b3c78d8df99b7bf33a69 /src
parentgl_state: Remove scissor test tracking (diff)
downloadyuzu-d3e433a38048c5d32c0929446008586e975ccd0e.tar.gz
yuzu-d3e433a38048c5d32c0929446008586e975ccd0e.tar.xz
yuzu-d3e433a38048c5d32c0929446008586e975ccd0e.zip
gl_state: Remove viewport and depth range tracking
Diffstat (limited to 'src')
-rw-r--r--src/video_core/engines/maxwell_3d.h18
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp24
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h2
-rw-r--r--src/video_core/renderer_opengl/gl_state.cpp29
-rw-r--r--src/video_core/renderer_opengl/gl_state.h12
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.cpp53
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.h2
7 files changed, 39 insertions, 101 deletions
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h
index 3a641c182..2134d6e4f 100644
--- a/src/video_core/engines/maxwell_3d.h
+++ b/src/video_core/engines/maxwell_3d.h
@@ -574,7 +574,7 @@ public:
574 f32 translate_z; 574 f32 translate_z;
575 INSERT_UNION_PADDING_WORDS(2); 575 INSERT_UNION_PADDING_WORDS(2);
576 576
577 Common::Rectangle<s32> GetRect() const { 577 Common::Rectangle<f32> GetRect() const {
578 return { 578 return {
579 GetX(), // left 579 GetX(), // left
580 GetY() + GetHeight(), // top 580 GetY() + GetHeight(), // top
@@ -583,20 +583,20 @@ public:
583 }; 583 };
584 }; 584 };
585 585
586 s32 GetX() const { 586 f32 GetX() const {
587 return static_cast<s32>(std::max(0.0f, translate_x - std::fabs(scale_x))); 587 return std::max(0.0f, translate_x - std::fabs(scale_x));
588 } 588 }
589 589
590 s32 GetY() const { 590 f32 GetY() const {
591 return static_cast<s32>(std::max(0.0f, translate_y - std::fabs(scale_y))); 591 return std::max(0.0f, translate_y - std::fabs(scale_y));
592 } 592 }
593 593
594 s32 GetWidth() const { 594 f32 GetWidth() const {
595 return static_cast<s32>(translate_x + std::fabs(scale_x)) - GetX(); 595 return translate_x + std::fabs(scale_x) - GetX();
596 } 596 }
597 597
598 s32 GetHeight() const { 598 f32 GetHeight() const {
599 return static_cast<s32>(translate_y + std::fabs(scale_y)) - GetY(); 599 return translate_y + std::fabs(scale_y) - GetY();
600 } 600 }
601 }; 601 };
602 602
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 3ccedcf55..63295761a 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -360,7 +360,6 @@ void RasterizerOpenGL::ConfigureFramebuffers() {
360 texture_cache.GuardRenderTargets(false); 360 texture_cache.GuardRenderTargets(false);
361 361
362 state.draw.draw_framebuffer = framebuffer_cache.GetFramebuffer(key); 362 state.draw.draw_framebuffer = framebuffer_cache.GetFramebuffer(key);
363 SyncViewport(state);
364} 363}
365 364
366void RasterizerOpenGL::ConfigureClearFramebuffer(OpenGLState& current_state, bool using_color_fb, 365void RasterizerOpenGL::ConfigureClearFramebuffer(OpenGLState& current_state, bool using_color_fb,
@@ -405,7 +404,6 @@ void RasterizerOpenGL::Clear() {
405 SCOPE_EXIT({ prev_state.Apply(); }); 404 SCOPE_EXIT({ prev_state.Apply(); });
406 405
407 OpenGLState clear_state{OpenGLState::GetCurState()}; 406 OpenGLState clear_state{OpenGLState::GetCurState()};
408 clear_state.SetDefaultViewports();
409 if (regs.clear_buffers.R || regs.clear_buffers.G || regs.clear_buffers.B || 407 if (regs.clear_buffers.R || regs.clear_buffers.G || regs.clear_buffers.B ||
410 regs.clear_buffers.A) { 408 regs.clear_buffers.A) {
411 use_color = true; 409 use_color = true;
@@ -464,7 +462,6 @@ void RasterizerOpenGL::Clear() {
464 462
465 ConfigureClearFramebuffer(clear_state, use_color, use_depth, use_stencil); 463 ConfigureClearFramebuffer(clear_state, use_color, use_depth, use_stencil);
466 464
467 SyncViewport(clear_state);
468 SyncRasterizeEnable(clear_state); 465 SyncRasterizeEnable(clear_state);
469 if (regs.clear_flags.scissor) { 466 if (regs.clear_flags.scissor) {
470 SyncScissorTest(); 467 SyncScissorTest();
@@ -496,6 +493,7 @@ void RasterizerOpenGL::Draw(bool is_indexed, bool is_instanced) {
496 493
497 query_cache.UpdateCounters(); 494 query_cache.UpdateCounters();
498 495
496 SyncViewport();
499 SyncRasterizeEnable(state); 497 SyncRasterizeEnable(state);
500 SyncColorMask(); 498 SyncColorMask();
501 SyncFragmentColorClampState(); 499 SyncFragmentColorClampState();
@@ -935,22 +933,14 @@ void RasterizerOpenGL::SetupImage(u32 binding, const Tegra::Texture::TICEntry& t
935 state.images[binding] = view->GetTexture(); 933 state.images[binding] = view->GetTexture();
936} 934}
937 935
938void RasterizerOpenGL::SyncViewport(OpenGLState& current_state) { 936void RasterizerOpenGL::SyncViewport() {
939 const auto& regs = system.GPU().Maxwell3D().regs; 937 const auto& regs = system.GPU().Maxwell3D().regs;
940 const bool geometry_shaders_enabled = 938 for (std::size_t i = 0; i < Maxwell::NumViewports; ++i) {
941 regs.IsShaderConfigEnabled(static_cast<size_t>(Maxwell::ShaderProgram::Geometry));
942 const std::size_t viewport_count =
943 geometry_shaders_enabled ? Tegra::Engines::Maxwell3D::Regs::NumViewports : 1;
944 for (std::size_t i = 0; i < viewport_count; i++) {
945 auto& viewport = current_state.viewports[i];
946 const auto& src = regs.viewports[i]; 939 const auto& src = regs.viewports[i];
947 const Common::Rectangle<s32> viewport_rect{regs.viewport_transform[i].GetRect()}; 940 const Common::Rectangle<f32> rect{regs.viewport_transform[i].GetRect()};
948 viewport.x = viewport_rect.left; 941 glViewportIndexedf(static_cast<GLuint>(i), rect.left, rect.bottom, rect.GetWidth(),
949 viewport.y = viewport_rect.bottom; 942 rect.GetHeight());
950 viewport.width = viewport_rect.GetWidth(); 943 glDepthRangef(src.depth_range_near, src.depth_range_far);
951 viewport.height = viewport_rect.GetHeight();
952 viewport.depth_range_far = src.depth_range_far;
953 viewport.depth_range_near = src.depth_range_near;
954 } 944 }
955 945
956 bool flip_y = false; 946 bool flip_y = false;
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index 0450657a7..d1d0aec32 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -130,7 +130,7 @@ private:
130 const GLShader::ImageEntry& entry); 130 const GLShader::ImageEntry& entry);
131 131
132 /// Syncs the viewport and depth range to match the guest state 132 /// Syncs the viewport and depth range to match the guest state
133 void SyncViewport(OpenGLState& current_state); 133 void SyncViewport();
134 134
135 /// Syncs the depth clamp state 135 /// Syncs the depth clamp state
136 void SyncDepthClamp(); 136 void SyncDepthClamp();
diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp
index dcea16fd3..7c08cc3c2 100644
--- a/src/video_core/renderer_opengl/gl_state.cpp
+++ b/src/video_core/renderer_opengl/gl_state.cpp
@@ -85,10 +85,6 @@ void Enable(GLenum cap, GLuint index, bool& current_value, bool new_value) {
85 85
86OpenGLState::OpenGLState() = default; 86OpenGLState::OpenGLState() = default;
87 87
88void OpenGLState::SetDefaultViewports() {
89 viewports.fill(Viewport{});
90}
91
92void OpenGLState::ApplyFramebufferState() { 88void OpenGLState::ApplyFramebufferState() {
93 if (UpdateValue(cur_state.draw.read_framebuffer, draw.read_framebuffer)) { 89 if (UpdateValue(cur_state.draw.read_framebuffer, draw.read_framebuffer)) {
94 glBindFramebuffer(GL_READ_FRAMEBUFFER, draw.read_framebuffer); 90 glBindFramebuffer(GL_READ_FRAMEBUFFER, draw.read_framebuffer);
@@ -150,30 +146,6 @@ void OpenGLState::ApplyStencilTest() {
150 ConfigStencil(GL_BACK, stencil.back, cur_state.stencil.back); 146 ConfigStencil(GL_BACK, stencil.back, cur_state.stencil.back);
151} 147}
152 148
153void OpenGLState::ApplyViewport() {
154 for (GLuint i = 0; i < static_cast<GLuint>(Maxwell::NumViewports); ++i) {
155 const auto& updated = viewports[i];
156 auto& current = cur_state.viewports[i];
157
158 if (current.x != updated.x || current.y != updated.y || current.width != updated.width ||
159 current.height != updated.height) {
160 current.x = updated.x;
161 current.y = updated.y;
162 current.width = updated.width;
163 current.height = updated.height;
164 glViewportIndexedf(i, static_cast<GLfloat>(updated.x), static_cast<GLfloat>(updated.y),
165 static_cast<GLfloat>(updated.width),
166 static_cast<GLfloat>(updated.height));
167 }
168 if (current.depth_range_near != updated.depth_range_near ||
169 current.depth_range_far != updated.depth_range_far) {
170 current.depth_range_near = updated.depth_range_near;
171 current.depth_range_far = updated.depth_range_far;
172 glDepthRangeIndexed(i, updated.depth_range_near, updated.depth_range_far);
173 }
174 }
175}
176
177void OpenGLState::ApplyGlobalBlending() { 149void OpenGLState::ApplyGlobalBlending() {
178 const Blend& updated = blend[0]; 150 const Blend& updated = blend[0];
179 Blend& current = cur_state.blend[0]; 151 Blend& current = cur_state.blend[0];
@@ -283,7 +255,6 @@ void OpenGLState::Apply() {
283 ApplyProgramPipeline(); 255 ApplyProgramPipeline();
284 ApplyClipDistances(); 256 ApplyClipDistances();
285 ApplyRasterizerDiscard(); 257 ApplyRasterizerDiscard();
286 ApplyViewport();
287 ApplyStencilTest(); 258 ApplyStencilTest();
288 ApplyBlending(); 259 ApplyBlending();
289 ApplyTextures(); 260 ApplyTextures();
diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h
index 44eb35dd5..b4c957c0d 100644
--- a/src/video_core/renderer_opengl/gl_state.h
+++ b/src/video_core/renderer_opengl/gl_state.h
@@ -56,16 +56,6 @@ public:
56 GLuint program_pipeline = 0; // GL_PROGRAM_PIPELINE_BINDING 56 GLuint program_pipeline = 0; // GL_PROGRAM_PIPELINE_BINDING
57 } draw; 57 } draw;
58 58
59 struct Viewport {
60 GLint x = 0;
61 GLint y = 0;
62 GLint width = 0;
63 GLint height = 0;
64 GLfloat depth_range_near = 0.0f; // GL_DEPTH_RANGE
65 GLfloat depth_range_far = 1.0f; // GL_DEPTH_RANGE
66 };
67 std::array<Viewport, Tegra::Engines::Maxwell3D::Regs::NumViewports> viewports;
68
69 std::array<bool, 8> clip_distance = {}; // GL_CLIP_DISTANCE 59 std::array<bool, 8> clip_distance = {}; // GL_CLIP_DISTANCE
70 60
71 struct { 61 struct {
@@ -82,7 +72,6 @@ public:
82 return cur_state; 72 return cur_state;
83 } 73 }
84 74
85 void SetDefaultViewports();
86 /// Apply this state as the current OpenGL state 75 /// Apply this state as the current OpenGL state
87 void Apply(); 76 void Apply();
88 77
@@ -92,7 +81,6 @@ public:
92 void ApplyClipDistances(); 81 void ApplyClipDistances();
93 void ApplyRasterizerDiscard(); 82 void ApplyRasterizerDiscard();
94 void ApplyStencilTest(); 83 void ApplyStencilTest();
95 void ApplyViewport();
96 void ApplyTargetBlending(std::size_t target, bool force); 84 void ApplyTargetBlending(std::size_t target, bool force);
97 void ApplyGlobalBlending(); 85 void ApplyGlobalBlending();
98 void ApplyBlending(); 86 void ApplyBlending();
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp
index 0d5ef9ef6..12e820979 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.cpp
+++ b/src/video_core/renderer_opengl/renderer_opengl.cpp
@@ -205,8 +205,8 @@ constexpr GLint TexCoordLocation = 1;
205constexpr GLint ModelViewMatrixLocation = 0; 205constexpr GLint ModelViewMatrixLocation = 0;
206 206
207struct ScreenRectVertex { 207struct ScreenRectVertex {
208 constexpr ScreenRectVertex(GLfloat x, GLfloat y, GLfloat u, GLfloat v) 208 constexpr ScreenRectVertex(u32 x, u32 y, GLfloat u, GLfloat v)
209 : position{{x, y}}, tex_coord{{u, v}} {} 209 : position{{static_cast<GLfloat>(x), static_cast<GLfloat>(y)}}, tex_coord{{u, v}} {}
210 210
211 std::array<GLfloat, 2> position; 211 std::array<GLfloat, 2> position;
212 std::array<GLfloat, 2> tex_coord; 212 std::array<GLfloat, 2> tex_coord;
@@ -514,8 +514,18 @@ void RendererOpenGL::ConfigureFramebufferTexture(TextureInfo& texture,
514 glTextureStorage2D(texture.resource.handle, 1, internal_format, texture.width, texture.height); 514 glTextureStorage2D(texture.resource.handle, 1, internal_format, texture.width, texture.height);
515} 515}
516 516
517void RendererOpenGL::DrawScreenTriangles(const ScreenInfo& screen_info, float x, float y, float w, 517void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) {
518 float h) { 518 if (renderer_settings.set_background_color) {
519 // Update background color before drawing
520 glClearColor(Settings::values.bg_red, Settings::values.bg_green, Settings::values.bg_blue,
521 0.0f);
522 }
523
524 // Set projection matrix
525 const std::array ortho_matrix =
526 MakeOrthographicMatrix(static_cast<float>(layout.width), static_cast<float>(layout.height));
527 glUniformMatrix3x2fv(ModelViewMatrixLocation, 1, GL_FALSE, ortho_matrix.data());
528
519 const auto& texcoords = screen_info.display_texcoords; 529 const auto& texcoords = screen_info.display_texcoords;
520 auto left = texcoords.left; 530 auto left = texcoords.left;
521 auto right = texcoords.right; 531 auto right = texcoords.right;
@@ -547,12 +557,14 @@ void RendererOpenGL::DrawScreenTriangles(const ScreenInfo& screen_info, float x,
547 static_cast<f32>(screen_info.texture.height); 557 static_cast<f32>(screen_info.texture.height);
548 } 558 }
549 559
560 const auto& screen = layout.screen;
550 const std::array vertices = { 561 const std::array vertices = {
551 ScreenRectVertex(x, y, texcoords.top * scale_u, left * scale_v), 562 ScreenRectVertex(screen.left, screen.top, texcoords.top * scale_u, left * scale_v),
552 ScreenRectVertex(x + w, y, texcoords.bottom * scale_u, left * scale_v), 563 ScreenRectVertex(screen.right, screen.top, texcoords.bottom * scale_u, left * scale_v),
553 ScreenRectVertex(x, y + h, texcoords.top * scale_u, right * scale_v), 564 ScreenRectVertex(screen.left, screen.bottom, texcoords.top * scale_u, right * scale_v),
554 ScreenRectVertex(x + w, y + h, texcoords.bottom * scale_u, right * scale_v), 565 ScreenRectVertex(screen.right, screen.bottom, texcoords.bottom * scale_u, right * scale_v),
555 }; 566 };
567 glNamedBufferSubData(vertex_buffer.handle, 0, sizeof(vertices), std::data(vertices));
556 568
557 state.textures[0] = screen_info.display_texture; 569 state.textures[0] = screen_info.display_texture;
558 state.Apply(); 570 state.Apply();
@@ -572,6 +584,7 @@ void RendererOpenGL::DrawScreenTriangles(const ScreenInfo& screen_info, float x,
572 glCullFace(GL_BACK); 584 glCullFace(GL_BACK);
573 glFrontFace(GL_CW); 585 glFrontFace(GL_CW);
574 glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 586 glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
587 glViewport(0, 0, layout.width, layout.height);
575 588
576 glVertexAttribFormat(PositionLocation, 2, GL_FLOAT, GL_FALSE, 589 glVertexAttribFormat(PositionLocation, 2, GL_FLOAT, GL_FALSE,
577 offsetof(ScreenRectVertex, position)); 590 offsetof(ScreenRectVertex, position));
@@ -581,7 +594,7 @@ void RendererOpenGL::DrawScreenTriangles(const ScreenInfo& screen_info, float x,
581 glVertexAttribBinding(TexCoordLocation, 0); 594 glVertexAttribBinding(TexCoordLocation, 0);
582 glBindVertexBuffer(0, vertex_buffer.handle, 0, sizeof(ScreenRectVertex)); 595 glBindVertexBuffer(0, vertex_buffer.handle, 0, sizeof(ScreenRectVertex));
583 596
584 glNamedBufferSubData(vertex_buffer.handle, 0, sizeof(vertices), std::data(vertices)); 597 glClear(GL_COLOR_BUFFER_BIT);
585 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 598 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
586 599
587 // Restore default state 600 // Restore default state
@@ -589,28 +602,6 @@ void RendererOpenGL::DrawScreenTriangles(const ScreenInfo& screen_info, float x,
589 state.Apply(); 602 state.Apply();
590} 603}
591 604
592void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) {
593 if (renderer_settings.set_background_color) {
594 // Update background color before drawing
595 glClearColor(Settings::values.bg_red, Settings::values.bg_green, Settings::values.bg_blue,
596 0.0f);
597 }
598
599 const auto& screen = layout.screen;
600
601 glViewport(0, 0, layout.width, layout.height);
602 glClear(GL_COLOR_BUFFER_BIT);
603
604 // Set projection matrix
605 const std::array ortho_matrix =
606 MakeOrthographicMatrix(static_cast<float>(layout.width), static_cast<float>(layout.height));
607 glUniformMatrix3x2fv(ModelViewMatrixLocation, 1, GL_FALSE, ortho_matrix.data());
608
609 DrawScreenTriangles(screen_info, static_cast<float>(screen.left),
610 static_cast<float>(screen.top), static_cast<float>(screen.GetWidth()),
611 static_cast<float>(screen.GetHeight()));
612}
613
614void RendererOpenGL::TryPresent(int timeout_ms) { 605void RendererOpenGL::TryPresent(int timeout_ms) {
615 const auto& layout = render_window.GetFramebufferLayout(); 606 const auto& layout = render_window.GetFramebufferLayout();
616 auto frame = frame_mailbox->TryGetPresentFrame(timeout_ms); 607 auto frame = frame_mailbox->TryGetPresentFrame(timeout_ms);
diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h
index 978a4d0eb..42a2141d8 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.h
+++ b/src/video_core/renderer_opengl/renderer_opengl.h
@@ -76,8 +76,6 @@ private:
76 /// Draws the emulated screens to the emulator window. 76 /// Draws the emulated screens to the emulator window.
77 void DrawScreen(const Layout::FramebufferLayout& layout); 77 void DrawScreen(const Layout::FramebufferLayout& layout);
78 78
79 void DrawScreenTriangles(const ScreenInfo& screen_info, float x, float y, float w, float h);
80
81 void RenderScreenshot(); 79 void RenderScreenshot();
82 80
83 /// Loads framebuffer from emulated memory into the active OpenGL texture. 81 /// Loads framebuffer from emulated memory into the active OpenGL texture.