yuzu/src/video_core/renderer_opengl/gl_rasterizer.h

272 lines
9.9 KiB
C
Raw Normal View History

2022-11-05 16:58:44 +04:00
// SPDX-FileCopyrightText: 2015 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <array>
#include <cstddef>
#include <optional>
#include <boost/container/static_vector.hpp>
#include <glad/glad.h>
#include "common/common_types.h"
#include "video_core/control/channel_state_cache.h"
#include "video_core/engines/maxwell_dma.h"
#include "video_core/rasterizer_interface.h"
2023-01-07 02:12:33 +04:00
#include "video_core/renderer_opengl/blit_image.h"
2024-02-01 22:47:57 +04:00
#include "video_core/renderer_opengl/gl_blit_screen.h"
2022-11-05 16:58:44 +04:00
#include "video_core/renderer_opengl/gl_buffer_cache.h"
#include "video_core/renderer_opengl/gl_device.h"
#include "video_core/renderer_opengl/gl_fence_manager.h"
#include "video_core/renderer_opengl/gl_query_cache.h"
#include "video_core/renderer_opengl/gl_shader_cache.h"
#include "video_core/renderer_opengl/gl_texture_cache.h"
namespace Core::Memory {
class Memory;
}
namespace Core::Frontend {
class EmuWindow;
}
namespace Tegra {
class MemoryManager;
}
namespace OpenGL {
2024-02-01 22:47:57 +04:00
struct FramebufferTextureInfo;
2022-11-05 16:58:44 +04:00
struct ShaderEntries;
struct BindlessSSBO {
GLuint64EXT address;
GLsizei length;
GLsizei padding;
};
static_assert(sizeof(BindlessSSBO) * CHAR_BIT == 128);
class AccelerateDMA : public Tegra::Engines::AccelerateDMAInterface {
public:
2023-03-07 21:49:48 +04:00
explicit AccelerateDMA(BufferCache& buffer_cache, TextureCache& texture_cache);
2022-11-05 16:58:44 +04:00
bool BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) override;
bool BufferClear(GPUVAddr src_address, u64 amount, u32 value) override;
2023-02-12 16:02:04 +04:00
bool ImageToBuffer(const Tegra::DMA::ImageCopy& copy_info, const Tegra::DMA::ImageOperand& src,
2023-03-07 21:49:48 +04:00
const Tegra::DMA::BufferOperand& dst) override;
2023-02-12 16:02:04 +04:00
bool BufferToImage(const Tegra::DMA::ImageCopy& copy_info, const Tegra::DMA::BufferOperand& src,
2023-03-07 21:49:48 +04:00
const Tegra::DMA::ImageOperand& dst) override;
2023-02-12 16:02:04 +04:00
2022-11-05 16:58:44 +04:00
private:
2023-03-07 21:49:48 +04:00
template <bool IS_IMAGE_UPLOAD>
bool DmaBufferImageCopy(const Tegra::DMA::ImageCopy& copy_info,
const Tegra::DMA::BufferOperand& src,
const Tegra::DMA::ImageOperand& dst);
2022-11-05 16:58:44 +04:00
BufferCache& buffer_cache;
2023-03-07 21:49:48 +04:00
TextureCache& texture_cache;
2022-11-05 16:58:44 +04:00
};
2024-01-07 13:47:31 +04:00
class RasterizerOpenGL : public VideoCore::RasterizerInterface,
2022-11-05 16:58:44 +04:00
protected VideoCommon::ChannelSetupCaches<VideoCommon::ChannelInfo> {
public:
explicit RasterizerOpenGL(Core::Frontend::EmuWindow& emu_window_, Tegra::GPU& gpu_,
2024-01-07 13:47:31 +04:00
Tegra::MaxwellDeviceMemoryManager& device_memory_,
2024-02-01 22:47:57 +04:00
const Device& device_, ProgramManager& program_manager_,
StateTracker& state_tracker_);
2022-11-05 16:58:44 +04:00
~RasterizerOpenGL() override;
void Draw(bool is_indexed, u32 instance_count) override;
2022-12-25 10:12:57 +04:00
void DrawIndirect() override;
2023-01-07 02:12:33 +04:00
void DrawTexture() override;
2022-11-17 21:04:39 +04:00
void Clear(u32 layer_count) override;
2022-11-05 16:58:44 +04:00
void DispatchCompute() override;
2023-08-24 20:22:48 +04:00
void ResetCounter(VideoCommon::QueryType type) override;
void Query(GPUVAddr gpu_addr, VideoCommon::QueryType type,
VideoCommon::QueryPropertiesFlags flags, u32 payload, u32 subreport) override;
2022-11-05 16:58:44 +04:00
void BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr, u32 size) override;
void DisableGraphicsUniformBuffer(size_t stage, u32 index) override;
void FlushAll() override;
2024-01-07 13:47:31 +04:00
void FlushRegion(DAddr addr, u64 size,
2022-12-25 10:12:57 +04:00
VideoCommon::CacheType which = VideoCommon::CacheType::All) override;
2024-01-07 13:47:31 +04:00
bool MustFlushRegion(DAddr addr, u64 size,
2022-12-25 10:12:57 +04:00
VideoCommon::CacheType which = VideoCommon::CacheType::All) override;
2024-01-07 13:47:31 +04:00
VideoCore::RasterizerDownloadArea GetFlushArea(PAddr addr, u64 size) override;
void InvalidateRegion(DAddr addr, u64 size,
2022-12-25 10:12:57 +04:00
VideoCommon::CacheType which = VideoCommon::CacheType::All) override;
2024-01-07 13:47:31 +04:00
void OnCacheInvalidation(PAddr addr, u64 size) override;
bool OnCPUWrite(PAddr addr, u64 size) override;
2022-11-05 16:58:44 +04:00
void InvalidateGPUCache() override;
2024-01-07 13:47:31 +04:00
void UnmapMemory(DAddr addr, u64 size) override;
2022-11-05 16:58:44 +04:00
void ModifyGPUMemory(size_t as_id, GPUVAddr addr, u64 size) override;
void SignalFence(std::function<void()>&& func) override;
void SyncOperation(std::function<void()>&& func) override;
void SignalSyncPoint(u32 value) override;
void SignalReference() override;
2023-08-24 20:22:48 +04:00
void ReleaseFences(bool force = true) override;
2022-12-25 10:12:57 +04:00
void FlushAndInvalidateRegion(
2024-01-07 13:47:31 +04:00
DAddr addr, u64 size, VideoCommon::CacheType which = VideoCommon::CacheType::All) override;
2022-11-05 16:58:44 +04:00
void WaitForIdle() override;
void FragmentBarrier() override;
void TiledCacheBarrier() override;
void FlushCommands() override;
void TickFrame() override;
2022-12-25 10:12:57 +04:00
bool AccelerateConditionalRendering() override;
2022-11-05 16:58:44 +04:00
bool AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Surface& src,
const Tegra::Engines::Fermi2D::Surface& dst,
const Tegra::Engines::Fermi2D::Config& copy_config) override;
Tegra::Engines::AccelerateDMAInterface& AccessAccelerateDMA() override;
void AccelerateInlineToMemory(GPUVAddr address, size_t copy_size,
std::span<const u8> memory) override;
void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
const VideoCore::DiskResourceLoadCallback& callback) override;
/// Returns true when there are commands queued to the OpenGL server.
bool AnyCommandQueued() const {
return num_queued_commands > 0;
}
void InitializeChannel(Tegra::Control::ChannelState& channel) override;
void BindChannel(Tegra::Control::ChannelState& channel) override;
void ReleaseChannel(s32 channel_id) override;
2023-12-22 22:51:46 +04:00
void RegisterTransformFeedback(GPUVAddr tfb_object_addr) override;
bool HasDrawTransformFeedback() override {
return true;
}
2024-02-01 22:47:57 +04:00
std::optional<FramebufferTextureInfo> AccelerateDisplay(const Tegra::FramebufferConfig& config,
VAddr framebuffer_addr,
u32 pixel_stride);
2022-11-05 16:58:44 +04:00
private:
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;
2022-12-25 10:12:57 +04:00
template <typename Func>
void PrepareDraw(bool is_indexed, Func&&);
2022-11-05 16:58:44 +04:00
/// Syncs state to match guest's
void SyncState();
/// Syncs the viewport and depth range to match the guest state
void SyncViewport();
/// Syncs the depth clamp state
void SyncDepthClamp();
/// Syncs the clip enabled status to match the guest state
void SyncClipEnabled(u32 clip_mask);
/// Syncs the clip coefficients to match the guest state
void SyncClipCoef();
/// Syncs the cull mode to match the guest state
void SyncCullMode();
2023-03-13 07:44:48 +04:00
/// Syncs the primitive restart to match the guest state
2022-11-05 16:58:44 +04:00
void SyncPrimitiveRestart();
/// Syncs the depth test state to match the guest state
void SyncDepthTestState();
/// Syncs the stencil test state to match the guest state
void SyncStencilTestState();
/// Syncs the blend state to match the guest state
void SyncBlendState();
/// Syncs the LogicOp state to match the guest state
void SyncLogicOpState();
/// Syncs the the color clamp state
void SyncFragmentColorClampState();
/// Syncs the alpha coverage and alpha to one
void SyncMultiSampleState();
/// Syncs the scissor test state to match the guest state
void SyncScissorTest();
/// Syncs the point state to match the guest state
void SyncPointState();
/// Syncs the line state to match the guest state
void SyncLineState();
/// Syncs the rasterizer enable state to match the guest state
void SyncRasterizeEnable();
/// Syncs polygon modes to match the guest state
void SyncPolygonModes();
/// Syncs Color Mask
void SyncColorMask();
/// Syncs the polygon offsets
void SyncPolygonOffset();
/// Syncs the alpha test state to match the guest state
void SyncAlphaTest();
/// Syncs the framebuffer sRGB state to match the guest state
void SyncFramebufferSRGB();
/// Syncs vertex formats to match the guest state
void SyncVertexFormats();
/// Syncs vertex instances to match the guest state
void SyncVertexInstances();
/// Begin a transform feedback
void BeginTransformFeedback(GraphicsPipeline* pipeline, GLenum primitive_mode);
/// End a transform feedback
void EndTransformFeedback();
2023-12-20 05:37:09 +04:00
void QueryFallback(GPUVAddr gpu_addr, VideoCommon::QueryType type,
VideoCommon::QueryPropertiesFlags flags, u32 payload, u32 subreport);
2022-11-05 16:58:44 +04:00
Tegra::GPU& gpu;
2024-01-07 13:47:31 +04:00
Tegra::MaxwellDeviceMemoryManager& device_memory;
2022-11-05 16:58:44 +04:00
const Device& device;
ProgramManager& program_manager;
StateTracker& state_tracker;
2023-05-29 02:16:57 +04:00
StagingBufferPool staging_buffer_pool;
2022-11-05 16:58:44 +04:00
TextureCacheRuntime texture_cache_runtime;
TextureCache texture_cache;
BufferCacheRuntime buffer_cache_runtime;
BufferCache buffer_cache;
ShaderCache shader_cache;
QueryCache query_cache;
AccelerateDMA accelerate_dma;
FenceManagerOpenGL fence_manager;
2023-01-07 02:12:33 +04:00
BlitImageHelper blit_image;
2022-11-05 16:58:44 +04: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;
std::array<GLuint, MAX_TEXTURES> texture_handles{};
std::array<GLuint, MAX_IMAGES> image_handles{};
2023-03-13 07:44:48 +04:00
/// Number of commands queued to the OpenGL driver. Reset on flush.
2022-11-05 16:58:44 +04:00
size_t num_queued_commands = 0;
bool has_written_global_memory = false;
u32 last_clip_distance_mask = 0;
};
} // namespace OpenGL