From c41cfb0f8cca8818f0a512d58f4c43820321e622 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Tue, 27 Nov 2012 14:22:57 +0000 Subject: [PATCH] Add a shader d3d9 tri test. --- apps/d3d10/tri.cpp | 4 +- apps/d3d9/CMakeLists.txt | 4 +- apps/d3d9/tri.cpp | 6 +- apps/d3d9/tri_pp.cpp | 207 ++++++++++++++++++++++++++++++++++ apps/d3d9/tri_pp.ref.txt | 36 ++++++ apps/d3dcommon/CMakeLists.txt | 1 + apps/d3dcommon/tri_ps_2_0.h | 39 +++++++ apps/d3dcommon/tri_vs_2_0.h | 45 ++++++++ 8 files changed, 338 insertions(+), 4 deletions(-) create mode 100644 apps/d3d9/tri_pp.cpp create mode 100644 apps/d3d9/tri_pp.ref.txt create mode 100755 apps/d3dcommon/tri_ps_2_0.h create mode 100755 apps/d3dcommon/tri_vs_2_0.h diff --git a/apps/d3d10/tri.cpp b/apps/d3d10/tri.cpp index 08b6701..1821342 100644 --- a/apps/d3d10/tri.cpp +++ b/apps/d3d10/tri.cpp @@ -42,7 +42,9 @@ static IDXGISwapChain* g_pSwapChain = NULL; static ID3D10Device * g_pDevice = NULL; -int main(int argc, char *argv[]){ +int +main(int argc, char *argv[]) +{ HRESULT hr; HINSTANCE hInstance = GetModuleHandle(NULL); diff --git a/apps/d3d9/CMakeLists.txt b/apps/d3d9/CMakeLists.txt index 999879b..6e9fec9 100644 --- a/apps/d3d9/CMakeLists.txt +++ b/apps/d3d9/CMakeLists.txt @@ -1,4 +1,5 @@ include_directories ( + ${CMAKE_CURRENT_SOURCE_DIR}/../d3dcommon ${DirectX_D3D9_INCLUDE_DIR} ) @@ -10,10 +11,11 @@ set (api d3d9) set (targets tri + tri_pp ) foreach (target ${targets}) - add_executable (${api}_${target} WIN32 ${target}.cpp) + add_executable (${api}_${target} ${target}.cpp) set_target_properties (${api}_${target} PROPERTIES OUTPUT_NAME ${target}) if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${target}.ref.txt) diff --git a/apps/d3d9/tri.cpp b/apps/d3d9/tri.cpp index 8166734..8c3fda7 100644 --- a/apps/d3d9/tri.cpp +++ b/apps/d3d9/tri.cpp @@ -34,11 +34,13 @@ static IDirect3DDevice9 * g_pDevice = NULL; static D3DPRESENT_PARAMETERS g_PresentationParameters; -int WINAPI -WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow) +int +main(int argc, char *argv[]) { HRESULT hr; + HINSTANCE hInstance = GetModuleHandle(NULL); + WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, diff --git a/apps/d3d9/tri_pp.cpp b/apps/d3d9/tri_pp.cpp new file mode 100644 index 0000000..8c55d43 --- /dev/null +++ b/apps/d3d9/tri_pp.cpp @@ -0,0 +1,207 @@ +/************************************************************************** + * + * Copyright 2012 Jose Fonseca + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + **************************************************************************/ + + +#include + +#include + +#include + +#include "tri_vs_2_0.h" +#include "tri_ps_2_0.h" + + +static IDirect3D9 * g_pD3D = NULL; +static IDirect3DDevice9 * g_pDevice = NULL; +static D3DPRESENT_PARAMETERS g_PresentationParameters; + + +int +main(int argc, char *argv[]) +{ + HRESULT hr; + + HINSTANCE hInstance = GetModuleHandle(NULL); + + WNDCLASSEX wc = { + sizeof(WNDCLASSEX), + CS_CLASSDC, + DefWindowProc, + 0, + 0, + hInstance, + NULL, + NULL, + NULL, + NULL, + "SimpleDX9", + NULL + }; + RegisterClassEx(&wc); + + const int WindowWidth = 250; + const int WindowHeight = 250; + BOOL Windowed = TRUE; + + DWORD dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW; + + RECT rect = {0, 0, WindowWidth, WindowHeight}; + AdjustWindowRect(&rect, dwStyle, FALSE); + + HWND hWnd = CreateWindow(wc.lpszClassName, + "Simple example using DirectX9", + dwStyle, + CW_USEDEFAULT, CW_USEDEFAULT, + rect.right - rect.left, + rect.bottom - rect.top, + NULL, + NULL, + hInstance, + NULL); + if (!hWnd) { + return 1; + } + + ShowWindow(hWnd, SW_SHOW); + + g_pD3D = Direct3DCreate9(D3D_SDK_VERSION); + if (!g_pD3D) { + return 1; + } + + D3DCAPS9 caps; + hr = g_pD3D->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps); + if (FAILED(hr)) { + return 1; + } + + DWORD dwBehaviorFlags; + if ((caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0 || + caps.VertexShaderVersion < D3DVS_VERSION(1, 1)) { + dwBehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; + } else { + dwBehaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING; + } + + ZeroMemory(&g_PresentationParameters, sizeof g_PresentationParameters); + g_PresentationParameters.Windowed = Windowed; + if (!Windowed) { + g_PresentationParameters.BackBufferWidth = WindowWidth; + g_PresentationParameters.BackBufferHeight = WindowHeight; + } + g_PresentationParameters.BackBufferCount = 1; + g_PresentationParameters.SwapEffect = D3DSWAPEFFECT_FLIP; + if (!Windowed) { + g_PresentationParameters.BackBufferFormat = D3DFMT_X8R8G8B8; + } else { + g_PresentationParameters.BackBufferFormat = D3DFMT_UNKNOWN; + } + g_PresentationParameters.hDeviceWindow = hWnd; + + g_PresentationParameters.EnableAutoDepthStencil = FALSE; + g_PresentationParameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + + hr = g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, + D3DDEVTYPE_HAL, + hWnd, + dwBehaviorFlags, + &g_PresentationParameters, + &g_pDevice); + if (FAILED(hr)) { + return 1; + } + + D3DCOLOR clearColor = D3DCOLOR_COLORVALUE(0.3f, 0.1f, 0.3f, 1.0f); + g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET, clearColor, 1.0f, 0); + + struct Vertex { + float position[4]; + float color[4]; + }; + + static const Vertex vertices[] = { + { { -0.9f, -0.9f, 0.5f, 1.0f}, { 0.8f, 0.0f, 0.0f, 0.1f } }, + { { 0.9f, -0.9f, 0.5f, 1.0f}, { 0.0f, 0.9f, 0.0f, 0.1f } }, + { { 0.0f, 0.9f, 0.5f, 1.0f}, { 0.0f, 0.0f, 0.7f, 0.1f } }, + }; + + static const D3DVERTEXELEMENT9 VertexElements[] = { + { 0, offsetof(Vertex, position), D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, + { 0, offsetof(Vertex, color), D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 }, + D3DDECL_END() + }; + + LPDIRECT3DVERTEXDECLARATION9 pVertexDeclaration = NULL; + hr = g_pDevice->CreateVertexDeclaration(VertexElements, &pVertexDeclaration); + if (FAILED(hr)) { + return 1; + } + g_pDevice->SetVertexDeclaration(pVertexDeclaration); + + LPDIRECT3DVERTEXSHADER9 pVertexShader = NULL; + hr = g_pDevice->CreateVertexShader((CONST DWORD *)g_vs20_VS, &pVertexShader); + if (FAILED(hr)) { + return 1; + } + g_pDevice->SetVertexShader(pVertexShader); + + LPDIRECT3DPIXELSHADER9 pPixelShader = NULL; + hr = g_pDevice->CreatePixelShader((CONST DWORD *)g_ps20_PS, &pPixelShader); + if (FAILED(hr)) { + return 1; + } + g_pDevice->SetPixelShader(pPixelShader); + + g_pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); + + g_pDevice->BeginScene(); + + g_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, vertices, sizeof(Vertex)); + + g_pDevice->EndScene(); + + g_pDevice->Present(NULL, NULL, NULL, NULL); + + pPixelShader->Release(); + pPixelShader = NULL; + + pVertexShader->Release(); + pVertexShader = NULL; + + pVertexDeclaration->Release(); + pVertexDeclaration = NULL; + + g_pDevice->Release(); + g_pDevice = NULL; + + g_pD3D->Release(); + g_pD3D = NULL; + + DestroyWindow(hWnd); + + return 0; +} + diff --git a/apps/d3d9/tri_pp.ref.txt b/apps/d3d9/tri_pp.ref.txt new file mode 100644 index 0000000..ca32328 --- /dev/null +++ b/apps/d3d9/tri_pp.ref.txt @@ -0,0 +1,36 @@ +Direct3DCreate9(SDKVersion = 32) = +IDirect3D9::GetDeviceCaps(this = , Adapter = D3DADAPTER_DEFAULT, DeviceType = D3DDEVTYPE_HAL, pCaps = &) = D3D_OK +IDirect3D9::CreateDevice(this = , Adapter = D3DADAPTER_DEFAULT, DeviceType = D3DDEVTYPE_HAL, hFocusWindow = , BehaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING, pPresentationParameters = &{BackBufferWidth = 250, BackBufferHeight = 250, BackBufferFormat = D3DFMT_X8R8G8B8, BackBufferCount = 1, MultiSampleType = D3DMULTISAMPLE_NONE, MultiSampleQuality = 0, SwapEffect = D3DSWAPEFFECT_FLIP, hDeviceWindow = , Windowed = TRUE, EnableAutoDepthStencil = FALSE, AutoDepthStencilFormat = D3DFMT_UNKNOWN, Flags = 0, FullScreen_RefreshRateInHz = 0, PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE}, ppReturnedDeviceInterface = &) = D3D_OK +IDirect3DDevice9::Clear(this = , Count = 0, pRects = NULL, Flags = D3DCLEAR_TARGET, Color = 0xff4c194c, Z = 1, Stencil = 0) = D3D_OK +IDirect3DDevice9::CreateVertexDeclaration(this = , pVertexElements = {{Stream = 0, Offset = 0, Type = D3DDECLTYPE_FLOAT4, Method = D3DDECLMETHOD_DEFAULT, Usage = D3DDECLUSAGE_POSITION, UsageIndex = 0}, {Stream = 0, Offset = 16, Type = D3DDECLTYPE_FLOAT4, Method = D3DDECLMETHOD_DEFAULT, Usage = D3DDECLUSAGE_COLOR, UsageIndex = 0}, {Stream = 255, Offset = 0, Type = D3DDECLTYPE_UNUSED, Method = D3DDECLMETHOD_DEFAULT, Usage = D3DDECLUSAGE_POSITION, UsageIndex = 0}}, ppDecl = &) = D3D_OK +IDirect3DDevice9::SetVertexDeclaration(this = , pDecl = ) = D3D_OK +IDirect3DDevice9::CreateVertexShader(this = , pFunction = "// +// Generated by Microsoft (R) HLSL Shader Compiler 9.30.960.8229 + vs_2_0 + dcl_position v0 + dcl_color v1 + mov oPos, v0 + mov oD0, v1 + +// approximately 2 instruction slots used +", ppShader = &) = D3D_OK +IDirect3DDevice9::SetVertexShader(this = , pShader = ) = D3D_OK +IDirect3DDevice9::CreatePixelShader(this = , pFunction = "// +// Generated by Microsoft (R) HLSL Shader Compiler 9.30.960.8229 + ps_2_0 + dcl v0 + mov oC0, v0 + +// approximately 1 instruction slot used +", ppShader = &) = D3D_OK +IDirect3DDevice9::SetPixelShader(this = , pShader = ) = D3D_OK +IDirect3DDevice9::SetRenderState(this = , State = D3DRS_CULLMODE, Value = D3DCULL_NONE) = D3D_OK +IDirect3DDevice9::BeginScene(this = ) = D3D_OK +IDirect3DDevice9::DrawPrimitiveUP(this = , PrimitiveType = D3DPT_TRIANGLELIST, PrimitiveCount = 1, pVertexStreamZeroData = blob(96), VertexStreamZeroStride = 32) = D3D_OK +IDirect3DDevice9::EndScene(this = ) = D3D_OK +IDirect3DDevice9::Present(this = , pSourceRect = NULL, pDestRect = NULL, hDestWindowOverride = NULL, pDirtyRegion = NULL) = D3D_OK +IDirect3DPixelShader9::Release(this = ) = 0 +IDirect3DVertexShader9::Release(this = ) = 0 +IDirect3DVertexDeclaration9::Release(this = ) = 0 +IDirect3DDevice9::Release(this = ) = 0 +IDirect3D9::Release(this = ) = 0 diff --git a/apps/d3dcommon/CMakeLists.txt b/apps/d3dcommon/CMakeLists.txt index 0bf6111..06ce322 100644 --- a/apps/d3dcommon/CMakeLists.txt +++ b/apps/d3dcommon/CMakeLists.txt @@ -19,6 +19,7 @@ macro (fxc VS_PROFILE PS_PROFILE) set (HEADERS ${HEADERS} ${VS_HEADER} ${PS_HEADER}) endmacro () +fxc (vs_2_0 ps_2_0) fxc (vs_4_0 ps_4_0) fxc (vs_4_0_level_9_1 ps_4_0_level_9_1) diff --git a/apps/d3dcommon/tri_ps_2_0.h b/apps/d3dcommon/tri_ps_2_0.h new file mode 100755 index 0000000..ce3e1e8 --- /dev/null +++ b/apps/d3dcommon/tri_ps_2_0.h @@ -0,0 +1,39 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.30.960.8229 +// +// fxc /nologo /Qstrip_reflect /T ps_2_0 /E PS /Fh +// Z:/projects/apitrace/tests/apps/d3dcommon/tri_ps_2_0.h +// Z:/projects/apitrace/tests/apps/d3dcommon/tri.fx +// + ps_2_0 + dcl v0 + mov oC0, v0 + +// approximately 1 instruction slot used +#endif + +const BYTE g_ps20_PS[] = +{ + 0, 2, 255, 255, 254, 255, + 22, 0, 67, 84, 65, 66, + 28, 0, 0, 0, 35, 0, + 0, 0, 0, 2, 255, 255, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 0, + 28, 0, 0, 0, 112, 115, + 95, 50, 95, 48, 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, + 51, 48, 46, 57, 54, 48, + 46, 56, 50, 50, 57, 0, + 31, 0, 0, 2, 0, 0, + 0, 128, 0, 0, 15, 144, + 1, 0, 0, 2, 0, 8, + 15, 128, 0, 0, 228, 144, + 255, 255, 0, 0 +}; diff --git a/apps/d3dcommon/tri_vs_2_0.h b/apps/d3dcommon/tri_vs_2_0.h new file mode 100755 index 0000000..dbb621d --- /dev/null +++ b/apps/d3dcommon/tri_vs_2_0.h @@ -0,0 +1,45 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 9.30.960.8229 +// +// fxc /nologo /Qstrip_reflect /T vs_2_0 /E VS /Fh +// Z:/projects/apitrace/tests/apps/d3dcommon/tri_vs_2_0.h +// Z:/projects/apitrace/tests/apps/d3dcommon/tri.fx +// + vs_2_0 + dcl_position v0 + dcl_color v1 + mov oPos, v0 + mov oD0, v1 + +// approximately 2 instruction slots used +#endif + +const BYTE g_vs20_VS[] = +{ + 0, 2, 254, 255, 254, 255, + 22, 0, 67, 84, 65, 66, + 28, 0, 0, 0, 35, 0, + 0, 0, 0, 2, 254, 255, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 0, + 28, 0, 0, 0, 118, 115, + 95, 50, 95, 48, 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, + 51, 48, 46, 57, 54, 48, + 46, 56, 50, 50, 57, 0, + 31, 0, 0, 2, 0, 0, + 0, 128, 0, 0, 15, 144, + 31, 0, 0, 2, 10, 0, + 0, 128, 1, 0, 15, 144, + 1, 0, 0, 2, 0, 0, + 15, 192, 0, 0, 228, 144, + 1, 0, 0, 2, 0, 0, + 15, 208, 1, 0, 228, 144, + 255, 255, 0, 0 +}; -- 2.43.0