2013-08-17 11:23:51 +02: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 12:46:14 +02:00
|
|
|
#include <d3d9.h>
|
2014-09-10 10:44:22 +02:00
|
|
|
|
2020-10-05 20:58:33 +02:00
|
|
|
#include "Common/Data/Collections/Hashmaps.h"
|
2015-07-26 22:38:40 +02:00
|
|
|
#include "GPU/GPUState.h"
|
2014-08-24 22:16:32 -07:00
|
|
|
#include "GPU/Common/GPUDebugInterface.h"
|
2013-09-15 12:46:14 +02:00
|
|
|
#include "GPU/Common/IndexGenerator.h"
|
2014-09-10 10:44:22 +02:00
|
|
|
#include "GPU/Common/VertexDecoderCommon.h"
|
2014-09-13 15:13:34 +02:00
|
|
|
#include "GPU/Common/DrawEngineCommon.h"
|
2015-10-24 23:49:05 +02:00
|
|
|
#include "GPU/Common/GPUStateUtils.h"
|
2013-08-17 11:23:51 +02:00
|
|
|
|
2013-09-15 08:53:21 -07:00
|
|
|
struct DecVtxFormat;
|
2015-07-26 22:38:40 +02:00
|
|
|
struct UVScale;
|
2013-09-15 08:53:21 -07:00
|
|
|
|
2014-09-10 14:07:30 +02:00
|
|
|
class VSShader;
|
2013-09-15 12:46:14 +02:00
|
|
|
class ShaderManagerDX9;
|
|
|
|
class TextureCacheDX9;
|
|
|
|
class FramebufferManagerDX9;
|
2013-08-17 11:23:51 +02: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 01:03:08 -07:00
|
|
|
enum {
|
|
|
|
VAI_FLAG_VERTEXFULLALPHA = 1,
|
|
|
|
};
|
|
|
|
|
2013-08-17 11:23:51 +02:00
|
|
|
// Try to keep this POD.
|
2013-09-15 12:46:14 +02:00
|
|
|
class VertexArrayInfoDX9 {
|
2013-08-17 11:23:51 +02:00
|
|
|
public:
|
2013-09-15 12:46:14 +02:00
|
|
|
VertexArrayInfoDX9() {
|
2013-08-17 11:23:51 +02:00
|
|
|
status = VAI_NEW;
|
|
|
|
vbo = 0;
|
|
|
|
ebo = 0;
|
2013-09-04 11:19:36 +02:00
|
|
|
prim = GE_PRIM_INVALID;
|
2013-08-17 11:23:51 +02:00
|
|
|
numDraws = 0;
|
|
|
|
numFrames = 0;
|
2013-08-17 15:11:27 +02:00
|
|
|
lastFrame = gpuStats.numFlips;
|
2013-08-17 11:23:51 +02:00
|
|
|
numVerts = 0;
|
|
|
|
drawsUntilNextFullHash = 0;
|
2014-09-09 01:03:08 -07:00
|
|
|
flags = 0;
|
2013-08-17 11:23:51 +02:00
|
|
|
}
|
2013-09-15 12:46:14 +02:00
|
|
|
~VertexArrayInfoDX9();
|
2014-09-09 01:03:08 -07:00
|
|
|
|
2017-08-17 11:22:23 +02:00
|
|
|
enum Status : uint8_t {
|
2013-08-17 11:23:51 +02:00
|
|
|
VAI_NEW,
|
|
|
|
VAI_HASHING,
|
|
|
|
VAI_RELIABLE, // cache, don't hash
|
|
|
|
VAI_UNRELIABLE, // never cache
|
|
|
|
};
|
|
|
|
|
2020-08-27 20:37:49 -07:00
|
|
|
uint64_t hash;
|
2014-09-14 13:50:57 -07:00
|
|
|
u32 minihash;
|
2013-08-17 11:23:51 +02:00
|
|
|
|
|
|
|
LPDIRECT3DVERTEXBUFFER9 vbo;
|
|
|
|
LPDIRECT3DINDEXBUFFER9 ebo;
|
|
|
|
|
2013-11-15 14:24:25 +01:00
|
|
|
// Precalculated parameter for drawRangeElements
|
2013-08-17 11:23:51 +02:00
|
|
|
u16 numVerts;
|
2013-11-15 14:24:25 +01:00
|
|
|
u16 maxIndex;
|
2013-08-17 11:23:51 +02:00
|
|
|
s8 prim;
|
2017-08-17 11:22:23 +02:00
|
|
|
Status status;
|
2013-08-17 11:23:51 +02:00
|
|
|
|
|
|
|
// ID information
|
|
|
|
int numDraws;
|
|
|
|
int numFrames;
|
|
|
|
int lastFrame; // So that we can forget.
|
|
|
|
u16 drawsUntilNextFullHash;
|
2014-09-09 01:03:08 -07:00
|
|
|
u8 flags;
|
2013-08-17 11:23:51 +02:00
|
|
|
};
|
|
|
|
|
2018-07-13 18:35:44 +09:00
|
|
|
class TessellationDataTransferDX9 : public TessellationDataTransfer {
|
|
|
|
public:
|
|
|
|
TessellationDataTransferDX9() {}
|
|
|
|
~TessellationDataTransferDX9() {}
|
2018-09-29 13:39:02 +09:00
|
|
|
void SendDataToShader(const SimpleVertex *const *points, int size_u, int size_v, u32 vertType, const Spline::Weight2D &weights) override;
|
2018-07-13 18:35:44 +09:00
|
|
|
};
|
|
|
|
|
2013-08-17 11:23:51 +02:00
|
|
|
// Handles transform, lighting and drawing.
|
2016-04-10 10:21:48 +02:00
|
|
|
class DrawEngineDX9 : public DrawEngineCommon {
|
2013-08-17 11:23:51 +02:00
|
|
|
public:
|
2017-03-02 11:39:02 +01:00
|
|
|
DrawEngineDX9(Draw::DrawContext *draw);
|
2022-12-10 20:32:12 -08:00
|
|
|
~DrawEngineDX9();
|
2014-09-18 00:40:25 +02:00
|
|
|
|
2013-09-15 12:46:14 +02:00
|
|
|
void SetShaderManager(ShaderManagerDX9 *shaderManager) {
|
2013-08-17 11:23:51 +02:00
|
|
|
shaderManager_ = shaderManager;
|
|
|
|
}
|
2013-09-15 12:46:14 +02:00
|
|
|
void SetTextureCache(TextureCacheDX9 *textureCache) {
|
2013-08-17 11:23:51 +02:00
|
|
|
textureCache_ = textureCache;
|
|
|
|
}
|
2013-09-15 12:46:14 +02:00
|
|
|
void SetFramebufferManager(FramebufferManagerDX9 *fbManager) {
|
2013-08-17 11:23:51 +02:00
|
|
|
framebufferManager_ = fbManager;
|
|
|
|
}
|
|
|
|
void InitDeviceObjects();
|
|
|
|
void DestroyDeviceObjects();
|
|
|
|
|
2017-03-17 10:27:49 +01:00
|
|
|
void ClearTrackedVertexArrays() override;
|
2020-05-24 20:57:59 +02:00
|
|
|
|
|
|
|
void BeginFrame();
|
2013-08-17 11:23:51 +02:00
|
|
|
|
2013-08-20 18:47:11 +02:00
|
|
|
// So that this can be inlined
|
|
|
|
void Flush() {
|
|
|
|
if (!numDrawCalls)
|
|
|
|
return;
|
|
|
|
DoFlush();
|
|
|
|
}
|
|
|
|
|
2015-03-14 18:11:00 -07:00
|
|
|
void FinishDeferred() {
|
|
|
|
if (!numDrawCalls)
|
|
|
|
return;
|
2017-11-19 12:38:52 +01:00
|
|
|
DecodeVerts(decoded);
|
2015-03-14 18:11:00 -07:00
|
|
|
}
|
|
|
|
|
2015-04-08 21:37:54 +02:00
|
|
|
void DispatchFlush() override { Flush(); }
|
2014-09-14 14:04:09 -07:00
|
|
|
|
2020-04-04 11:52:32 -07:00
|
|
|
protected:
|
|
|
|
// Not currently supported.
|
|
|
|
bool UpdateUseHWTessellation(bool enable) override { return false; }
|
2020-05-24 20:57:59 +02:00
|
|
|
void DecimateTrackedVertexArrays();
|
2020-04-04 11:52:32 -07:00
|
|
|
|
2013-08-17 11:23:51 +02:00
|
|
|
private:
|
2022-12-01 19:15:38 +01:00
|
|
|
void Invalidate(InvalidationCallbackFlags flags);
|
2014-09-13 13:53:04 +02:00
|
|
|
void DoFlush();
|
|
|
|
|
2013-08-17 11:23:51 +02:00
|
|
|
void ApplyDrawState(int prim);
|
2014-09-13 12:27:20 +02:00
|
|
|
void ApplyDrawStateLate();
|
|
|
|
|
2014-09-10 14:07:30 +02:00
|
|
|
IDirect3DVertexDeclaration9 *SetupDecFmtForDraw(VSShader *vshader, const DecVtxFormat &decFmt, u32 pspFmt);
|
2013-08-17 11:23:51 +02:00
|
|
|
|
2014-09-14 13:50:57 -07:00
|
|
|
void MarkUnreliable(VertexArrayInfoDX9 *vai);
|
2013-08-17 11:23:51 +02:00
|
|
|
|
2017-06-02 12:03:46 +02:00
|
|
|
LPDIRECT3DDEVICE9 device_ = nullptr;
|
2020-05-24 20:57:59 +02:00
|
|
|
Draw::DrawContext *draw_;
|
2013-08-17 11:23:51 +02:00
|
|
|
|
2017-08-20 15:33:53 +02:00
|
|
|
PrehashMap<VertexArrayInfoDX9 *, nullptr> vai_;
|
|
|
|
DenseHashMap<u32, IDirect3DVertexDeclaration9 *, nullptr> vertexDeclMap_;
|
2017-02-05 19:38:52 +01:00
|
|
|
|
|
|
|
// SimpleVertex
|
2017-06-02 12:03:46 +02:00
|
|
|
IDirect3DVertexDeclaration9* transformedVertexDecl_ = nullptr;
|
2017-02-05 19:38:52 +01:00
|
|
|
|
2013-08-17 11:23:51 +02:00
|
|
|
// Other
|
2017-06-02 12:03:46 +02:00
|
|
|
ShaderManagerDX9 *shaderManager_ = nullptr;
|
|
|
|
TextureCacheDX9 *textureCache_ = nullptr;
|
|
|
|
FramebufferManagerDX9 *framebufferManager_ = nullptr;
|
2014-09-10 10:28:44 +02:00
|
|
|
|
2017-01-10 14:41:01 +09:00
|
|
|
// Hardware tessellation
|
2018-07-13 18:35:44 +09:00
|
|
|
TessellationDataTransferDX9 *tessDataTransferDX9;
|
2020-05-24 20:57:59 +02:00
|
|
|
|
2022-02-19 20:40:27 +01:00
|
|
|
FBOTexState fboTexBindState_ = FBO_TEX_NONE;
|
|
|
|
|
2020-05-24 20:57:59 +02:00
|
|
|
int lastRenderStepId_ = -1;
|
2022-09-03 14:47:47 +02:00
|
|
|
|
|
|
|
bool fboTexNeedsBind_ = false;
|
2013-08-17 11:23:51 +02:00
|
|
|
};
|