]> git.cworth.org Git - apitrace-tests/commitdiff
Add a shader d3d9 tri test.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Tue, 27 Nov 2012 14:22:57 +0000 (14:22 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Tue, 27 Nov 2012 14:22:57 +0000 (14:22 +0000)
apps/d3d10/tri.cpp
apps/d3d9/CMakeLists.txt
apps/d3d9/tri.cpp
apps/d3d9/tri_pp.cpp [new file with mode: 0644]
apps/d3d9/tri_pp.ref.txt [new file with mode: 0644]
apps/d3dcommon/CMakeLists.txt
apps/d3dcommon/tri_ps_2_0.h [new file with mode: 0755]
apps/d3dcommon/tri_vs_2_0.h [new file with mode: 0755]

index 08b67017edb1d5ce96f28c07912ce7c81b7b4a8a..18213427e5a8df6154cd7fd538e482350aaeddb0 100644 (file)
@@ -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);
index 999879bc71062208c3a1af496559f9cdfd7b1ba6..6e9fec909ff80bc4abe60772226a0db47dd0b045 100644 (file)
@@ -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)
index 816673497027b8c9421642139caa8d8047f930d5..8c3fda7baa76e6ae7151837a85903a24ba7afc19 100644 (file)
@@ -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 (file)
index 0000000..8c55d43
--- /dev/null
@@ -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 <stddef.h>
+
+#include <windows.h>
+
+#include <d3d9.h>
+
+#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 (file)
index 0000000..ca32328
--- /dev/null
@@ -0,0 +1,36 @@
+Direct3DCreate9(SDKVersion = 32) = <pD3D>
+IDirect3D9::GetDeviceCaps(this = <pD3D>, Adapter = D3DADAPTER_DEFAULT, DeviceType = D3DDEVTYPE_HAL, pCaps = &<Caps>) = D3D_OK
+IDirect3D9::CreateDevice(this = <pD3D>, Adapter = D3DADAPTER_DEFAULT, DeviceType = D3DDEVTYPE_HAL, hFocusWindow = <hWnd>, BehaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING, pPresentationParameters = &{BackBufferWidth = 250, BackBufferHeight = 250, BackBufferFormat = D3DFMT_X8R8G8B8, BackBufferCount = 1, MultiSampleType = D3DMULTISAMPLE_NONE, MultiSampleQuality = 0, SwapEffect = D3DSWAPEFFECT_FLIP, hDeviceWindow = <hWnd>, Windowed = TRUE, EnableAutoDepthStencil = FALSE, AutoDepthStencilFormat = D3DFMT_UNKNOWN, Flags = 0, FullScreen_RefreshRateInHz = 0, PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE}, ppReturnedDeviceInterface = &<pDevice>) = D3D_OK
+IDirect3DDevice9::Clear(this = <pDevice>, Count = 0, pRects = NULL, Flags = D3DCLEAR_TARGET, Color = 0xff4c194c, Z = 1, Stencil = 0) = D3D_OK
+IDirect3DDevice9::CreateVertexDeclaration(this = <pDevice>, 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 = &<pVertexDeclaration>) = D3D_OK
+IDirect3DDevice9::SetVertexDeclaration(this = <pDevice>, pDecl = <pVertexDeclaration>) = D3D_OK
+IDirect3DDevice9::CreateVertexShader(this = <pDevice>, 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 = &<pVertexShader>) = D3D_OK
+IDirect3DDevice9::SetVertexShader(this = <pDevice>, pShader = <pVertexShader>) = D3D_OK
+IDirect3DDevice9::CreatePixelShader(this = <pDevice>, 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 = &<pPixelShader>) = D3D_OK
+IDirect3DDevice9::SetPixelShader(this = <pDevice>, pShader = <pPixelShader>) = D3D_OK
+IDirect3DDevice9::SetRenderState(this = <pDevice>, State = D3DRS_CULLMODE, Value = D3DCULL_NONE) = D3D_OK
+IDirect3DDevice9::BeginScene(this = <pDevice>) = D3D_OK
+IDirect3DDevice9::DrawPrimitiveUP(this = <pDevice>, PrimitiveType = D3DPT_TRIANGLELIST, PrimitiveCount = 1, pVertexStreamZeroData = blob(96), VertexStreamZeroStride = 32) = D3D_OK
+IDirect3DDevice9::EndScene(this = <pDevice>) = D3D_OK
+IDirect3DDevice9::Present(this = <pDevice>, pSourceRect = NULL, pDestRect = NULL, hDestWindowOverride = NULL, pDirtyRegion = NULL) = D3D_OK
+IDirect3DPixelShader9::Release(this = <pPixelShader>) = 0
+IDirect3DVertexShader9::Release(this = <pVertexShader>) = 0
+IDirect3DVertexDeclaration9::Release(this = <pVertexDeclaration>) = 0
+IDirect3DDevice9::Release(this = <pDevice>) = 0
+IDirect3D9::Release(this = <pD3D>) = 0
index 0bf6111e5991187d23428b0625a29d10b8fadfdb..06ce3220d92ee5ee9b0d58e3684483fe738e7850 100644 (file)
@@ -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 (executable)
index 0000000..ce3e1e8
--- /dev/null
@@ -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 (executable)
index 0000000..dbb621d
--- /dev/null
@@ -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
+};