mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
DX11: Introduce a StateManager class, might improve performance a little.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5740 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -20,8 +20,11 @@
|
||||
#include <d3d11.h>
|
||||
#include "Common.h"
|
||||
#include "D3DBlob.h"
|
||||
#include "GfxState.h"
|
||||
|
||||
#define SAFE_RELEASE(x) { if (x) (x)->Release(); (x) = NULL; }
|
||||
#define SAFE_DELETE(x) { if (x) delete (x); (x) = NULL; }
|
||||
#define SAFE_DELETE_ARRAY(x) { if (x) delete[] (x); (x) = NULL; }
|
||||
#define CHECK(cond, Message, ...) if (!(cond)) { PanicAlert(__FUNCTION__ "Failed in %s at line %d: " Message, __FILE__, __LINE__, __VA_ARGS__); }
|
||||
|
||||
class D3DTexture2D;
|
||||
@ -57,81 +60,4 @@ inline void SetDebugObjectName(ID3D11DeviceChild* resource, const char* name)
|
||||
#endif
|
||||
}
|
||||
|
||||
// stores the pipeline state to use when calling VertexManager::Flush()
|
||||
class EmuGfxState
|
||||
{
|
||||
public:
|
||||
EmuGfxState();
|
||||
~EmuGfxState();
|
||||
|
||||
void SetVShader(ID3D11VertexShader* shader, D3DBlob* bcode);
|
||||
void SetPShader(ID3D11PixelShader* shader);
|
||||
void SetInputElements(const D3D11_INPUT_ELEMENT_DESC* elems, UINT num);
|
||||
void SetShaderResource(int stage, ID3D11ShaderResourceView* srv);
|
||||
|
||||
void ApplyState(); // apply current state
|
||||
void AlphaPass(); // only modify the current state to enable the alpha pass
|
||||
void ResetShaderResources(); // disable all shader resources
|
||||
|
||||
// blend state
|
||||
void SetAlphaBlendEnable(bool enable);
|
||||
void SetRenderTargetWriteMask(UINT8 mask);
|
||||
void SetSrcBlend(D3D11_BLEND val) // TODO: Check whether e.g. the dest color check is needed here
|
||||
{
|
||||
blenddesc.RenderTarget[0].SrcBlend = val;
|
||||
if (val == D3D11_BLEND_SRC_COLOR) blenddesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
|
||||
else if (val == D3D11_BLEND_INV_SRC_COLOR) blenddesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
else if (val == D3D11_BLEND_DEST_COLOR) blenddesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
|
||||
else if (val == D3D11_BLEND_INV_DEST_COLOR) blenddesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
|
||||
else blenddesc.RenderTarget[0].SrcBlendAlpha = val;
|
||||
}
|
||||
void SetDestBlend(D3D11_BLEND val)
|
||||
{
|
||||
blenddesc.RenderTarget[0].DestBlend = val;
|
||||
if (val == D3D11_BLEND_SRC_COLOR) blenddesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_SRC_ALPHA;
|
||||
else if (val == D3D11_BLEND_INV_SRC_COLOR) blenddesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
else if (val == D3D11_BLEND_DEST_COLOR) blenddesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
|
||||
else if (val == D3D11_BLEND_INV_DEST_COLOR) blenddesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
|
||||
else blenddesc.RenderTarget[0].DestBlendAlpha = val;
|
||||
}
|
||||
void SetBlendOp(D3D11_BLEND_OP val)
|
||||
{
|
||||
blenddesc.RenderTarget[0].BlendOp = val;
|
||||
blenddesc.RenderTarget[0].BlendOpAlpha = val;
|
||||
}
|
||||
|
||||
// sampler states
|
||||
void SetSamplerFilter(DWORD stage, D3D11_FILTER filter) { samplerdesc[stage].Filter = filter; }
|
||||
|
||||
// TODO: add methods for changing the other states instead of modifying them directly
|
||||
|
||||
D3D11_SAMPLER_DESC samplerdesc[8];
|
||||
D3D11_RASTERIZER_DESC rastdesc;
|
||||
D3D11_DEPTH_STENCIL_DESC depthdesc;
|
||||
|
||||
float psconstants[116];
|
||||
float vsconstants[952];
|
||||
bool vscbufchanged;
|
||||
bool pscbufchanged;
|
||||
|
||||
private:
|
||||
ID3D11VertexShader* vertexshader;
|
||||
D3DBlob* vsbytecode;
|
||||
ID3D11PixelShader* pixelshader;
|
||||
D3DBlob* psbytecode;
|
||||
bool vshaderchanged;
|
||||
|
||||
ID3D11Buffer* vscbuf;
|
||||
ID3D11Buffer* pscbuf;
|
||||
|
||||
ID3D11InputLayout* inp_layout;
|
||||
D3D11_INPUT_ELEMENT_DESC inp_elems[32];
|
||||
int num_inp_elems;
|
||||
|
||||
ID3D11ShaderResourceView* shader_resources[8];
|
||||
D3D11_BLEND_DESC blenddesc;
|
||||
};
|
||||
|
||||
extern EmuGfxState* gfxstate;
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user