2013-08-17 09:23:51 +00:00
|
|
|
// Copyright (c) 2012- 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 <map>
|
|
|
|
|
2013-09-15 10:46:14 +00:00
|
|
|
#include <d3d9.h>
|
2014-09-10 08:44:22 +00:00
|
|
|
|
2014-08-25 05:16:32 +00:00
|
|
|
#include "GPU/Common/GPUDebugInterface.h"
|
2013-09-15 10:46:14 +00:00
|
|
|
#include "GPU/Common/IndexGenerator.h"
|
2014-09-10 08:44:22 +00:00
|
|
|
#include "GPU/Common/VertexDecoderCommon.h"
|
2013-08-17 09:23:51 +00:00
|
|
|
|
2013-09-15 15:53:21 +00:00
|
|
|
struct DecVtxFormat;
|
|
|
|
|
|
|
|
namespace DX9 {
|
|
|
|
|
2014-09-10 12:07:30 +00:00
|
|
|
class VSShader;
|
2013-09-15 10:46:14 +00:00
|
|
|
class ShaderManagerDX9;
|
|
|
|
class TextureCacheDX9;
|
|
|
|
class FramebufferManagerDX9;
|
2013-08-17 09:23:51 +00:00
|
|
|
|
|
|
|
// States transitions:
|
|
|
|
// On creation: DRAWN_NEW
|
|
|
|
// DRAWN_NEW -> DRAWN_HASHING
|
|
|
|
// DRAWN_HASHING -> DRAWN_RELIABLE
|
|
|
|
// DRAWN_HASHING -> DRAWN_UNRELIABLE
|
|
|
|
// DRAWN_ONCE -> UNRELIABLE
|
|
|
|
// DRAWN_RELIABLE -> DRAWN_SAFE
|
|
|
|
// UNRELIABLE -> death
|
|
|
|
// DRAWN_ONCE -> death
|
|
|
|
// DRAWN_RELIABLE -> death
|
|
|
|
|
2014-09-09 08:03:08 +00:00
|
|
|
enum {
|
|
|
|
VAI_FLAG_VERTEXFULLALPHA = 1,
|
|
|
|
};
|
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
|
|
|
|
// Don't bother storing information about draws smaller than this.
|
|
|
|
enum {
|
|
|
|
VERTEX_CACHE_THRESHOLD = 20,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Try to keep this POD.
|
2013-09-15 10:46:14 +00:00
|
|
|
class VertexArrayInfoDX9 {
|
2013-08-17 09:23:51 +00:00
|
|
|
public:
|
2013-09-15 10:46:14 +00:00
|
|
|
VertexArrayInfoDX9() {
|
2013-08-17 09:23:51 +00:00
|
|
|
status = VAI_NEW;
|
|
|
|
vbo = 0;
|
|
|
|
ebo = 0;
|
|
|
|
numDCs = 0;
|
2013-09-04 09:19:36 +00:00
|
|
|
prim = GE_PRIM_INVALID;
|
2013-08-17 09:23:51 +00:00
|
|
|
numDraws = 0;
|
|
|
|
numFrames = 0;
|
2013-08-17 13:11:27 +00:00
|
|
|
lastFrame = gpuStats.numFlips;
|
2013-08-17 09:23:51 +00:00
|
|
|
numVerts = 0;
|
|
|
|
drawsUntilNextFullHash = 0;
|
2014-09-09 08:03:08 +00:00
|
|
|
flags = 0;
|
2013-08-17 09:23:51 +00:00
|
|
|
}
|
2013-09-15 10:46:14 +00:00
|
|
|
~VertexArrayInfoDX9();
|
2014-09-09 08:03:08 +00:00
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
enum Status {
|
|
|
|
VAI_NEW,
|
|
|
|
VAI_HASHING,
|
|
|
|
VAI_RELIABLE, // cache, don't hash
|
|
|
|
VAI_UNRELIABLE, // never cache
|
|
|
|
};
|
|
|
|
|
|
|
|
u32 hash;
|
|
|
|
|
|
|
|
Status status;
|
|
|
|
|
|
|
|
LPDIRECT3DVERTEXBUFFER9 vbo;
|
|
|
|
LPDIRECT3DINDEXBUFFER9 ebo;
|
|
|
|
|
2013-11-15 13:24:25 +00:00
|
|
|
// Precalculated parameter for drawRangeElements
|
2013-08-17 09:23:51 +00:00
|
|
|
u16 numVerts;
|
2013-11-15 13:24:25 +00:00
|
|
|
u16 maxIndex;
|
2013-08-17 09:23:51 +00:00
|
|
|
s8 prim;
|
|
|
|
|
|
|
|
// ID information
|
|
|
|
u8 numDCs;
|
|
|
|
int numDraws;
|
|
|
|
int numFrames;
|
|
|
|
int lastFrame; // So that we can forget.
|
|
|
|
u16 drawsUntilNextFullHash;
|
2014-09-09 08:03:08 +00:00
|
|
|
u8 flags;
|
2013-08-17 09:23:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Handles transform, lighting and drawing.
|
2013-09-15 10:46:14 +00:00
|
|
|
class TransformDrawEngineDX9 {
|
2013-08-17 09:23:51 +00:00
|
|
|
public:
|
2013-09-15 10:46:14 +00:00
|
|
|
TransformDrawEngineDX9();
|
|
|
|
virtual ~TransformDrawEngineDX9();
|
2013-11-15 13:24:25 +00:00
|
|
|
|
|
|
|
void SubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int forceIndexType, int *bytesRead);
|
|
|
|
void SubmitSpline(void* control_points, void* indices, int count_u, int count_v, int type_u, int type_v, GEPatchPrimType prim_type, u32 vertType);
|
|
|
|
void SubmitBezier(void* control_points, void* indices, int count_u, int count_v, GEPatchPrimType prim_type, u32 vertType);
|
|
|
|
bool TestBoundingBox(void* control_points, int vertexCount, u32 vertType);
|
2013-08-25 11:56:29 +00:00
|
|
|
|
2014-08-25 05:16:32 +00:00
|
|
|
bool GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices);
|
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
void DecodeVerts();
|
2013-09-15 10:46:14 +00:00
|
|
|
void SetShaderManager(ShaderManagerDX9 *shaderManager) {
|
2013-08-17 09:23:51 +00:00
|
|
|
shaderManager_ = shaderManager;
|
|
|
|
}
|
2013-09-15 10:46:14 +00:00
|
|
|
void SetTextureCache(TextureCacheDX9 *textureCache) {
|
2013-08-17 09:23:51 +00:00
|
|
|
textureCache_ = textureCache;
|
|
|
|
}
|
2013-09-15 10:46:14 +00:00
|
|
|
void SetFramebufferManager(FramebufferManagerDX9 *fbManager) {
|
2013-08-17 09:23:51 +00:00
|
|
|
framebufferManager_ = fbManager;
|
|
|
|
}
|
|
|
|
void InitDeviceObjects();
|
|
|
|
void DestroyDeviceObjects();
|
|
|
|
void GLLost() {};
|
|
|
|
|
|
|
|
void DecimateTrackedVertexArrays();
|
|
|
|
void ClearTrackedVertexArrays();
|
|
|
|
|
|
|
|
void SetupVertexDecoder(u32 vertType);
|
|
|
|
|
|
|
|
// This requires a SetupVertexDecoder call first.
|
|
|
|
int EstimatePerVertexCost();
|
|
|
|
|
2013-08-20 16:47:11 +00:00
|
|
|
// So that this can be inlined
|
|
|
|
void Flush() {
|
|
|
|
if (!numDrawCalls)
|
|
|
|
return;
|
|
|
|
DoFlush();
|
|
|
|
}
|
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
private:
|
2013-08-20 16:47:11 +00:00
|
|
|
void DoFlush();
|
2014-09-10 12:07:30 +00:00
|
|
|
void SoftwareTransformAndDraw(int prim, u8 *decoded, int vertexCount, u32 vertexType, void *inds, int indexType, const DecVtxFormat &decVtxFormat, int maxIndex);
|
2013-08-17 09:23:51 +00:00
|
|
|
void ApplyDrawState(int prim);
|
|
|
|
bool IsReallyAClear(int numVerts) const;
|
2014-09-10 12:07:30 +00:00
|
|
|
IDirect3DVertexDeclaration9 *SetupDecFmtForDraw(VSShader *vshader, const DecVtxFormat &decFmt, u32 pspFmt);
|
2013-08-17 09:23:51 +00:00
|
|
|
|
2013-11-15 13:24:25 +00:00
|
|
|
// Preprocessing for spline/bezier
|
2014-09-10 08:28:44 +00:00
|
|
|
u32 NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, VertexDecoder *dec, int lowerBound, int upperBound, u32 vertType);
|
2013-11-15 13:24:25 +00:00
|
|
|
u32 NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, u32 vertType);
|
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
// drawcall ID
|
|
|
|
u32 ComputeFastDCID();
|
|
|
|
u32 ComputeHash(); // Reads deferred vertex data.
|
|
|
|
|
2014-09-10 08:28:44 +00:00
|
|
|
VertexDecoder *GetVertexDecoder(u32 vtype);
|
2013-08-17 09:23:51 +00:00
|
|
|
|
|
|
|
// Defer all vertex decoding to a Flush, so that we can hash and cache the
|
|
|
|
// generated buffers without having to redecode them every time.
|
|
|
|
struct DeferredDrawCall {
|
|
|
|
void *verts;
|
|
|
|
void *inds;
|
|
|
|
u32 vertType;
|
|
|
|
u8 indexType;
|
|
|
|
u8 prim;
|
|
|
|
u16 vertexCount;
|
|
|
|
u16 indexLowerBound;
|
|
|
|
u16 indexUpperBound;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Vertex collector state
|
|
|
|
IndexGenerator indexGen;
|
|
|
|
int collectedVerts;
|
2013-09-04 09:19:36 +00:00
|
|
|
GEPrimitiveType prevPrim_;
|
2013-08-17 09:23:51 +00:00
|
|
|
|
|
|
|
// Cached vertex decoders
|
2014-09-10 08:28:44 +00:00
|
|
|
std::map<u32, VertexDecoder *> decoderMap_;
|
|
|
|
VertexDecoder *dec_;
|
2013-08-17 09:23:51 +00:00
|
|
|
u32 lastVType_;
|
|
|
|
|
|
|
|
// Vertex collector buffers
|
|
|
|
u8 *decoded;
|
|
|
|
u16 *decIndex;
|
|
|
|
|
|
|
|
TransformedVertex *transformed;
|
|
|
|
TransformedVertex *transformedExpanded;
|
|
|
|
|
2013-09-15 10:46:14 +00:00
|
|
|
std::map<u32, VertexArrayInfoDX9 *> vai_;
|
2014-09-07 20:07:12 +00:00
|
|
|
std::map<u32, IDirect3DVertexDeclaration9 *> vertexDeclMap_;
|
2013-11-15 13:24:25 +00:00
|
|
|
|
|
|
|
// Fixed index buffer for easy quad generation from spline/bezier
|
|
|
|
u16 *quadIndices_;
|
2013-08-23 15:24:51 +00:00
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
// Other
|
2013-09-15 10:46:14 +00:00
|
|
|
ShaderManagerDX9 *shaderManager_;
|
|
|
|
TextureCacheDX9 *textureCache_;
|
|
|
|
FramebufferManagerDX9 *framebufferManager_;
|
2013-08-17 09:23:51 +00:00
|
|
|
|
|
|
|
enum { MAX_DEFERRED_DRAW_CALLS = 128 };
|
|
|
|
DeferredDrawCall drawCalls[MAX_DEFERRED_DRAW_CALLS];
|
|
|
|
int numDrawCalls;
|
2013-10-27 21:43:58 +00:00
|
|
|
int vertexCountInDrawCalls;
|
2013-08-20 16:47:11 +00:00
|
|
|
|
|
|
|
int decimationCounter_;
|
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
UVScale *uvScale;
|
2014-09-10 08:28:44 +00:00
|
|
|
|
|
|
|
VertexDecoderOptions decOptions_;
|
2013-08-17 09:23:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Only used by SW transform
|
|
|
|
struct Color4 {
|
|
|
|
float a, r, g, b;
|
|
|
|
|
|
|
|
Color4() : r(0), g(0), b(0), a(0) { }
|
|
|
|
Color4(float _r, float _g, float _b, float _a=1.0f)
|
|
|
|
: r(_r), g(_g), b(_b), a(_a) {
|
|
|
|
}
|
|
|
|
Color4(const float in[4]) {a=in[0];r=in[1];g=in[2];b=in[3];}
|
|
|
|
Color4(const float in[3], float alpha) {r=in[0];g=in[1];b=in[2];a=alpha;}
|
|
|
|
|
|
|
|
const float &operator [](int i) const {return *(&a + i);}
|
|
|
|
|
|
|
|
Color4 operator *(float f) const {
|
|
|
|
return Color4(f*r,f*g,f*b,f*a);
|
|
|
|
}
|
|
|
|
Color4 operator *(const Color4 &c) const {
|
|
|
|
return Color4(r*c.r,g*c.g,b*c.b,a*c.a);
|
|
|
|
}
|
|
|
|
Color4 operator +(const Color4 &c) const {
|
|
|
|
return Color4(r+c.r,g+c.g,b+c.b,a+c.a);
|
|
|
|
}
|
|
|
|
void operator +=(const Color4 &c) {
|
|
|
|
r+=c.r;
|
|
|
|
g+=c.g;
|
|
|
|
b+=c.b;
|
|
|
|
a+=c.a;
|
|
|
|
}
|
|
|
|
void GetFromRGB(u32 col) {
|
|
|
|
b = ((col>>16) & 0xff)/255.0f;
|
|
|
|
g = ((col>>8) & 0xff)/255.0f;
|
|
|
|
r = ((col>>0) & 0xff)/255.0f;
|
|
|
|
}
|
|
|
|
void GetFromA(u32 col) {
|
|
|
|
a = (col&0xff)/255.0f;
|
|
|
|
}
|
|
|
|
};
|
2013-09-15 15:53:21 +00:00
|
|
|
|
|
|
|
};
|