Move most backend functionality to VideoCommon

This commit is contained in:
Stenzek
2019-02-15 11:59:50 +10:00
parent 933f3ba008
commit f039149198
182 changed files with 8334 additions and 15917 deletions

View File

@ -25,6 +25,16 @@ struct Slope
bool dirty;
};
// 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
};
class VertexManagerBase
{
private:
@ -42,19 +52,24 @@ public:
// We may convert triangle-fans to triangle-lists, almost 3x as many indices.
static constexpr u32 MAXIBUFFERSIZE = MathUtil::NextPowerOf2(MAX_PRIMITIVES_PER_COMMAND * 3);
// Streaming buffer sizes.
// Texel buffer will fit the maximum size of an encoded GX texture. 1024x1024, RGBA8 = 4MB.
static constexpr u32 VERTEX_STREAM_BUFFER_SIZE = 40 * 1024 * 1024;
static constexpr u32 INDEX_STREAM_BUFFER_SIZE = 4 * 1024 * 1024;
static constexpr u32 UNIFORM_STREAM_BUFFER_SIZE = 16 * 1024 * 1024;
static constexpr u32 TEXEL_STREAM_BUFFER_SIZE = 16 * 1024 * 1024;
VertexManagerBase();
// needs to be virtual for DX11's dtor
virtual ~VertexManagerBase();
virtual bool Initialize();
PrimitiveType GetCurrentPrimitiveType() const { return m_current_primitive_type; }
DataReader PrepareForAdditionalData(int primitive, u32 count, u32 stride, bool cullall);
void FlushData(u32 count, u32 stride);
void Flush();
virtual std::unique_ptr<NativeVertexFormat>
CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) = 0;
void DoState(PointerWrap& p);
std::pair<size_t, size_t> ResetFlushAspectRatioCount();
@ -70,38 +85,69 @@ public:
}
// Utility pipeline drawing (e.g. EFB copies, post-processing, UI).
virtual void UploadUtilityUniforms(const void* uniforms, u32 uniforms_size) = 0;
virtual void UploadUtilityUniforms(const void* uniforms, u32 uniforms_size);
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);
// 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();
protected:
// Vertex buffers/index buffer creation.
virtual void CreateDeviceObjects() {}
virtual void DestroyDeviceObjects() {}
// When utility uniforms are used, the GX uniforms need to be re-written afterwards.
static void InvalidateConstants();
// Prepares the buffer for the next batch of vertices.
virtual void ResetBuffer(u32 vertex_stride, bool cull_all) = 0;
virtual void ResetBuffer(u32 vertex_stride);
// Commits/uploads the current batch of vertices.
virtual void CommitBuffer(u32 num_vertices, u32 vertex_stride, u32 num_indices,
u32* out_base_vertex, u32* out_base_index) = 0;
u32* out_base_vertex, u32* out_base_index);
// Uploads uniform buffers for GX draws.
virtual void UploadConstants() = 0;
virtual void UploadUniforms();
// Issues the draw call for the current batch in the backend.
virtual void DrawCurrentBatch(u32 base_index, u32 num_indices, u32 base_vertex) = 0;
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();
u8* m_cur_buffer_pointer = nullptr;
u8* m_base_buffer_pointer = nullptr;
u8* m_end_buffer_pointer = nullptr;
u32 GetRemainingSize() const;
static u32 GetRemainingIndices(int primitive);
// 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;
Slope m_zslope = {};
void CalculateZSlope(NativeVertexFormat* format);
VideoCommon::GXPipelineUid m_current_pipeline_config;
VideoCommon::GXUberPipelineUid m_current_uber_pipeline_config;
@ -114,12 +160,22 @@ protected:
bool m_cull_all = false;
private:
// 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();
bool m_is_flushed = true;
size_t m_flush_count_4_3 = 0;
size_t m_flush_count_anamorphic = 0;
void UpdatePipelineConfig();
void UpdatePipelineObject();
// 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;
};
extern std::unique_ptr<VertexManagerBase> g_vertex_manager;