2015-05-24 06:32:32 +02:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2014-02-10 19:54:46 +01:00
|
|
|
#pragma once
|
2010-10-03 10:20:24 +02:00
|
|
|
|
2015-12-21 03:49:49 +01:00
|
|
|
#include <memory>
|
2013-02-27 05:47:50 +01:00
|
|
|
#include <vector>
|
2015-12-21 03:49:49 +01:00
|
|
|
|
2014-09-08 03:06:58 +02:00
|
|
|
#include "Common/CommonTypes.h"
|
2018-05-11 01:06:19 +02:00
|
|
|
#include "Common/MathUtil.h"
|
2017-04-30 10:07:57 +02:00
|
|
|
#include "VideoCommon/RenderState.h"
|
2018-02-24 16:15:35 +01:00
|
|
|
#include "VideoCommon/ShaderCache.h"
|
2013-02-27 05:47:50 +01:00
|
|
|
|
2016-01-31 20:51:55 +01:00
|
|
|
class DataReader;
|
2010-11-26 10:25:08 +01:00
|
|
|
class NativeVertexFormat;
|
2012-01-04 09:42:22 +01:00
|
|
|
class PointerWrap;
|
2016-01-17 22:54:31 +01:00
|
|
|
struct PortableVertexDeclaration;
|
2010-11-26 10:25:08 +01:00
|
|
|
|
2015-01-13 10:55:25 +01:00
|
|
|
struct Slope
|
|
|
|
{
|
|
|
|
float dfdx;
|
|
|
|
float dfdy;
|
|
|
|
float f0;
|
2015-01-23 15:15:09 +01:00
|
|
|
bool dirty;
|
2015-01-13 10:55:25 +01:00
|
|
|
};
|
|
|
|
|
2019-02-15 02:59:50 +01:00
|
|
|
// View format of the input data to the texture decoding shader.
|
|
|
|
enum TexelBufferFormat : u32
|
|
|
|
{
|
|
|
|
TEXEL_BUFFER_FORMAT_R8_UINT,
|
|
|
|
TEXEL_BUFFER_FORMAT_R16_UINT,
|
|
|
|
TEXEL_BUFFER_FORMAT_RGBA8_UINT,
|
|
|
|
TEXEL_BUFFER_FORMAT_R32G32_UINT,
|
|
|
|
NUM_TEXEL_BUFFER_FORMATS
|
|
|
|
};
|
|
|
|
|
2015-11-01 22:54:41 +01:00
|
|
|
class VertexManagerBase
|
2010-10-03 10:20:24 +02:00
|
|
|
{
|
2013-02-22 06:12:53 +01:00
|
|
|
private:
|
2016-10-01 09:37:17 +02:00
|
|
|
// 3 pos
|
|
|
|
static constexpr u32 SMALLEST_POSSIBLE_VERTEX = sizeof(float) * 3;
|
|
|
|
// 3 pos, 3*3 normal, 2*u32 color, 8*4 tex, 1 posMat
|
|
|
|
static constexpr u32 LARGEST_POSSIBLE_VERTEX = sizeof(float) * 45 + sizeof(u32) * 2;
|
2013-10-29 06:23:17 +01:00
|
|
|
|
2016-10-01 09:37:17 +02:00
|
|
|
static constexpr u32 MAX_PRIMITIVES_PER_COMMAND = 65535;
|
2013-10-29 06:23:17 +01:00
|
|
|
|
2010-10-03 10:20:24 +02:00
|
|
|
public:
|
2016-10-01 09:37:17 +02:00
|
|
|
static constexpr u32 MAXVBUFFERSIZE =
|
2018-05-11 01:06:19 +02:00
|
|
|
MathUtil::NextPowerOf2(MAX_PRIMITIVES_PER_COMMAND * LARGEST_POSSIBLE_VERTEX);
|
2013-10-29 06:23:17 +01:00
|
|
|
|
2013-02-22 06:12:53 +01:00
|
|
|
// We may convert triangle-fans to triangle-lists, almost 3x as many indices.
|
2018-05-11 01:06:19 +02:00
|
|
|
static constexpr u32 MAXIBUFFERSIZE = MathUtil::NextPowerOf2(MAX_PRIMITIVES_PER_COMMAND * 3);
|
2010-10-03 10:20:24 +02:00
|
|
|
|
2019-02-15 02:59:50 +01:00
|
|
|
// Streaming buffer sizes.
|
|
|
|
// Texel buffer will fit the maximum size of an encoded GX texture. 1024x1024, RGBA8 = 4MB.
|
2019-03-24 05:24:03 +01:00
|
|
|
static constexpr u32 VERTEX_STREAM_BUFFER_SIZE = 48 * 1024 * 1024;
|
|
|
|
static constexpr u32 INDEX_STREAM_BUFFER_SIZE = 8 * 1024 * 1024;
|
|
|
|
static constexpr u32 UNIFORM_STREAM_BUFFER_SIZE = 32 * 1024 * 1024;
|
2019-02-15 02:59:50 +01:00
|
|
|
static constexpr u32 TEXEL_STREAM_BUFFER_SIZE = 16 * 1024 * 1024;
|
|
|
|
|
2015-11-01 22:54:41 +01:00
|
|
|
VertexManagerBase();
|
|
|
|
virtual ~VertexManagerBase();
|
2010-10-03 10:20:24 +02:00
|
|
|
|
2019-02-15 02:59:50 +01:00
|
|
|
virtual bool Initialize();
|
|
|
|
|
2017-04-30 10:07:57 +02:00
|
|
|
PrimitiveType GetCurrentPrimitiveType() const { return m_current_primitive_type; }
|
2016-08-22 05:02:37 +02:00
|
|
|
DataReader PrepareForAdditionalData(int primitive, u32 count, u32 stride, bool cullall);
|
|
|
|
void FlushData(u32 count, u32 stride);
|
2010-10-03 10:20:24 +02:00
|
|
|
|
2016-08-22 05:02:37 +02:00
|
|
|
void Flush();
|
2010-10-03 10:20:24 +02:00
|
|
|
|
2016-08-22 05:02:37 +02:00
|
|
|
void DoState(PointerWrap& p);
|
2013-10-29 06:23:17 +01:00
|
|
|
|
2017-03-03 23:36:51 +01:00
|
|
|
std::pair<size_t, size_t> ResetFlushAspectRatioCount();
|
|
|
|
|
2018-02-24 16:15:35 +01:00
|
|
|
// State setters, called from register update functions.
|
|
|
|
void SetRasterizationStateChanged() { m_rasterization_state_changed = true; }
|
|
|
|
void SetDepthStateChanged() { m_depth_state_changed = true; }
|
|
|
|
void SetBlendingStateChanged() { m_blending_state_changed = true; }
|
|
|
|
void InvalidatePipelineObject()
|
|
|
|
{
|
|
|
|
m_current_pipeline_object = nullptr;
|
|
|
|
m_pipeline_config_changed = true;
|
|
|
|
}
|
|
|
|
|
2018-11-27 08:16:53 +01:00
|
|
|
// Utility pipeline drawing (e.g. EFB copies, post-processing, UI).
|
2019-02-15 02:59:50 +01:00
|
|
|
virtual void UploadUtilityUniforms(const void* uniforms, u32 uniforms_size);
|
2018-11-27 08:16:53 +01:00
|
|
|
void UploadUtilityVertices(const void* vertices, u32 vertex_stride, u32 num_vertices,
|
|
|
|
const u16* indices, u32 num_indices, u32* out_base_vertex,
|
|
|
|
u32* out_base_index);
|
|
|
|
|
2019-02-15 02:59:50 +01:00
|
|
|
// Determine how many bytes there are in each element of the texel buffer.
|
|
|
|
// Needed for alignment and stride calculations.
|
|
|
|
static u32 GetTexelBufferElementSize(TexelBufferFormat buffer_format);
|
|
|
|
|
|
|
|
// Texel buffer, used for palette conversion.
|
|
|
|
virtual bool UploadTexelBuffer(const void* data, u32 data_size, TexelBufferFormat format,
|
|
|
|
u32* out_offset);
|
|
|
|
|
|
|
|
// The second set of parameters uploads a second blob in the same buffer, used for GPU texture
|
|
|
|
// decoding for palette textures, as both the texture data and palette must be uploaded.
|
|
|
|
virtual bool UploadTexelBuffer(const void* data, u32 data_size, TexelBufferFormat format,
|
|
|
|
u32* out_offset, const void* palette_data, u32 palette_size,
|
|
|
|
TexelBufferFormat palette_format, u32* out_palette_offset);
|
|
|
|
|
|
|
|
// CPU access tracking - call after a draw call is made.
|
|
|
|
void OnDraw();
|
|
|
|
|
|
|
|
// Call after CPU access is requested.
|
|
|
|
void OnCPUEFBAccess();
|
|
|
|
|
|
|
|
// Call after an EFB copy to RAM. If true, the current command buffer should be executed.
|
|
|
|
void OnEFBCopyToRAM();
|
|
|
|
|
|
|
|
// Call at the end of a frame.
|
|
|
|
void OnEndFrame();
|
|
|
|
|
2010-10-03 10:20:24 +02:00
|
|
|
protected:
|
2019-02-15 02:59:50 +01:00
|
|
|
// When utility uniforms are used, the GX uniforms need to be re-written afterwards.
|
|
|
|
static void InvalidateConstants();
|
2018-11-27 08:16:53 +01:00
|
|
|
|
|
|
|
// Prepares the buffer for the next batch of vertices.
|
2019-02-15 02:59:50 +01:00
|
|
|
virtual void ResetBuffer(u32 vertex_stride);
|
2018-11-27 08:16:53 +01:00
|
|
|
|
|
|
|
// Commits/uploads the current batch of vertices.
|
|
|
|
virtual void CommitBuffer(u32 num_vertices, u32 vertex_stride, u32 num_indices,
|
2019-02-15 02:59:50 +01:00
|
|
|
u32* out_base_vertex, u32* out_base_index);
|
2018-11-27 08:16:53 +01:00
|
|
|
|
|
|
|
// Uploads uniform buffers for GX draws.
|
2019-02-15 02:59:50 +01:00
|
|
|
virtual void UploadUniforms();
|
2018-11-27 08:16:53 +01:00
|
|
|
|
|
|
|
// Issues the draw call for the current batch in the backend.
|
2019-02-15 02:59:50 +01:00
|
|
|
virtual void DrawCurrentBatch(u32 base_index, u32 num_indices, u32 base_vertex);
|
|
|
|
|
|
|
|
u32 GetRemainingSize() const;
|
|
|
|
static u32 GetRemainingIndices(int primitive);
|
|
|
|
|
|
|
|
void CalculateZSlope(NativeVertexFormat* format);
|
|
|
|
void LoadTextures();
|
2013-10-29 06:23:17 +01:00
|
|
|
|
2016-08-22 05:02:37 +02:00
|
|
|
u8* m_cur_buffer_pointer = nullptr;
|
|
|
|
u8* m_base_buffer_pointer = nullptr;
|
|
|
|
u8* m_end_buffer_pointer = nullptr;
|
2014-12-09 08:35:04 +01:00
|
|
|
|
2019-02-15 02:59:50 +01:00
|
|
|
// Alternative buffers in CPU memory for primitives we are going to discard.
|
|
|
|
std::vector<u8> m_cpu_vertex_buffer;
|
|
|
|
std::vector<u16> m_cpu_index_buffer;
|
2014-12-09 08:35:04 +01:00
|
|
|
|
2016-08-22 05:02:37 +02:00
|
|
|
Slope m_zslope = {};
|
2015-01-13 10:55:25 +01:00
|
|
|
|
2018-03-01 10:21:06 +01:00
|
|
|
VideoCommon::GXPipelineUid m_current_pipeline_config;
|
|
|
|
VideoCommon::GXUberPipelineUid m_current_uber_pipeline_config;
|
2018-02-24 16:15:35 +01:00
|
|
|
const AbstractPipeline* m_current_pipeline_object = nullptr;
|
2017-04-30 10:07:57 +02:00
|
|
|
PrimitiveType m_current_primitive_type = PrimitiveType::Points;
|
2018-02-24 16:15:35 +01:00
|
|
|
bool m_pipeline_config_changed = true;
|
|
|
|
bool m_rasterization_state_changed = true;
|
|
|
|
bool m_depth_state_changed = true;
|
|
|
|
bool m_blending_state_changed = true;
|
|
|
|
bool m_cull_all = false;
|
2015-01-24 02:37:20 +01:00
|
|
|
|
2014-01-23 13:11:38 +01:00
|
|
|
private:
|
2019-02-15 02:59:50 +01:00
|
|
|
// Minimum number of draws per command buffer when attempting to preempt a readback operation.
|
|
|
|
static constexpr u32 MINIMUM_DRAW_CALLS_PER_COMMAND_BUFFER_FOR_READBACK = 10;
|
|
|
|
|
|
|
|
void UpdatePipelineConfig();
|
|
|
|
void UpdatePipelineObject();
|
|
|
|
|
2016-08-22 05:02:37 +02:00
|
|
|
bool m_is_flushed = true;
|
2017-03-03 23:36:51 +01:00
|
|
|
size_t m_flush_count_4_3 = 0;
|
|
|
|
size_t m_flush_count_anamorphic = 0;
|
2013-10-29 06:23:17 +01:00
|
|
|
|
2019-02-15 02:59:50 +01:00
|
|
|
// CPU access tracking
|
|
|
|
u32 m_draw_counter = 0;
|
|
|
|
u32 m_last_efb_copy_draw_counter = 0;
|
|
|
|
std::vector<u32> m_cpu_accesses_this_frame;
|
|
|
|
std::vector<u32> m_scheduled_command_buffer_kicks;
|
|
|
|
bool m_allow_background_execution = true;
|
2010-10-03 10:20:24 +02:00
|
|
|
};
|
|
|
|
|
2015-12-21 03:49:49 +01:00
|
|
|
extern std::unique_ptr<VertexManagerBase> g_vertex_manager;
|