#pragma once
#include <d3d11.h>
#include <d3d11_1.h>
#include <wrl/client.h>
#include "Common/Data/Collections/Hashmaps.h"
#include "GPU/Common/VertexDecoderCommon.h"
#include "GPU/Common/DrawEngineCommon.h"
#include "GPU/D3D11/StateMappingD3D11.h"
#include "GPU/D3D11/D3D11Util.h"
struct DecVtxFormat;
struct UVScale;
class D3D11VertexShader;
class ShaderManagerD3D11;
class TextureCacheD3D11;
class FramebufferManagerD3D11;
class TessellationDataTransferD3D11 : public TessellationDataTransfer {
private:
ID3D11DeviceContext *context_;
ID3D11Device *device_;
Microsoft::WRL::ComPtr<ID3D11Buffer> buf[3]{};
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> view[3]{};
D3D11_BUFFER_DESC desc{};
int prevSize = 0;
int prevSizeWU = 0, prevSizeWV = 0;
public:
TessellationDataTransferD3D11(ID3D11DeviceContext *context, ID3D11Device *device);
~TessellationDataTransferD3D11();
void SendDataToShader(const SimpleVertex *const *points, int size_u, int size_v, u32 vertType, const Spline::Weight2D &weights) override;
};
class DrawEngineD3D11 : public DrawEngineCommon {
public:
DrawEngineD3D11(Draw::DrawContext *draw, ID3D11Device *device, ID3D11DeviceContext *context);
~DrawEngineD3D11();
void DeviceLost() override;
void DeviceRestore(Draw::DrawContext *draw) override;
void SetShaderManager(ShaderManagerD3D11 *shaderManager) {
shaderManager_ = shaderManager;
}
void SetTextureCache(TextureCacheD3D11 *textureCache) {
textureCache_ = textureCache;
}
void SetFramebufferManager(FramebufferManagerD3D11 *fbManager) {
framebufferManager_ = fbManager;
}
void InitDeviceObjects();
void DestroyDeviceObjects();
void BeginFrame() override;
void Flush() override;
void FinishDeferred() {
DecodeVerts(dec_, decoded_);
}
void NotifyConfigChanged() override;
void ClearInputLayoutMap();
private:
void Invalidate(InvalidationCallbackFlags flags);
void ApplyDrawState(int prim);
void ApplyDrawStateLate(bool applyStencilRef, uint8_t stencilRef);
HRESULT SetupDecFmtForDraw(D3D11VertexShader *vshader, const DecVtxFormat &decFmt, u32 pspFmt, ID3D11InputLayout **);
Draw::DrawContext *draw_;
ID3D11Device *device_;
ID3D11Device1 *device1_;
ID3D11DeviceContext *context_;
ID3D11DeviceContext1 *context1_;
struct InputLayoutKey {
D3D11VertexShader *vshader;
u32 decFmtId;
bool operator <(const InputLayoutKey &other) const {
if (decFmtId < other.decFmtId)
return true;
if (decFmtId > other.decFmtId)
return false;
return vshader < other.vshader;
}
};
DenseHashMap<InputLayoutKey, ID3D11InputLayout *> inputLayoutMap_;
ShaderManagerD3D11 *shaderManager_ = nullptr;
TextureCacheD3D11 *textureCache_ = nullptr;
FramebufferManagerD3D11 *framebufferManager_ = nullptr;
PushBufferD3D11 *pushVerts_ = nullptr;
PushBufferD3D11 *pushInds_ = nullptr;
DenseHashMap<uint64_t, ID3D11BlendState *> blendCache_;
DenseHashMap<uint64_t, ID3D11BlendState1 *> blendCache1_;
DenseHashMap<uint64_t, ID3D11DepthStencilState *> depthStencilCache_;
DenseHashMap<uint32_t, ID3D11RasterizerState *> rasterCache_;
ID3D11BlendState *blendState_ = nullptr;
ID3D11BlendState1 *blendState1_ = nullptr;
ID3D11DepthStencilState *depthStencilState_ = nullptr;
ID3D11RasterizerState *rasterState_ = nullptr;
D3D11StateKeys keys_{};
D3D11DynamicState dynState_{};
TessellationDataTransferD3D11 *tessDataTransferD3D11 = nullptr;
int lastRenderStepId_ = -1;
};