1 #pragma once
2 
3 #include <cstdint>
4 #include <d3d11.h>
5 
6 #include "Common/GPU/thin3d.h"
7 
8 // TODO: Do this more progressively. No need to compute the entire state if the entire state hasn't changed.
9 
10 struct D3D11BlendKey {
11 	union {
12 		uint64_t value;
13 		struct {
14 			// Blend
15 			unsigned int blendEnable : 1;
16 			unsigned int srcColor : 5;  // D3D11_BLEND
17 			unsigned int destColor : 5;  // D3D11_BLEND
18 			unsigned int srcAlpha : 5;  // D3D11_BLEND
19 			unsigned int destAlpha : 5;  // D3D11_BLEND
20 			unsigned int blendOpColor : 3;  // D3D11_BLEND_OP
21 			unsigned int blendOpAlpha : 3;  // D3D11_BLEND_OP
22 			unsigned int logicOpEnable : 1;
23 			unsigned int logicOp : 4;  // D3D11_LOGIC_OP
24 			unsigned int colorWriteMask : 4;
25 		};
26 	};
27 };
28 
29 struct D3D11DepthStencilKey {
30 	union {
31 		uint64_t value;
32 		struct {
33 			// Depth/Stencil
34 			unsigned int depthTestEnable : 1;
35 			unsigned int depthWriteEnable : 1;
36 			unsigned int depthCompareOp : 4;  // D3D11_COMPARISON   (-1 and we could fit it in 3 bits)
37 			unsigned int stencilTestEnable : 1;
38 			unsigned int stencilCompareFunc : 4;  // D3D11_COMPARISON
39 			unsigned int stencilPassOp : 4; // D3D11_STENCIL_OP
40 			unsigned int stencilFailOp : 4; // D3D11_STENCIL_OP
41 			unsigned int stencilDepthFailOp : 4;  // D3D11_STENCIL_OP
42 			unsigned int stencilWriteMask : 8;  // Unfortunately these are baked into the state on D3D11
43 			unsigned int stencilCompareMask : 8;
44 		};
45 	};
46 };
47 
48 struct D3D11RasterKey {
49 	union {
50 		uint32_t value;
51 		struct {
52 			unsigned int cullMode : 2;  // D3D11_CULL_MODE
53 			unsigned int depthClipEnable : 1;
54 		};
55 	};
56 };
57 
58 // In D3D11 we cache blend state objects etc, and we simply emit keys, which are then also used to create these objects.
59 struct D3D11StateKeys {
60 	D3D11BlendKey blend;
61 	D3D11DepthStencilKey depthStencil;
62 	D3D11RasterKey raster;
63 };
64 
65 struct D3D11DynamicState {
66 	int topology;
67 	bool useBlendColor;
68 	uint32_t blendColor;
69 	bool useStencil;
70 	uint8_t stencilRef;
71 	Draw::Viewport viewport;
72 	D3D11_RECT scissor;
73 };
74