]> git.cworth.org Git - apitrace-tests/commitdiff
Simple D3D9 app.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 3 May 2012 10:20:41 +0000 (11:20 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 3 May 2012 10:20:41 +0000 (11:20 +0100)
CMakeLists.txt
README.markdown
app_driver.py
apps/CMakeLists.txt
apps/d3d9/CMakeLists.txt [new file with mode: 0644]
apps/d3d9/tri.cpp [new file with mode: 0644]
apps/d3d9/tri.ref.txt [new file with mode: 0644]
base_driver.py
traces/CMakeLists.txt

index cd7f9d114453ba84dc6a11b4434f614370746e9c..67bbb3c2492f6b0a2762f114d9705d39a3d4d10d 100644 (file)
@@ -2,8 +2,23 @@ cmake_minimum_required (VERSION 2.8)
 
 project (apitrace-tests)
 
 
 project (apitrace-tests)
 
+find_path (APITRACE_SOURCE_DIR NAMES cmake/FindDirectX.cmake PATHS .. ../.. DOC "apitrace source tree" NO_DEFAULT_PATH)
+if (NOT EXISTS ${APITRACE_SOURCE_DIR})
+    message (SEND_ERROR "Please specify path to apitrace source tree via APITRACE_SOURCE_DIR")
+endif ()
+
+find_program (APITRACE_EXECUTABLE NAMES apitrace PATHS ${APITRACE_SOURCE_DIR} DOC "apitrace executable")
+if (NOT EXISTS ${APITRACE_EXECUTABLE})
+    message (SEND_ERROR "Please specify path to apitrace executable via APITRACE_EXECUTABLE")
+endif ()
+
 include (FindPkgConfig)
 
 include (FindPkgConfig)
 
+if (APITRACE_SOURCE_DIR)
+    set (CMAKE_MODULE_PATH ${APITRACE_SOURCE_DIR}/cmake)
+    find_package (DirectX)
+endif ()
+
 # Set default built type
 if (NOT CMAKE_BUILD_TYPE)
    set (CMAKE_BUILD_TYPE Debug
 # Set default built type
 if (NOT CMAKE_BUILD_TYPE)
    set (CMAKE_BUILD_TYPE Debug
@@ -64,8 +79,6 @@ if (MSVC)
        add_definitions (-wd4244) # conversion' conversion from 'type1' to 'type2', possible loss of data
 endif ()
 
        add_definitions (-wd4244) # conversion' conversion from 'type1' to 'type2', possible loss of data
 endif ()
 
-find_program (APITRACE_EXECUTABLE apitrace DOC "apitrace executable")
-
 enable_testing()
 
 add_subdirectory (apps)
 enable_testing()
 
 add_subdirectory (apps)
index 28204282f236c039f845b8a1af123426c77c837c..c32d9e62a32906f1310aea079edf6a1ce5707624 100644 (file)
@@ -8,7 +8,7 @@ In addition to apitrace requirements, it also requires:
 
 To run the test suite do on Unices:
 
 
 To run the test suite do on Unices:
 
-    cmake -DAPITRACE_EXECUTABLE=/path/to/apitrace -H. -B./build
+    cmake -DAPITRACE_SOURCE_DIR=/path/to/apitrace/tree -DAPITRACE_EXECUTABLE=/path/to/apitrace/build/apitrace -H. -B./build
     export CTEST_OUTPUT_ON_FAILURE=1
     make -C ./build all test
 
     export CTEST_OUTPUT_ON_FAILURE=1
     make -C ./build all test
 
index 33d2d5e65dccfa09326a92ecf00c232242400eca..2c7a319a5d556b7006711a70cd0464c4793dc35a 100755 (executable)
@@ -170,11 +170,20 @@ class AppDriver(Driver):
         if p.returncode:
             skip('application returned code %i' % p.returncode)
 
         if p.returncode:
             skip('application returned code %i' % p.returncode)
 
-    api_map = {
+    api_trace_map = {
         'gl': 'gl',
         'egl_gl': 'egl',
         'egl_gles1': 'egl',
         'egl_gles2': 'egl',
         'gl': 'gl',
         'egl_gl': 'egl',
         'egl_gles1': 'egl',
         'egl_gles2': 'egl',
+        'd3d9': 'd3d9',
+    }
+
+    api_retrace_map = {
+        'gl': 'glretrace',
+        'egl_gl': 'eglretrace',
+        'egl_gles1': 'eglretrace',
+        'egl_gles2': 'eglretrace',
+        'd3d9': 'd3dretrace',
     }
 
     def traceApp(self):
     }
 
     def traceApp(self):
@@ -202,7 +211,7 @@ class AppDriver(Driver):
         
         cmd = [
             options.apitrace, 'trace', 
         
         cmd = [
             options.apitrace, 'trace', 
-            '--api', self.api_map[self.api],
+            '--api', self.api_trace_map[self.api],
             '--output', self.trace_file,
             '--'
         ] + cmd
             '--output', self.trace_file,
             '--'
         ] + cmd
@@ -395,7 +404,7 @@ class AppDriver(Driver):
             pass
 
     def _retrace(self, args = None, stdout=subprocess.PIPE):
             pass
 
     def _retrace(self, args = None, stdout=subprocess.PIPE):
-        retrace = self.api_map[self.api] + 'retrace'
+        retrace = self.api_retrace_map[self.api]
         cmd = [get_build_program(retrace)]
         if self.doubleBuffer:
             cmd += ['-db']
         cmd = [get_build_program(retrace)]
         if self.doubleBuffer:
             cmd += ['-db']
index 179370948b714a967c1df95b2dc768dc11c8e4d3..98c41f5ce55b18d25e906e0e206887f22215f677 100644 (file)
@@ -15,6 +15,7 @@ function (ADD_APP_TEST)
         COMMAND
         python ${CMAKE_SOURCE_DIR}/app_driver.py
             --apitrace ${APITRACE_EXECUTABLE}
         COMMAND
         python ${CMAKE_SOURCE_DIR}/app_driver.py
             --apitrace ${APITRACE_EXECUTABLE}
+            --apitrace-source ${APITRACE_SOURCE_DIR}
             --api ${api}
             --ref-dump ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_REF}
             --
             --api ${api}
             --ref-dump ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_REF}
             --
@@ -30,3 +31,7 @@ endif ()
 if (EGL_FOUND)
     add_subdirectory (egl)
 endif ()
 if (EGL_FOUND)
     add_subdirectory (egl)
 endif ()
+
+if (DirectX_D3D9_FOUND)
+    add_subdirectory (d3d9)
+endif ()
diff --git a/apps/d3d9/CMakeLists.txt b/apps/d3d9/CMakeLists.txt
new file mode 100644 (file)
index 0000000..999879b
--- /dev/null
@@ -0,0 +1,27 @@
+include_directories (
+    ${DirectX_D3D9_INCLUDE_DIR}
+)
+
+link_libraries (
+    ${DirectX_D3D9_LIBRARY}
+)
+
+set (api d3d9)
+
+set (targets
+    tri
+)
+
+foreach (target ${targets})
+    add_executable (${api}_${target} WIN32 ${target}.cpp)
+    set_target_properties (${api}_${target} PROPERTIES OUTPUT_NAME ${target})
+
+    if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${target}.ref.txt)
+        add_app_test(
+            NAME ${api}_${target}
+            TARGET ${api}_${target}
+            REF ${target}.ref.txt
+        )
+    endif ()
+endforeach (target)
+
diff --git a/apps/d3d9/tri.cpp b/apps/d3d9/tri.cpp
new file mode 100644 (file)
index 0000000..8166734
--- /dev/null
@@ -0,0 +1,168 @@
+/**************************************************************************
+ *
+ * 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 <windows.h>
+
+#include <d3d9.h>
+
+
+static IDirect3D9 * g_pD3D = NULL;
+static IDirect3DDevice9 * g_pDevice = NULL;
+static D3DPRESENT_PARAMETERS g_PresentationParameters;
+
+
+int WINAPI
+WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow)
+{
+    HRESULT hr;
+
+    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)) {
+        g_pD3D->Release();
+        g_pD3D = NULL;
+        return 1;
+    }
+
+    struct Vertex {
+        float x, y, z;
+        DWORD color;
+    };
+
+
+    D3DCOLOR clearColor = D3DCOLOR_COLORVALUE(0.3f, 0.1f, 0.3f, 1.0f);
+    g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET, clearColor, 1.0f, 0);
+    g_pDevice->BeginScene();
+
+    g_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
+    g_pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
+
+    static const Vertex vertices[] = {
+        { -0.9f, -0.9f, 0.5f, D3DCOLOR_COLORVALUE(0.8f, 0.0f, 0.0f, 0.1f) },
+        {  0.9f, -0.9f, 0.5f, D3DCOLOR_COLORVALUE(0.0f, 0.9f, 0.0f, 0.1f) },
+        {  0.0f,  0.9f, 0.5f, D3DCOLOR_COLORVALUE(0.0f, 0.0f, 0.7f, 0.1f) },
+    };
+
+    g_pDevice->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE);
+    g_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, vertices, sizeof(Vertex));
+
+    g_pDevice->EndScene();
+
+    g_pDevice->Present(NULL, NULL, NULL, NULL);
+
+
+    g_pDevice->Release();
+    g_pDevice = NULL;
+    g_pD3D->Release();
+    g_pD3D = NULL;
+
+    DestroyWindow(hWnd);
+
+    return 0;
+}
+
diff --git a/apps/d3d9/tri.ref.txt b/apps/d3d9/tri.ref.txt
new file mode 100644 (file)
index 0000000..e69de29
index 1be143288fffd5af79245757674b0434aabd66a1..1971fce5a88d616608c918fd16b6152ceadd0673 100644 (file)
@@ -107,6 +107,9 @@ def get_build_program(program):
 
 
 def get_scripts_path():
 
 
 def get_scripts_path():
+    if options.apitrace_source:
+        return os.path.join(options.apitrace_source, 'scripts')
+
     bin_path = get_bin_path()
 
     try_paths = [
     bin_path = get_bin_path()
 
     try_paths = [
@@ -147,6 +150,10 @@ class Driver:
             '--apitrace', metavar='PROGRAM',
             type='string', dest='apitrace', default=default_apitrace,
             help='path to apitrace executable')
             '--apitrace', metavar='PROGRAM',
             type='string', dest='apitrace', default=default_apitrace,
             help='path to apitrace executable')
+        optparser.add_option(
+            '--apitrace-source', metavar='PATH',
+            type='string', dest='apitrace_source',
+            help='path to apitrace source tree')
         optparser.add_option(
             '-C', '--directory', metavar='PATH',
             type='string', dest='cwd', default=None,
         optparser.add_option(
             '-C', '--directory', metavar='PATH',
             type='string', dest='cwd', default=None,
index c1e0500d20418113b840159f77e722e734a3f8b7..983be78a58735e6df5e01afa460b50aebe6494c6 100644 (file)
@@ -8,6 +8,7 @@ foreach (script ${scripts})
         COMMAND
         python ${CMAKE_SOURCE_DIR}/tool_driver.py
             --apitrace ${APITRACE_EXECUTABLE}
         COMMAND
         python ${CMAKE_SOURCE_DIR}/tool_driver.py
             --apitrace ${APITRACE_EXECUTABLE}
+            --apitrace-source ${APITRACE_SOURCE_DIR}
             ${CMAKE_CURRENT_SOURCE_DIR}/${script}
     )
 endforeach (script)
             ${CMAKE_CURRENT_SOURCE_DIR}/${script}
     )
 endforeach (script)