2018-03-20 04:00:59 +01:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
2019-01-21 20:38:23 +01:00
|
|
|
#include <atomic>
|
2018-03-20 04:00:59 +01:00
|
|
|
#include <cstddef>
|
|
|
|
#include <memory>
|
2018-10-30 05:03:25 +01:00
|
|
|
#include <optional>
|
2018-08-10 10:29:37 +02:00
|
|
|
#include <tuple>
|
2018-07-03 23:55:44 +02:00
|
|
|
#include <utility>
|
2018-08-29 00:43:08 +02:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
#include <boost/container/static_vector.hpp>
|
|
|
|
|
2018-03-20 04:00:59 +01:00
|
|
|
#include <glad/glad.h>
|
2018-08-29 00:43:08 +02:00
|
|
|
|
2018-03-20 04:00:59 +01:00
|
|
|
#include "common/common_types.h"
|
2019-05-31 22:33:21 +02:00
|
|
|
#include "video_core/engines/const_buffer_info.h"
|
2018-04-08 06:00:11 +02:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2021-07-10 18:19:10 +02:00
|
|
|
#include "video_core/engines/maxwell_dma.h"
|
2019-10-27 07:40:08 +01:00
|
|
|
#include "video_core/rasterizer_accelerated.h"
|
2018-03-20 04:00:59 +01:00
|
|
|
#include "video_core/rasterizer_interface.h"
|
2018-08-29 00:27:03 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_buffer_cache.h"
|
2019-04-10 20:56:12 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_device.h"
|
2020-02-18 01:19:26 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_fence_manager.h"
|
2019-07-28 00:40:10 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_query_cache.h"
|
2018-03-20 04:00:59 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
2018-08-23 23:30:27 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_cache.h"
|
2018-04-07 11:22:08 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
2019-12-29 01:45:56 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_state_tracker.h"
|
2019-04-11 22:14:55 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_texture_cache.h"
|
2019-07-12 01:09:53 +02:00
|
|
|
#include "video_core/textures/texture.h"
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2020-06-12 02:24:45 +02:00
|
|
|
namespace Core::Memory {
|
|
|
|
class Memory;
|
2019-01-15 20:28:42 +01:00
|
|
|
}
|
|
|
|
|
2018-08-12 02:20:19 +02:00
|
|
|
namespace Core::Frontend {
|
|
|
|
class EmuWindow;
|
|
|
|
}
|
|
|
|
|
2019-05-07 16:55:18 +02:00
|
|
|
namespace Tegra {
|
|
|
|
class MemoryManager;
|
|
|
|
}
|
|
|
|
|
2018-08-21 10:18:27 +02:00
|
|
|
namespace OpenGL {
|
|
|
|
|
|
|
|
struct ScreenInfo;
|
2020-12-30 06:25:23 +01:00
|
|
|
struct ShaderEntries;
|
2018-08-21 10:18:27 +02:00
|
|
|
|
2020-10-20 08:15:50 +02:00
|
|
|
struct BindlessSSBO {
|
|
|
|
GLuint64EXT address;
|
|
|
|
GLsizei length;
|
|
|
|
GLsizei padding;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(BindlessSSBO) * CHAR_BIT == 128);
|
|
|
|
|
2021-07-10 18:19:10 +02:00
|
|
|
class AccelerateDMA : public Tegra::Engines::AccelerateDMAInterface {
|
|
|
|
public:
|
|
|
|
explicit AccelerateDMA(BufferCache& buffer_cache);
|
|
|
|
|
|
|
|
bool BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) override;
|
|
|
|
|
2021-07-13 03:33:08 +02:00
|
|
|
bool BufferClear(GPUVAddr src_address, u64 amount, u32 value) override;
|
|
|
|
|
2021-07-10 18:19:10 +02:00
|
|
|
private:
|
|
|
|
BufferCache& buffer_cache;
|
|
|
|
};
|
|
|
|
|
2019-10-27 07:40:08 +01:00
|
|
|
class RasterizerOpenGL : public VideoCore::RasterizerAccelerated {
|
2018-03-20 04:00:59 +01:00
|
|
|
public:
|
2020-12-05 17:40:14 +01:00
|
|
|
explicit RasterizerOpenGL(Core::Frontend::EmuWindow& emu_window_, Tegra::GPU& gpu_,
|
|
|
|
Core::Memory::Memory& cpu_memory_, const Device& device_,
|
|
|
|
ScreenInfo& screen_info_, ProgramManager& program_manager_,
|
|
|
|
StateTracker& state_tracker_);
|
2018-03-20 04:00:59 +01:00
|
|
|
~RasterizerOpenGL() override;
|
|
|
|
|
2020-02-14 22:09:37 +01:00
|
|
|
void Draw(bool is_indexed, bool is_instanced) override;
|
2018-06-07 06:54:25 +02:00
|
|
|
void Clear() override;
|
2021-02-17 00:52:12 +01:00
|
|
|
void DispatchCompute() override;
|
2019-07-28 00:40:10 +02:00
|
|
|
void ResetCounter(VideoCore::QueryType type) override;
|
2019-11-28 06:15:34 +01:00
|
|
|
void Query(GPUVAddr gpu_addr, VideoCore::QueryType type, std::optional<u64> timestamp) override;
|
2021-01-17 00:48:58 +01:00
|
|
|
void BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr, u32 size) override;
|
2021-06-01 19:26:43 +02:00
|
|
|
void DisableGraphicsUniformBuffer(size_t stage, u32 index) override;
|
2018-03-20 04:00:59 +01:00
|
|
|
void FlushAll() override;
|
2020-04-05 18:58:23 +02:00
|
|
|
void FlushRegion(VAddr addr, u64 size) override;
|
2020-02-18 03:29:04 +01:00
|
|
|
bool MustFlushRegion(VAddr addr, u64 size) override;
|
2020-04-05 18:58:23 +02:00
|
|
|
void InvalidateRegion(VAddr addr, u64 size) override;
|
2020-02-16 14:51:37 +01:00
|
|
|
void OnCPUWrite(VAddr addr, u64 size) override;
|
|
|
|
void SyncGuestHost() override;
|
2020-12-30 06:25:23 +01:00
|
|
|
void UnmapMemory(VAddr addr, u64 size) override;
|
2021-06-12 15:52:27 +02:00
|
|
|
void ModifyGPUMemory(GPUVAddr addr, u64 size) override;
|
2020-02-19 18:40:37 +01:00
|
|
|
void SignalSemaphore(GPUVAddr addr, u32 value) override;
|
|
|
|
void SignalSyncPoint(u32 value) override;
|
2021-07-06 22:23:10 +02:00
|
|
|
void SignalReference() override;
|
2020-02-17 23:10:23 +01:00
|
|
|
void ReleaseFences() override;
|
2020-04-05 18:58:23 +02:00
|
|
|
void FlushAndInvalidateRegion(VAddr addr, u64 size) override;
|
2020-04-28 07:14:11 +02:00
|
|
|
void WaitForIdle() override;
|
2020-12-30 06:25:23 +01:00
|
|
|
void FragmentBarrier() override;
|
|
|
|
void TiledCacheBarrier() override;
|
2019-07-26 20:20:43 +02:00
|
|
|
void FlushCommands() override;
|
2019-06-20 08:22:25 +02:00
|
|
|
void TickFrame() override;
|
2020-12-30 06:25:23 +01:00
|
|
|
bool AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Surface& src,
|
|
|
|
const Tegra::Engines::Fermi2D::Surface& dst,
|
2019-05-18 10:57:49 +02:00
|
|
|
const Tegra::Engines::Fermi2D::Config& copy_config) override;
|
2021-07-10 18:19:10 +02:00
|
|
|
Tegra::Engines::AccelerateDMAInterface& AccessAccelerateDMA() override;
|
2018-08-21 01:34:02 +02:00
|
|
|
bool AccelerateDisplay(const Tegra::FramebufferConfig& config, VAddr framebuffer_addr,
|
|
|
|
u32 pixel_stride) override;
|
2021-06-22 05:04:55 +02:00
|
|
|
void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
2019-01-21 20:38:23 +01:00
|
|
|
const VideoCore::DiskResourceLoadCallback& callback) override;
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2019-11-26 22:52:15 +01:00
|
|
|
/// Returns true when there are commands queued to the OpenGL server.
|
|
|
|
bool AnyCommandQueued() const {
|
|
|
|
return num_queued_commands > 0;
|
|
|
|
}
|
|
|
|
|
2018-03-20 04:00:59 +01:00
|
|
|
private:
|
2020-12-30 06:25:23 +01:00
|
|
|
static constexpr size_t MAX_TEXTURES = 192;
|
|
|
|
static constexpr size_t MAX_IMAGES = 48;
|
|
|
|
static constexpr size_t MAX_IMAGE_VIEWS = MAX_TEXTURES + MAX_IMAGES;
|
|
|
|
|
2021-01-17 00:48:58 +01:00
|
|
|
/// Syncs state to match guest's
|
|
|
|
void SyncState();
|
|
|
|
|
2018-11-02 04:21:25 +01:00
|
|
|
/// Syncs the viewport and depth range to match the guest state
|
2019-12-26 05:50:38 +01:00
|
|
|
void SyncViewport();
|
2018-03-27 02:45:10 +02:00
|
|
|
|
2019-12-26 01:57:10 +01:00
|
|
|
/// Syncs the depth clamp state
|
|
|
|
void SyncDepthClamp();
|
|
|
|
|
2018-03-20 04:00:59 +01:00
|
|
|
/// Syncs the clip enabled status to match the guest state
|
2019-12-29 06:03:05 +01:00
|
|
|
void SyncClipEnabled(u32 clip_mask);
|
2018-03-20 04:00:59 +01:00
|
|
|
|
|
|
|
/// Syncs the clip coefficients to match the guest state
|
|
|
|
void SyncClipCoef();
|
|
|
|
|
|
|
|
/// Syncs the cull mode to match the guest state
|
|
|
|
void SyncCullMode();
|
|
|
|
|
2018-10-26 01:04:13 +02:00
|
|
|
/// Syncs the primitve restart to match the guest state
|
|
|
|
void SyncPrimitiveRestart();
|
|
|
|
|
2018-07-02 20:33:06 +02:00
|
|
|
/// Syncs the depth test state to match the guest state
|
|
|
|
void SyncDepthTestState();
|
|
|
|
|
2018-08-22 06:35:31 +02:00
|
|
|
/// Syncs the stencil test state to match the guest state
|
|
|
|
void SyncStencilTestState();
|
|
|
|
|
2018-06-09 00:05:52 +02:00
|
|
|
/// Syncs the blend state to match the guest state
|
|
|
|
void SyncBlendState();
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2018-08-21 01:44:47 +02:00
|
|
|
/// Syncs the LogicOp state to match the guest state
|
|
|
|
void SyncLogicOpState();
|
|
|
|
|
2018-11-14 02:09:01 +01:00
|
|
|
/// Syncs the the color clamp state
|
|
|
|
void SyncFragmentColorClampState();
|
|
|
|
|
2018-11-14 04:02:54 +01:00
|
|
|
/// Syncs the alpha coverage and alpha to one
|
|
|
|
void SyncMultiSampleState();
|
|
|
|
|
2018-10-09 02:49:36 +02:00
|
|
|
/// Syncs the scissor test state to match the guest state
|
2019-12-26 05:28:17 +01:00
|
|
|
void SyncScissorTest();
|
2018-10-09 02:49:36 +02:00
|
|
|
|
2018-09-28 06:31:01 +02:00
|
|
|
/// Syncs the point state to match the guest state
|
|
|
|
void SyncPointState();
|
|
|
|
|
2020-02-25 01:02:32 +01:00
|
|
|
/// Syncs the line state to match the guest state
|
|
|
|
void SyncLineState();
|
|
|
|
|
2019-12-18 23:26:52 +01:00
|
|
|
/// Syncs the rasterizer enable state to match the guest state
|
2019-12-26 06:11:01 +01:00
|
|
|
void SyncRasterizeEnable();
|
2019-12-18 23:26:52 +01:00
|
|
|
|
2020-02-24 23:43:57 +01:00
|
|
|
/// Syncs polygon modes to match the guest state
|
|
|
|
void SyncPolygonModes();
|
|
|
|
|
2018-11-05 03:46:06 +01:00
|
|
|
/// Syncs Color Mask
|
|
|
|
void SyncColorMask();
|
|
|
|
|
2018-11-27 00:31:44 +01:00
|
|
|
/// Syncs the polygon offsets
|
|
|
|
void SyncPolygonOffset();
|
|
|
|
|
2019-05-22 01:28:09 +02:00
|
|
|
/// Syncs the alpha test state to match the guest state
|
|
|
|
void SyncAlphaTest();
|
2018-10-12 02:29:11 +02:00
|
|
|
|
2019-12-26 05:01:41 +01:00
|
|
|
/// Syncs the framebuffer sRGB state to match the guest state
|
|
|
|
void SyncFramebufferSRGB();
|
|
|
|
|
2021-01-17 00:48:58 +01:00
|
|
|
/// Syncs vertex formats to match the guest state
|
|
|
|
void SyncVertexFormats();
|
|
|
|
|
|
|
|
/// Syncs vertex instances to match the guest state
|
|
|
|
void SyncVertexInstances();
|
|
|
|
|
2020-06-03 07:48:41 +02:00
|
|
|
/// Syncs transform feedback state to match guest state
|
|
|
|
/// @note Only valid on assembly shaders
|
|
|
|
void SyncTransformFeedback();
|
|
|
|
|
2020-03-02 23:31:26 +01:00
|
|
|
/// Begin a transform feedback
|
|
|
|
void BeginTransformFeedback(GLenum primitive_mode);
|
|
|
|
|
|
|
|
/// End a transform feedback
|
|
|
|
void EndTransformFeedback();
|
|
|
|
|
2020-06-12 02:24:45 +02:00
|
|
|
Tegra::GPU& gpu;
|
|
|
|
Tegra::Engines::Maxwell3D& maxwell3d;
|
|
|
|
Tegra::Engines::KeplerCompute& kepler_compute;
|
|
|
|
Tegra::MemoryManager& gpu_memory;
|
|
|
|
|
2020-05-18 03:32:49 +02:00
|
|
|
const Device& device;
|
2020-06-12 02:24:45 +02:00
|
|
|
ScreenInfo& screen_info;
|
|
|
|
ProgramManager& program_manager;
|
|
|
|
StateTracker& state_tracker;
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
TextureCacheRuntime texture_cache_runtime;
|
|
|
|
TextureCache texture_cache;
|
2021-01-17 00:48:58 +01:00
|
|
|
BufferCacheRuntime buffer_cache_runtime;
|
|
|
|
BufferCache buffer_cache;
|
2018-08-23 23:30:27 +02:00
|
|
|
ShaderCacheOpenGL shader_cache;
|
2019-11-26 22:52:15 +01:00
|
|
|
QueryCache query_cache;
|
2021-07-10 18:19:10 +02:00
|
|
|
AccelerateDMA accelerate_dma;
|
2020-02-18 01:19:26 +01:00
|
|
|
FenceManagerOpenGL fence_manager;
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
boost::container::static_vector<u32, MAX_IMAGE_VIEWS> image_view_indices;
|
|
|
|
std::array<ImageViewId, MAX_IMAGE_VIEWS> image_view_ids;
|
|
|
|
boost::container::static_vector<GLuint, MAX_TEXTURES> sampler_handles;
|
2021-01-17 00:48:58 +01:00
|
|
|
std::array<GLuint, MAX_TEXTURES> texture_handles{};
|
|
|
|
std::array<GLuint, MAX_IMAGES> image_handles{};
|
2020-05-18 03:32:49 +02:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
/// Number of commands queued to the OpenGL driver. Resetted on flush.
|
2019-11-26 22:30:21 +01:00
|
|
|
std::size_t num_queued_commands = 0;
|
2019-12-29 06:03:05 +01:00
|
|
|
|
|
|
|
u32 last_clip_distance_mask = 0;
|
2018-03-20 04:00:59 +01:00
|
|
|
};
|
2018-08-21 10:18:27 +02:00
|
|
|
|
|
|
|
} // namespace OpenGL
|