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
|
|
|
|
|
2013-09-15 10:46:14 +00:00
|
|
|
#include <d3d9.h>
|
2014-09-10 08:44:22 +00:00
|
|
|
|
2020-10-05 18:58:33 +00:00
|
|
|
#include "Common/Data/Collections/Hashmaps.h"
|
2015-07-26 20:38:40 +00:00
|
|
|
#include "GPU/GPUState.h"
|
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"
|
2014-09-13 13:13:34 +00:00
|
|
|
#include "GPU/Common/DrawEngineCommon.h"
|
2015-10-24 21:49:05 +00:00
|
|
|
#include "GPU/Common/GPUStateUtils.h"
|
2013-08-17 09:23:51 +00:00
|
|
|
|
2013-09-15 15:53:21 +00:00
|
|
|
struct DecVtxFormat;
|
2015-07-26 20:38:40 +00:00
|
|
|
struct UVScale;
|
2013-09-15 15:53:21 +00:00
|
|
|
|
|
|
|
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
|
|
|
// 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;
|
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
|
|
|
|
2017-08-17 09:22:23 +00:00
|
|
|
enum Status : uint8_t {
|
2013-08-17 09:23:51 +00:00
|
|
|
VAI_NEW,
|
|
|
|
VAI_HASHING,
|
|
|
|
VAI_RELIABLE, // cache, don't hash
|
|
|
|
VAI_UNRELIABLE, // never cache
|
|
|
|
};
|
|
|
|
|
2020-08-28 03:37:49 +00:00
|
|
|
uint64_t hash;
|
2014-09-14 20:50:57 +00:00
|
|
|
u32 minihash;
|
2013-08-17 09:23:51 +00:00
|
|
|
|
|
|
|
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;
|
2017-08-17 09:22:23 +00:00
|
|
|
Status status;
|
2013-08-17 09:23:51 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
};
|
|
|
|
|
2018-07-13 09:35:44 +00:00
|
|
|
class TessellationDataTransferDX9 : public TessellationDataTransfer {
|
|
|
|
public:
|
|
|
|
TessellationDataTransferDX9() {}
|
|
|
|
~TessellationDataTransferDX9() {}
|
2018-09-29 04:39:02 +00:00
|
|
|
void SendDataToShader(const SimpleVertex *const *points, int size_u, int size_v, u32 vertType, const Spline::Weight2D &weights) override;
|
2018-07-13 09:35:44 +00:00
|
|
|
};
|
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
// Handles transform, lighting and drawing.
|
2016-04-10 08:21:48 +00:00
|
|
|
class DrawEngineDX9 : public DrawEngineCommon {
|
2013-08-17 09:23:51 +00:00
|
|
|
public:
|
2017-03-02 10:39:02 +00:00
|
|
|
DrawEngineDX9(Draw::DrawContext *draw);
|
2016-04-10 08:21:48 +00:00
|
|
|
virtual ~DrawEngineDX9();
|
2014-09-17 22:40:25 +00:00
|
|
|
|
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();
|
|
|
|
|
2017-03-17 09:27:49 +00:00
|
|
|
void ClearTrackedVertexArrays() override;
|
2020-05-24 18:57:59 +00:00
|
|
|
|
|
|
|
void BeginFrame();
|
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();
|
|
|
|
}
|
|
|
|
|
2015-03-15 01:11:00 +00:00
|
|
|
void FinishDeferred() {
|
|
|
|
if (!numDrawCalls)
|
|
|
|
return;
|
2017-11-19 11:38:52 +00:00
|
|
|
DecodeVerts(decoded);
|
2015-03-15 01:11:00 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 19:37:54 +00:00
|
|
|
void DispatchFlush() override { Flush(); }
|
2014-09-14 21:04:09 +00:00
|
|
|
|
2020-04-04 18:52:32 +00:00
|
|
|
protected:
|
|
|
|
// Not currently supported.
|
|
|
|
bool UpdateUseHWTessellation(bool enable) override { return false; }
|
2020-05-24 18:57:59 +00:00
|
|
|
void DecimateTrackedVertexArrays();
|
2020-04-04 18:52:32 +00:00
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
private:
|
2014-09-13 11:53:04 +00:00
|
|
|
void DoFlush();
|
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
void ApplyDrawState(int prim);
|
2014-09-13 10:27:20 +00:00
|
|
|
void ApplyDrawStateLate();
|
2020-11-08 12:14:23 +00:00
|
|
|
void ResetFramebufferRead();
|
2014-09-13 10:27:20 +00:00
|
|
|
|
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
|
|
|
|
2014-09-14 20:50:57 +00:00
|
|
|
void MarkUnreliable(VertexArrayInfoDX9 *vai);
|
2013-08-17 09:23:51 +00:00
|
|
|
|
2017-06-02 10:03:46 +00:00
|
|
|
LPDIRECT3DDEVICE9 device_ = nullptr;
|
2020-05-24 18:57:59 +00:00
|
|
|
Draw::DrawContext *draw_;
|
2013-08-17 09:23:51 +00:00
|
|
|
|
2017-08-20 13:33:53 +00:00
|
|
|
PrehashMap<VertexArrayInfoDX9 *, nullptr> vai_;
|
|
|
|
DenseHashMap<u32, IDirect3DVertexDeclaration9 *, nullptr> vertexDeclMap_;
|
2017-02-05 18:38:52 +00:00
|
|
|
|
|
|
|
// SimpleVertex
|
2017-06-02 10:03:46 +00:00
|
|
|
IDirect3DVertexDeclaration9* transformedVertexDecl_ = nullptr;
|
2017-02-05 18:38:52 +00:00
|
|
|
|
2013-08-17 09:23:51 +00:00
|
|
|
// Other
|
2017-06-02 10:03:46 +00:00
|
|
|
ShaderManagerDX9 *shaderManager_ = nullptr;
|
|
|
|
TextureCacheDX9 *textureCache_ = nullptr;
|
|
|
|
FramebufferManagerDX9 *framebufferManager_ = nullptr;
|
2014-09-10 08:28:44 +00:00
|
|
|
|
2017-01-10 05:41:01 +00:00
|
|
|
// Hardware tessellation
|
2018-07-13 09:35:44 +00:00
|
|
|
TessellationDataTransferDX9 *tessDataTransferDX9;
|
2020-05-24 18:57:59 +00:00
|
|
|
|
|
|
|
int lastRenderStepId_ = -1;
|
2013-08-17 09:23:51 +00:00
|
|
|
};
|
|
|
|
|
2014-09-17 19:37:53 +00:00
|
|
|
} // namespace
|