2017-02-08 17:07:34 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
2017-02-08 16:47:07 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2017-11-05 19:10:05 +00:00
|
|
|
#include <map>
|
2017-02-08 17:07:34 +00:00
|
|
|
#include <d3d11.h>
|
2017-02-18 01:14:10 +00:00
|
|
|
#include <d3d11_1.h>
|
2017-02-08 17:07:34 +00:00
|
|
|
|
2017-08-20 09:30:19 +00:00
|
|
|
#include "Common/Hashmaps.h"
|
2017-02-08 17:07:34 +00:00
|
|
|
#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/D3D11/FragmentShaderGeneratorD3D11.h"
|
2017-02-12 17:29:58 +00:00
|
|
|
#include "GPU/D3D11/StateMappingD3D11.h"
|
2017-02-08 17:07:34 +00:00
|
|
|
#include "GPU/D3D11/D3D11Util.h"
|
|
|
|
|
|
|
|
struct DecVtxFormat;
|
|
|
|
struct UVScale;
|
|
|
|
|
|
|
|
class D3D11VertexShader;
|
|
|
|
class ShaderManagerD3D11;
|
|
|
|
class TextureCacheD3D11;
|
|
|
|
class FramebufferManagerD3D11;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
enum {
|
|
|
|
VAI11_FLAG_VERTEXFULLALPHA = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Try to keep this POD.
|
|
|
|
class VertexArrayInfoD3D11 {
|
|
|
|
public:
|
|
|
|
VertexArrayInfoD3D11() {
|
|
|
|
status = VAI_NEW;
|
|
|
|
vbo = 0;
|
|
|
|
ebo = 0;
|
|
|
|
prim = GE_PRIM_INVALID;
|
|
|
|
numDraws = 0;
|
|
|
|
numFrames = 0;
|
|
|
|
lastFrame = gpuStats.numFlips;
|
|
|
|
numVerts = 0;
|
|
|
|
drawsUntilNextFullHash = 0;
|
|
|
|
flags = 0;
|
|
|
|
}
|
|
|
|
~VertexArrayInfoD3D11();
|
|
|
|
|
2017-08-17 09:22:23 +00:00
|
|
|
enum Status : uint8_t {
|
2017-02-08 17:07:34 +00:00
|
|
|
VAI_NEW,
|
|
|
|
VAI_HASHING,
|
|
|
|
VAI_RELIABLE, // cache, don't hash
|
|
|
|
VAI_UNRELIABLE, // never cache
|
|
|
|
};
|
|
|
|
|
|
|
|
ReliableHashType hash;
|
|
|
|
u32 minihash;
|
|
|
|
|
|
|
|
ID3D11Buffer *vbo;
|
|
|
|
ID3D11Buffer *ebo;
|
|
|
|
|
|
|
|
// Precalculated parameter for drawRangeElements
|
|
|
|
u16 numVerts;
|
|
|
|
u16 maxIndex;
|
|
|
|
s8 prim;
|
2017-08-17 09:22:23 +00:00
|
|
|
Status status;
|
2017-02-08 17:07:34 +00:00
|
|
|
|
|
|
|
// ID information
|
|
|
|
int numDraws;
|
|
|
|
int numFrames;
|
|
|
|
int lastFrame; // So that we can forget.
|
|
|
|
u16 drawsUntilNextFullHash;
|
|
|
|
u8 flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Handles transform, lighting and drawing.
|
|
|
|
class DrawEngineD3D11 : public DrawEngineCommon {
|
2017-02-08 16:47:07 +00:00
|
|
|
public:
|
2017-02-10 09:26:18 +00:00
|
|
|
DrawEngineD3D11(Draw::DrawContext *draw, ID3D11Device *device, ID3D11DeviceContext *context);
|
2017-02-08 17:07:34 +00:00
|
|
|
virtual ~DrawEngineD3D11();
|
|
|
|
|
|
|
|
void SubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int *bytesRead);
|
|
|
|
|
|
|
|
void SetShaderManager(ShaderManagerD3D11 *shaderManager) {
|
|
|
|
shaderManager_ = shaderManager;
|
|
|
|
}
|
|
|
|
void SetTextureCache(TextureCacheD3D11 *textureCache) {
|
|
|
|
textureCache_ = textureCache;
|
|
|
|
}
|
|
|
|
void SetFramebufferManager(FramebufferManagerD3D11 *fbManager) {
|
|
|
|
framebufferManager_ = fbManager;
|
|
|
|
}
|
|
|
|
void InitDeviceObjects();
|
|
|
|
void DestroyDeviceObjects();
|
|
|
|
|
2017-02-10 09:26:18 +00:00
|
|
|
void BeginFrame();
|
2017-02-08 17:07:34 +00:00
|
|
|
|
|
|
|
void SetupVertexDecoder(u32 vertType);
|
|
|
|
void SetupVertexDecoderInternal(u32 vertType);
|
|
|
|
|
|
|
|
// So that this can be inlined
|
|
|
|
void Flush() {
|
|
|
|
if (!numDrawCalls)
|
|
|
|
return;
|
|
|
|
DoFlush();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FinishDeferred() {
|
|
|
|
if (!numDrawCalls)
|
|
|
|
return;
|
|
|
|
DecodeVerts();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DispatchFlush() override { Flush(); }
|
|
|
|
void DispatchSubmitPrim(void *verts, void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int *bytesRead) override {
|
|
|
|
SubmitPrim(verts, inds, prim, vertexCount, vertType, bytesRead);
|
|
|
|
}
|
|
|
|
|
2017-03-17 09:27:49 +00:00
|
|
|
void ClearTrackedVertexArrays() override;
|
|
|
|
|
2017-03-17 10:26:11 +00:00
|
|
|
void Resized() override;
|
|
|
|
|
2017-02-08 17:07:34 +00:00
|
|
|
private:
|
|
|
|
void DecodeVerts();
|
|
|
|
void DoFlush();
|
|
|
|
|
|
|
|
void ApplyDrawState(int prim);
|
|
|
|
void ApplyDrawStateLate(bool applyStencilRef, uint8_t stencilRef);
|
2017-02-17 11:21:18 +00:00
|
|
|
void ResetShaderBlending();
|
2017-02-08 17:07:34 +00:00
|
|
|
|
2017-03-17 10:26:11 +00:00
|
|
|
void ClearInputLayoutMap();
|
|
|
|
|
2017-02-08 17:07:34 +00:00
|
|
|
ID3D11InputLayout *SetupDecFmtForDraw(D3D11VertexShader *vshader, const DecVtxFormat &decFmt, u32 pspFmt);
|
|
|
|
|
|
|
|
void MarkUnreliable(VertexArrayInfoD3D11 *vai);
|
|
|
|
|
2017-02-10 09:26:18 +00:00
|
|
|
Draw::DrawContext *draw_; // Used for framebuffer related things exclusively.
|
2017-02-08 17:07:34 +00:00
|
|
|
ID3D11Device *device_;
|
2017-02-18 01:14:10 +00:00
|
|
|
ID3D11Device1 *device1_;
|
2017-02-08 17:07:34 +00:00
|
|
|
ID3D11DeviceContext *context_;
|
2017-02-18 01:14:10 +00:00
|
|
|
ID3D11DeviceContext1 *context1_;
|
2017-02-08 17:07:34 +00:00
|
|
|
|
2017-08-20 13:33:53 +00:00
|
|
|
PrehashMap<VertexArrayInfoD3D11 *, nullptr> vai_;
|
2017-02-08 17:07:34 +00:00
|
|
|
|
2017-02-10 09:26:18 +00:00
|
|
|
struct InputLayoutKey {
|
|
|
|
D3D11VertexShader *vshader;
|
2017-04-04 09:09:29 +00:00
|
|
|
u32 vertType;
|
2017-02-10 09:26:18 +00:00
|
|
|
bool operator <(const InputLayoutKey &other) const {
|
|
|
|
if (vertType < other.vertType)
|
|
|
|
return true;
|
|
|
|
if (vertType > other.vertType)
|
|
|
|
return false;
|
|
|
|
return vshader < other.vshader;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-08-20 13:33:53 +00:00
|
|
|
DenseHashMap<InputLayoutKey, ID3D11InputLayout *, nullptr> inputLayoutMap_;
|
2017-02-08 17:07:34 +00:00
|
|
|
|
|
|
|
// Other
|
2017-06-02 10:03:46 +00:00
|
|
|
ShaderManagerD3D11 *shaderManager_ = nullptr;
|
|
|
|
TextureCacheD3D11 *textureCache_ = nullptr;
|
|
|
|
FramebufferManagerD3D11 *framebufferManager_ = nullptr;
|
2017-02-08 17:07:34 +00:00
|
|
|
|
|
|
|
// Pushbuffers
|
|
|
|
PushBufferD3D11 *pushVerts_;
|
|
|
|
PushBufferD3D11 *pushInds_;
|
|
|
|
|
2017-11-05 19:10:05 +00:00
|
|
|
// D3D11 state object caches.
|
|
|
|
// TODO: Change them to DenseHashMaps.
|
2017-02-13 00:22:55 +00:00
|
|
|
std::map<uint64_t, ID3D11BlendState *> blendCache_;
|
2017-02-18 01:14:10 +00:00
|
|
|
std::map<uint64_t, ID3D11BlendState1 *> blendCache1_;
|
2017-02-13 00:22:55 +00:00
|
|
|
std::map<uint64_t, ID3D11DepthStencilState *> depthStencilCache_;
|
2017-02-08 17:07:34 +00:00
|
|
|
std::map<uint32_t, ID3D11RasterizerState *> rasterCache_;
|
|
|
|
|
2017-02-09 23:37:56 +00:00
|
|
|
// Keep the depth state between ApplyDrawState and ApplyDrawStateLate
|
2017-02-18 01:14:10 +00:00
|
|
|
ID3D11RasterizerState *rasterState_ = nullptr;
|
|
|
|
ID3D11BlendState *blendState_ = nullptr;
|
|
|
|
ID3D11BlendState1 *blendState1_ = nullptr;
|
|
|
|
ID3D11DepthStencilState *depthStencilState_ = nullptr;
|
2017-02-09 23:37:56 +00:00
|
|
|
|
2017-02-12 17:29:58 +00:00
|
|
|
// State keys
|
|
|
|
D3D11StateKeys keys_{};
|
|
|
|
D3D11DynamicState dynState_{};
|
|
|
|
|
2017-02-08 17:07:34 +00:00
|
|
|
// Hardware tessellation
|
|
|
|
class TessellationDataTransferD3D11 : public TessellationDataTransfer {
|
|
|
|
private:
|
2017-03-04 13:46:55 +00:00
|
|
|
ID3D11DeviceContext *context_;
|
|
|
|
ID3D11Device *device_;
|
|
|
|
ID3D11Texture1D *data_tex[3];
|
|
|
|
ID3D11ShaderResourceView *view[3];
|
|
|
|
D3D11_TEXTURE1D_DESC desc;
|
|
|
|
D3D11_BOX dstBox;
|
2017-02-08 17:07:34 +00:00
|
|
|
public:
|
2017-03-04 13:46:55 +00:00
|
|
|
TessellationDataTransferD3D11(ID3D11DeviceContext *context_, ID3D11Device *device_)
|
|
|
|
: TessellationDataTransfer(), context_(context_), device_(device_), data_tex(), view(), desc(), dstBox{0, 0, 0, 1, 1, 1} {
|
|
|
|
desc.CPUAccessFlags = 0;
|
|
|
|
desc.Usage = D3D11_USAGE_DEFAULT;
|
|
|
|
desc.ArraySize = 1;
|
|
|
|
desc.MipLevels = 1;
|
|
|
|
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
2017-02-08 17:07:34 +00:00
|
|
|
}
|
|
|
|
~TessellationDataTransferD3D11() {
|
2017-03-04 13:46:55 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
if (data_tex[i]) {
|
|
|
|
data_tex[i]->Release();
|
|
|
|
view[i]->Release();
|
|
|
|
}
|
|
|
|
}
|
2017-02-08 17:07:34 +00:00
|
|
|
}
|
|
|
|
void SendDataToShader(const float *pos, const float *tex, const float *col, int size, bool hasColor, bool hasTexCoords) override;
|
|
|
|
};
|
|
|
|
};
|