2015-05-23 22:32:32 -06:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2014-02-10 11:54:46 -07:00
|
|
|
#pragma once
|
2010-10-03 02:20:24 -06:00
|
|
|
|
2015-12-20 19:49:49 -07:00
|
|
|
#include <memory>
|
2013-02-26 21:47:50 -07:00
|
|
|
#include <vector>
|
2015-12-20 19:49:49 -07:00
|
|
|
|
2014-09-07 19:06:58 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2018-05-10 17:06:19 -06:00
|
|
|
#include "Common/MathUtil.h"
|
2017-04-30 02:07:57 -06:00
|
|
|
#include "VideoCommon/RenderState.h"
|
2018-02-24 08:15:35 -07:00
|
|
|
#include "VideoCommon/ShaderCache.h"
|
2013-02-26 21:47:50 -07:00
|
|
|
|
2016-01-31 12:51:55 -07:00
|
|
|
class DataReader;
|
2010-11-26 02:25:08 -07:00
|
|
|
class NativeVertexFormat;
|
2012-01-04 01:42:22 -07:00
|
|
|
class PointerWrap;
|
2016-01-17 14:54:31 -07:00
|
|
|
struct PortableVertexDeclaration;
|
2010-11-26 02:25:08 -07:00
|
|
|
|
2015-01-13 02:55:25 -07:00
|
|
|
struct Slope
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
float dfdx;
|
|
|
|
float dfdy;
|
|
|
|
float f0;
|
|
|
|
bool dirty;
|
2015-01-13 02:55:25 -07:00
|
|
|
};
|
|
|
|
|
2019-02-14 18:59:50 -07: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 14:54:41 -07:00
|
|
|
class VertexManagerBase
|
2010-10-03 02:20:24 -06:00
|
|
|
{
|
2013-02-21 22:12:53 -07:00
|
|
|
private:
|
2016-10-01 01:37:17 -06: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-28 23:23:17 -06:00
|
|
|
|
2016-10-01 01:37:17 -06:00
|
|
|
static constexpr u32 MAX_PRIMITIVES_PER_COMMAND = 65535;
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2010-10-03 02:20:24 -06:00
|
|
|
public:
|
2016-10-01 01:37:17 -06:00
|
|
|
static constexpr u32 MAXVBUFFERSIZE =
|
2018-05-10 17:06:19 -06:00
|
|
|
MathUtil::NextPowerOf2(MAX_PRIMITIVES_PER_COMMAND * LARGEST_POSSIBLE_VERTEX);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
// We may convert triangle-fans to triangle-lists, almost 3x as many indices.
|
2018-05-10 17:06:19 -06:00
|
|
|
static constexpr u32 MAXIBUFFERSIZE = MathUtil::NextPowerOf2(MAX_PRIMITIVES_PER_COMMAND * 3);
|
2010-10-03 02:20:24 -06:00
|
|
|
|
2019-02-14 18:59:50 -07:00
|
|
|
// Streaming buffer sizes.
|
|
|
|
// Texel buffer will fit the maximum size of an encoded GX texture. 1024x1024, RGBA8 = 4MB.
|
2019-03-23 22:24:03 -06: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-14 18:59:50 -07:00
|
|
|
static constexpr u32 TEXEL_STREAM_BUFFER_SIZE = 16 * 1024 * 1024;
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
VertexManagerBase();
|
|
|
|
virtual ~VertexManagerBase();
|
2010-10-03 02:20:24 -06:00
|
|
|
|
2019-02-14 18:59:50 -07:00
|
|
|
virtual bool Initialize();
|
|
|
|
|
2017-04-30 02:07:57 -06:00
|
|
|
PrimitiveType GetCurrentPrimitiveType() const { return m_current_primitive_type; }
|
2016-08-21 21:02:37 -06:00
|
|
|
DataReader PrepareForAdditionalData(int primitive, u32 count, u32 stride, bool cullall);
|
|
|
|
void FlushData(u32 count, u32 stride);
|
2010-10-03 02:20:24 -06:00
|
|
|
|
2016-08-21 21:02:37 -06:00
|
|
|
void Flush();
|
2010-10-03 02:20:24 -06:00
|
|
|
|
2016-08-21 21:02:37 -06:00
|
|
|
void DoState(PointerWrap& p);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2017-03-03 15:36:51 -07:00
|
|
|
std::pair<size_t, size_t> ResetFlushAspectRatioCount();
|
|
|
|
|
2018-02-24 08:15:35 -07: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 00:16:53 -07:00
|
|
|
// Utility pipeline drawing (e.g. EFB copies, post-processing, UI).
|
2019-02-14 18:59:50 -07:00
|
|
|
virtual void UploadUtilityUniforms(const void* uniforms, u32 uniforms_size);
|
2018-11-27 00:16:53 -07: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-14 18:59:50 -07: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 02:20:24 -06:00
|
|
|
protected:
|
2019-02-14 18:59:50 -07:00
|
|
|
// When utility uniforms are used, the GX uniforms need to be re-written afterwards.
|
|
|
|
static void InvalidateConstants();
|
2018-11-27 00:16:53 -07:00
|
|
|
|
|
|
|
// Prepares the buffer for the next batch of vertices.
|
2019-02-14 18:59:50 -07:00
|
|
|
virtual void ResetBuffer(u32 vertex_stride);
|
2018-11-27 00:16:53 -07:00
|
|
|
|
|
|
|
// Commits/uploads the current batch of vertices.
|
|
|
|
virtual void CommitBuffer(u32 num_vertices, u32 vertex_stride, u32 num_indices,
|
2019-02-14 18:59:50 -07:00
|
|
|
u32* out_base_vertex, u32* out_base_index);
|
2018-11-27 00:16:53 -07:00
|
|
|
|
|
|
|
// Uploads uniform buffers for GX draws.
|
2019-02-14 18:59:50 -07:00
|
|
|
virtual void UploadUniforms();
|
2018-11-27 00:16:53 -07:00
|
|
|
|
|
|
|
// Issues the draw call for the current batch in the backend.
|
2019-02-14 18:59:50 -07: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-28 23:23:17 -06:00
|
|
|
|
2016-08-21 21:02:37 -06:00
|
|
|
u8* m_cur_buffer_pointer = nullptr;
|
|
|
|
u8* m_base_buffer_pointer = nullptr;
|
|
|
|
u8* m_end_buffer_pointer = nullptr;
|
2014-12-09 00:35:04 -07:00
|
|
|
|
2019-02-14 18:59:50 -07: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 00:35:04 -07:00
|
|
|
|
2016-08-21 21:02:37 -06:00
|
|
|
Slope m_zslope = {};
|
2015-01-13 02:55:25 -07:00
|
|
|
|
2018-03-01 02:21:06 -07:00
|
|
|
VideoCommon::GXPipelineUid m_current_pipeline_config;
|
|
|
|
VideoCommon::GXUberPipelineUid m_current_uber_pipeline_config;
|
2018-02-24 08:15:35 -07:00
|
|
|
const AbstractPipeline* m_current_pipeline_object = nullptr;
|
2017-04-30 02:07:57 -06:00
|
|
|
PrimitiveType m_current_primitive_type = PrimitiveType::Points;
|
2018-02-24 08:15:35 -07: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-23 18:37:20 -07:00
|
|
|
|
2014-01-23 05:11:38 -07:00
|
|
|
private:
|
2019-02-14 18:59:50 -07: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-21 21:02:37 -06:00
|
|
|
bool m_is_flushed = true;
|
2017-03-03 15:36:51 -07:00
|
|
|
size_t m_flush_count_4_3 = 0;
|
|
|
|
size_t m_flush_count_anamorphic = 0;
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2019-02-14 18:59:50 -07: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 02:20:24 -06:00
|
|
|
};
|
|
|
|
|
2015-12-20 19:49:49 -07:00
|
|
|
extern std::unique_ptr<VertexManagerBase> g_vertex_manager;
|