ppsspp/GPU/Directx9/DrawEngineDX9.h

180 lines
4.3 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 <d3d9.h>
#include "Common/Data/Collections/Hashmaps.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"
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,
};
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
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
};
uint64_t hash;
u32 minihash;
2013-08-17 09:23:51 +00:00
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;
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
};
class TessellationDataTransferDX9 : public TessellationDataTransfer {
public:
TessellationDataTransferDX9() {}
~TessellationDataTransferDX9() {}
void SendDataToShader(const SimpleVertex *const *points, int size_u, int size_v, u32 vertType, const Spline::Weight2D &weights) override;
};
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:
2017-03-02 10:39:02 +00:00
DrawEngineDX9(Draw::DrawContext *draw);
virtual ~DrawEngineDX9();
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 ClearTrackedVertexArrays() override;
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();
}
void FinishDeferred() {
if (!numDrawCalls)
return;
DecodeVerts(decoded);
}
void DispatchFlush() override { Flush(); }
2014-09-14 21:04:09 +00:00
protected:
// Not currently supported.
bool UpdateUseHWTessellation(bool enable) override { return false; }
void DecimateTrackedVertexArrays();
2013-08-17 09:23:51 +00:00
private:
void DoFlush();
2013-08-17 09:23:51 +00:00
void ApplyDrawState(int prim);
void ApplyDrawStateLate();
void ResetFramebufferRead();
IDirect3DVertexDeclaration9 *SetupDecFmtForDraw(VSShader *vshader, const DecVtxFormat &decFmt, u32 pspFmt);
2013-08-17 09:23:51 +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;
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;
// Hardware tessellation
TessellationDataTransferDX9 *tessDataTransferDX9;
int lastRenderStepId_ = -1;
2013-08-17 09:23:51 +00:00
};
} // namespace