2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00

gl_state: Remove texture and sampler tracking

This commit is contained in:
ReinUsesLisp 2019-12-26 04:01:11 -03:00
parent 1bc0da3dea
commit 9677db03da
5 changed files with 8 additions and 60 deletions

View file

@ -633,7 +633,6 @@ void RasterizerOpenGL::DispatchCompute(GPUVAddr code_addr) {
bind_ubo_pushbuffer.Bind(); bind_ubo_pushbuffer.Bind();
bind_ssbo_pushbuffer.Bind(); bind_ssbo_pushbuffer.Bind();
state.ApplyTextures();
state.ApplyImages(); state.ApplyImages();
state.ApplyShaderProgram(); state.ApplyShaderProgram();
state.ApplyProgramPipeline(); state.ApplyProgramPipeline();
@ -861,20 +860,20 @@ void RasterizerOpenGL::SetupTexture(u32 binding, const Tegra::Texture::FullTextu
const auto view = texture_cache.GetTextureSurface(texture.tic, entry); const auto view = texture_cache.GetTextureSurface(texture.tic, entry);
if (!view) { if (!view) {
// Can occur when texture addr is null or its memory is unmapped/invalid // Can occur when texture addr is null or its memory is unmapped/invalid
state.samplers[binding] = 0; glBindSampler(binding, 0);
state.textures[binding] = 0; glBindTextureUnit(binding, 0);
return; return;
} }
state.textures[binding] = view->GetTexture(); glBindTextureUnit(binding, view->GetTexture());
if (view->GetSurfaceParams().IsBuffer()) { if (view->GetSurfaceParams().IsBuffer()) {
return; return;
} }
state.samplers[binding] = sampler_cache.GetSampler(texture.tsc);
// Apply swizzle to textures that are not buffers. // Apply swizzle to textures that are not buffers.
view->ApplySwizzle(texture.tic.x_source, texture.tic.y_source, texture.tic.z_source, view->ApplySwizzle(texture.tic.x_source, texture.tic.y_source, texture.tic.z_source,
texture.tic.w_source); texture.tic.w_source);
glBindSampler(binding, sampler_cache.GetSampler(texture.tsc));
} }
void RasterizerOpenGL::SetupDrawImages(std::size_t stage_index, const Shader& shader) { void RasterizerOpenGL::SetupDrawImages(std::size_t stage_index, const Shader& shader) {

View file

@ -47,7 +47,6 @@ void OGLTexture::Release() {
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion); MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteTextures(1, &handle); glDeleteTextures(1, &handle);
OpenGLState::GetCurState().UnbindTexture(handle).Apply();
handle = 0; handle = 0;
} }
@ -65,7 +64,6 @@ void OGLTextureView::Release() {
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion); MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteTextures(1, &handle); glDeleteTextures(1, &handle);
OpenGLState::GetCurState().UnbindTexture(handle).Apply();
handle = 0; handle = 0;
} }
@ -83,7 +81,6 @@ void OGLSampler::Release() {
MICROPROFILE_SCOPE(OpenGL_ResourceDeletion); MICROPROFILE_SCOPE(OpenGL_ResourceDeletion);
glDeleteSamplers(1, &handle); glDeleteSamplers(1, &handle);
OpenGLState::GetCurState().ResetSampler(handle).Apply();
handle = 0; handle = 0;
} }

View file

@ -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() { void OpenGLState::ApplyImages() {
if (const auto update = UpdateArray(cur_state.images, images)) { if (const auto update = UpdateArray(cur_state.images, images)) {
glBindImageTextures(update->first, update->second, images.data() + update->first); glBindImageTextures(update->first, update->second, images.data() + update->first);
@ -146,30 +124,10 @@ void OpenGLState::Apply() {
ApplyFramebufferState(); ApplyFramebufferState();
ApplyShaderProgram(); ApplyShaderProgram();
ApplyProgramPipeline(); ApplyProgramPipeline();
ApplyTextures();
ApplySamplers();
ApplyImages(); ApplyImages();
ApplyRenderBuffer(); 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) { OpenGLState& OpenGLState::ResetProgram(GLuint handle) {
if (draw.shader_program == handle) { if (draw.shader_program == handle) {
draw.shader_program = 0; draw.shader_program = 0;

View file

@ -13,10 +13,7 @@ namespace OpenGL {
class OpenGLState { class OpenGLState {
public: public:
static constexpr std::size_t NumSamplers = 32 * 5;
static constexpr std::size_t NumImages = 8 * 5; static constexpr std::size_t NumImages = 8 * 5;
std::array<GLuint, NumSamplers> textures = {};
std::array<GLuint, NumSamplers> samplers = {};
std::array<GLuint, NumImages> images = {}; std::array<GLuint, NumImages> images = {};
struct { struct {
@ -41,14 +38,10 @@ public:
void ApplyFramebufferState(); void ApplyFramebufferState();
void ApplyShaderProgram(); void ApplyShaderProgram();
void ApplyProgramPipeline(); void ApplyProgramPipeline();
void ApplyTextures();
void ApplySamplers();
void ApplyImages(); void ApplyImages();
void ApplyRenderBuffer(); void ApplyRenderBuffer();
/// Resets any references to the given resource /// Resets any references to the given resource
OpenGLState& UnbindTexture(GLuint handle);
OpenGLState& ResetSampler(GLuint handle);
OpenGLState& ResetProgram(GLuint handle); OpenGLState& ResetProgram(GLuint handle);
OpenGLState& ResetPipeline(GLuint handle); OpenGLState& ResetPipeline(GLuint handle);
OpenGLState& ResetFramebuffer(GLuint handle); OpenGLState& ResetFramebuffer(GLuint handle);

View file

@ -566,7 +566,6 @@ void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) {
}; };
glNamedBufferSubData(vertex_buffer.handle, 0, sizeof(vertices), std::data(vertices)); glNamedBufferSubData(vertex_buffer.handle, 0, sizeof(vertices), std::data(vertices));
state.textures[0] = screen_info.display_texture;
state.Apply(); state.Apply();
// TODO: Signal state tracker about these changes // TODO: Signal state tracker about these changes
@ -598,11 +597,13 @@ void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) {
glVertexAttribBinding(TexCoordLocation, 0); glVertexAttribBinding(TexCoordLocation, 0);
glBindVertexBuffer(0, vertex_buffer.handle, 0, sizeof(ScreenRectVertex)); glBindVertexBuffer(0, vertex_buffer.handle, 0, sizeof(ScreenRectVertex));
glBindTextureUnit(0, screen_info.display_texture);
glBindSampler(0, 0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
// Restore default state // Restore default state
state.textures[0] = 0;
state.Apply(); state.Apply();
} }