2021-05-23 09:28:34 +02:00
|
|
|
// Copyright 2021 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "common/bit_field.h"
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "shader_recompiler/shader_info.h"
|
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
|
|
|
#include "video_core/memory_manager.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_buffer_cache.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_texture_cache.h"
|
2021-05-21 23:17:53 +02:00
|
|
|
#include "video_core/transform_feedback.h"
|
2021-05-23 09:28:34 +02:00
|
|
|
|
|
|
|
namespace OpenGL {
|
|
|
|
|
2021-06-15 03:06:29 +02:00
|
|
|
namespace ShaderContext {
|
|
|
|
struct Context;
|
|
|
|
}
|
|
|
|
|
2021-05-26 23:32:59 +02:00
|
|
|
class Device;
|
2021-05-23 09:28:34 +02:00
|
|
|
class ProgramManager;
|
|
|
|
|
|
|
|
using Maxwell = Tegra::Engines::Maxwell3D::Regs;
|
2021-06-15 03:06:29 +02:00
|
|
|
using ShaderWorker = Common::StatefulThreadWorker<ShaderContext::Context>;
|
2021-05-23 09:28:34 +02:00
|
|
|
|
2021-05-25 23:58:28 +02:00
|
|
|
struct GraphicsPipelineKey {
|
2021-05-23 09:28:34 +02:00
|
|
|
std::array<u64, 6> unique_hashes;
|
|
|
|
union {
|
|
|
|
u32 raw;
|
|
|
|
BitField<0, 1, u32> xfb_enabled;
|
|
|
|
BitField<1, 1, u32> early_z;
|
|
|
|
BitField<2, 4, Maxwell::PrimitiveTopology> gs_input_topology;
|
|
|
|
BitField<6, 2, Maxwell::TessellationPrimitive> tessellation_primitive;
|
|
|
|
BitField<8, 2, Maxwell::TessellationSpacing> tessellation_spacing;
|
|
|
|
BitField<10, 1, u32> tessellation_clockwise;
|
|
|
|
};
|
|
|
|
std::array<u32, 3> padding;
|
2021-05-21 23:17:53 +02:00
|
|
|
VideoCommon::TransformFeedbackState xfb_state;
|
2021-05-23 09:28:34 +02:00
|
|
|
|
|
|
|
size_t Hash() const noexcept;
|
|
|
|
|
2021-05-25 23:58:28 +02:00
|
|
|
bool operator==(const GraphicsPipelineKey&) const noexcept;
|
2021-05-23 09:28:34 +02:00
|
|
|
|
2021-05-25 23:58:28 +02:00
|
|
|
bool operator!=(const GraphicsPipelineKey& rhs) const noexcept {
|
2021-05-23 09:28:34 +02:00
|
|
|
return !operator==(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] size_t Size() const noexcept {
|
|
|
|
if (xfb_enabled != 0) {
|
2021-05-25 23:58:28 +02:00
|
|
|
return sizeof(GraphicsPipelineKey);
|
2021-05-23 09:28:34 +02:00
|
|
|
} else {
|
2021-05-25 23:58:28 +02:00
|
|
|
return offsetof(GraphicsPipelineKey, padding);
|
2021-05-23 09:28:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2021-05-25 23:58:28 +02:00
|
|
|
static_assert(std::has_unique_object_representations_v<GraphicsPipelineKey>);
|
|
|
|
static_assert(std::is_trivially_copyable_v<GraphicsPipelineKey>);
|
|
|
|
static_assert(std::is_trivially_constructible_v<GraphicsPipelineKey>);
|
2021-05-23 09:28:34 +02:00
|
|
|
|
2021-05-25 23:58:28 +02:00
|
|
|
class GraphicsPipeline {
|
2021-05-23 09:28:34 +02:00
|
|
|
public:
|
2021-05-26 23:32:59 +02:00
|
|
|
explicit GraphicsPipeline(const Device& device, TextureCache& texture_cache_,
|
|
|
|
BufferCache& buffer_cache_, Tegra::MemoryManager& gpu_memory_,
|
2021-05-25 23:58:28 +02:00
|
|
|
Tegra::Engines::Maxwell3D& maxwell3d_,
|
|
|
|
ProgramManager& program_manager_, StateTracker& state_tracker_,
|
2021-06-15 03:06:29 +02:00
|
|
|
ShaderWorker* thread_worker, VideoCore::ShaderNotify* shader_notify,
|
|
|
|
std::array<std::string, 5> sources,
|
2021-05-25 23:58:28 +02:00
|
|
|
const std::array<const Shader::Info*, 5>& infos,
|
|
|
|
const VideoCommon::TransformFeedbackState* xfb_state);
|
2021-05-23 09:28:34 +02:00
|
|
|
|
|
|
|
void Configure(bool is_indexed);
|
|
|
|
|
2021-05-21 23:17:53 +02:00
|
|
|
void ConfigureTransformFeedback() const {
|
|
|
|
if (num_xfb_attribs != 0) {
|
|
|
|
ConfigureTransformFeedbackImpl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-26 23:32:59 +02:00
|
|
|
[[nodiscard]] bool WritesGlobalMemory() const noexcept {
|
|
|
|
return writes_global_memory;
|
|
|
|
}
|
|
|
|
|
2021-06-15 03:06:29 +02:00
|
|
|
[[nodiscard]] bool IsBuilt() const noexcept {
|
|
|
|
return is_built.load(std::memory_order::relaxed);
|
|
|
|
}
|
|
|
|
|
2021-05-23 09:28:34 +02:00
|
|
|
private:
|
2021-05-21 23:17:53 +02:00
|
|
|
void GenerateTransformFeedbackState(const VideoCommon::TransformFeedbackState& xfb_state);
|
|
|
|
|
|
|
|
void ConfigureTransformFeedbackImpl() const;
|
|
|
|
|
2021-05-23 09:28:34 +02:00
|
|
|
TextureCache& texture_cache;
|
|
|
|
BufferCache& buffer_cache;
|
|
|
|
Tegra::MemoryManager& gpu_memory;
|
|
|
|
Tegra::Engines::Maxwell3D& maxwell3d;
|
|
|
|
ProgramManager& program_manager;
|
|
|
|
StateTracker& state_tracker;
|
|
|
|
|
|
|
|
OGLProgram program;
|
2021-05-15 23:19:08 +02:00
|
|
|
std::array<OGLAssemblyProgram, 5> assembly_programs;
|
2021-05-20 21:53:51 +02:00
|
|
|
u32 enabled_stages_mask{};
|
2021-05-15 23:19:08 +02:00
|
|
|
|
2021-05-23 09:28:34 +02:00
|
|
|
std::array<Shader::Info, 5> stage_infos{};
|
2021-06-02 07:15:07 +02:00
|
|
|
std::array<u32, 5> enabled_uniform_buffer_masks{};
|
|
|
|
VideoCommon::UniformBufferSizes uniform_buffer_sizes{};
|
2021-05-23 09:28:34 +02:00
|
|
|
std::array<u32, 5> base_uniform_bindings{};
|
|
|
|
std::array<u32, 5> base_storage_bindings{};
|
|
|
|
std::array<u32, 5> num_texture_buffers{};
|
|
|
|
std::array<u32, 5> num_image_buffers{};
|
2021-05-21 23:17:53 +02:00
|
|
|
|
2021-05-26 23:32:59 +02:00
|
|
|
bool use_storage_buffers{};
|
|
|
|
bool writes_global_memory{};
|
2021-06-15 03:06:29 +02:00
|
|
|
std::atomic_bool is_built{false};
|
2021-05-26 23:32:59 +02:00
|
|
|
|
2021-05-21 23:17:53 +02:00
|
|
|
static constexpr std::size_t XFB_ENTRY_STRIDE = 3;
|
|
|
|
GLsizei num_xfb_attribs{};
|
|
|
|
GLsizei num_xfb_strides{};
|
|
|
|
std::array<GLint, 128 * XFB_ENTRY_STRIDE * Maxwell::NumTransformFeedbackBuffers> xfb_attribs{};
|
|
|
|
std::array<GLint, Maxwell::NumTransformFeedbackBuffers> xfb_streams{};
|
2021-05-23 09:28:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace OpenGL
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
template <>
|
2021-05-25 23:58:28 +02:00
|
|
|
struct hash<OpenGL::GraphicsPipelineKey> {
|
|
|
|
size_t operator()(const OpenGL::GraphicsPipelineKey& k) const noexcept {
|
2021-05-23 09:28:34 +02:00
|
|
|
return k.Hash();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace std
|