VERY experimental Nintendo Switch 2 emulator
C++
gl_state: Remove texture and sampler tracking
ReinUsesLisp3e8bde451d68
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cppindex f916f348ff..669a7c3352 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) {bind_ubo_pushbuffer.Bind();bind_ssbo_pushbuffer.Bind();- state.ApplyTextures();state.ApplyImages();state.ApplyShaderProgram();state.ApplyProgramPipeline();@@ -861,20 +860,20 @@ void RasterizerOpenGL::SetupTexture(u32 binding, const Tegra::Texture::FullTextuconst auto view = texture_cache.GetTextureSurface(texture.tic, entry);if (!view) {// Can occur when texture addr is null or its memory is unmapped/invalid- state.samplers[binding] = 0;- state.textures[binding] = 0;+ glBindSampler(binding, 0);+ glBindTextureUnit(binding, 0);return;}- state.textures[binding] = view->GetTexture();+ glBindTextureUnit(binding, view->GetTexture());if (view->GetSurfaceParams().IsBuffer()) {return;}- state.samplers[binding] = sampler_cache.GetSampler(texture.tsc);-// Apply swizzle to textures that are not buffers.view->ApplySwizzle(texture.tic.x_source, texture.tic.y_source, texture.tic.z_source,texture.tic.w_source);++ glBindSampler(binding, sampler_cache.GetSampler(texture.tsc));}void 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.cppindex 00355c1daa..80666a9ed5 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() {MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);glDeleteTextures(1, &handle);- OpenGLState::GetCurState().UnbindTexture(handle).Apply();handle = 0;}@@ -65,7 +64,6 @@ void OGLTextureView::Release() {MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);glDeleteTextures(1, &handle);- OpenGLState::GetCurState().UnbindTexture(handle).Apply();handle = 0;}@@ -83,7 +81,6 @@ void OGLSampler::Release() {MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);glDeleteSamplers(1, &handle);- OpenGLState::GetCurState().ResetSampler(handle).Apply();handle = 0;}diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cppindex 3cdb9b4a05..98de72b5f1 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() {}}-void OpenGLState::ApplyTextures() {- const std::size_t size = std::size(textures);- for (std::size_t i = 0; i < size; ++i) {- if (UpdateValue(cur_state.textures[i], textures[i])) {- // BindTextureUnit doesn't support binding null textures, skip those binds.- // TODO(Rodrigo): Stop using null textures- if (textures[i] != 0) {- glBindTextureUnit(static_cast<GLuint>(i), textures[i]);- }- }- }-}--void OpenGLState::ApplySamplers() {- const std::size_t size = std::size(samplers);- for (std::size_t i = 0; i < size; ++i) {- if (UpdateValue(cur_state.samplers[i], samplers[i])) {- glBindSampler(static_cast<GLuint>(i), samplers[i]);- }- }-}-void OpenGLState::ApplyImages() {if (const auto update = UpdateArray(cur_state.images, images)) {glBindImageTextures(update->first, update->second, images.data() + update->first);@@ -146,30 +124,10 @@ void OpenGLState::Apply() {ApplyFramebufferState();ApplyShaderProgram();ApplyProgramPipeline();- ApplyTextures();- ApplySamplers();ApplyImages();ApplyRenderBuffer();}-OpenGLState& OpenGLState::UnbindTexture(GLuint handle) {- for (auto& texture : textures) {- if (texture == handle) {- texture = 0;- }- }- return *this;-}--OpenGLState& OpenGLState::ResetSampler(GLuint handle) {- for (auto& sampler : samplers) {- if (sampler == handle) {- sampler = 0;- }- }- return *this;-}-OpenGLState& OpenGLState::ResetProgram(GLuint handle) {if (draw.shader_program == handle) {draw.shader_program = 0;diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.hindex 29126b80a5..25dd56452a 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 {class OpenGLState {public:- static constexpr std::size_t NumSamplers = 32 * 5;static constexpr std::size_t NumImages = 8 * 5;- std::array<GLuint, NumSamplers> textures = {};- std::array<GLuint, NumSamplers> samplers = {};std::array<GLuint, NumImages> images = {};struct {@@ -41,14 +38,10 @@ public:void ApplyFramebufferState();void ApplyShaderProgram();void ApplyProgramPipeline();- void ApplyTextures();- void ApplySamplers();void ApplyImages();void ApplyRenderBuffer();/// Resets any references to the given resource- OpenGLState& UnbindTexture(GLuint handle);- OpenGLState& ResetSampler(GLuint handle);OpenGLState& ResetProgram(GLuint handle);OpenGLState& ResetPipeline(GLuint handle);OpenGLState& ResetFramebuffer(GLuint handle);diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cppindex 053d8602b4..1295121f5b 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) {};glNamedBufferSubData(vertex_buffer.handle, 0, sizeof(vertices), std::data(vertices));- state.textures[0] = screen_info.display_texture;state.Apply();// TODO: Signal state tracker about these changes@@ -598,11 +597,13 @@ void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) {glVertexAttribBinding(TexCoordLocation, 0);glBindVertexBuffer(0, vertex_buffer.handle, 0, sizeof(ScreenRectVertex));+ glBindTextureUnit(0, screen_info.display_texture);+ glBindSampler(0, 0);+glClear(GL_COLOR_BUFFER_BIT);glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);// Restore default state- state.textures[0] = 0;state.Apply();}