2014-09-26 16:06:55 +00:00
|
|
|
// Copyright (c) 2013- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
2015-04-08 19:35:00 +00:00
|
|
|
#include <unordered_map>
|
2014-09-26 16:06:55 +00:00
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
2017-08-20 17:10:52 +00:00
|
|
|
#include "Common/Hashmaps.h"
|
2014-09-26 16:06:55 +00:00
|
|
|
|
2017-01-23 15:57:16 +00:00
|
|
|
#include "GPU/GPUState.h"
|
2014-09-26 16:06:55 +00:00
|
|
|
#include "GPU/Common/GPUDebugInterface.h"
|
2017-06-02 10:03:46 +00:00
|
|
|
#include "GPU/Common/IndexGenerator.h"
|
2015-04-08 19:35:00 +00:00
|
|
|
#include "GPU/Common/VertexDecoderCommon.h"
|
2014-09-26 16:06:55 +00:00
|
|
|
|
|
|
|
class VertexDecoder;
|
|
|
|
|
2015-01-29 13:12:24 +00:00
|
|
|
enum {
|
|
|
|
VERTEX_BUFFER_MAX = 65536,
|
2015-03-01 14:28:11 +00:00
|
|
|
DECODED_VERTEX_BUFFER_SIZE = VERTEX_BUFFER_MAX * 64,
|
|
|
|
DECODED_INDEX_BUFFER_SIZE = VERTEX_BUFFER_MAX * 16,
|
2017-03-09 07:11:24 +00:00
|
|
|
SPLINE_BUFFER_SIZE = VERTEX_BUFFER_MAX * 26, // At least, this buffer needs greater than 1679616 bytes for Mist Dragon morphing in FF4CC.
|
2015-01-29 13:12:24 +00:00
|
|
|
};
|
|
|
|
|
2017-06-02 10:25:47 +00:00
|
|
|
// Avoiding the full include of TextureDecoder.h.
|
|
|
|
#if (defined(_M_SSE) && defined(_M_X64)) || defined(ARM64)
|
|
|
|
typedef u64 ReliableHashType;
|
|
|
|
#else
|
|
|
|
typedef u32 ReliableHashType;
|
|
|
|
#endif
|
|
|
|
|
2014-09-26 16:06:55 +00:00
|
|
|
class DrawEngineCommon {
|
|
|
|
public:
|
2015-04-08 19:35:00 +00:00
|
|
|
DrawEngineCommon();
|
2014-09-26 16:06:55 +00:00
|
|
|
virtual ~DrawEngineCommon();
|
|
|
|
|
|
|
|
bool GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices);
|
|
|
|
|
|
|
|
static u32 NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, VertexDecoder *dec, int lowerBound, int upperBound, u32 vertType);
|
|
|
|
|
2015-04-08 19:44:54 +00:00
|
|
|
// Flush is normally non-virtual but here's a virtual way to call it, used by the shared spline code, which is expensive anyway.
|
|
|
|
// Not really sure if these wrappers are worth it...
|
2015-04-08 19:37:54 +00:00
|
|
|
virtual void DispatchFlush() = 0;
|
2018-02-26 10:26:52 +00:00
|
|
|
|
|
|
|
// This would seem to be unnecessary now, but is still required for splines/beziers to work in the software backend since SubmitPrim
|
|
|
|
// is different. Should probably refactor that.
|
2018-02-26 10:33:17 +00:00
|
|
|
virtual void DispatchSubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int *bytesRead) {
|
|
|
|
SubmitPrim(verts, inds, prim, vertexCount, vertType, bytesRead);
|
|
|
|
}
|
2015-04-08 19:44:54 +00:00
|
|
|
|
2017-11-17 12:36:48 +00:00
|
|
|
bool TestBoundingBox(void* control_points, int vertexCount, u32 vertType, int *bytesRead);
|
2018-02-26 10:02:52 +00:00
|
|
|
|
|
|
|
void SubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int *bytesRead);
|
2016-04-11 00:12:48 +00:00
|
|
|
void SubmitSpline(const void *control_points, const void *indices, int tess_u, int tess_v, int count_u, int count_v, int type_u, int type_v, GEPatchPrimType prim_type, bool computeNormals, bool patchFacing, u32 vertType, int *bytesRead);
|
2016-04-10 19:59:06 +00:00
|
|
|
void SubmitBezier(const void *control_points, const void *indices, int tess_u, int tess_v, int count_u, int count_v, GEPatchPrimType prim_type, bool computeNormals, bool patchFacing, u32 vertType, int *bytesRead);
|
2015-04-08 19:37:54 +00:00
|
|
|
|
2015-10-21 21:06:32 +00:00
|
|
|
std::vector<std::string> DebugGetVertexLoaderIDs();
|
|
|
|
std::string DebugGetVertexLoaderString(std::string id, DebugShaderStringType stringType);
|
2017-01-23 15:57:16 +00:00
|
|
|
|
2017-03-17 10:26:11 +00:00
|
|
|
virtual void Resized();
|
2017-03-17 09:27:49 +00:00
|
|
|
|
2017-10-20 09:06:06 +00:00
|
|
|
bool IsCodePtrVertexDecoder(const u8 *ptr) const {
|
|
|
|
return decJitCache_->IsInSpace(ptr);
|
|
|
|
}
|
2018-02-26 12:51:14 +00:00
|
|
|
int GetNumDrawCalls() const {
|
|
|
|
return numDrawCalls;
|
|
|
|
}
|
2017-10-20 09:06:06 +00:00
|
|
|
|
2014-09-26 16:06:55 +00:00
|
|
|
protected:
|
2017-03-17 09:27:49 +00:00
|
|
|
virtual void ClearTrackedVertexArrays() {}
|
|
|
|
|
2017-11-19 11:38:52 +00:00
|
|
|
int ComputeNumVertsToDecode() const;
|
|
|
|
void DecodeVerts(u8 *dest);
|
|
|
|
|
2015-04-08 19:44:54 +00:00
|
|
|
// Preprocessing for spline/bezier
|
2017-11-17 12:36:48 +00:00
|
|
|
u32 NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, u32 vertType, int *vertexSize = nullptr);
|
2015-04-08 19:44:54 +00:00
|
|
|
|
2017-06-02 10:16:43 +00:00
|
|
|
// Utility for vertex caching
|
|
|
|
u32 ComputeMiniHash();
|
2017-06-02 10:25:47 +00:00
|
|
|
ReliableHashType ComputeHash();
|
2017-06-02 10:16:43 +00:00
|
|
|
|
2017-06-02 10:09:57 +00:00
|
|
|
// Vertex decoding
|
|
|
|
void DecodeVertsStep(u8 *dest, int &i, int &decodedVerts);
|
|
|
|
|
2017-02-17 11:21:27 +00:00
|
|
|
bool ApplyShaderBlending();
|
2016-09-19 02:40:44 +00:00
|
|
|
|
2015-04-08 19:35:00 +00:00
|
|
|
VertexDecoder *GetVertexDecoder(u32 vtype);
|
|
|
|
|
2016-04-10 08:52:51 +00:00
|
|
|
inline int IndexSize(u32 vtype) const {
|
|
|
|
const u32 indexType = (vtype & GE_VTYPE_IDX_MASK);
|
|
|
|
if (indexType == GE_VTYPE_IDX_16BIT) {
|
|
|
|
return 2;
|
|
|
|
} else if (indexType == GE_VTYPE_IDX_32BIT) {
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-09-26 16:06:55 +00:00
|
|
|
// Vertex collector buffers
|
2017-06-02 10:03:46 +00:00
|
|
|
u8 *decoded = nullptr;
|
|
|
|
u16 *decIndex = nullptr;
|
|
|
|
u8 *splineBuffer = nullptr;
|
2015-04-08 19:35:00 +00:00
|
|
|
|
|
|
|
// Cached vertex decoders
|
2017-03-17 09:27:49 +00:00
|
|
|
u32 lastVType_ = -1;
|
2017-08-20 17:10:52 +00:00
|
|
|
DenseHashMap<u32, VertexDecoder *, nullptr> decoderMap_;
|
2017-06-02 09:47:14 +00:00
|
|
|
VertexDecoder *dec_ = nullptr;
|
2017-06-02 11:06:14 +00:00
|
|
|
VertexDecoderJitCache *decJitCache_ = nullptr;
|
|
|
|
VertexDecoderOptions decOptions_{};
|
2015-04-08 19:35:00 +00:00
|
|
|
|
2017-06-02 10:25:47 +00:00
|
|
|
TransformedVertex *transformed = nullptr;
|
|
|
|
TransformedVertex *transformedExpanded = nullptr;
|
|
|
|
|
2017-06-02 10:03:46 +00:00
|
|
|
// Defer all vertex decoding to a "Flush" (except when software skinning)
|
|
|
|
struct DeferredDrawCall {
|
|
|
|
void *verts;
|
|
|
|
void *inds;
|
|
|
|
u8 indexType;
|
|
|
|
s8 prim;
|
|
|
|
u32 vertexCount;
|
|
|
|
u16 indexLowerBound;
|
|
|
|
u16 indexUpperBound;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum { MAX_DEFERRED_DRAW_CALLS = 128 };
|
|
|
|
DeferredDrawCall drawCalls[MAX_DEFERRED_DRAW_CALLS];
|
|
|
|
int numDrawCalls = 0;
|
|
|
|
int vertexCountInDrawCalls_ = 0;
|
|
|
|
UVScale uvScale[MAX_DEFERRED_DRAW_CALLS];
|
|
|
|
|
|
|
|
int decimationCounter_ = 0;
|
|
|
|
int decodeCounter_ = 0;
|
|
|
|
u32 dcid_ = 0;
|
|
|
|
|
|
|
|
// Vertex collector state
|
|
|
|
IndexGenerator indexGen;
|
|
|
|
int decodedVerts_ = 0;
|
|
|
|
GEPrimitiveType prevPrim_ = GE_PRIM_INVALID;
|
|
|
|
|
2015-04-08 19:35:00 +00:00
|
|
|
// Fixed index buffer for easy quad generation from spline/bezier
|
2017-06-02 10:03:46 +00:00
|
|
|
u16 *quadIndices_ = nullptr;
|
2017-01-08 13:14:35 +00:00
|
|
|
|
2017-02-17 11:21:18 +00:00
|
|
|
// Shader blending state
|
2017-06-02 10:03:46 +00:00
|
|
|
bool fboTexNeedBind_ = false;
|
|
|
|
bool fboTexBound_ = false;
|
2017-02-17 11:21:18 +00:00
|
|
|
|
2017-01-08 13:14:35 +00:00
|
|
|
// Hardware tessellation
|
|
|
|
int numPatches;
|
|
|
|
class TessellationDataTransfer {
|
|
|
|
protected:
|
2017-11-11 19:36:44 +00:00
|
|
|
// TODO: These aren't used by all backends.
|
2017-01-08 13:14:35 +00:00
|
|
|
int prevSize;
|
|
|
|
int prevSizeTex;
|
|
|
|
int prevSizeCol;
|
|
|
|
public:
|
2017-01-24 19:00:03 +00:00
|
|
|
virtual ~TessellationDataTransfer() {}
|
2017-01-08 18:37:21 +00:00
|
|
|
// Send spline/bezier's control points to vertex shader through floating point texture.
|
2017-11-12 10:00:11 +00:00
|
|
|
virtual void PrepareBuffers(float *&pos, float *&tex, float *&col, int &posStride, int &texStride, int &colStride, int size, bool hasColor, bool hasTexCoords) {
|
|
|
|
posStride = 4;
|
|
|
|
texStride = 4;
|
|
|
|
colStride = 4;
|
|
|
|
}
|
2017-01-08 13:14:35 +00:00
|
|
|
virtual void SendDataToShader(const float *pos, const float *tex, const float *col, int size, bool hasColor, bool hasTexCoords) = 0;
|
2018-01-19 23:05:59 +00:00
|
|
|
virtual void EndFrame() {}
|
2017-01-08 13:14:35 +00:00
|
|
|
};
|
|
|
|
TessellationDataTransfer *tessDataTransfer;
|
2015-03-01 14:28:11 +00:00
|
|
|
};
|