summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp11
-rw-r--r--src/video_core/renderer_opengl/gl_resource_manager.cpp3
-rw-r--r--src/video_core/renderer_opengl/gl_state.cpp42
-rw-r--r--src/video_core/renderer_opengl/gl_state.h7
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.cpp5
5 files changed, 8 insertions, 60 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index f916f348f..669a7c335 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -633,7 +633,6 @@ void RasterizerOpenGL::DispatchCompute(GPUVAddr code_addr) {
633 bind_ubo_pushbuffer.Bind(); 633 bind_ubo_pushbuffer.Bind();
634 bind_ssbo_pushbuffer.Bind(); 634 bind_ssbo_pushbuffer.Bind();
635 635
636 state.ApplyTextures();
637 state.ApplyImages(); 636 state.ApplyImages();
638 state.ApplyShaderProgram(); 637 state.ApplyShaderProgram();
639 state.ApplyProgramPipeline(); 638 state.ApplyProgramPipeline();
@@ -861,20 +860,20 @@ void RasterizerOpenGL::SetupTexture(u32 binding, const Tegra::Texture::FullTextu
861 const auto view = texture_cache.GetTextureSurface(texture.tic, entry); 860 const auto view = texture_cache.GetTextureSurface(texture.tic, entry);
862 if (!view) { 861 if (!view) {
863 // Can occur when texture addr is null or its memory is unmapped/invalid 862 // Can occur when texture addr is null or its memory is unmapped/invalid
864 state.samplers[binding] = 0; 863 glBindSampler(binding, 0);
865 state.textures[binding] = 0; 864 glBindTextureUnit(binding, 0);
866 return; 865 return;
867 } 866 }
868 state.textures[binding] = view->GetTexture(); 867 glBindTextureUnit(binding, view->GetTexture());
869 868
870 if (view->GetSurfaceParams().IsBuffer()) { 869 if (view->GetSurfaceParams().IsBuffer()) {
871 return; 870 return;
872 } 871 }
873 state.samplers[binding] = sampler_cache.GetSampler(texture.tsc);
874
875 // Apply swizzle to textures that are not buffers. 872 // Apply swizzle to textures that are not buffers.
876 view->ApplySwizzle(texture.tic.x_source, texture.tic.y_source, texture.tic.z_source, 873 view->ApplySwizzle(texture.tic.x_source, texture.tic.y_source, texture.tic.z_source,
877 texture.tic.w_source); 874 texture.tic.w_source);
875
876 glBindSampler(binding, sampler_cache.GetSampler(texture.tsc));
878} 877}
879 878
880void RasterizerOpenGL::SetupDrawImages(std::size_t stage_index, const Shader& shader) { 879void RasterizerOpenGL::SetupDrawImages(std::size_t stage_index, const Shader& shader) {
diff --git a/src/video_core/renderer_opengl/gl_resource_manager.cpp b/src/video_core/renderer_opengl/gl_resource_manager.cpp
index 00355c1da..80666a9ed 100644
--- a/src/video_core/renderer_opengl/gl_resource_manager.cpp
+++ b/src/video_core/renderer_opengl/gl_resource_manager.cpp
@@ -47,7 +47,6 @@ void OGLTexture::Release() {
47 47
48 MICROPROFILE_SCOPE(OpenGL_ResourceDeletion); 48 MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
49 glDeleteTextures(1, &handle); 49 glDeleteTextures(1, &handle);
50 OpenGLState::GetCurState().UnbindTexture(handle).Apply();
51 handle = 0; 50 handle = 0;
52} 51}
53 52
@@ -65,7 +64,6 @@ void OGLTextureView::Release() {
65 64
66 MICROPROFILE_SCOPE(OpenGL_ResourceDeletion); 65 MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
67 glDeleteTextures(1, &handle); 66 glDeleteTextures(1, &handle);
68 OpenGLState::GetCurState().UnbindTexture(handle).Apply();
69 handle = 0; 67 handle = 0;
70} 68}
71 69
@@ -83,7 +81,6 @@ void OGLSampler::Release() {
83 81
84 MICROPROFILE_SCOPE(OpenGL_ResourceDeletion); 82 MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
85 glDeleteSamplers(1, &handle); 83 glDeleteSamplers(1, &handle);
86 OpenGLState::GetCurState().ResetSampler(handle).Apply();
87 handle = 0; 84 handle = 0;
88} 85}
89 86
diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp
index 3cdb9b4a0..98de72b5f 100644
--- a/src/video_core/renderer_opengl/gl_state.cpp
+++ b/src/video_core/renderer_opengl/gl_state.cpp
@@ -113,28 +113,6 @@ void OpenGLState::ApplyRenderBuffer() {
113 } 113 }
114} 114}
115 115
116void OpenGLState::ApplyTextures() {
117 const std::size_t size = std::size(textures);
118 for (std::size_t i = 0; i < size; ++i) {
119 if (UpdateValue(cur_state.textures[i], textures[i])) {
120 // BindTextureUnit doesn't support binding null textures, skip those binds.
121 // TODO(Rodrigo): Stop using null textures
122 if (textures[i] != 0) {
123 glBindTextureUnit(static_cast<GLuint>(i), textures[i]);
124 }
125 }
126 }
127}
128
129void OpenGLState::ApplySamplers() {
130 const std::size_t size = std::size(samplers);
131 for (std::size_t i = 0; i < size; ++i) {
132 if (UpdateValue(cur_state.samplers[i], samplers[i])) {
133 glBindSampler(static_cast<GLuint>(i), samplers[i]);
134 }
135 }
136}
137
138void OpenGLState::ApplyImages() { 116void OpenGLState::ApplyImages() {
139 if (const auto update = UpdateArray(cur_state.images, images)) { 117 if (const auto update = UpdateArray(cur_state.images, images)) {
140 glBindImageTextures(update->first, update->second, images.data() + update->first); 118 glBindImageTextures(update->first, update->second, images.data() + update->first);
@@ -146,30 +124,10 @@ void OpenGLState::Apply() {
146 ApplyFramebufferState(); 124 ApplyFramebufferState();
147 ApplyShaderProgram(); 125 ApplyShaderProgram();
148 ApplyProgramPipeline(); 126 ApplyProgramPipeline();
149 ApplyTextures();
150 ApplySamplers();
151 ApplyImages(); 127 ApplyImages();
152 ApplyRenderBuffer(); 128 ApplyRenderBuffer();
153} 129}
154 130
155OpenGLState& OpenGLState::UnbindTexture(GLuint handle) {
156 for (auto& texture : textures) {
157 if (texture == handle) {
158 texture = 0;
159 }
160 }
161 return *this;
162}
163
164OpenGLState& OpenGLState::ResetSampler(GLuint handle) {
165 for (auto& sampler : samplers) {
166 if (sampler == handle) {
167 sampler = 0;
168 }
169 }
170 return *this;
171}
172
173OpenGLState& OpenGLState::ResetProgram(GLuint handle) { 131OpenGLState& OpenGLState::ResetProgram(GLuint handle) {
174 if (draw.shader_program == handle) { 132 if (draw.shader_program == handle) {
175 draw.shader_program = 0; 133 draw.shader_program = 0;
diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h
index 29126b80a..25dd56452 100644
--- a/src/video_core/renderer_opengl/gl_state.h
+++ b/src/video_core/renderer_opengl/gl_state.h
@@ -13,10 +13,7 @@ namespace OpenGL {
13 13
14class OpenGLState { 14class OpenGLState {
15public: 15public:
16 static constexpr std::size_t NumSamplers = 32 * 5;
17 static constexpr std::size_t NumImages = 8 * 5; 16 static constexpr std::size_t NumImages = 8 * 5;
18 std::array<GLuint, NumSamplers> textures = {};
19 std::array<GLuint, NumSamplers> samplers = {};
20 std::array<GLuint, NumImages> images = {}; 17 std::array<GLuint, NumImages> images = {};
21 18
22 struct { 19 struct {
@@ -41,14 +38,10 @@ public:
41 void ApplyFramebufferState(); 38 void ApplyFramebufferState();
42 void ApplyShaderProgram(); 39 void ApplyShaderProgram();
43 void ApplyProgramPipeline(); 40 void ApplyProgramPipeline();
44 void ApplyTextures();
45 void ApplySamplers();
46 void ApplyImages(); 41 void ApplyImages();
47 void ApplyRenderBuffer(); 42 void ApplyRenderBuffer();
48 43
49 /// Resets any references to the given resource 44 /// Resets any references to the given resource
50 OpenGLState& UnbindTexture(GLuint handle);
51 OpenGLState& ResetSampler(GLuint handle);
52 OpenGLState& ResetProgram(GLuint handle); 45 OpenGLState& ResetProgram(GLuint handle);
53 OpenGLState& ResetPipeline(GLuint handle); 46 OpenGLState& ResetPipeline(GLuint handle);
54 OpenGLState& ResetFramebuffer(GLuint handle); 47 OpenGLState& ResetFramebuffer(GLuint handle);
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp
index 053d8602b..1295121f5 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.cpp
+++ b/src/video_core/renderer_opengl/renderer_opengl.cpp
@@ -566,7 +566,6 @@ void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) {
566 }; 566 };
567 glNamedBufferSubData(vertex_buffer.handle, 0, sizeof(vertices), std::data(vertices)); 567 glNamedBufferSubData(vertex_buffer.handle, 0, sizeof(vertices), std::data(vertices));
568 568
569 state.textures[0] = screen_info.display_texture;
570 state.Apply(); 569 state.Apply();
571 570
572 // TODO: Signal state tracker about these changes 571 // TODO: Signal state tracker about these changes
@@ -598,11 +597,13 @@ void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) {
598 glVertexAttribBinding(TexCoordLocation, 0); 597 glVertexAttribBinding(TexCoordLocation, 0);
599 glBindVertexBuffer(0, vertex_buffer.handle, 0, sizeof(ScreenRectVertex)); 598 glBindVertexBuffer(0, vertex_buffer.handle, 0, sizeof(ScreenRectVertex));
600 599
600 glBindTextureUnit(0, screen_info.display_texture);
601 glBindSampler(0, 0);
602
601 glClear(GL_COLOR_BUFFER_BIT); 603 glClear(GL_COLOR_BUFFER_BIT);
602 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 604 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
603 605
604 // Restore default state 606 // Restore default state
605 state.textures[0] = 0;
606 state.Apply(); 607 state.Apply();
607} 608}
608 609