mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 03:59:36 +00:00
Add Roboto font, misc icons and text things
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
static unsigned char gs_shaderData[] = {
|
||||
68, 88, 66, 67, 181, 133, 124, 121, 179, 141, 64, 216, 166, 21, 153,
|
||||
10, 33, 21, 80, 169, 1, 0, 0, 0, 152, 2, 0, 0, 5, 0,
|
||||
0, 0, 52, 0, 0, 0, 224, 0, 0, 0, 56, 1, 0, 0, 108,
|
||||
1, 0, 0, 28, 2, 0, 0, 82, 68, 69, 70, 164, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 28, 0, 0,
|
||||
0, 0, 4, 255, 255, 0, 137, 0, 0, 122, 0, 0, 0, 92, 0,
|
||||
0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
|
||||
107, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 4, 0, 0,
|
||||
0, 255, 255, 255, 255, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0,
|
||||
0, 0, 115, 117, 114, 102, 97, 99, 101, 83, 97, 109, 112, 108, 101,
|
||||
114, 0, 115, 117, 114, 102, 97, 99, 101, 84, 101, 120, 116, 117, 114,
|
||||
101, 0, 77, 105, 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41,
|
||||
32, 72, 76, 83, 76, 32, 83, 104, 97, 100, 101, 114, 32, 67, 111,
|
||||
109, 112, 105, 108, 101, 114, 32, 49, 48, 46, 49, 0, 171, 171, 73,
|
||||
83, 71, 78, 80, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0,
|
||||
56, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0,
|
||||
0, 0, 0, 0, 0, 15, 0, 0, 0, 68, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3,
|
||||
3, 0, 0, 83, 86, 95, 80, 79, 83, 73, 84, 73, 79, 78, 0,
|
||||
84, 69, 88, 67, 79, 79, 82, 68, 0, 171, 171, 171, 79, 83, 71,
|
||||
78, 44, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0, 0, 32, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0,
|
||||
0, 0, 0, 15, 0, 0, 0, 83, 86, 95, 84, 65, 82, 71, 69,
|
||||
84, 0, 171, 171, 83, 72, 68, 82, 168, 0, 0, 0, 64, 0, 0,
|
||||
0, 42, 0, 0, 0, 90, 0, 0, 3, 0, 96, 16, 0, 0, 0,
|
||||
0, 0, 88, 24, 0, 4, 0, 112, 16, 0, 0, 0, 0, 0, 85,
|
||||
85, 0, 0, 98, 16, 0, 3, 50, 16, 16, 0, 1, 0, 0, 0,
|
||||
101, 0, 0, 3, 242, 32, 16, 0, 0, 0, 0, 0, 104, 0, 0,
|
||||
2, 1, 0, 0, 0, 69, 0, 0, 9, 242, 0, 16, 0, 0, 0,
|
||||
0, 0, 70, 16, 16, 0, 1, 0, 0, 0, 70, 126, 16, 0, 0,
|
||||
0, 0, 0, 0, 96, 16, 0, 0, 0, 0, 0, 54, 0, 0, 5,
|
||||
18, 32, 16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 0, 0, 0,
|
||||
0, 54, 0, 0, 5, 98, 32, 16, 0, 0, 0, 0, 0, 6, 17,
|
||||
16, 0, 1, 0, 0, 0, 54, 0, 0, 5, 130, 32, 16, 0, 0,
|
||||
0, 0, 0, 1, 64, 0, 0, 0, 0, 128, 63, 62, 0, 0, 1,
|
||||
83, 84, 65, 84, 116, 0, 0, 0, 5, 0, 0, 0, 1, 0, 0,
|
||||
0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
};
|
||||
|
||||
namespace GpBinarizedShaders
|
||||
{
|
||||
const unsigned char *g_drawQuad15BitP_D3D11[2] = { gs_shaderData, gs_shaderData + sizeof(gs_shaderData) };
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
static unsigned char gs_shaderData[] = {
|
||||
68, 88, 66, 67, 96, 46, 192, 91, 73, 216, 92, 145, 77, 166, 215,
|
||||
215, 59, 255, 4, 67, 1, 0, 0, 0, 240, 2, 0, 0, 5, 0,
|
||||
0, 0, 52, 0, 0, 0, 224, 0, 0, 0, 56, 1, 0, 0, 108,
|
||||
1, 0, 0, 116, 2, 0, 0, 82, 68, 69, 70, 164, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 28, 0, 0,
|
||||
0, 0, 4, 255, 255, 0, 137, 0, 0, 122, 0, 0, 0, 92, 0,
|
||||
0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 255,
|
||||
255, 255, 255, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
|
||||
107, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 2, 0, 0,
|
||||
0, 255, 255, 255, 255, 1, 0, 0, 0, 1, 0, 0, 0, 13, 0,
|
||||
0, 0, 115, 117, 114, 102, 97, 99, 101, 84, 101, 120, 116, 117, 114,
|
||||
101, 0, 112, 97, 108, 101, 116, 116, 101, 84, 101, 120, 116, 117, 114,
|
||||
101, 0, 77, 105, 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41,
|
||||
32, 72, 76, 83, 76, 32, 83, 104, 97, 100, 101, 114, 32, 67, 111,
|
||||
109, 112, 105, 108, 101, 114, 32, 49, 48, 46, 49, 0, 171, 171, 73,
|
||||
83, 71, 78, 80, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0,
|
||||
56, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0,
|
||||
0, 0, 0, 0, 0, 15, 0, 0, 0, 68, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3,
|
||||
3, 0, 0, 83, 86, 95, 80, 79, 83, 73, 84, 73, 79, 78, 0,
|
||||
84, 69, 88, 67, 79, 79, 82, 68, 0, 171, 171, 171, 79, 83, 71,
|
||||
78, 44, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0, 0, 32, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0,
|
||||
0, 0, 0, 15, 0, 0, 0, 83, 86, 95, 84, 65, 82, 71, 69,
|
||||
84, 0, 171, 171, 83, 72, 68, 82, 0, 1, 0, 0, 64, 0, 0,
|
||||
0, 64, 0, 0, 0, 88, 24, 0, 4, 0, 112, 16, 0, 0, 0,
|
||||
0, 0, 68, 68, 0, 0, 88, 16, 0, 4, 0, 112, 16, 0, 1,
|
||||
0, 0, 0, 85, 85, 0, 0, 98, 16, 0, 3, 50, 16, 16, 0,
|
||||
1, 0, 0, 0, 101, 0, 0, 3, 242, 32, 16, 0, 0, 0, 0,
|
||||
0, 104, 0, 0, 2, 1, 0, 0, 0, 27, 0, 0, 5, 50, 0,
|
||||
16, 0, 0, 0, 0, 0, 70, 16, 16, 0, 1, 0, 0, 0, 54,
|
||||
0, 0, 8, 194, 0, 16, 0, 0, 0, 0, 0, 2, 64, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 45, 0, 0, 7, 242, 0, 16, 0, 0, 0, 0, 0, 70, 14,
|
||||
16, 0, 0, 0, 0, 0, 70, 126, 16, 0, 0, 0, 0, 0, 54,
|
||||
0, 0, 8, 226, 0, 16, 0, 0, 0, 0, 0, 2, 64, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 45, 0, 0, 7, 242, 0, 16, 0, 0, 0, 0, 0, 70, 14,
|
||||
16, 0, 0, 0, 0, 0, 70, 126, 16, 0, 1, 0, 0, 0, 54,
|
||||
0, 0, 5, 114, 32, 16, 0, 0, 0, 0, 0, 70, 2, 16, 0,
|
||||
0, 0, 0, 0, 54, 0, 0, 5, 130, 32, 16, 0, 0, 0, 0,
|
||||
0, 1, 64, 0, 0, 0, 0, 128, 63, 62, 0, 0, 1, 83, 84,
|
||||
65, 84, 116, 0, 0, 0, 8, 0, 0, 0, 1, 0, 0, 0, 0,
|
||||
0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0,
|
||||
};
|
||||
|
||||
namespace GpBinarizedShaders
|
||||
{
|
||||
const unsigned char *g_drawQuadPaletteP_D3D11[2] = { gs_shaderData, gs_shaderData + sizeof(gs_shaderData) };
|
||||
};
|
||||
52
GpDisplayDriver_D3D11/CompiledShaders/DrawQuadRGBP_D3D11.cpp
Normal file
52
GpDisplayDriver_D3D11/CompiledShaders/DrawQuadRGBP_D3D11.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
static unsigned char gs_shaderData[] = {
|
||||
68, 88, 66, 67, 181, 133, 124, 121, 179, 141, 64, 216, 166, 21, 153,
|
||||
10, 33, 21, 80, 169, 1, 0, 0, 0, 152, 2, 0, 0, 5, 0,
|
||||
0, 0, 52, 0, 0, 0, 224, 0, 0, 0, 56, 1, 0, 0, 108,
|
||||
1, 0, 0, 28, 2, 0, 0, 82, 68, 69, 70, 164, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 28, 0, 0,
|
||||
0, 0, 4, 255, 255, 0, 137, 0, 0, 122, 0, 0, 0, 92, 0,
|
||||
0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
|
||||
107, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 4, 0, 0,
|
||||
0, 255, 255, 255, 255, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0,
|
||||
0, 0, 115, 117, 114, 102, 97, 99, 101, 83, 97, 109, 112, 108, 101,
|
||||
114, 0, 115, 117, 114, 102, 97, 99, 101, 84, 101, 120, 116, 117, 114,
|
||||
101, 0, 77, 105, 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41,
|
||||
32, 72, 76, 83, 76, 32, 83, 104, 97, 100, 101, 114, 32, 67, 111,
|
||||
109, 112, 105, 108, 101, 114, 32, 49, 48, 46, 49, 0, 171, 171, 73,
|
||||
83, 71, 78, 80, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0,
|
||||
56, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0,
|
||||
0, 0, 0, 0, 0, 15, 0, 0, 0, 68, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3,
|
||||
3, 0, 0, 83, 86, 95, 80, 79, 83, 73, 84, 73, 79, 78, 0,
|
||||
84, 69, 88, 67, 79, 79, 82, 68, 0, 171, 171, 171, 79, 83, 71,
|
||||
78, 44, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0, 0, 32, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0,
|
||||
0, 0, 0, 15, 0, 0, 0, 83, 86, 95, 84, 65, 82, 71, 69,
|
||||
84, 0, 171, 171, 83, 72, 68, 82, 168, 0, 0, 0, 64, 0, 0,
|
||||
0, 42, 0, 0, 0, 90, 0, 0, 3, 0, 96, 16, 0, 0, 0,
|
||||
0, 0, 88, 24, 0, 4, 0, 112, 16, 0, 0, 0, 0, 0, 85,
|
||||
85, 0, 0, 98, 16, 0, 3, 50, 16, 16, 0, 1, 0, 0, 0,
|
||||
101, 0, 0, 3, 242, 32, 16, 0, 0, 0, 0, 0, 104, 0, 0,
|
||||
2, 1, 0, 0, 0, 69, 0, 0, 9, 242, 0, 16, 0, 0, 0,
|
||||
0, 0, 70, 16, 16, 0, 1, 0, 0, 0, 70, 126, 16, 0, 0,
|
||||
0, 0, 0, 0, 96, 16, 0, 0, 0, 0, 0, 54, 0, 0, 5,
|
||||
18, 32, 16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 0, 0, 0,
|
||||
0, 54, 0, 0, 5, 98, 32, 16, 0, 0, 0, 0, 0, 6, 17,
|
||||
16, 0, 1, 0, 0, 0, 54, 0, 0, 5, 130, 32, 16, 0, 0,
|
||||
0, 0, 0, 1, 64, 0, 0, 0, 0, 128, 63, 62, 0, 0, 1,
|
||||
83, 84, 65, 84, 116, 0, 0, 0, 5, 0, 0, 0, 1, 0, 0,
|
||||
0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
};
|
||||
|
||||
namespace GpBinarizedShaders
|
||||
{
|
||||
const unsigned char *g_drawQuadRGBP_D3D11[2] = { gs_shaderData, gs_shaderData + sizeof(gs_shaderData) };
|
||||
};
|
||||
59
GpDisplayDriver_D3D11/CompiledShaders/DrawQuadV_D3D11.cpp
Normal file
59
GpDisplayDriver_D3D11/CompiledShaders/DrawQuadV_D3D11.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
static unsigned char gs_shaderData[] = {
|
||||
68, 88, 66, 67, 201, 152, 69, 241, 255, 40, 36, 8, 50, 11, 168,
|
||||
246, 127, 135, 38, 130, 1, 0, 0, 0, 8, 3, 0, 0, 5, 0,
|
||||
0, 0, 52, 0, 0, 0, 72, 1, 0, 0, 124, 1, 0, 0, 212,
|
||||
1, 0, 0, 140, 2, 0, 0, 82, 68, 69, 70, 12, 1, 0, 0,
|
||||
1, 0, 0, 0, 88, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0,
|
||||
0, 0, 4, 254, 255, 0, 137, 0, 0, 225, 0, 0, 0, 60, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
|
||||
83, 68, 114, 97, 119, 81, 117, 97, 100, 86, 101, 114, 116, 101, 120,
|
||||
67, 111, 110, 115, 116, 97, 110, 116, 115, 0, 171, 171, 171, 60, 0,
|
||||
0, 0, 2, 0, 0, 0, 112, 0, 0, 0, 32, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 160, 0, 0, 0, 0, 0, 0, 0,
|
||||
16, 0, 0, 0, 2, 0, 0, 0, 184, 0, 0, 0, 0, 0, 0,
|
||||
0, 200, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 2, 0,
|
||||
0, 0, 184, 0, 0, 0, 0, 0, 0, 0, 110, 100, 99, 79, 114,
|
||||
105, 103, 105, 110, 65, 110, 100, 68, 105, 109, 101, 110, 115, 105, 111,
|
||||
110, 115, 0, 171, 1, 0, 3, 0, 1, 0, 4, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 115, 117, 114, 102, 97, 99, 101, 68, 105, 109,
|
||||
101, 110, 115, 105, 111, 110, 115, 95, 85, 110, 117, 115, 101, 100, 0,
|
||||
77, 105, 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41, 32, 72,
|
||||
76, 83, 76, 32, 83, 104, 97, 100, 101, 114, 32, 67, 111, 109, 112,
|
||||
105, 108, 101, 114, 32, 49, 48, 46, 49, 0, 171, 171, 171, 73, 83,
|
||||
71, 78, 44, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0, 0, 32,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0,
|
||||
0, 0, 0, 0, 3, 3, 0, 0, 80, 79, 83, 73, 84, 73, 79,
|
||||
78, 0, 171, 171, 171, 79, 83, 71, 78, 80, 0, 0, 0, 2, 0,
|
||||
0, 0, 8, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||
0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0,
|
||||
68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0,
|
||||
0, 1, 0, 0, 0, 3, 12, 0, 0, 83, 86, 95, 80, 79, 83,
|
||||
73, 84, 73, 79, 78, 0, 84, 69, 88, 67, 79, 79, 82, 68, 0,
|
||||
171, 171, 171, 83, 72, 68, 82, 176, 0, 0, 0, 64, 0, 1, 0,
|
||||
44, 0, 0, 0, 89, 0, 0, 4, 70, 142, 32, 0, 0, 0, 0,
|
||||
0, 2, 0, 0, 0, 95, 0, 0, 3, 50, 16, 16, 0, 0, 0,
|
||||
0, 0, 103, 0, 0, 4, 242, 32, 16, 0, 0, 0, 0, 0, 1,
|
||||
0, 0, 0, 101, 0, 0, 3, 50, 32, 16, 0, 1, 0, 0, 0,
|
||||
50, 0, 0, 11, 50, 32, 16, 0, 0, 0, 0, 0, 70, 16, 16,
|
||||
0, 0, 0, 0, 0, 230, 138, 32, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 70, 128, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 54,
|
||||
0, 0, 8, 194, 32, 16, 0, 0, 0, 0, 0, 2, 64, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128,
|
||||
63, 56, 0, 0, 8, 50, 32, 16, 0, 1, 0, 0, 0, 70, 16,
|
||||
16, 0, 0, 0, 0, 0, 70, 128, 32, 0, 0, 0, 0, 0, 1,
|
||||
0, 0, 0, 62, 0, 0, 1, 83, 84, 65, 84, 116, 0, 0, 0,
|
||||
4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0,
|
||||
0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
namespace GpBinarizedShaders
|
||||
{
|
||||
const unsigned char *g_drawQuadV_D3D11[2] = { gs_shaderData, gs_shaderData + sizeof(gs_shaderData) };
|
||||
};
|
||||
787
GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp
Normal file
787
GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp
Normal file
@@ -0,0 +1,787 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include "GpDisplayDriverD3D11.h"
|
||||
#include "GpDisplayDriverSurfaceD3D11.h"
|
||||
#include "GpWindows.h"
|
||||
#include "IGpColorCursor_Win32.h"
|
||||
#include "IGpFiber.h"
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi1_2.h>
|
||||
#include <float.h>
|
||||
#include <emmintrin.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <new>
|
||||
|
||||
#pragma comment (lib, "d3d11.lib")
|
||||
|
||||
namespace GpBinarizedShaders
|
||||
{
|
||||
extern const unsigned char *g_drawQuadV_D3D11[2];
|
||||
extern const unsigned char *g_drawQuadPaletteP_D3D11[2];
|
||||
extern const unsigned char *g_drawQuadRGBP_D3D11[2];
|
||||
extern const unsigned char *g_drawQuad15BitP_D3D11[2];
|
||||
}
|
||||
|
||||
struct GpShaderCodeBlob
|
||||
{
|
||||
const void *m_data;
|
||||
size_t m_size;
|
||||
};
|
||||
|
||||
static GpShaderCodeBlob GetBinarizedShader(const unsigned char **shaderPointers)
|
||||
{
|
||||
GpShaderCodeBlob blob;
|
||||
blob.m_data = shaderPointers[0];
|
||||
blob.m_size = shaderPointers[1] - shaderPointers[0];
|
||||
|
||||
return blob;
|
||||
}
|
||||
|
||||
void DebugPrintf(const char *fmt, ...)
|
||||
{
|
||||
char buf[256];
|
||||
va_list argp;
|
||||
va_start(argp, fmt);
|
||||
vsnprintf_s(buf, 255, fmt, argp);
|
||||
OutputDebugString(buf);
|
||||
va_end(argp);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
case WM_DESTROY:
|
||||
{
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
void StartD3DForWindow(HWND hWnd, GpComPtr<IDXGISwapChain1>& outSwapChain, GpComPtr<ID3D11Device>& outDevice, GpComPtr<ID3D11DeviceContext>& outContext)
|
||||
{
|
||||
DXGI_SWAP_CHAIN_DESC1 swapChainDesc;
|
||||
|
||||
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
|
||||
|
||||
swapChainDesc.BufferCount = 2;
|
||||
swapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
swapChainDesc.SampleDesc.Count = 1;
|
||||
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
||||
|
||||
DXGI_SWAP_CHAIN_FULLSCREEN_DESC swapChainFullscreenDesc;
|
||||
|
||||
ZeroMemory(&swapChainFullscreenDesc, sizeof(swapChainFullscreenDesc));
|
||||
|
||||
swapChainFullscreenDesc.Windowed = TRUE;
|
||||
swapChainFullscreenDesc.RefreshRate.Numerator = 60;
|
||||
swapChainFullscreenDesc.RefreshRate.Denominator = 1;
|
||||
|
||||
UINT flags = 0;
|
||||
const D3D_FEATURE_LEVEL featureLevels[] =
|
||||
{
|
||||
D3D_FEATURE_LEVEL_10_0
|
||||
};
|
||||
|
||||
flags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||
|
||||
ID3D11Device *device = NULL;
|
||||
ID3D11DeviceContext *context = NULL;
|
||||
|
||||
D3D_FEATURE_LEVEL selectedFeatureLevel;
|
||||
|
||||
HRESULT result = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, featureLevels, sizeof(featureLevels) / sizeof(featureLevels[0]),
|
||||
D3D11_SDK_VERSION, &device, &selectedFeatureLevel, &context);
|
||||
|
||||
IDXGIDevice2 *dxgiDevice = nullptr;
|
||||
result = device->QueryInterface(__uuidof(IDXGIDevice2), reinterpret_cast<void**>(&dxgiDevice));
|
||||
|
||||
IDXGIAdapter *dxgiAdapter = nullptr;
|
||||
result = dxgiDevice->GetAdapter(&dxgiAdapter);
|
||||
|
||||
IDXGIFactory2 *dxgiFactory = nullptr;
|
||||
result = dxgiAdapter->GetParent(__uuidof(IDXGIFactory2), reinterpret_cast<void**>(&dxgiFactory));
|
||||
|
||||
IDXGISwapChain1 *swapChain = nullptr;
|
||||
result = dxgiFactory->CreateSwapChainForHwnd(device, hWnd, &swapChainDesc, nullptr, nullptr, &swapChain);
|
||||
|
||||
// GP TODO: Fix the error handling here, it's bad...
|
||||
outSwapChain = swapChain;
|
||||
outDevice = device;
|
||||
outContext = context;
|
||||
}
|
||||
|
||||
bool GpDisplayDriverD3D11::InitResources()
|
||||
{
|
||||
// Fetch back buffer
|
||||
m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<LPVOID*>(m_backBufferTexture.GetMutablePtr()));
|
||||
|
||||
{
|
||||
D3D11_TEXTURE2D_DESC bbTextureDesc;
|
||||
m_backBufferTexture->GetDesc(&bbTextureDesc);
|
||||
|
||||
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
|
||||
rtvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
|
||||
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
|
||||
rtvDesc.Texture2D.MipSlice = 0;
|
||||
|
||||
if (m_device->CreateRenderTargetView(m_backBufferTexture, &rtvDesc, m_backBufferRTV.GetMutablePtr()) != S_OK)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Quad vertex constant buffer
|
||||
{
|
||||
D3D11_BUFFER_DESC bufferDesc;
|
||||
bufferDesc.ByteWidth = sizeof(DrawQuadVertexConstants);
|
||||
bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
bufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
||||
bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
bufferDesc.MiscFlags = 0;
|
||||
bufferDesc.StructureByteStride = 0;
|
||||
|
||||
if (m_device->CreateBuffer(&bufferDesc, nullptr, m_drawQuadVertexConstantBuffer.GetMutablePtr()) != S_OK)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Quad index buffer
|
||||
{
|
||||
const uint16_t indexBufferData[] = { 0, 1, 2, 1, 3, 2 };
|
||||
|
||||
D3D11_BUFFER_DESC bufferDesc;
|
||||
bufferDesc.ByteWidth = sizeof(indexBufferData);
|
||||
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
bufferDesc.CPUAccessFlags = 0;
|
||||
bufferDesc.MiscFlags = 0;
|
||||
bufferDesc.StructureByteStride = 0;
|
||||
|
||||
D3D11_SUBRESOURCE_DATA initialData;
|
||||
initialData.pSysMem = indexBufferData;
|
||||
initialData.SysMemPitch = 0;
|
||||
initialData.SysMemSlicePitch = 0;
|
||||
|
||||
if (m_device->CreateBuffer(&bufferDesc, &initialData, m_quadIndexBuffer.GetMutablePtr()) != S_OK)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Quad vertex buffer
|
||||
{
|
||||
const float vertexBufferData[] =
|
||||
{
|
||||
0.f, 0.0f,
|
||||
1.f, 0.f,
|
||||
0.f, 1.f,
|
||||
1.f, 1.f,
|
||||
};
|
||||
|
||||
D3D11_BUFFER_DESC bufferDesc;
|
||||
bufferDesc.ByteWidth = sizeof(vertexBufferData);
|
||||
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
bufferDesc.CPUAccessFlags = 0;
|
||||
bufferDesc.MiscFlags = 0;
|
||||
bufferDesc.StructureByteStride = 0;
|
||||
|
||||
D3D11_SUBRESOURCE_DATA initialData;
|
||||
initialData.pSysMem = vertexBufferData;
|
||||
initialData.SysMemPitch = 0;
|
||||
initialData.SysMemSlicePitch = 0;
|
||||
|
||||
if (m_device->CreateBuffer(&bufferDesc, &initialData, m_quadVertexBuffer.GetMutablePtr()) != S_OK)
|
||||
return false;
|
||||
}
|
||||
|
||||
const GpShaderCodeBlob drawQuadVBlob = GetBinarizedShader(GpBinarizedShaders::g_drawQuadV_D3D11);
|
||||
const GpShaderCodeBlob drawQuadPalettePBlob = GetBinarizedShader(GpBinarizedShaders::g_drawQuadPaletteP_D3D11);
|
||||
const GpShaderCodeBlob drawQuadRGBPBlob = GetBinarizedShader(GpBinarizedShaders::g_drawQuadRGBP_D3D11);
|
||||
const GpShaderCodeBlob drawQuad15BitPBlob = GetBinarizedShader(GpBinarizedShaders::g_drawQuad15BitP_D3D11);
|
||||
|
||||
m_device->CreateVertexShader(drawQuadVBlob.m_data, drawQuadVBlob.m_size, nullptr, m_drawQuadVertexShader.GetMutablePtr());
|
||||
m_device->CreatePixelShader(drawQuadPalettePBlob.m_data, drawQuadPalettePBlob.m_size, nullptr, m_drawQuadPalettePixelShader.GetMutablePtr());
|
||||
m_device->CreatePixelShader(drawQuadRGBPBlob.m_data, drawQuadRGBPBlob.m_size, nullptr, m_drawQuadRGBPixelShader.GetMutablePtr());
|
||||
m_device->CreatePixelShader(drawQuad15BitPBlob.m_data, drawQuad15BitPBlob.m_size, nullptr, m_drawQuad15BitPixelShader.GetMutablePtr());
|
||||
|
||||
// Quad input layout
|
||||
{
|
||||
D3D11_INPUT_ELEMENT_DESC descs[] =
|
||||
{
|
||||
"POSITION", // Semantic name
|
||||
0, // Semantic index
|
||||
DXGI_FORMAT_R32G32_FLOAT, // Format
|
||||
0, // Input slot
|
||||
0, // Aligned byte offset
|
||||
D3D11_INPUT_PER_VERTEX_DATA, // Input slot class
|
||||
0 // Instance data step rate
|
||||
};
|
||||
|
||||
m_device->CreateInputLayout(descs, sizeof(descs) / sizeof(descs[0]), drawQuadVBlob.m_data, drawQuadVBlob.m_size, m_drawQuadInputLayout.GetMutablePtr());
|
||||
}
|
||||
|
||||
// Quad depth stencil state
|
||||
{
|
||||
D3D11_DEPTH_STENCIL_DESC desc;
|
||||
desc.DepthEnable = FALSE;
|
||||
desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
|
||||
desc.DepthFunc = D3D11_COMPARISON_ALWAYS;
|
||||
desc.StencilEnable = FALSE;
|
||||
desc.StencilReadMask = 0;
|
||||
desc.StencilWriteMask = 0;
|
||||
desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
|
||||
desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
|
||||
desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
||||
desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
||||
desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
|
||||
desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
|
||||
desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
||||
desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
||||
|
||||
if (m_device->CreateDepthStencilState(&desc, m_drawQuadDepthStencilState.GetMutablePtr()) != S_OK)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Nearest neighbor sampler desc
|
||||
{
|
||||
D3D11_SAMPLER_DESC samplerDesc;
|
||||
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
|
||||
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.MipLODBias = 0.f;
|
||||
samplerDesc.MaxAnisotropy = 1;
|
||||
samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
|
||||
samplerDesc.BorderColor[0] = samplerDesc.BorderColor[1] = samplerDesc.BorderColor[2] = samplerDesc.BorderColor[3] = 1.0f;
|
||||
samplerDesc.MinLOD = -FLT_MAX;
|
||||
samplerDesc.MaxLOD = FLT_MAX;
|
||||
|
||||
if (m_device->CreateSamplerState(&samplerDesc, m_nearestNeighborSamplerState.GetMutablePtr()) != S_OK)
|
||||
return false;
|
||||
}
|
||||
|
||||
DXGI_FORMAT paletteTextureFormat = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
|
||||
|
||||
// Palette texture
|
||||
{
|
||||
D3D11_TEXTURE1D_DESC desc;
|
||||
desc.Width = 256;
|
||||
desc.MipLevels = 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = paletteTextureFormat;
|
||||
desc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
uint8_t initialDataBytes[256][4];
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
for (int ch = 0; ch < 4; ch++)
|
||||
initialDataBytes[i][ch] = 255;
|
||||
}
|
||||
|
||||
D3D11_SUBRESOURCE_DATA initialData;
|
||||
initialData.pSysMem = initialDataBytes[0];
|
||||
initialData.SysMemPitch = 256 * 4;
|
||||
initialData.SysMemSlicePitch = 256 * 4;
|
||||
|
||||
if (m_device->CreateTexture1D(&desc, &initialData, m_paletteTexture.GetMutablePtr()) != S_OK)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Palette texture SRV
|
||||
{
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC desc;
|
||||
desc.Format = paletteTextureFormat;
|
||||
desc.ViewDimension = D3D_SRV_DIMENSION_TEXTURE1D;
|
||||
desc.Texture1D.MostDetailedMip = 0;
|
||||
desc.Texture1D.MipLevels = 1;
|
||||
|
||||
if (m_device->CreateShaderResourceView(m_paletteTexture, &desc, m_paletteTextureSRV.GetMutablePtr()) != S_OK)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool GpDisplayDriverD3D11::PresentFrameAndSync()
|
||||
{
|
||||
SynchronizeCursors();
|
||||
|
||||
float clearColor[4] = { 0.5f, 0.5f, 0.5f, 1.0f };
|
||||
|
||||
m_deviceContext->ClearRenderTargetView(m_backBufferRTV, clearColor);
|
||||
|
||||
ID3D11RenderTargetView *const rtv = m_backBufferRTV;
|
||||
m_deviceContext->OMSetRenderTargets(1, &rtv, nullptr);
|
||||
|
||||
{
|
||||
D3D11_VIEWPORT viewport;
|
||||
viewport.TopLeftX = 0;
|
||||
viewport.TopLeftY = 0;
|
||||
viewport.Width = static_cast<FLOAT>(m_windowWidth);
|
||||
viewport.Height = static_cast<FLOAT>(m_windowHeight);
|
||||
viewport.MinDepth = 0.0f;
|
||||
viewport.MaxDepth = 1.0f;
|
||||
|
||||
m_deviceContext->RSSetViewports(1, &viewport);
|
||||
}
|
||||
|
||||
m_properties.m_renderFunc(m_properties.m_renderFuncContext);
|
||||
|
||||
DXGI_PRESENT_PARAMETERS presentParams;
|
||||
|
||||
ZeroMemory(&presentParams, sizeof(presentParams));
|
||||
|
||||
UINT lastPresentCount = 0;
|
||||
|
||||
if (FAILED(m_swapChain->GetLastPresentCount(&lastPresentCount)))
|
||||
return false;
|
||||
|
||||
if (FAILED(m_swapChain->Present1(1, 0, &presentParams)))
|
||||
return false;
|
||||
|
||||
//DebugPrintf("r: %i\n", static_cast<int>(r));
|
||||
|
||||
DXGI_FRAME_STATISTICS stats;
|
||||
if (FAILED(m_swapChain->GetFrameStatistics(&stats)))
|
||||
return false;
|
||||
|
||||
if (stats.SyncQPCTime.QuadPart != 0)
|
||||
{
|
||||
if (m_syncTimeBase.QuadPart == 0)
|
||||
m_syncTimeBase = stats.SyncQPCTime;
|
||||
|
||||
LARGE_INTEGER timestamp;
|
||||
timestamp.QuadPart = stats.SyncQPCTime.QuadPart - m_syncTimeBase.QuadPart;
|
||||
|
||||
bool compacted = false;
|
||||
if (m_presentHistory.Size() > 0)
|
||||
{
|
||||
CompactedPresentHistoryItem &lastItem = m_presentHistory[m_presentHistory.Size() - 1];
|
||||
LONGLONG timeDelta = timestamp.QuadPart - lastItem.m_timestamp.QuadPart;
|
||||
|
||||
if (timeDelta < 0)
|
||||
timeDelta = 0; // This should never happen
|
||||
|
||||
if (timeDelta * static_cast<LONGLONG>(m_properties.m_frameTimeLockDenominator) < m_QPFrequency.QuadPart * static_cast<LONGLONG>(m_properties.m_frameTimeLockNumerator))
|
||||
{
|
||||
lastItem.m_numFrames++;
|
||||
compacted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!compacted)
|
||||
{
|
||||
if (m_presentHistory.Size() == m_presentHistory.CAPACITY)
|
||||
m_presentHistory.RemoveFromStart();
|
||||
|
||||
CompactedPresentHistoryItem *newItem = m_presentHistory.Append();
|
||||
newItem->m_timestamp = timestamp;
|
||||
newItem->m_numFrames = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_presentHistory.Size() >= 2)
|
||||
{
|
||||
const size_t presentHistorySizeMinusOne = m_presentHistory.Size() - 1;
|
||||
unsigned int numFrames = 0;
|
||||
for (size_t i = 0; i < presentHistorySizeMinusOne; i++)
|
||||
numFrames += m_presentHistory[i].m_numFrames;
|
||||
|
||||
LONGLONG timeFrame = m_presentHistory[presentHistorySizeMinusOne].m_timestamp.QuadPart - m_presentHistory[0].m_timestamp.QuadPart;
|
||||
|
||||
unsigned int cancelledFrames = 0;
|
||||
LONGLONG cancelledTime = 0;
|
||||
|
||||
const int overshootTolerance = 2;
|
||||
|
||||
for (size_t i = 0; i < presentHistorySizeMinusOne; i++)
|
||||
{
|
||||
LONGLONG blockTimeframe = m_presentHistory[i + 1].m_timestamp.QuadPart - m_presentHistory[i].m_timestamp.QuadPart;
|
||||
unsigned int blockNumFrames = m_presentHistory[i].m_numFrames;
|
||||
|
||||
if (blockTimeframe * static_cast<LONGLONG>(numFrames) >= timeFrame * static_cast<LONGLONG>(blockNumFrames) * overshootTolerance)
|
||||
{
|
||||
cancelledTime += blockTimeframe;
|
||||
cancelledFrames += blockNumFrames;
|
||||
}
|
||||
}
|
||||
|
||||
numFrames -= cancelledFrames;
|
||||
timeFrame -= cancelledTime;
|
||||
|
||||
// timeFrame / numFrames = Frame timestep
|
||||
// Unless Frame timestep is within the frame lock range, a.k.a.
|
||||
// timeFrame / numFrames / qpFreq >= minFrameTimeNum / minFrameTimeDenom
|
||||
|
||||
bool isInFrameTimeLock = false;
|
||||
if (timeFrame * static_cast<LONGLONG>(m_properties.m_frameTimeLockMinDenominator) >= static_cast<LONGLONG>(numFrames) * static_cast<LONGLONG>(m_properties.m_frameTimeLockMinNumerator) * m_QPFrequency.QuadPart
|
||||
&& timeFrame * static_cast<LONGLONG>(m_properties.m_frameTimeLockMaxDenominator) <= static_cast<LONGLONG>(numFrames) * static_cast<LONGLONG>(m_properties.m_frameTimeLockMaxNumerator) * m_QPFrequency.QuadPart)
|
||||
{
|
||||
isInFrameTimeLock = true;
|
||||
}
|
||||
|
||||
LONGLONG frameTimeStep = m_frameTimeSliceSize;
|
||||
if (!isInFrameTimeLock)
|
||||
{
|
||||
const int MAX_FRAMES_PER_STEP = 4;
|
||||
|
||||
frameTimeStep = timeFrame / numFrames;
|
||||
if (frameTimeStep > m_frameTimeSliceSize * MAX_FRAMES_PER_STEP)
|
||||
frameTimeStep = m_frameTimeSliceSize * MAX_FRAMES_PER_STEP;
|
||||
}
|
||||
|
||||
m_frameTimeAccumulated += frameTimeStep;
|
||||
while (m_frameTimeAccumulated >= m_frameTimeSliceSize)
|
||||
{
|
||||
m_properties.m_tickFunc(m_properties.m_tickFuncContext, m_vosFiber);
|
||||
m_frameTimeAccumulated -= m_frameTimeSliceSize;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GpDisplayDriverD3D11::SynchronizeCursors()
|
||||
{
|
||||
HCURSOR replacementCursor = nullptr;
|
||||
|
||||
if (m_activeCursor)
|
||||
{
|
||||
if (m_pendingCursor != m_activeCursor)
|
||||
{
|
||||
if (m_pendingCursor == nullptr)
|
||||
{
|
||||
m_currentStandardCursor = m_pendingStandardCursor;
|
||||
ChangeToStandardCursor(m_currentStandardCursor);
|
||||
|
||||
m_activeCursor->DecRef();
|
||||
m_activeCursor = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
ChangeToCursor(m_pendingCursor->GetHCursor());
|
||||
|
||||
m_pendingCursor->IncRef();
|
||||
m_activeCursor->DecRef();
|
||||
m_activeCursor = m_pendingCursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_pendingCursor)
|
||||
{
|
||||
m_pendingCursor->IncRef();
|
||||
m_activeCursor = m_pendingCursor;
|
||||
|
||||
ChangeToCursor(m_activeCursor->GetHCursor());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_pendingStandardCursor != m_currentStandardCursor)
|
||||
{
|
||||
ChangeToStandardCursor(m_pendingStandardCursor);
|
||||
m_currentStandardCursor = m_pendingStandardCursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GpDisplayDriverD3D11::ChangeToCursor(HCURSOR cursor)
|
||||
{
|
||||
if (m_mouseIsInClientArea)
|
||||
SetCursor(cursor);
|
||||
|
||||
SetClassLongPtrW(m_hwnd, GCLP_HCURSOR, reinterpret_cast<LONG_PTR>(cursor));
|
||||
}
|
||||
|
||||
void GpDisplayDriverD3D11::ChangeToStandardCursor(EGpStandardCursor_t cursor)
|
||||
{
|
||||
switch (cursor)
|
||||
{
|
||||
case EGpStandardCursors::kArrow:
|
||||
default:
|
||||
ChangeToCursor(m_arrowCursor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GpDisplayDriverD3D11::Run()
|
||||
{
|
||||
WNDCLASSEX wc;
|
||||
|
||||
LPVOID fiber = ConvertThreadToFiberEx(this, 0);
|
||||
if (!fiber)
|
||||
return; // ???
|
||||
|
||||
m_vosFiber = m_osGlobals->m_createFiberFunc(fiber);
|
||||
|
||||
ZeroMemory(&wc, sizeof(wc));
|
||||
|
||||
wc.cbSize = sizeof(WNDCLASSEX);
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wc.lpfnWndProc = WinProc;
|
||||
wc.hInstance = m_osGlobals->m_hInstance;
|
||||
wc.hCursor = m_arrowCursor;
|
||||
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
|
||||
wc.lpszClassName = "GPD3D11WindowClass";
|
||||
|
||||
RegisterClassEx(&wc);
|
||||
|
||||
LONG windowStyle = WS_OVERLAPPEDWINDOW;
|
||||
HMENU menus = NULL;
|
||||
|
||||
// TODO: Fix the resolution here
|
||||
RECT wr = { 0, 0, m_windowWidth, m_windowHeight };
|
||||
AdjustWindowRect(&wr, windowStyle, menus != NULL);
|
||||
|
||||
m_hwnd = CreateWindowExW(NULL, L"GPD3D11WindowClass", L"GlidePort (Direct3D 11)", WS_OVERLAPPEDWINDOW, 300, 300, wr.right - wr.left, wr.bottom - wr.top, NULL, menus, m_osGlobals->m_hInstance, NULL);
|
||||
|
||||
ShowWindow(m_hwnd, m_osGlobals->m_nCmdShow);
|
||||
|
||||
StartD3DForWindow(m_hwnd, m_swapChain, m_device, m_deviceContext);
|
||||
|
||||
InitResources();
|
||||
|
||||
LARGE_INTEGER lastTimestamp;
|
||||
memset(&lastTimestamp, 0, sizeof(lastTimestamp));
|
||||
|
||||
MSG msg;
|
||||
for (;;)
|
||||
{
|
||||
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
|
||||
DispatchMessage(&msg);
|
||||
|
||||
if (msg.message == WM_QUIT)
|
||||
break;
|
||||
else if (msg.message == WM_MOUSEMOVE)
|
||||
m_mouseIsInClientArea = true;
|
||||
else if (msg.message == WM_MOUSELEAVE)
|
||||
m_mouseIsInClientArea = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
PresentFrameAndSync();
|
||||
}
|
||||
}
|
||||
|
||||
// Exit
|
||||
ConvertFiberToThread();
|
||||
}
|
||||
|
||||
void GpDisplayDriverD3D11::Shutdown()
|
||||
{
|
||||
this->~GpDisplayDriverD3D11();
|
||||
free(this);
|
||||
}
|
||||
|
||||
void GpDisplayDriverD3D11::GetDisplayResolution(unsigned int *width, unsigned int *height, GpPixelFormat_t *pixelFormat)
|
||||
{
|
||||
if (width)
|
||||
*width = m_windowWidth;
|
||||
if (height)
|
||||
*height = m_windowHeight;
|
||||
if (pixelFormat)
|
||||
*pixelFormat = GpPixelFormats::k8BitStandard;
|
||||
}
|
||||
|
||||
IGpDisplayDriverSurface *GpDisplayDriverD3D11::CreateSurface(size_t width, size_t height, GpPixelFormat_t pixelFormat)
|
||||
{
|
||||
return GpDisplayDriverSurfaceD3D11::Create(m_device, m_deviceContext, width, height, pixelFormat);
|
||||
}
|
||||
|
||||
void GpDisplayDriverD3D11::DrawSurface(IGpDisplayDriverSurface *surface, size_t x, size_t y, size_t width, size_t height)
|
||||
{
|
||||
ID3D11Buffer *vbPtr = m_quadVertexBuffer;
|
||||
UINT vbStride = sizeof(float) * 2;
|
||||
UINT zero = 0;
|
||||
|
||||
GpDisplayDriverSurfaceD3D11 *d3d11Surface = static_cast<GpDisplayDriverSurfaceD3D11*>(surface);
|
||||
|
||||
//m_deviceContext->OMSetDepthStencilState(m_drawQuadDepthStencilState, 0);
|
||||
|
||||
{
|
||||
const float twoDivWidth = 2.0f / static_cast<float>(m_windowWidth);
|
||||
const float negativeTwoDivHeight = -2.0f / static_cast<float>(m_windowHeight);
|
||||
|
||||
DrawQuadVertexConstants constantsData;
|
||||
constantsData.m_ndcOriginX = static_cast<float>(x) * twoDivWidth - 1.0f;
|
||||
constantsData.m_ndcOriginY = static_cast<float>(y) * negativeTwoDivHeight + 1.0f;
|
||||
constantsData.m_ndcWidth = static_cast<float>(width) * twoDivWidth;
|
||||
constantsData.m_ndcHeight = static_cast<float>(height) * negativeTwoDivHeight;
|
||||
|
||||
constantsData.m_surfaceDimensionX = static_cast<float>(d3d11Surface->GetWidth());
|
||||
constantsData.m_surfaceDimensionY = static_cast<float>(d3d11Surface->GetHeight());
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mappedConstants;
|
||||
if (m_deviceContext->Map(m_drawQuadVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedConstants) == S_OK)
|
||||
{
|
||||
memcpy(mappedConstants.pData, &constantsData, sizeof(constantsData));
|
||||
m_deviceContext->Unmap(m_drawQuadVertexConstantBuffer, 0);
|
||||
}
|
||||
}
|
||||
|
||||
m_deviceContext->IASetVertexBuffers(0, 1, &vbPtr, &vbStride, &zero);
|
||||
m_deviceContext->IASetIndexBuffer(m_quadIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
|
||||
m_deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
m_deviceContext->IASetInputLayout(m_drawQuadInputLayout);
|
||||
|
||||
ID3D11Buffer *vsConstants = m_drawQuadVertexConstantBuffer;
|
||||
m_deviceContext->VSSetShader(m_drawQuadVertexShader, nullptr, 0);
|
||||
m_deviceContext->VSSetConstantBuffers(0, 1, &vsConstants);
|
||||
|
||||
ID3D11SamplerState *samplerStates[] =
|
||||
{
|
||||
m_nearestNeighborSamplerState,
|
||||
};
|
||||
m_deviceContext->PSSetSamplers(0, sizeof(samplerStates) / sizeof(samplerStates[0]), samplerStates);
|
||||
|
||||
GpPixelFormat_t pixelFormat = d3d11Surface->GetPixelFormat();
|
||||
if (pixelFormat == GpPixelFormats::k8BitStandard || pixelFormat == GpPixelFormats::k8BitCustom)
|
||||
{
|
||||
ID3D11ShaderResourceView *psResourceViews[] =
|
||||
{
|
||||
d3d11Surface->GetSRV(),
|
||||
m_paletteTextureSRV
|
||||
};
|
||||
|
||||
m_deviceContext->PSSetShader(m_drawQuadPalettePixelShader, nullptr, 0);
|
||||
m_deviceContext->PSSetShaderResources(0, sizeof(psResourceViews) / sizeof(psResourceViews[0]), psResourceViews);
|
||||
}
|
||||
else if (pixelFormat == GpPixelFormats::kRGB555)
|
||||
{
|
||||
ID3D11ShaderResourceView *psResourceViews[] =
|
||||
{
|
||||
d3d11Surface->GetSRV(),
|
||||
};
|
||||
|
||||
m_deviceContext->PSSetShader(m_drawQuad15BitPixelShader, nullptr, 0);
|
||||
m_deviceContext->PSSetShaderResources(0, sizeof(psResourceViews) / sizeof(psResourceViews[0]), psResourceViews);
|
||||
}
|
||||
else if (pixelFormat == GpPixelFormats::kRGB32)
|
||||
{
|
||||
ID3D11ShaderResourceView *psResourceViews[] =
|
||||
{
|
||||
d3d11Surface->GetSRV(),
|
||||
};
|
||||
|
||||
m_deviceContext->PSSetShader(m_drawQuadRGBPixelShader, nullptr, 0);
|
||||
m_deviceContext->PSSetShaderResources(0, sizeof(psResourceViews) / sizeof(psResourceViews[0]), psResourceViews);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_deviceContext->DrawIndexed(6, 0, 0);
|
||||
}
|
||||
|
||||
IGpColorCursor *GpDisplayDriverD3D11::LoadColorCursor(int cursorID)
|
||||
{
|
||||
const size_t bufSize = MAX_PATH;
|
||||
wchar_t path[bufSize];
|
||||
|
||||
int sz = _snwprintf(path, bufSize, L"%sPackaged\\WinCursors\\%i.cur", m_osGlobals->m_baseDir, cursorID);
|
||||
if (sz < 0 || static_cast<size_t>(sz) >= bufSize)
|
||||
return nullptr;
|
||||
|
||||
return m_osGlobals->m_loadColorCursorFunc(path);
|
||||
}
|
||||
|
||||
// We can't just set the cursor because we want to post WM_SETCURSOR to keep it limited
|
||||
// to the game window area, but depending on the fiber implementation, this may not be
|
||||
// the window thread.
|
||||
void GpDisplayDriverD3D11::SetColorCursor(IGpColorCursor *colorCursor)
|
||||
{
|
||||
IGpColorCursor_Win32 *winCursor = static_cast<IGpColorCursor_Win32*>(colorCursor);
|
||||
|
||||
winCursor->IncRef();
|
||||
|
||||
if (m_pendingCursor)
|
||||
m_pendingCursor->DecRef();
|
||||
|
||||
m_pendingCursor = winCursor;
|
||||
}
|
||||
|
||||
void GpDisplayDriverD3D11::SetStandardCursor(EGpStandardCursor_t standardCursor)
|
||||
{
|
||||
if (m_pendingCursor)
|
||||
{
|
||||
m_pendingCursor->DecRef();
|
||||
m_pendingCursor = nullptr;
|
||||
}
|
||||
|
||||
m_pendingStandardCursor = standardCursor;
|
||||
}
|
||||
|
||||
void GpDisplayDriverD3D11::UpdatePalette(const void *paletteData)
|
||||
{
|
||||
const size_t dataSize = 256 * 4;
|
||||
const uint8_t *paletteDataBytes = static_cast<const uint8_t *>(paletteData);
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mappedResource;
|
||||
if (m_deviceContext->Map(m_paletteTexture, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource) == S_OK)
|
||||
{
|
||||
uint8_t *textureDataBytes = static_cast<uint8_t *>(mappedResource.pData);
|
||||
|
||||
for (size_t chunkOffset = 0; chunkOffset < dataSize; chunkOffset += sizeof(__m128i))
|
||||
{
|
||||
__m128i chunkData = _mm_loadu_si128(reinterpret_cast<const __m128i*>(paletteDataBytes + chunkOffset));
|
||||
_mm_stream_si128(reinterpret_cast<__m128i*>(textureDataBytes + chunkOffset), chunkData);
|
||||
}
|
||||
|
||||
m_deviceContext->Unmap(m_paletteTexture, 0);
|
||||
}
|
||||
}
|
||||
|
||||
GpDisplayDriverD3D11 *GpDisplayDriverD3D11::Create(const GpDisplayDriverProperties &properties)
|
||||
{
|
||||
void *storage = malloc(sizeof(GpDisplayDriverD3D11));
|
||||
if (!storage)
|
||||
return nullptr;
|
||||
|
||||
return new (storage) GpDisplayDriverD3D11(properties);
|
||||
}
|
||||
|
||||
GpDisplayDriverD3D11::GpDisplayDriverD3D11(const GpDisplayDriverProperties &properties)
|
||||
: m_properties(properties)
|
||||
, m_frameTimeAccumulated(0)
|
||||
, m_windowWidth(640)
|
||||
, m_windowHeight(480)
|
||||
, m_vosFiber(nullptr)
|
||||
, m_osGlobals(static_cast<GpWindowsGlobals*>(properties.m_osGlobals))
|
||||
, m_pendingCursor(nullptr)
|
||||
, m_activeCursor(nullptr)
|
||||
, m_currentStandardCursor(EGpStandardCursors::kArrow)
|
||||
, m_pendingStandardCursor(EGpStandardCursors::kArrow)
|
||||
, m_mouseIsInClientArea(false)
|
||||
{
|
||||
memset(&m_syncTimeBase, 0, sizeof(m_syncTimeBase));
|
||||
|
||||
QueryPerformanceFrequency(&m_QPFrequency);
|
||||
|
||||
m_frameTimeSliceSize = m_QPFrequency.QuadPart * static_cast<LONGLONG>(properties.m_frameTimeLockNumerator) / static_cast<LONGLONG>(properties.m_frameTimeLockDenominator);
|
||||
|
||||
m_arrowCursor = reinterpret_cast<HCURSOR>(LoadImageW(nullptr, MAKEINTRESOURCEW(OCR_NORMAL), IMAGE_CURSOR, 0, 0, LR_SHARED));
|
||||
}
|
||||
|
||||
GpDisplayDriverD3D11::~GpDisplayDriverD3D11()
|
||||
{
|
||||
// GP TODO: Sloppy cleanup... Close the window!!
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) IGpDisplayDriver *GpDriver_CreateDisplayDriver_D3D11(const GpDisplayDriverProperties &properties)
|
||||
{
|
||||
return GpDisplayDriverD3D11::Create(properties);
|
||||
}
|
||||
123
GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h
Normal file
123
GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h
Normal file
@@ -0,0 +1,123 @@
|
||||
#pragma once
|
||||
|
||||
#include "GpWindows.h"
|
||||
#include "GpRingBuffer.h"
|
||||
|
||||
#include "IGpDisplayDriver.h"
|
||||
#include "GpCoreDefs.h"
|
||||
#include "GpDisplayDriverProperties.h"
|
||||
#include "GpComPtr.h"
|
||||
|
||||
#include "GpPixelFormat.h"
|
||||
|
||||
struct GpWindowsGlobals;
|
||||
struct IGpColorCursor_Win32;
|
||||
struct IGpFiber;
|
||||
|
||||
struct IDXGISwapChain1;
|
||||
struct ID3D11Buffer;
|
||||
struct ID3D11DepthStencilState;
|
||||
struct ID3D11Device;
|
||||
struct ID3D11DeviceContext;
|
||||
struct ID3D11InputLayout;
|
||||
struct ID3D11PixelShader;
|
||||
struct ID3D11RenderTargetView;
|
||||
struct ID3D11SamplerState;
|
||||
struct ID3D11ShaderResourceView;
|
||||
struct ID3D11Texture1D;
|
||||
struct ID3D11Texture2D;
|
||||
struct ID3D11VertexShader;
|
||||
|
||||
class GpDisplayDriverD3D11 : public IGpDisplayDriver
|
||||
{
|
||||
public:
|
||||
void Run() override;
|
||||
void Shutdown() override;
|
||||
|
||||
void GetDisplayResolution(unsigned int *width, unsigned int *height, GpPixelFormat_t *bpp) override;
|
||||
|
||||
IGpDisplayDriverSurface *CreateSurface(size_t width, size_t height, GpPixelFormat_t pixelFormat) override;
|
||||
void DrawSurface(IGpDisplayDriverSurface *surface, size_t x, size_t y, size_t width, size_t height) override;
|
||||
|
||||
IGpColorCursor *LoadColorCursor(int cursorID) override;
|
||||
void SetColorCursor(IGpColorCursor *colorCursor) override;
|
||||
void SetStandardCursor(EGpStandardCursor_t standardCursor) override;
|
||||
|
||||
void UpdatePalette(const void *paletteData) override;
|
||||
|
||||
static GpDisplayDriverD3D11 *Create(const GpDisplayDriverProperties &properties);
|
||||
|
||||
private:
|
||||
struct DrawQuadVertexConstants
|
||||
{
|
||||
float m_ndcOriginX;
|
||||
float m_ndcOriginY;
|
||||
float m_ndcWidth;
|
||||
float m_ndcHeight;
|
||||
|
||||
float m_surfaceDimensionX;
|
||||
float m_surfaceDimensionY;
|
||||
float m_unused[2];
|
||||
};
|
||||
|
||||
struct CompactedPresentHistoryItem
|
||||
{
|
||||
LARGE_INTEGER m_timestamp;
|
||||
unsigned int m_numFrames;
|
||||
};
|
||||
|
||||
GpDisplayDriverD3D11(const GpDisplayDriverProperties &properties);
|
||||
~GpDisplayDriverD3D11();
|
||||
|
||||
bool InitResources();
|
||||
bool PresentFrameAndSync();
|
||||
|
||||
void SynchronizeCursors();
|
||||
void ChangeToCursor(HCURSOR cursor);
|
||||
void ChangeToStandardCursor(EGpStandardCursor_t cursor);
|
||||
|
||||
GpComPtr<IDXGISwapChain1> m_swapChain;
|
||||
GpComPtr<ID3D11Device> m_device;
|
||||
GpComPtr<ID3D11DeviceContext> m_deviceContext;
|
||||
GpComPtr<ID3D11Buffer> m_quadIndexBuffer;
|
||||
GpComPtr<ID3D11Buffer> m_quadVertexBuffer;
|
||||
GpComPtr<ID3D11InputLayout> m_drawQuadInputLayout;
|
||||
GpComPtr<ID3D11VertexShader> m_drawQuadVertexShader;
|
||||
GpComPtr<ID3D11PixelShader> m_drawQuadPalettePixelShader;
|
||||
GpComPtr<ID3D11PixelShader> m_drawQuad15BitPixelShader;
|
||||
GpComPtr<ID3D11PixelShader> m_drawQuadRGBPixelShader;
|
||||
GpComPtr<ID3D11Buffer> m_drawQuadVertexConstantBuffer;
|
||||
GpComPtr<ID3D11DepthStencilState> m_drawQuadDepthStencilState;
|
||||
GpComPtr<ID3D11SamplerState> m_nearestNeighborSamplerState;
|
||||
GpComPtr<ID3D11Texture1D> m_paletteTexture;
|
||||
GpComPtr<ID3D11ShaderResourceView> m_paletteTextureSRV;
|
||||
|
||||
GpComPtr<ID3D11Texture2D> m_backBufferTexture;
|
||||
GpComPtr<ID3D11RenderTargetView> m_backBufferRTV;
|
||||
|
||||
GpRingBuffer<CompactedPresentHistoryItem, 60> m_presentHistory;
|
||||
GpDisplayDriverProperties m_properties;
|
||||
|
||||
LARGE_INTEGER m_syncTimeBase;
|
||||
LARGE_INTEGER m_QPFrequency;
|
||||
UINT m_expectedSyncDelta;
|
||||
bool m_isResettingSwapChain;
|
||||
|
||||
LONGLONG m_frameTimeAccumulated;
|
||||
LONGLONG m_frameTimeSliceSize;
|
||||
|
||||
DWORD m_windowWidth;
|
||||
DWORD m_windowHeight;
|
||||
|
||||
IGpColorCursor_Win32 *m_activeCursor;
|
||||
IGpColorCursor_Win32 *m_pendingCursor;
|
||||
EGpStandardCursor_t m_currentStandardCursor;
|
||||
EGpStandardCursor_t m_pendingStandardCursor;
|
||||
bool m_mouseIsInClientArea;
|
||||
|
||||
IGpFiber *m_vosFiber;
|
||||
GpWindowsGlobals *m_osGlobals;
|
||||
|
||||
HCURSOR m_arrowCursor;
|
||||
HWND m_hwnd;
|
||||
};
|
||||
7
GpDisplayDriver_D3D11/GpDisplayDriverFactoryD3D11.cpp
Normal file
7
GpDisplayDriver_D3D11/GpDisplayDriverFactoryD3D11.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "GpDisplayDriverFactoryD3D11.h"
|
||||
#include "GpDisplayDriverD3D11.h"
|
||||
|
||||
IGpDisplayDriver *GpDisplayDriverFactoryD3D11::Create(const GpDisplayDriverProperties &properties)
|
||||
{
|
||||
return GpDisplayDriverD3D11::Create(properties);
|
||||
}
|
||||
10
GpDisplayDriver_D3D11/GpDisplayDriverFactoryD3D11.h
Normal file
10
GpDisplayDriver_D3D11/GpDisplayDriverFactoryD3D11.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
struct IGpDisplayDriver;
|
||||
struct GpDisplayDriverProperties;
|
||||
|
||||
class GpDisplayDriverFactoryD3D11
|
||||
{
|
||||
public:
|
||||
static IGpDisplayDriver *Create(const GpDisplayDriverProperties &properties);
|
||||
};
|
||||
153
GpDisplayDriver_D3D11/GpDisplayDriverSurfaceD3D11.cpp
Normal file
153
GpDisplayDriver_D3D11/GpDisplayDriverSurfaceD3D11.cpp
Normal file
@@ -0,0 +1,153 @@
|
||||
#include "GpDisplayDriverSurfaceD3D11.h"
|
||||
#include "GpComPtr.h"
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <emmintrin.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <new>
|
||||
|
||||
void GpDisplayDriverSurfaceD3D11::Upload(const void *data, size_t x, size_t y, size_t width, size_t height, size_t pitch)
|
||||
{
|
||||
D3D11_BOX box;
|
||||
box.left = x;
|
||||
box.right = x + width;
|
||||
box.top = y;
|
||||
box.bottom = y + height;
|
||||
box.front = 0;
|
||||
box.back = 1;
|
||||
|
||||
m_deviceContext->UpdateSubresource(m_texture, 0, &box, data, pitch, height * pitch);
|
||||
}
|
||||
|
||||
void GpDisplayDriverSurfaceD3D11::UploadEntire(const void *data, size_t pitch)
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE mappedRes;
|
||||
if (m_deviceContext->Map(m_texture, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedRes) == S_OK)
|
||||
{
|
||||
if (mappedRes.RowPitch < pitch || (pitch % 16) != 0)
|
||||
return; // This should not happen, D3D10+ feature level should guarantee 16-byte alignment
|
||||
|
||||
const size_t destPitch = mappedRes.RowPitch;
|
||||
|
||||
const uint8_t *srcBytes = static_cast<const uint8_t*>(data);
|
||||
uint8_t *destBytes = static_cast<uint8_t*>(mappedRes.pData);
|
||||
|
||||
const size_t height = m_height;
|
||||
const size_t numM128PerRow = pitch / 16;
|
||||
|
||||
for (size_t row = 0; row < height; row++)
|
||||
{
|
||||
for (size_t moffs = 0; moffs < numM128PerRow; moffs++)
|
||||
{
|
||||
const __m128i v = _mm_load_si128(reinterpret_cast<const __m128i*>(srcBytes + moffs * 16));
|
||||
_mm_stream_si128(reinterpret_cast<__m128i*>(destBytes + moffs * 16), v);
|
||||
}
|
||||
|
||||
srcBytes += pitch;
|
||||
destBytes += destPitch;
|
||||
}
|
||||
|
||||
m_deviceContext->Unmap(m_texture, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void GpDisplayDriverSurfaceD3D11::Destroy()
|
||||
{
|
||||
this->~GpDisplayDriverSurfaceD3D11();
|
||||
free(this);
|
||||
}
|
||||
|
||||
ID3D11ShaderResourceView *GpDisplayDriverSurfaceD3D11::GetSRV() const
|
||||
{
|
||||
return m_srv;
|
||||
}
|
||||
|
||||
GpPixelFormat_t GpDisplayDriverSurfaceD3D11::GetPixelFormat() const
|
||||
{
|
||||
return m_pixelFormat;
|
||||
}
|
||||
|
||||
size_t GpDisplayDriverSurfaceD3D11::GetWidth() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
size_t GpDisplayDriverSurfaceD3D11::GetHeight() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
GpDisplayDriverSurfaceD3D11 *GpDisplayDriverSurfaceD3D11::Create(ID3D11Device *device, ID3D11DeviceContext *deviceContext, size_t width, size_t height, GpPixelFormat_t pixelFormat)
|
||||
{
|
||||
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R8_UNORM;
|
||||
|
||||
switch (pixelFormat)
|
||||
{
|
||||
case GpPixelFormats::k8BitCustom:
|
||||
case GpPixelFormats::k8BitStandard:
|
||||
dxgiFormat = DXGI_FORMAT_R8_UINT;
|
||||
break;
|
||||
case GpPixelFormats::kRGB555:
|
||||
dxgiFormat = DXGI_FORMAT_R16_UINT;
|
||||
break;
|
||||
case GpPixelFormats::kRGB32:
|
||||
dxgiFormat = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
|
||||
break;
|
||||
case GpPixelFormats::kRGB24: // RGB24 is not supported as a surface format (PL must convert it)
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
D3D11_TEXTURE2D_DESC textureDesc;
|
||||
textureDesc.Width = static_cast<UINT>(width);
|
||||
textureDesc.Height = static_cast<UINT>(height);
|
||||
textureDesc.MipLevels = 1;
|
||||
textureDesc.ArraySize = 1;
|
||||
textureDesc.Format = dxgiFormat;
|
||||
textureDesc.SampleDesc.Count = 1;
|
||||
textureDesc.SampleDesc.Quality = 0;
|
||||
textureDesc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
textureDesc.MiscFlags = 0;
|
||||
|
||||
GpComPtr<ID3D11Texture2D> texture;
|
||||
if (device->CreateTexture2D(&textureDesc, nullptr, texture.GetMutablePtr()) != S_OK)
|
||||
return nullptr;
|
||||
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
|
||||
srvDesc.Format = dxgiFormat;
|
||||
srvDesc.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2D;
|
||||
srvDesc.Texture2D.MipLevels = 1;
|
||||
srvDesc.Texture2D.MostDetailedMip = 0;
|
||||
|
||||
GpComPtr<ID3D11ShaderResourceView> srv;
|
||||
if (device->CreateShaderResourceView(texture, &srvDesc, srv.GetMutablePtr()) != S_OK)
|
||||
return nullptr;
|
||||
|
||||
void *storage = malloc(sizeof(GpDisplayDriverSurfaceD3D11));
|
||||
if (!storage)
|
||||
{
|
||||
texture->Release();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return new (storage) GpDisplayDriverSurfaceD3D11(device, deviceContext, texture, srv, width, height, pixelFormat);
|
||||
}
|
||||
|
||||
GpDisplayDriverSurfaceD3D11::GpDisplayDriverSurfaceD3D11(ID3D11Device *device, ID3D11DeviceContext *deviceContext, ID3D11Texture2D *texture, ID3D11ShaderResourceView *srv, size_t width, size_t height, GpPixelFormat_t pixelFormat)
|
||||
: m_width(width)
|
||||
, m_height(height)
|
||||
, m_pixelFormat(pixelFormat)
|
||||
, m_device(device)
|
||||
, m_deviceContext(deviceContext)
|
||||
, m_texture(texture)
|
||||
, m_srv(srv)
|
||||
{
|
||||
}
|
||||
|
||||
GpDisplayDriverSurfaceD3D11::~GpDisplayDriverSurfaceD3D11()
|
||||
{
|
||||
}
|
||||
38
GpDisplayDriver_D3D11/GpDisplayDriverSurfaceD3D11.h
Normal file
38
GpDisplayDriver_D3D11/GpDisplayDriverSurfaceD3D11.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "IGpDisplayDriverSurface.h"
|
||||
#include "GpComPtr.h"
|
||||
#include "GpPixelFormat.h"
|
||||
|
||||
struct ID3D11Device;
|
||||
struct ID3D11DeviceContext;
|
||||
struct ID3D11ShaderResourceView;
|
||||
struct ID3D11Texture2D;
|
||||
|
||||
class GpDisplayDriverSurfaceD3D11 final : public IGpDisplayDriverSurface
|
||||
{
|
||||
public:
|
||||
virtual void Upload(const void *data, size_t x, size_t y, size_t width, size_t height, size_t pitch) override;
|
||||
virtual void UploadEntire(const void *data, size_t pitch) override;
|
||||
virtual void Destroy() override;
|
||||
|
||||
ID3D11ShaderResourceView *GetSRV() const;
|
||||
GpPixelFormat_t GetPixelFormat() const;
|
||||
size_t GetWidth() const;
|
||||
size_t GetHeight() const;
|
||||
|
||||
static GpDisplayDriverSurfaceD3D11 *Create(ID3D11Device *device, ID3D11DeviceContext *deviceContext, size_t width, size_t height, GpPixelFormat_t pixelFormat);
|
||||
|
||||
private:
|
||||
GpDisplayDriverSurfaceD3D11(ID3D11Device *device, ID3D11DeviceContext *deviceContext, ID3D11Texture2D *texture, ID3D11ShaderResourceView *srv, size_t width, size_t height, GpPixelFormat_t pixelFormat);
|
||||
~GpDisplayDriverSurfaceD3D11();
|
||||
|
||||
size_t m_width;
|
||||
size_t m_height;
|
||||
GpPixelFormat_t m_pixelFormat;
|
||||
ID3D11Device *m_device;
|
||||
ID3D11DeviceContext *m_deviceContext;
|
||||
|
||||
GpComPtr<ID3D11Texture2D> m_texture;
|
||||
GpComPtr<ID3D11ShaderResourceView> m_srv;
|
||||
};
|
||||
142
GpDisplayDriver_D3D11/GpDisplayDriver_D3D11.vcxproj
Normal file
142
GpDisplayDriver_D3D11/GpDisplayDriver_D3D11.vcxproj
Normal file
@@ -0,0 +1,142 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{FFC961AC-55B4-4A38-A83E-06AE98F59ACC}</ProjectGuid>
|
||||
<RootNamespace>GpDisplayDriverD3D11</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\GpCommon.props" />
|
||||
<Import Project="..\Common.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\GpCommon.props" />
|
||||
<Import Project="..\Common.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\GpCommon.props" />
|
||||
<Import Project="..\Common.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\GpCommon.props" />
|
||||
<Import Project="..\Common.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="CompiledShaders\DrawQuad15BitP_D3D11.cpp" />
|
||||
<ClCompile Include="CompiledShaders\DrawQuadPaletteP_D3D11.cpp" />
|
||||
<ClCompile Include="CompiledShaders\DrawQuadRGBP_D3D11.cpp" />
|
||||
<ClCompile Include="CompiledShaders\DrawQuadV_D3D11.cpp" />
|
||||
<ClCompile Include="GpDisplayDriverD3D11.cpp" />
|
||||
<ClCompile Include="GpDisplayDriverFactoryD3D11.cpp" />
|
||||
<ClCompile Include="GpDisplayDriverSurfaceD3D11.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="GpDisplayDriverD3D11.h" />
|
||||
<ClInclude Include="GpDisplayDriverFactoryD3D11.h" />
|
||||
<ClInclude Include="GpDisplayDriverSurfaceD3D11.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
54
GpDisplayDriver_D3D11/GpDisplayDriver_D3D11.vcxproj.filters
Normal file
54
GpDisplayDriver_D3D11/GpDisplayDriver_D3D11.vcxproj.filters
Normal file
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\CompiledShaders">
|
||||
<UniqueIdentifier>{05b8d8ff-66e2-4d10-83a1-29582f2ae9f1}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="GpDisplayDriverD3D11.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GpDisplayDriverFactoryD3D11.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GpDisplayDriverSurfaceD3D11.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CompiledShaders\DrawQuad15BitP_D3D11.cpp">
|
||||
<Filter>Source Files\CompiledShaders</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CompiledShaders\DrawQuadPaletteP_D3D11.cpp">
|
||||
<Filter>Source Files\CompiledShaders</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CompiledShaders\DrawQuadRGBP_D3D11.cpp">
|
||||
<Filter>Source Files\CompiledShaders</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CompiledShaders\DrawQuadV_D3D11.cpp">
|
||||
<Filter>Source Files\CompiledShaders</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="GpDisplayDriverD3D11.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GpDisplayDriverFactoryD3D11.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GpDisplayDriverSurfaceD3D11.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user