mirror of
https://github.com/yuzu-mirror/yuzu
synced 2024-12-22 02:33:12 +00:00
Correct Mipmaps View method in Texture Cache
This commit is contained in:
parent
d86f9cd709
commit
1af4414861
3 changed files with 29 additions and 32 deletions
|
@ -233,7 +233,8 @@ CachedSurface::CachedSurface(const GPUVAddr gpu_addr, const SurfaceParams& param
|
||||||
main.num_layers = params.is_layered ? params.depth : 1;
|
main.num_layers = params.is_layered ? params.depth : 1;
|
||||||
main.target = params.target;
|
main.target = params.target;
|
||||||
main_view = CreateView(main);
|
main_view = CreateView(main);
|
||||||
main_view->DecorateViewName(gpu_addr, params.TargetName() + "V:" + std::to_string(view_count++));
|
main_view->DecorateViewName(gpu_addr,
|
||||||
|
params.TargetName() + "V:" + std::to_string(view_count++));
|
||||||
}
|
}
|
||||||
|
|
||||||
CachedSurface::~CachedSurface() {
|
CachedSurface::~CachedSurface() {
|
||||||
|
@ -350,7 +351,7 @@ void CachedSurface::DecorateSurfaceName() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CachedSurfaceView::DecorateViewName(GPUVAddr gpu_addr, std::string prefix) {
|
void CachedSurfaceView::DecorateViewName(GPUVAddr gpu_addr, std::string prefix) {
|
||||||
LabelGLObject(GL_TEXTURE, texture_view.texture.handle, gpu_addr, prefix);
|
LabelGLObject(GL_TEXTURE, texture_view.handle, gpu_addr, prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
View CachedSurface::CreateView(const ViewParams& view_key) {
|
View CachedSurface::CreateView(const ViewParams& view_key) {
|
||||||
|
@ -364,6 +365,7 @@ CachedSurfaceView::CachedSurfaceView(CachedSurface& surface, const ViewParams& p
|
||||||
: VideoCommon::ViewBase(params), surface{surface} {
|
: VideoCommon::ViewBase(params), surface{surface} {
|
||||||
target = GetTextureTarget(params.target);
|
target = GetTextureTarget(params.target);
|
||||||
texture_view = CreateTextureView();
|
texture_view = CreateTextureView();
|
||||||
|
swizzle = EncodeSwizzle(SwizzleSource::R, SwizzleSource::G, SwizzleSource::B, SwizzleSource::A);
|
||||||
}
|
}
|
||||||
|
|
||||||
CachedSurfaceView::~CachedSurfaceView() = default;
|
CachedSurfaceView::~CachedSurfaceView() = default;
|
||||||
|
@ -371,20 +373,24 @@ CachedSurfaceView::~CachedSurfaceView() = default;
|
||||||
void CachedSurfaceView::Attach(GLenum attachment) const {
|
void CachedSurfaceView::Attach(GLenum attachment) const {
|
||||||
ASSERT(params.num_layers == 1 && params.num_levels == 1);
|
ASSERT(params.num_layers == 1 && params.num_levels == 1);
|
||||||
|
|
||||||
switch (params.target) {
|
const auto& owner_params = surface.GetSurfaceParams();
|
||||||
|
|
||||||
|
switch (owner_params.target) {
|
||||||
case SurfaceTarget::Texture1D:
|
case SurfaceTarget::Texture1D:
|
||||||
glFramebufferTexture1D(GL_DRAW_FRAMEBUFFER, attachment, target,
|
glFramebufferTexture1D(GL_DRAW_FRAMEBUFFER, attachment, surface.GetTarget(),
|
||||||
surface.GetTexture(), params.base_level);
|
surface.GetTexture(),
|
||||||
|
params.base_level);
|
||||||
break;
|
break;
|
||||||
case SurfaceTarget::Texture2D:
|
case SurfaceTarget::Texture2D:
|
||||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, target,
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, surface.GetTarget(),
|
||||||
surface.GetTexture(), params.base_level);
|
surface.GetTexture(),
|
||||||
|
params.base_level);
|
||||||
break;
|
break;
|
||||||
case SurfaceTarget::Texture1DArray:
|
case SurfaceTarget::Texture1DArray:
|
||||||
case SurfaceTarget::Texture2DArray:
|
case SurfaceTarget::Texture2DArray:
|
||||||
case SurfaceTarget::TextureCubemap:
|
case SurfaceTarget::TextureCubemap:
|
||||||
case SurfaceTarget::TextureCubeArray:
|
case SurfaceTarget::TextureCubeArray:
|
||||||
glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, attachment, target,
|
glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, attachment, surface.GetTexture(),
|
||||||
params.base_level, params.base_layer);
|
params.base_level, params.base_layer);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -394,22 +400,22 @@ void CachedSurfaceView::Attach(GLenum attachment) const {
|
||||||
|
|
||||||
void CachedSurfaceView::ApplySwizzle(SwizzleSource x_source, SwizzleSource y_source,
|
void CachedSurfaceView::ApplySwizzle(SwizzleSource x_source, SwizzleSource y_source,
|
||||||
SwizzleSource z_source, SwizzleSource w_source) {
|
SwizzleSource z_source, SwizzleSource w_source) {
|
||||||
u32 swizzle = EncodeSwizzle(x_source, y_source, z_source, w_source);
|
u32 new_swizzle = EncodeSwizzle(x_source, y_source, z_source, w_source);
|
||||||
if (swizzle == texture_view.swizzle)
|
if (new_swizzle == swizzle)
|
||||||
return;
|
return;
|
||||||
|
swizzle = new_swizzle;
|
||||||
const std::array<GLint, 4> gl_swizzle = {GetSwizzleSource(x_source), GetSwizzleSource(y_source),
|
const std::array<GLint, 4> gl_swizzle = {GetSwizzleSource(x_source), GetSwizzleSource(y_source),
|
||||||
GetSwizzleSource(z_source),
|
GetSwizzleSource(z_source),
|
||||||
GetSwizzleSource(w_source)};
|
GetSwizzleSource(w_source)};
|
||||||
glTextureParameteriv(texture_view.texture.handle, GL_TEXTURE_SWIZZLE_RGBA, gl_swizzle.data());
|
glTextureParameteriv(texture_view.handle, GL_TEXTURE_SWIZZLE_RGBA, gl_swizzle.data());
|
||||||
texture_view.swizzle = swizzle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CachedSurfaceView::TextureView CachedSurfaceView::CreateTextureView() const {
|
OGLTextureView CachedSurfaceView::CreateTextureView() const {
|
||||||
const auto& owner_params = surface.GetSurfaceParams();
|
const auto& owner_params = surface.GetSurfaceParams();
|
||||||
TextureView texture_view;
|
OGLTextureView tv;
|
||||||
texture_view.texture.Create();
|
tv.Create();
|
||||||
|
|
||||||
const GLuint handle{texture_view.texture.handle};
|
const GLuint handle{tv.handle};
|
||||||
const FormatTuple& tuple{
|
const FormatTuple& tuple{
|
||||||
GetFormatTuple(owner_params.pixel_format, owner_params.component_type)};
|
GetFormatTuple(owner_params.pixel_format, owner_params.component_type)};
|
||||||
|
|
||||||
|
@ -418,11 +424,7 @@ CachedSurfaceView::TextureView CachedSurfaceView::CreateTextureView() const {
|
||||||
|
|
||||||
ApplyTextureDefaults(owner_params, handle);
|
ApplyTextureDefaults(owner_params, handle);
|
||||||
|
|
||||||
u32 swizzle =
|
return tv;
|
||||||
EncodeSwizzle(SwizzleSource::R, SwizzleSource::G, SwizzleSource::B, SwizzleSource::A);
|
|
||||||
texture_view.swizzle = swizzle;
|
|
||||||
|
|
||||||
return texture_view;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureCacheOpenGL::TextureCacheOpenGL(Core::System& system,
|
TextureCacheOpenGL::TextureCacheOpenGL(Core::System& system,
|
||||||
|
|
|
@ -74,7 +74,7 @@ public:
|
||||||
void Attach(GLenum attachment) const;
|
void Attach(GLenum attachment) const;
|
||||||
|
|
||||||
GLuint GetTexture() {
|
GLuint GetTexture() {
|
||||||
return texture_view.texture.handle;
|
return texture_view.handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SurfaceParams& GetSurfaceParams() const {
|
const SurfaceParams& GetSurfaceParams() const {
|
||||||
|
@ -104,11 +104,6 @@ public:
|
||||||
void DecorateViewName(GPUVAddr gpu_addr, std::string prefix);
|
void DecorateViewName(GPUVAddr gpu_addr, std::string prefix);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct TextureView {
|
|
||||||
OGLTextureView texture;
|
|
||||||
u32 swizzle;
|
|
||||||
};
|
|
||||||
|
|
||||||
u32 EncodeSwizzle(Tegra::Texture::SwizzleSource x_source,
|
u32 EncodeSwizzle(Tegra::Texture::SwizzleSource x_source,
|
||||||
Tegra::Texture::SwizzleSource y_source,
|
Tegra::Texture::SwizzleSource y_source,
|
||||||
Tegra::Texture::SwizzleSource z_source,
|
Tegra::Texture::SwizzleSource z_source,
|
||||||
|
@ -117,12 +112,13 @@ private:
|
||||||
(static_cast<u32>(z_source) << 8) | static_cast<u32>(w_source);
|
(static_cast<u32>(z_source) << 8) | static_cast<u32>(w_source);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureView CreateTextureView() const;
|
OGLTextureView CreateTextureView() const;
|
||||||
|
|
||||||
CachedSurface& surface;
|
CachedSurface& surface;
|
||||||
GLenum target{};
|
GLenum target{};
|
||||||
|
|
||||||
TextureView texture_view;
|
OGLTextureView texture_view;
|
||||||
|
u32 swizzle;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TextureCacheOpenGL final : public TextureCacheBase {
|
class TextureCacheOpenGL final : public TextureCacheBase {
|
||||||
|
|
|
@ -282,8 +282,7 @@ public:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const std::size_t size = view_params.GetGuestSizeInBytes();
|
const std::size_t size = view_params.GetGuestSizeInBytes();
|
||||||
const GPUVAddr relative_address = view_addr - gpu_addr;
|
auto layer_mipmap = GetLayerMipmap(view_addr);
|
||||||
auto layer_mipmap = GetLayerMipmap(relative_address);
|
|
||||||
if (!layer_mipmap) {
|
if (!layer_mipmap) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -298,7 +297,7 @@ public:
|
||||||
vp.num_layers = 1;
|
vp.num_layers = 1;
|
||||||
vp.base_level = mipmap;
|
vp.base_level = mipmap;
|
||||||
vp.num_levels = 1;
|
vp.num_levels = 1;
|
||||||
vp.target = params.target;
|
vp.target = view_params.target;
|
||||||
return {GetView(vp)};
|
return {GetView(vp)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue