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

gl_rasterizer_cache: Move swizzling to textures instead of state

This commit is contained in:
ReinUsesLisp 2019-01-06 23:02:27 -03:00
parent 3bbaa98c78
commit 704744bb72
6 changed files with 35 additions and 28 deletions

View file

@ -1022,11 +1022,11 @@ void RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, const Shader& s
if (surface != nullptr) { if (surface != nullptr) {
unit.texture = unit.texture =
entry.IsArray() ? surface->TextureLayer().handle : surface->Texture().handle; entry.IsArray() ? surface->TextureLayer().handle : surface->Texture().handle;
unit.target = entry.IsArray() ? surface->TargetLayer() : surface->Target(); const GLenum target = entry.IsArray() ? surface->TargetLayer() : surface->Target();
unit.swizzle.r = MaxwellToGL::SwizzleSource(texture.tic.x_source); surface->UpdateSwizzle(texture.tic.x_source, texture.tic.y_source, texture.tic.z_source,
unit.swizzle.g = MaxwellToGL::SwizzleSource(texture.tic.y_source); texture.tic.w_source);
unit.swizzle.b = MaxwellToGL::SwizzleSource(texture.tic.z_source); unit.texture = handle;
unit.swizzle.a = MaxwellToGL::SwizzleSource(texture.tic.w_source); unit.target = target;
} else { } else {
// 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
unit.texture = 0; unit.texture = 0;

View file

@ -857,6 +857,8 @@ void CachedSurface::EnsureTextureView() {
glTextureView(texture_view.handle, target, texture.handle, gl_internal_format, 0, glTextureView(texture_view.handle, target, texture.handle, gl_internal_format, 0,
params.max_mip_level, 0, 1); params.max_mip_level, 0, 1);
ApplyTextureDefaults(texture_view.handle, params.max_mip_level); ApplyTextureDefaults(texture_view.handle, params.max_mip_level);
glTextureParameteriv(texture_view.handle, GL_TEXTURE_SWIZZLE_RGBA,
reinterpret_cast<const GLint*>(swizzle.data()));
} }
MICROPROFILE_DEFINE(OpenGL_TextureUL, "OpenGL", "Texture Upload", MP_RGB(128, 192, 64)); MICROPROFILE_DEFINE(OpenGL_TextureUL, "OpenGL", "Texture Upload", MP_RGB(128, 192, 64));
@ -870,6 +872,24 @@ void CachedSurface::UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle
UploadGLMipmapTexture(i, read_fb_handle, draw_fb_handle); UploadGLMipmapTexture(i, read_fb_handle, draw_fb_handle);
} }
void CachedSurface::UpdateSwizzle(Tegra::Texture::SwizzleSource swizzle_x,
Tegra::Texture::SwizzleSource swizzle_y,
Tegra::Texture::SwizzleSource swizzle_z,
Tegra::Texture::SwizzleSource swizzle_w) {
const GLenum new_x = MaxwellToGL::SwizzleSource(swizzle_x);
const GLenum new_y = MaxwellToGL::SwizzleSource(swizzle_y);
const GLenum new_z = MaxwellToGL::SwizzleSource(swizzle_z);
const GLenum new_w = MaxwellToGL::SwizzleSource(swizzle_w);
if (swizzle[0] != new_x || swizzle[1] != new_y || swizzle[2] != new_z || swizzle[3] != new_w) {
swizzle = {new_x, new_y, new_z, new_w};
const auto swizzle_data = reinterpret_cast<const GLint*>(swizzle.data());
glTextureParameteriv(texture.handle, GL_TEXTURE_SWIZZLE_RGBA, swizzle_data);
if (texture_view.handle != 0) {
glTextureParameteriv(texture_view.handle, GL_TEXTURE_SWIZZLE_RGBA, swizzle_data);
}
}
}
RasterizerCacheOpenGL::RasterizerCacheOpenGL(RasterizerOpenGL& rasterizer) RasterizerCacheOpenGL::RasterizerCacheOpenGL(RasterizerOpenGL& rasterizer)
: RasterizerCache{rasterizer} { : RasterizerCache{rasterizer} {
read_framebuffer.Create(); read_framebuffer.Create();

View file

@ -382,6 +382,11 @@ public:
// Upload data in gl_buffer to this surface's texture // Upload data in gl_buffer to this surface's texture
void UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle); void UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle);
void UpdateSwizzle(Tegra::Texture::SwizzleSource swizzle_x,
Tegra::Texture::SwizzleSource swizzle_y,
Tegra::Texture::SwizzleSource swizzle_z,
Tegra::Texture::SwizzleSource swizzle_w);
private: private:
void UploadGLMipmapTexture(u32 mip_map, GLuint read_fb_handle, GLuint draw_fb_handle); void UploadGLMipmapTexture(u32 mip_map, GLuint read_fb_handle, GLuint draw_fb_handle);
@ -394,6 +399,7 @@ private:
GLenum gl_target{}; GLenum gl_target{};
GLenum gl_internal_format{}; GLenum gl_internal_format{};
std::size_t cached_size_in_bytes{}; std::size_t cached_size_in_bytes{};
std::array<GLenum, 4> swizzle{GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA};
}; };
class RasterizerCacheOpenGL final : public RasterizerCache<Surface> { class RasterizerCacheOpenGL final : public RasterizerCache<Surface> {

View file

@ -463,7 +463,8 @@ void OpenGLState::ApplyPolygonOffset() const {
void OpenGLState::ApplyTextures() const { void OpenGLState::ApplyTextures() const {
bool has_delta{}; bool has_delta{};
std::size_t first{}, last{}; std::size_t first{};
std::size_t last{};
std::array<GLuint, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> textures; std::array<GLuint, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> textures;
for (std::size_t i = 0; i < std::size(texture_units); ++i) { for (std::size_t i = 0; i < std::size(texture_units); ++i) {
@ -478,16 +479,6 @@ void OpenGLState::ApplyTextures() const {
} }
last = i; last = i;
} }
// Update the texture swizzle
if (textures[i] != 0 && (texture_unit.swizzle.r != cur_state_texture_unit.swizzle.r ||
texture_unit.swizzle.g != cur_state_texture_unit.swizzle.g ||
texture_unit.swizzle.b != cur_state_texture_unit.swizzle.b ||
texture_unit.swizzle.a != cur_state_texture_unit.swizzle.a)) {
std::array<GLint, 4> mask = {texture_unit.swizzle.r, texture_unit.swizzle.g,
texture_unit.swizzle.b, texture_unit.swizzle.a};
glTextureParameteriv(texture_unit.texture, GL_TEXTURE_SWIZZLE_RGBA, mask.data());
}
} }
if (has_delta) { if (has_delta) {
@ -498,7 +489,8 @@ void OpenGLState::ApplyTextures() const {
void OpenGLState::ApplySamplers() const { void OpenGLState::ApplySamplers() const {
bool has_delta{}; bool has_delta{};
std::size_t first{}, last{}; std::size_t first{};
std::size_t last{};
std::array<GLuint, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> samplers; std::array<GLuint, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> samplers;
for (std::size_t i = 0; i < std::size(samplers); ++i) { for (std::size_t i = 0; i < std::size(samplers); ++i) {
samplers[i] = texture_units[i].sampler; samplers[i] = texture_units[i].sampler;

View file

@ -127,19 +127,9 @@ public:
GLuint texture; // GL_TEXTURE_BINDING_2D GLuint texture; // GL_TEXTURE_BINDING_2D
GLuint sampler; // GL_SAMPLER_BINDING GLuint sampler; // GL_SAMPLER_BINDING
GLenum target; GLenum target;
struct {
GLint r; // GL_TEXTURE_SWIZZLE_R
GLint g; // GL_TEXTURE_SWIZZLE_G
GLint b; // GL_TEXTURE_SWIZZLE_B
GLint a; // GL_TEXTURE_SWIZZLE_A
} swizzle;
void Unbind() { void Unbind() {
texture = 0; texture = 0;
swizzle.r = GL_RED;
swizzle.g = GL_GREEN;
swizzle.b = GL_BLUE;
swizzle.a = GL_ALPHA;
} }
void Reset() { void Reset() {

View file

@ -320,7 +320,6 @@ void RendererOpenGL::DrawScreenTriangles(const ScreenInfo& screen_info, float x,
}}; }};
state.texture_units[0].texture = screen_info.display_texture; state.texture_units[0].texture = screen_info.display_texture;
state.texture_units[0].swizzle = {GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA};
// Workaround brigthness problems in SMO by enabling sRGB in the final output // Workaround brigthness problems in SMO by enabling sRGB in the final output
// if it has been used in the frame. Needed because of this bug in QT: QTBUG-50987 // if it has been used in the frame. Needed because of this bug in QT: QTBUG-50987
state.framebuffer_srgb.enabled = OpenGLState::GetsRGBUsed(); state.framebuffer_srgb.enabled = OpenGLState::GetsRGBUsed();