texture_cache: Implement rendering to 3D textures
This allows rendering to 3D textures with more than one slice. Applications are allowed to render to more than one slice of a texture using gl_Layer from a VTG shader. This also requires reworking how 3D texture collisions are handled, for now, this commit allows rendering to slices but not to miplevels. When a render target attempts to write to a mipmap, we fallback to the previous implementation (copying or flushing as needed). - Fixes color correction 3D textures on UE4 games (rainbow effects). - Allows Xenoblade games to render to 3D textures directly.
This commit is contained in:
parent
2293e8a11a
commit
c95c254f3e
10 changed files with 196 additions and 144 deletions
|
@ -263,9 +263,14 @@ CachedSurface::CachedSurface(const GPUVAddr gpu_addr, const SurfaceParams& param
|
|||
target = GetTextureTarget(params.target);
|
||||
texture = CreateTexture(params, target, internal_format, texture_buffer);
|
||||
DecorateSurfaceName();
|
||||
main_view = CreateViewInner(
|
||||
ViewParams(params.target, 0, params.is_layered ? params.depth : 1, 0, params.num_levels),
|
||||
true);
|
||||
|
||||
u32 num_layers = 1;
|
||||
if (params.is_layered || params.target == SurfaceTarget::Texture3D) {
|
||||
num_layers = params.depth;
|
||||
}
|
||||
|
||||
main_view =
|
||||
CreateViewInner(ViewParams(params.target, 0, num_layers, 0, params.num_levels), true);
|
||||
}
|
||||
|
||||
CachedSurface::~CachedSurface() = default;
|
||||
|
@ -413,37 +418,40 @@ CachedSurfaceView::CachedSurfaceView(CachedSurface& surface, const ViewParams& p
|
|||
|
||||
CachedSurfaceView::~CachedSurfaceView() = default;
|
||||
|
||||
void CachedSurfaceView::Attach(GLenum attachment, GLenum target) const {
|
||||
void CachedSurfaceView::Attach(GLenum attachment, GLenum fb_target) const {
|
||||
ASSERT(params.num_levels == 1);
|
||||
|
||||
if (params.num_layers > 1) {
|
||||
// Layered framebuffer attachments
|
||||
UNIMPLEMENTED_IF(params.base_layer != 0);
|
||||
|
||||
switch (params.target) {
|
||||
case SurfaceTarget::Texture2DArray:
|
||||
glFramebufferTexture(target, attachment, GetTexture(), 0);
|
||||
break;
|
||||
default:
|
||||
UNIMPLEMENTED();
|
||||
if (params.target == SurfaceTarget::Texture3D) {
|
||||
if (params.num_layers > 1) {
|
||||
ASSERT(params.base_layer == 0);
|
||||
glFramebufferTexture(fb_target, attachment, surface.texture.handle, params.base_level);
|
||||
} else {
|
||||
glFramebufferTexture3D(fb_target, attachment, target, surface.texture.handle,
|
||||
params.base_level, params.base_layer);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (params.num_layers > 1) {
|
||||
UNIMPLEMENTED_IF(params.base_layer != 0);
|
||||
glFramebufferTexture(fb_target, attachment, GetTexture(), 0);
|
||||
return;
|
||||
}
|
||||
|
||||
const GLenum view_target = surface.GetTarget();
|
||||
const GLuint texture = surface.GetTexture();
|
||||
switch (surface.GetSurfaceParams().target) {
|
||||
case SurfaceTarget::Texture1D:
|
||||
glFramebufferTexture1D(target, attachment, view_target, texture, params.base_level);
|
||||
glFramebufferTexture1D(fb_target, attachment, view_target, texture, params.base_level);
|
||||
break;
|
||||
case SurfaceTarget::Texture2D:
|
||||
glFramebufferTexture2D(target, attachment, view_target, texture, params.base_level);
|
||||
glFramebufferTexture2D(fb_target, attachment, view_target, texture, params.base_level);
|
||||
break;
|
||||
case SurfaceTarget::Texture1DArray:
|
||||
case SurfaceTarget::Texture2DArray:
|
||||
case SurfaceTarget::TextureCubemap:
|
||||
case SurfaceTarget::TextureCubeArray:
|
||||
glFramebufferTextureLayer(target, attachment, texture, params.base_level,
|
||||
glFramebufferTextureLayer(fb_target, attachment, texture, params.base_level,
|
||||
params.base_layer);
|
||||
break;
|
||||
default:
|
||||
|
@ -500,8 +508,13 @@ OGLTextureView CachedSurfaceView::CreateTextureView() const {
|
|||
OGLTextureView texture_view;
|
||||
texture_view.Create();
|
||||
|
||||
glTextureView(texture_view.handle, target, surface.texture.handle, format, params.base_level,
|
||||
params.num_levels, params.base_layer, params.num_layers);
|
||||
if (target == GL_TEXTURE_3D) {
|
||||
glTextureView(texture_view.handle, target, surface.texture.handle, format,
|
||||
params.base_level, params.num_levels, 0, 1);
|
||||
} else {
|
||||
glTextureView(texture_view.handle, target, surface.texture.handle, format,
|
||||
params.base_level, params.num_levels, params.base_layer, params.num_layers);
|
||||
}
|
||||
ApplyTextureDefaults(surface.GetSurfaceParams(), texture_view.handle);
|
||||
|
||||
return texture_view;
|
||||
|
|
|
@ -80,8 +80,10 @@ public:
|
|||
explicit CachedSurfaceView(CachedSurface& surface, const ViewParams& params, bool is_proxy);
|
||||
~CachedSurfaceView();
|
||||
|
||||
/// Attaches this texture view to the current bound GL_DRAW_FRAMEBUFFER
|
||||
void Attach(GLenum attachment, GLenum target) const;
|
||||
/// @brief Attaches this texture view to the currently bound fb_target framebuffer
|
||||
/// @param attachment Attachment to bind textures to
|
||||
/// @param fb_target Framebuffer target to attach to (e.g. DRAW_FRAMEBUFFER)
|
||||
void Attach(GLenum attachment, GLenum fb_target) const;
|
||||
|
||||
GLuint GetTexture(Tegra::Texture::SwizzleSource x_source,
|
||||
Tegra::Texture::SwizzleSource y_source,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue