ppsspp/GPU/Directx9/DrawEngineDX9.h

235 lines
5.6 KiB
C
Raw Normal View History

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 <unordered_map>
2013-08-17 09:23:51 +00:00
#include <d3d9.h>
#include "GPU/GPUState.h"
#include "GPU/Common/GPUDebugInterface.h"
#include "GPU/Common/IndexGenerator.h"
#include "GPU/Common/VertexDecoderCommon.h"
#include "GPU/Common/DrawEngineCommon.h"
#include "GPU/Common/GPUStateUtils.h"
#include "GPU/Directx9/PixelShaderGeneratorDX9.h"
2013-08-17 09:23:51 +00:00
struct DecVtxFormat;
struct UVScale;
namespace DX9 {
class VSShader;
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,
};
// Avoiding the full include of TextureDecoder.h.
#if (defined(_M_SSE) && defined(_M_X64)) || defined(ARM64)
typedef u64 ReliableHashType;
#else
typedef u32 ReliableHashType;
#endif
2013-08-17 09:23:51 +00:00
// Try to keep this POD.
class VertexArrayInfoDX9 {
2013-08-17 09:23:51 +00:00
public:
VertexArrayInfoDX9() {
2013-08-17 09:23:51 +00:00
status = VAI_NEW;
vbo = 0;
ebo = 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
}
~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
};
ReliableHashType hash;
u32 minihash;
2013-08-17 09:23:51 +00:00
Status status;
LPDIRECT3DVERTEXBUFFER9 vbo;
LPDIRECT3DINDEXBUFFER9 ebo;
// Precalculated parameter for drawRangeElements
2013-08-17 09:23:51 +00:00
u16 numVerts;
u16 maxIndex;
2013-08-17 09:23:51 +00:00
s8 prim;
// ID information
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.
class DrawEngineDX9 : public DrawEngineCommon {
2013-08-17 09:23:51 +00:00
public:
DrawEngineDX9(LPDIRECT3DDEVICE9 device);
virtual ~DrawEngineDX9();
void SubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int *bytesRead);
2013-08-25 11:56:29 +00:00
void SetShaderManager(ShaderManagerDX9 *shaderManager) {
2013-08-17 09:23:51 +00:00
shaderManager_ = shaderManager;
}
void SetTextureCache(TextureCacheDX9 *textureCache) {
2013-08-17 09:23:51 +00:00
textureCache_ = textureCache;
}
void SetFramebufferManager(FramebufferManagerDX9 *fbManager) {
2013-08-17 09:23:51 +00:00
framebufferManager_ = fbManager;
}
void InitDeviceObjects();
void DestroyDeviceObjects();
void GLLost() {};
2014-09-11 23:48:43 +00:00
void Resized(); // TODO: Call
2013-08-17 09:23:51 +00:00
void DecimateTrackedVertexArrays();
void ClearTrackedVertexArrays();
void SetupVertexDecoder(u32 vertType);
void SetupVertexDecoderInternal(u32 vertType);
2013-08-17 09:23:51 +00:00
2013-08-20 16:47:11 +00:00
// So that this can be inlined
void Flush() {
if (!numDrawCalls)
return;
DoFlush();
}
void FinishDeferred() {
if (!numDrawCalls)
return;
DecodeVerts();
}
bool IsCodePtrVertexDecoder(const u8 *ptr) const;
void DispatchFlush() override { Flush(); }
2015-04-08 19:44:54 +00:00
void DispatchSubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int *bytesRead) override {
SubmitPrim(verts, inds, prim, vertexCount, vertType, bytesRead);
}
2014-09-14 21:04:09 +00:00
2013-08-17 09:23:51 +00:00
private:
void DecodeVerts();
void DecodeVertsStep();
void DoFlush();
2013-08-17 09:23:51 +00:00
void ApplyDrawState(int prim);
void ApplyDrawStateLate();
void ResetShaderBlending();
IDirect3DVertexDeclaration9 *SetupDecFmtForDraw(VSShader *vshader, const DecVtxFormat &decFmt, u32 pspFmt);
2013-08-17 09:23:51 +00:00
u32 ComputeMiniHash();
ReliableHashType ComputeHash(); // Reads deferred vertex data.
void MarkUnreliable(VertexArrayInfoDX9 *vai);
2013-08-17 09:23:51 +00:00
LPDIRECT3DDEVICE9 device_;
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;
s8 prim;
u32 vertexCount;
2013-08-17 09:23:51 +00:00
u16 indexLowerBound;
u16 indexUpperBound;
};
// Vertex collector state
IndexGenerator indexGen;
int decodedVerts_;
2013-09-04 09:19:36 +00:00
GEPrimitiveType prevPrim_;
2013-08-17 09:23:51 +00:00
u32 lastVType_;
TransformedVertex *transformed;
TransformedVertex *transformedExpanded;
std::unordered_map<u32, VertexArrayInfoDX9 *> vai_;
std::unordered_map<u32, IDirect3DVertexDeclaration9 *> vertexDeclMap_;
2017-02-05 18:38:52 +00:00
// SimpleVertex
IDirect3DVertexDeclaration9* transformedVertexDecl_;
2013-08-17 09:23:51 +00:00
// Other
ShaderManagerDX9 *shaderManager_;
TextureCacheDX9 *textureCache_;
FramebufferManagerDX9 *framebufferManager_;
2014-09-11 23:48:43 +00:00
2013-08-17 09:23:51 +00:00
enum { MAX_DEFERRED_DRAW_CALLS = 128 };
2013-08-17 09:23:51 +00:00
DeferredDrawCall drawCalls[MAX_DEFERRED_DRAW_CALLS];
int numDrawCalls;
int vertexCountInDrawCalls;
2013-08-20 16:47:11 +00:00
int decimationCounter_;
int decodeCounter_;
u32 dcid_;
2013-08-20 16:47:11 +00:00
UVScale uvScale[MAX_DEFERRED_DRAW_CALLS];
// Hardware tessellation
class TessellationDataTransferDX9 : public TessellationDataTransfer {
private:
int data_tex[3];
public:
TessellationDataTransferDX9() : TessellationDataTransfer(), data_tex() {
}
~TessellationDataTransferDX9() {
}
void SendDataToShader(const float *pos, const float *tex, const float *col, int size, bool hasColor, bool hasTexCoords) override;
};
2013-08-17 09:23:51 +00:00
};
} // namespace