From 0e029cc72de2c8e57fed0ba4eb2c2a9cc4c7a0f4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Fri, 4 May 2012 11:35:48 +0100 Subject: [PATCH 1/1] Precompile d3d10 shader. --- apps/d3d10/tri.cpp | 56 +++---------------- apps/d3d10/tri.fx | 15 ++++++ apps/d3d10/tri_ps.h | 112 ++++++++++++++++++++++++++++++++++++++ apps/d3d10/tri_vs.h | 128 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 263 insertions(+), 48 deletions(-) create mode 100644 apps/d3d10/tri.fx create mode 100644 apps/d3d10/tri_ps.h create mode 100644 apps/d3d10/tri_vs.h diff --git a/apps/d3d10/tri.cpp b/apps/d3d10/tri.cpp index 1539797..4ea8b93 100644 --- a/apps/d3d10/tri.cpp +++ b/apps/d3d10/tri.cpp @@ -33,7 +33,9 @@ #include "compat.h" #include -#include + +#include "tri_vs.h" +#include "tri_ps.h" static IDXGISwapChain* g_pSwapChain = NULL; @@ -129,38 +131,8 @@ int main(int argc, char *argv[]){ const float clearColor[4] = { 0.3f, 0.1f, 0.3f, 1.0f }; g_pDevice->ClearRenderTargetView(pRenderTargetView, clearColor); - const char *szShader = - "struct VS_OUTPUT {\n" - " float4 Pos : SV_POSITION;\n" - " float4 Color : COLOR0;\n" - "};\n" - "\n" - "VS_OUTPUT VS(float4 Pos : POSITION, float4 Color : COLOR) {\n" - " VS_OUTPUT Out;\n" - " Out.Pos = Pos;\n" - " Out.Color = Color;\n" - " return Out;\n" - "}\n" - "\n" - "float4 PS(VS_OUTPUT In) : SV_Target {\n" - " return In.Color;\n" - "}\n" - ; - - ID3D10Blob *pVertexShaderBlob = NULL; - ID3D10Blob *pErrorMsgs = NULL; - - hr = D3D10CompileShader(szShader, strlen(szShader), NULL, NULL, NULL, "VS", "vs_4_0", 0, &pVertexShaderBlob, &pErrorMsgs); - if (pErrorMsgs) { - fprintf(stderr, "%s\n", pErrorMsgs->GetBufferPointer()); - pErrorMsgs->Release(); - } - if (FAILED(hr)) { - return 1; - } - ID3D10VertexShader * pVertexShader; - hr = g_pDevice->CreateVertexShader((DWORD*)pVertexShaderBlob->GetBufferPointer(), pVertexShaderBlob->GetBufferSize(), &pVertexShader); + hr = g_pDevice->CreateVertexShader(g_VS, sizeof g_VS, &pVertexShader); struct Vertex { float position[4]; @@ -175,30 +147,18 @@ int main(int argc, char *argv[]){ ID3D10InputLayout *pVertexLayout = NULL; hr = g_pDevice->CreateInputLayout(InputElementDescs, 2, - pVertexShaderBlob->GetBufferPointer(), - pVertexShaderBlob->GetBufferSize(), + g_VS, + sizeof g_VS, &pVertexLayout); - pVertexShaderBlob->Release(); g_pDevice->IASetInputLayout(pVertexLayout); - - ID3D10Blob *pPixelShaderBlob = NULL; - pErrorMsgs = NULL; - hr = D3D10CompileShader(szShader, strlen(szShader), NULL, NULL, NULL, "PS", "ps_4_0", 0, &pPixelShaderBlob, &pErrorMsgs); - if (pErrorMsgs) { - fprintf(stderr, "%s\n", pErrorMsgs->GetBufferPointer()); - pErrorMsgs->Release(); - } + ID3D10PixelShader * pPixelShader; + hr = g_pDevice->CreatePixelShader(g_PS, sizeof g_PS, &pPixelShader); if (FAILED(hr)) { return 1; } - ID3D10PixelShader * pPixelShader; - hr = g_pDevice->CreatePixelShader((DWORD*)pPixelShaderBlob->GetBufferPointer(), pPixelShaderBlob->GetBufferSize(), &pPixelShader); - pPixelShaderBlob->Release(); - - g_pDevice->VSSetShader(pVertexShader); g_pDevice->PSSetShader(pPixelShader); diff --git a/apps/d3d10/tri.fx b/apps/d3d10/tri.fx new file mode 100644 index 0000000..c221f9d --- /dev/null +++ b/apps/d3d10/tri.fx @@ -0,0 +1,15 @@ +struct VS_OUTPUT { + float4 Pos : SV_POSITION; + float4 Color : COLOR0; +}; + +VS_OUTPUT VS(float4 Pos : POSITION, float4 Color : COLOR) { + VS_OUTPUT Out; + Out.Pos = Pos; + Out.Color = Color; + return Out; +} + +float4 PS(VS_OUTPUT In) : SV_Target { + return In.Color; +} diff --git a/apps/d3d10/tri_ps.h b/apps/d3d10/tri_ps.h new file mode 100644 index 0000000..0c9302a --- /dev/null +++ b/apps/d3d10/tri_ps.h @@ -0,0 +1,112 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /T ps_4_0 /E PS /Fh apps\d3d10\tri_ps.h apps\d3d10\tri.fx +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// SV_POSITION 0 xyzw 0 POS float +// COLOR 0 xyzw 1 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v1.xyzw +dcl_output o0.xyzw +mov o0.xyzw, v1.xyzw +ret +// Approximately 2 instruction slots used +#endif + +const BYTE g_PS[] = +{ + 68, 88, 66, 67, 150, 24, + 98, 193, 223, 185, 25, 11, + 105, 3, 199, 138, 10, 93, + 81, 50, 1, 0, 0, 0, + 208, 1, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 140, 0, 0, 0, 224, 0, + 0, 0, 20, 1, 0, 0, + 84, 1, 0, 0, 82, 68, + 69, 70, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 1, 0, 0, + 28, 0, 0, 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, 57, 46, 50, + 57, 46, 57, 53, 50, 46, + 51, 49, 49, 49, 0, 171, + 171, 171, 73, 83, 71, 78, + 76, 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, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 67, 79, 76, 79, 82, 0, + 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, 97, 114, + 103, 101, 116, 0, 171, 171, + 83, 72, 68, 82, 56, 0, + 0, 0, 64, 0, 0, 0, + 14, 0, 0, 0, 98, 16, + 0, 3, 242, 16, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 242, 32, 16, 0, + 0, 0, 0, 0, 70, 30, + 16, 0, 1, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 2, 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, 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 +}; diff --git a/apps/d3d10/tri_vs.h b/apps/d3d10/tri_vs.h new file mode 100644 index 0000000..478e5e2 --- /dev/null +++ b/apps/d3d10/tri_vs.h @@ -0,0 +1,128 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 +// +// +// fxc /T vs_4_0 /E VS /Fh apps\d3d10\tri_vs.h apps\d3d10\tri.fx +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// POSITION 0 xyzw 0 NONE float xyzw +// COLOR 0 xyzw 1 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------ ------ +// SV_POSITION 0 xyzw 0 POS float xyzw +// COLOR 0 xyzw 1 NONE float xyzw +// +vs_4_0 +dcl_input v0.xyzw +dcl_input v1.xyzw +dcl_output_siv o0.xyzw, position +dcl_output o1.xyzw +mov o0.xyzw, v0.xyzw +mov o1.xyzw, v1.xyzw +ret +// Approximately 3 instruction slots used +#endif + +const BYTE g_VS[] = +{ + 68, 88, 66, 67, 190, 171, + 186, 20, 44, 105, 95, 129, + 137, 204, 223, 72, 251, 159, + 126, 176, 1, 0, 0, 0, + 28, 2, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 140, 0, 0, 0, 220, 0, + 0, 0, 48, 1, 0, 0, + 160, 1, 0, 0, 82, 68, + 69, 70, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 1, 0, 0, + 28, 0, 0, 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, 57, 46, 50, + 57, 46, 57, 53, 50, 46, + 51, 49, 49, 49, 0, 171, + 171, 171, 73, 83, 71, 78, + 72, 0, 0, 0, 2, 0, + 0, 0, 8, 0, 0, 0, + 56, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 15, 0, 0, + 65, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 15, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 67, 79, 76, + 79, 82, 0, 171, 79, 83, + 71, 78, 76, 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, 15, 0, + 0, 0, 83, 86, 95, 80, + 79, 83, 73, 84, 73, 79, + 78, 0, 67, 79, 76, 79, + 82, 0, 171, 171, 83, 72, + 68, 82, 104, 0, 0, 0, + 64, 0, 1, 0, 26, 0, + 0, 0, 95, 0, 0, 3, + 242, 16, 16, 0, 0, 0, + 0, 0, 95, 0, 0, 3, + 242, 16, 16, 0, 1, 0, + 0, 0, 103, 0, 0, 4, + 242, 32, 16, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 1, 0, 0, 0, + 54, 0, 0, 5, 242, 32, + 16, 0, 0, 0, 0, 0, + 70, 30, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 242, 32, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 1, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 4, 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, + 0, 0, 0, 0, 0, 0, + 0, 0, 2, 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 +}; -- 2.43.0