2019-04-11 22:14:55 +02:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <functional>
|
2019-06-24 07:01:44 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <unordered_map>
|
2019-04-11 22:14:55 +02:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <glad/glad.h>
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "video_core/engines/shader_bytecode.h"
|
2019-06-02 01:12:00 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_device.h"
|
2019-04-24 23:47:59 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
2019-04-25 18:41:57 +02:00
|
|
|
#include "video_core/texture_cache/texture_cache.h"
|
2019-04-11 22:14:55 +02:00
|
|
|
|
|
|
|
namespace OpenGL {
|
|
|
|
|
|
|
|
using VideoCommon::SurfaceParams;
|
2019-05-07 16:57:16 +02:00
|
|
|
using VideoCommon::ViewParams;
|
2019-04-11 22:14:55 +02:00
|
|
|
|
|
|
|
class CachedSurfaceView;
|
|
|
|
class CachedSurface;
|
2019-04-21 01:01:26 +02:00
|
|
|
class TextureCacheOpenGL;
|
2019-12-29 01:45:56 +01:00
|
|
|
class StateTracker;
|
2019-04-11 22:14:55 +02:00
|
|
|
|
2019-04-17 01:01:07 +02:00
|
|
|
using Surface = std::shared_ptr<CachedSurface>;
|
2019-05-07 16:57:16 +02:00
|
|
|
using View = std::shared_ptr<CachedSurfaceView>;
|
|
|
|
using TextureCacheBase = VideoCommon::TextureCache<Surface, View>;
|
2019-04-11 22:14:55 +02:00
|
|
|
|
2019-05-07 16:57:16 +02:00
|
|
|
class CachedSurface final : public VideoCommon::SurfaceBase<View> {
|
2019-04-11 22:14:55 +02:00
|
|
|
friend CachedSurfaceView;
|
|
|
|
|
|
|
|
public:
|
2020-03-15 00:24:54 +01:00
|
|
|
explicit CachedSurface(GPUVAddr gpu_addr, const SurfaceParams& params, bool is_astc_supported);
|
2019-04-11 22:14:55 +02:00
|
|
|
~CachedSurface();
|
|
|
|
|
2019-07-05 03:10:59 +02:00
|
|
|
void UploadTexture(const std::vector<u8>& staging_buffer) override;
|
2019-05-07 16:57:16 +02:00
|
|
|
void DownloadTexture(std::vector<u8>& staging_buffer) override;
|
2019-04-25 18:41:57 +02:00
|
|
|
|
2019-04-14 06:44:16 +02:00
|
|
|
GLenum GetTarget() const {
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2019-04-11 22:14:55 +02:00
|
|
|
GLuint GetTexture() const {
|
|
|
|
return texture.handle;
|
|
|
|
}
|
|
|
|
|
2020-03-15 00:24:54 +01:00
|
|
|
bool IsCompressed() const {
|
|
|
|
return is_compressed;
|
|
|
|
}
|
|
|
|
|
2019-04-11 22:14:55 +02:00
|
|
|
protected:
|
2019-08-30 20:08:00 +02:00
|
|
|
void DecorateSurfaceName() override;
|
2019-04-17 01:01:07 +02:00
|
|
|
|
2019-05-07 16:57:16 +02:00
|
|
|
View CreateView(const ViewParams& view_key) override;
|
2019-06-24 07:01:44 +02:00
|
|
|
View CreateViewInner(const ViewParams& view_key, bool is_proxy);
|
2019-04-11 22:14:55 +02:00
|
|
|
|
|
|
|
private:
|
2019-07-05 03:10:59 +02:00
|
|
|
void UploadTextureMipmap(u32 level, const std::vector<u8>& staging_buffer);
|
2019-04-11 22:14:55 +02:00
|
|
|
|
|
|
|
GLenum internal_format{};
|
|
|
|
GLenum format{};
|
|
|
|
GLenum type{};
|
|
|
|
bool is_compressed{};
|
2019-04-14 06:44:16 +02:00
|
|
|
GLenum target{};
|
2019-05-07 16:57:16 +02:00
|
|
|
u32 view_count{};
|
2019-04-11 22:14:55 +02:00
|
|
|
|
|
|
|
OGLTexture texture;
|
2019-07-05 01:38:19 +02:00
|
|
|
OGLBuffer texture_buffer;
|
2019-04-11 22:14:55 +02:00
|
|
|
};
|
|
|
|
|
2019-05-07 16:57:16 +02:00
|
|
|
class CachedSurfaceView final : public VideoCommon::ViewBase {
|
2019-04-11 22:14:55 +02:00
|
|
|
public:
|
2019-07-05 03:10:59 +02:00
|
|
|
explicit CachedSurfaceView(CachedSurface& surface, const ViewParams& params, bool is_proxy);
|
2019-04-11 22:14:55 +02:00
|
|
|
~CachedSurfaceView();
|
|
|
|
|
2019-04-14 23:16:27 +02:00
|
|
|
/// Attaches this texture view to the current bound GL_DRAW_FRAMEBUFFER
|
2019-05-18 10:57:49 +02:00
|
|
|
void Attach(GLenum attachment, GLenum target) const;
|
2019-04-11 22:14:55 +02:00
|
|
|
|
2020-05-26 07:17:17 +02:00
|
|
|
GLuint GetTexture(Tegra::Texture::SwizzleSource x_source,
|
2019-09-06 04:26:05 +02:00
|
|
|
Tegra::Texture::SwizzleSource y_source,
|
|
|
|
Tegra::Texture::SwizzleSource z_source,
|
|
|
|
Tegra::Texture::SwizzleSource w_source);
|
|
|
|
|
|
|
|
void DecorateViewName(GPUVAddr gpu_addr, std::string prefix);
|
|
|
|
|
|
|
|
void MarkAsModified(u64 tick) {
|
|
|
|
surface.MarkAsModified(true, tick);
|
|
|
|
}
|
|
|
|
|
2019-07-05 03:10:59 +02:00
|
|
|
GLuint GetTexture() const {
|
2019-05-11 06:17:47 +02:00
|
|
|
if (is_proxy) {
|
|
|
|
return surface.GetTexture();
|
|
|
|
}
|
2020-05-26 07:17:17 +02:00
|
|
|
return main_view.handle;
|
2019-04-11 22:14:55 +02:00
|
|
|
}
|
|
|
|
|
2019-12-26 08:17:02 +01:00
|
|
|
GLenum GetFormat() const {
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
2019-04-11 22:14:55 +02:00
|
|
|
const SurfaceParams& GetSurfaceParams() const {
|
2019-05-07 16:57:16 +02:00
|
|
|
return surface.GetSurfaceParams();
|
2019-04-11 22:14:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-05-08 01:09:34 +02:00
|
|
|
OGLTextureView CreateTextureView() const;
|
2019-04-11 22:14:55 +02:00
|
|
|
|
|
|
|
CachedSurface& surface;
|
2020-05-26 07:17:17 +02:00
|
|
|
const GLenum format;
|
|
|
|
const GLenum target;
|
|
|
|
const bool is_proxy;
|
|
|
|
|
|
|
|
std::unordered_map<u32, OGLTextureView> view_cache;
|
|
|
|
OGLTextureView main_view;
|
2019-05-07 16:57:16 +02:00
|
|
|
|
2020-05-26 07:17:17 +02:00
|
|
|
// Use an invalid default so it always fails the comparison test
|
|
|
|
u32 current_swizzle = 0xffffffff;
|
|
|
|
GLuint current_view = 0;
|
2019-04-11 22:14:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class TextureCacheOpenGL final : public TextureCacheBase {
|
|
|
|
public:
|
2019-06-02 01:12:00 +02:00
|
|
|
explicit TextureCacheOpenGL(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
|
2019-12-29 01:45:56 +01:00
|
|
|
const Device& device, StateTracker& state_tracker);
|
2019-04-11 22:14:55 +02:00
|
|
|
~TextureCacheOpenGL();
|
|
|
|
|
|
|
|
protected:
|
2019-05-07 16:57:16 +02:00
|
|
|
Surface CreateSurface(GPUVAddr gpu_addr, const SurfaceParams& params) override;
|
2019-05-08 05:13:05 +02:00
|
|
|
|
2019-06-02 04:15:55 +02:00
|
|
|
void ImageCopy(Surface& src_surface, Surface& dst_surface,
|
2019-05-07 16:57:16 +02:00
|
|
|
const VideoCommon::CopyParams& copy_params) override;
|
2019-05-08 05:13:05 +02:00
|
|
|
|
2019-06-02 04:15:55 +02:00
|
|
|
void ImageBlit(View& src_view, View& dst_view,
|
2019-05-18 10:57:49 +02:00
|
|
|
const Tegra::Engines::Fermi2D::Config& copy_config) override;
|
2019-05-08 05:13:05 +02:00
|
|
|
|
2019-06-02 04:15:55 +02:00
|
|
|
void BufferCopy(Surface& src_surface, Surface& dst_surface) override;
|
2019-06-02 01:12:00 +02:00
|
|
|
|
2019-05-08 05:13:05 +02:00
|
|
|
private:
|
2019-06-02 01:12:00 +02:00
|
|
|
GLuint FetchPBO(std::size_t buffer_size);
|
|
|
|
|
2019-12-29 01:45:56 +01:00
|
|
|
StateTracker& state_tracker;
|
|
|
|
|
2019-05-08 05:13:05 +02:00
|
|
|
OGLFramebuffer src_framebuffer;
|
|
|
|
OGLFramebuffer dst_framebuffer;
|
2019-06-02 01:12:00 +02:00
|
|
|
std::unordered_map<u32, OGLBuffer> copy_pbo_cache;
|
2019-04-11 22:14:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace OpenGL
|