Update DirectX samples for Windows builds

This commit is contained in:
Rob Armstrong 2024-12-18 20:06:37 -08:00
parent fcd39008ec
commit a55d6682d2
8 changed files with 83 additions and 768 deletions

View File

@ -1,294 +0,0 @@
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//--------------------------------------------------------------------------------------
// File: dynlink_d3d10.h
//
// Shortcut macros and functions for using DX objects
//
// Copyright (c) Microsoft Corporation. All rights reserved
//--------------------------------------------------------------------------------------
#ifndef _DYNLINK_D3D10_H_
#define _DYNLINK_D3D10_H_
// Standard Windows includes
#include <windows.h>
#include <initguid.h>
#include <assert.h>
#include <wchar.h>
#include <mmsystem.h>
#include <commctrl.h> // for InitCommonControls()
#include <shellapi.h> // for ExtractIcon()
#include <new.h> // for placement new
#include <shlobj.h>
#include <math.h>
#include <limits.h>
#include <stdio.h>
// CRT's memory leak detection
#if defined(DEBUG) || defined(_DEBUG)
#include <crtdbg.h>
#endif
// Direct3D9 includes
#include <d3d9.h>
// Direct3D10 includes
#include <dxgi.h>
#include <d3d10_1.h>
#include <d3d10.h>
// XInput includes
#include <xinput.h>
// strsafe.h deprecates old unsecure string functions. If you
// really do not want to it to (not recommended), then uncomment the next line
//#define STRSAFE_NO_DEPRECATE
#ifndef STRSAFE_NO_DEPRECATE
#pragma deprecated("strncpy")
#pragma deprecated("wcsncpy")
#pragma deprecated("_tcsncpy")
#pragma deprecated("wcsncat")
#pragma deprecated("strncat")
#pragma deprecated("_tcsncat")
#endif
#pragma warning( disable : 4996 ) // disable deprecated warning
#include <strsafe.h>
#pragma warning( default : 4996 )
#include <DirectXMath.h>
using namespace DirectX;
//--------------------------------------------------------------------------------------
// Structs
//--------------------------------------------------------------------------------------
struct DXUTD3D9DeviceSettings
{
UINT AdapterOrdinal;
D3DDEVTYPE DeviceType;
D3DFORMAT AdapterFormat;
DWORD BehaviorFlags;
D3DPRESENT_PARAMETERS pp;
};
struct DXUTD3D10DeviceSettings
{
UINT AdapterOrdinal;
D3D10_DRIVER_TYPE DriverType;
UINT Output;
DXGI_SWAP_CHAIN_DESC sd;
UINT32 CreateFlags;
UINT32 SyncInterval;
DWORD PresentFlags;
bool AutoCreateDepthStencil; // DXUT will create the a depth stencil resource and view if true
DXGI_FORMAT AutoDepthStencilFormat;
};
enum DXUTDeviceVersion { DXUT_D3D9_DEVICE, DXUT_D3D10_DEVICE };
struct DXUTDeviceSettings
{
DXUTDeviceVersion ver;
union
{
DXUTD3D9DeviceSettings d3d9; // only valid if ver == DXUT_D3D9_DEVICE
DXUTD3D10DeviceSettings d3d10; // only valid if ver == DXUT_D3D10_DEVICE
};
};
//--------------------------------------------------------------------------------------
// Error codes
//--------------------------------------------------------------------------------------
#define DXUTERR_NODIRECT3D MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0901)
#define DXUTERR_NOCOMPATIBLEDEVICES MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0902)
#define DXUTERR_MEDIANOTFOUND MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0903)
#define DXUTERR_NONZEROREFCOUNT MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0904)
#define DXUTERR_CREATINGDEVICE MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0905)
#define DXUTERR_RESETTINGDEVICE MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0906)
#define DXUTERR_CREATINGDEVICEOBJECTS MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0907)
#define DXUTERR_RESETTINGDEVICEOBJECTS MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0908)
#define DXUTERR_DEVICEREMOVED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x090A)
typedef HRESULT(WINAPI *LPCREATEDXGIFACTORY)(REFIID, void **);
typedef HRESULT(WINAPI *LPD3D10CREATEDEVICE)(IDXGIAdapter *, D3D10_DRIVER_TYPE, HMODULE, UINT, UINT32,
ID3D10Device **);
typedef HRESULT(WINAPI *LPD3D10CREATEDEVICE1)(IDXGIAdapter *, D3D10_DRIVER_TYPE, HMODULE, UINT,
D3D10_FEATURE_LEVEL1, UINT, ID3D10Device1 **);
typedef HRESULT(WINAPI *LPD3D10CREATESTATEBLOCK)(ID3D10Device *pDevice, D3D10_STATE_BLOCK_MASK *pStateBlockMask,
ID3D10StateBlock **ppStateBlock);
typedef HRESULT(WINAPI *LPD3D10STATEBLOCKMASKUNION)(D3D10_STATE_BLOCK_MASK *pA, D3D10_STATE_BLOCK_MASK *pB,
D3D10_STATE_BLOCK_MASK *pResult);
typedef HRESULT(WINAPI *LPD3D10STATEBLOCKMASKINTERSECT)(D3D10_STATE_BLOCK_MASK *pA, D3D10_STATE_BLOCK_MASK *pB,
D3D10_STATE_BLOCK_MASK *pResult);
typedef HRESULT(WINAPI *LPD3D10STATEBLOCKMASKDIFFERENCE)(D3D10_STATE_BLOCK_MASK *pA, D3D10_STATE_BLOCK_MASK *pB,
D3D10_STATE_BLOCK_MASK *pResult);
typedef HRESULT(WINAPI *LPD3D10STATEBLOCKMASKENABLECAPTURE)(D3D10_STATE_BLOCK_MASK *pMask,
D3D10_DEVICE_STATE_TYPES StateType, UINT RangeStart,
UINT RangeLength);
typedef HRESULT(WINAPI *LPD3D10STATEBLOCKMASKDISABLECAPTURE)(D3D10_STATE_BLOCK_MASK *pMask,
D3D10_DEVICE_STATE_TYPES StateType, UINT RangeStart,
UINT RangeLength);
typedef HRESULT(WINAPI *LPD3D10STATEBLOCKMASKENABLEALL)(D3D10_STATE_BLOCK_MASK *pMask);
typedef HRESULT(WINAPI *LPD3D10STATEBLOCKMASKDISABLEALL)(D3D10_STATE_BLOCK_MASK *pMask);
typedef BOOL (WINAPI *LPD3D10STATEBLOCKMASKGETSETTING)(D3D10_STATE_BLOCK_MASK *pMask,
D3D10_DEVICE_STATE_TYPES StateType, UINT Entry);
typedef HRESULT(WINAPI *LPD3D10COMPILEEFFECTFROMMEMORY)(void *pData, SIZE_T DataLength, LPCSTR pSrcFileName,
CONST D3D10_SHADER_MACRO *pDefines,
ID3D10Include *pInclude, UINT HLSLFlags, UINT FXFlags,
ID3D10Blob **ppCompiledEffect, ID3D10Blob **ppErrors);
typedef HRESULT(WINAPI *LPD3D10CREATEEFFECTFROMMEMORY)(void *pData, SIZE_T DataLength, UINT FXFlags,
ID3D10Device *pDevice,
ID3D10EffectPool *pEffectPool,
ID3D10Effect **ppEffect);
typedef HRESULT(WINAPI *LPD3D10CREATEEFFECTPOOLFROMMEMORY)(void *pData, SIZE_T DataLength, UINT FXFlags,
ID3D10Device *pDevice, ID3D10EffectPool **ppEffectPool);
typedef HRESULT(WINAPI *LPD3D10CREATEDEVICEANDSWAPCHAIN)(IDXGIAdapter *pAdapter,
D3D10_DRIVER_TYPE DriverType,
HMODULE Software,
UINT Flags,
UINT SDKVersion,
DXGI_SWAP_CHAIN_DESC *pSwapChainDesc,
IDXGISwapChain **ppSwapChain,
ID3D10Device **ppDevice);
typedef HRESULT(WINAPI *LPD3D10CREATEDEVICEANDSWAPCHAIN1)(IDXGIAdapter *pAdapter,
D3D10_DRIVER_TYPE DriverType,
HMODULE Software,
UINT Flags,
D3D10_FEATURE_LEVEL1 HardwareLevel,
UINT SDKVersion,
DXGI_SWAP_CHAIN_DESC *pSwapChainDesc,
IDXGISwapChain **ppSwapChain,
ID3D10Device1 **ppDevice);
// Module and function pointers
static HMODULE g_hModDXGI = NULL;
static HMODULE g_hModD3D10 = NULL;
static HMODULE g_hModD3D101 = NULL;
static LPCREATEDXGIFACTORY sFnPtr_CreateDXGIFactory = NULL;
static LPD3D10CREATESTATEBLOCK sFnPtr_D3D10CreateStateBlock = NULL;
static LPD3D10CREATEDEVICE sFnPtr_D3D10CreateDevice = NULL;
static LPD3D10CREATEDEVICE1 sFnPtr_D3D10CreateDevice1 = NULL;
static LPD3D10STATEBLOCKMASKUNION sFnPtr_D3D10StateBlockMaskUnion = NULL;
static LPD3D10STATEBLOCKMASKINTERSECT sFnPtr_D3D10StateBlockMaskIntersect = NULL;
static LPD3D10STATEBLOCKMASKDIFFERENCE sFnPtr_D3D10StateBlockMaskDifference = NULL;
static LPD3D10STATEBLOCKMASKENABLECAPTURE sFnPtr_D3D10StateBlockMaskEnableCapture = NULL;
static LPD3D10STATEBLOCKMASKDISABLECAPTURE sFnPtr_D3D10StateBlockMaskDisableCapture = NULL;
static LPD3D10STATEBLOCKMASKENABLEALL sFnPtr_D3D10StateBlockMaskEnableAll = NULL;
static LPD3D10STATEBLOCKMASKDISABLEALL sFnPtr_D3D10StateBlockMaskDisableAll = NULL;
static LPD3D10STATEBLOCKMASKGETSETTING sFnPtr_D3D10StateBlockMaskGetSetting = NULL;
static LPD3D10COMPILEEFFECTFROMMEMORY sFnPtr_D3D10CompileEffectFromMemory = NULL;
static LPD3D10CREATEEFFECTFROMMEMORY sFnPtr_D3D10CreateEffectFromMemory = NULL;
static LPD3D10CREATEEFFECTPOOLFROMMEMORY sFnPtr_D3D10CreateEffectPoolFromMemory = NULL;
static LPD3D10CREATEDEVICEANDSWAPCHAIN sFnPtr_D3D10CreateDeviceAndSwapChain = NULL;
static LPD3D10CREATEDEVICEANDSWAPCHAIN1 sFnPtr_D3D10CreateDeviceAndSwapChain1 = NULL;
// unload the D3D10 DLLs
static bool dynlinkUnloadD3D10API(void)
{
if (g_hModD3D10)
{
FreeLibrary(g_hModD3D10);
g_hModD3D10 = NULL;
}
if (g_hModDXGI)
{
FreeLibrary(g_hModDXGI);
g_hModDXGI = NULL;
}
if (g_hModD3D101)
{
FreeLibrary(g_hModD3D101);
g_hModD3D101 = NULL;
}
return true;
}
// Dynamically load the D3D10 DLLs loaded and map the function pointers
static bool dynlinkLoadD3D10API(void)
{
// First check to see if the D3D10 Library is present.
// if it succeeds, then we can call GetProcAddress to grab all of the DX10 functions
g_hModD3D10 = LoadLibrary("d3d10.dll");
if (g_hModD3D10 != NULL)
{
sFnPtr_D3D10CreateStateBlock = (LPD3D10CREATESTATEBLOCK) GetProcAddress(g_hModD3D10, "D3D10CreateStateBlock");
sFnPtr_D3D10CreateDevice = (LPD3D10CREATEDEVICE) GetProcAddress(g_hModD3D10, "D3D10CreateDevice");
sFnPtr_D3D10StateBlockMaskUnion = (LPD3D10STATEBLOCKMASKUNION) GetProcAddress(g_hModD3D10, "D3D10StateBlockMaskUnion");
sFnPtr_D3D10StateBlockMaskIntersect = (LPD3D10STATEBLOCKMASKINTERSECT) GetProcAddress(g_hModD3D10, "D3D10StateBlockMaskIntersect");
sFnPtr_D3D10StateBlockMaskDifference = (LPD3D10STATEBLOCKMASKDIFFERENCE) GetProcAddress(g_hModD3D10, "D3D10StateBlockMaskDifference");
sFnPtr_D3D10StateBlockMaskEnableCapture = (LPD3D10STATEBLOCKMASKENABLECAPTURE) GetProcAddress(g_hModD3D10, "D3D10StateBlockMaskEnableCapture");
sFnPtr_D3D10StateBlockMaskDisableCapture = (LPD3D10STATEBLOCKMASKDISABLECAPTURE)GetProcAddress(g_hModD3D10, "D3D10StateBlockMaskDisableCapture");
sFnPtr_D3D10StateBlockMaskEnableAll = (LPD3D10STATEBLOCKMASKENABLEALL) GetProcAddress(g_hModD3D10, "D3D10StateBlockMaskEnableAll");
sFnPtr_D3D10StateBlockMaskDisableAll = (LPD3D10STATEBLOCKMASKDISABLEALL) GetProcAddress(g_hModD3D10, "D3D10StateBlockMaskDisableAll");
sFnPtr_D3D10StateBlockMaskGetSetting = (LPD3D10STATEBLOCKMASKGETSETTING) GetProcAddress(g_hModD3D10, "D3D10StateBlockMaskGetSetting");
sFnPtr_D3D10CompileEffectFromMemory = (LPD3D10COMPILEEFFECTFROMMEMORY) GetProcAddress(g_hModD3D10, "D3D10CompileEffectFromMemory");
sFnPtr_D3D10CreateEffectFromMemory = (LPD3D10CREATEEFFECTFROMMEMORY) GetProcAddress(g_hModD3D10, "D3D10CreateEffectFromMemory");
sFnPtr_D3D10CreateEffectPoolFromMemory = (LPD3D10CREATEEFFECTPOOLFROMMEMORY) GetProcAddress(g_hModD3D10, "D3D10CreateEffectPoolFromMemory");
sFnPtr_D3D10CreateDeviceAndSwapChain = (LPD3D10CREATEDEVICEANDSWAPCHAIN) GetProcAddress(g_hModD3D10, "D3D10CreateDeviceAndSwapChain");
}
g_hModDXGI = LoadLibrary("dxgi.dll");
if (g_hModDXGI)
{
sFnPtr_CreateDXGIFactory = (LPCREATEDXGIFACTORY) GetProcAddress(g_hModDXGI , "CreateDXGIFactory");
}
// This may fail if this machine isn't Windows Vista SP1 or later
g_hModD3D101 = LoadLibrary("d3d10_1.dll");
if (g_hModD3D101 != NULL)
{
sFnPtr_D3D10CreateDevice1 = (LPD3D10CREATEDEVICE1) GetProcAddress(g_hModD3D101, "D3D10CreateDevice1");
sFnPtr_D3D10CreateDeviceAndSwapChain1 = (LPD3D10CREATEDEVICEANDSWAPCHAIN1) GetProcAddress(g_hModD3D101, "D3D10CreateDeviceAndSwapChain1");
}
if (g_hModD3D10 == NULL || g_hModDXGI == NULL || g_hModD3D101 == NULL)
{
dynlinkUnloadD3D10API();
return false;
}
return true;
}
#endif

View File

@ -1,128 +0,0 @@
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
////////////////////////////////////////////////////////////////////////////////
//
// Utility funcs to wrap up saving a surface or the back buffer as a PPM file
// In addition, wraps up a threshold comparision of two PPMs.
//
// These functions are designed to be used to implement an automated QA testing
// for SDK samples.
//
// Author: Bryan Dudash
// Email: sdkfeedback@nvidia.com
//
// Copyright (c) NVIDIA Corporation. All rights reserved.
////////////////////////////////////////////////////////////////////////////////
#include <helper_functions.h>
#include <rendercheck_d3d10.h>
HRESULT CheckRenderD3D10::ActiveRenderTargetToPPM(ID3D10Device *pDevice,
const char *zFileName) {
ID3D10RenderTargetView *pRTV = NULL;
pDevice->OMGetRenderTargets(1, &pRTV, NULL);
ID3D10Resource *pSourceResource = NULL;
pRTV->GetResource(&pSourceResource);
return ResourceToPPM(pDevice, pSourceResource, zFileName);
}
HRESULT CheckRenderD3D10::ResourceToPPM(ID3D10Device *pDevice,
ID3D10Resource *pResource,
const char *zFileName) {
D3D10_RESOURCE_DIMENSION rType;
pResource->GetType(&rType);
if (rType != D3D10_RESOURCE_DIMENSION_TEXTURE2D) {
printf("SurfaceToPPM: pResource is not a 2D texture! Aborting...\n");
return E_FAIL;
}
ID3D10Texture2D *pSourceTexture = (ID3D10Texture2D *)pResource;
ID3D10Texture2D *pTargetTexture = NULL;
D3D10_TEXTURE2D_DESC desc;
pSourceTexture->GetDesc(&desc);
desc.BindFlags = 0;
desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
desc.Usage = D3D10_USAGE_STAGING;
if (FAILED(pDevice->CreateTexture2D(&desc, NULL, &pTargetTexture))) {
printf(
"SurfaceToPPM: Unable to create target Texture resoruce! Aborting... "
"\n");
return E_FAIL;
}
pDevice->CopyResource(pTargetTexture, pSourceTexture);
D3D10_MAPPED_TEXTURE2D mappedTex2D;
pTargetTexture->Map(0, D3D10_MAP_READ, 0, &mappedTex2D);
// Need to convert from dx pitch to pitch=width
unsigned char *pPPMData = new unsigned char[desc.Width * desc.Height * 4];
for (unsigned int iHeight = 0; iHeight < desc.Height; iHeight++) {
memcpy(
&(pPPMData[iHeight * desc.Width * 4]),
(unsigned char *)(mappedTex2D.pData) + iHeight * mappedTex2D.RowPitch,
desc.Width * 4);
}
pTargetTexture->Unmap(0);
// Prepends the PPM header info and bumps byte data afterwards
sdkSavePPM4ub(zFileName, pPPMData, desc.Width, desc.Height);
delete[] pPPMData;
pTargetTexture->Release();
return S_OK;
}
bool CheckRenderD3D10::PPMvsPPM(const char *src_file, const char *ref_file,
const char *exec_path, const float epsilon,
const float threshold) {
char *ref_file_path = sdkFindFilePath(ref_file, exec_path);
if (ref_file_path == NULL) {
printf(
"CheckRenderD3D10::PPMvsPPM unable to find <%s> in <%s> Aborting "
"comparison!\n",
ref_file, exec_path);
printf(">>> Check info.xml and [project//data] folder <%s> <<<\n",
ref_file);
printf("Aborting comparison!\n");
printf(" FAILURE!\n");
return false;
}
return (sdkComparePPM(src_file, ref_file_path, epsilon, threshold, true) ==
true);
}

View File

@ -1,53 +0,0 @@
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#ifndef _RENDERCHECK_D3D10_H_
#define _RENDERCHECK_D3D10_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <d3d10.h>
class CheckRenderD3D10 {
public:
CheckRenderD3D10() {}
static HRESULT ActiveRenderTargetToPPM(ID3D10Device *pDevice,
const char *zFileName);
static HRESULT ResourceToPPM(ID3D10Device *pDevice, ID3D10Resource *pResource,
const char *zFileName);
static bool PPMvsPPM(const char *src_file, const char *ref_file,
const char *exec_path, const float epsilon,
const float threshold = 0.0f);
};
#endif

View File

@ -1,167 +0,0 @@
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
////////////////////////////////////////////////////////////////////////////////
//
// Utility funcs to wrap up savings a surface or the back buffer as a PPM file
// In addition, wraps up a threshold comparision of two PPMs.
//
// These functions are designed to be used to implement an automated QA testing
// for SDK samples.
//
// Author: Bryan Dudash
// Email: sdkfeedback@nvidia.com
//
// Copyright (c) NVIDIA Corporation. All rights reserved.
////////////////////////////////////////////////////////////////////////////////
#include <helper_functions.h>
#include <rendercheck_d3d9.h>
// originally copied from checkrender_gl.cpp and slightly modified
bool CheckRenderD3D9::PPMvsPPM(const char *src_file, const char *ref_file,
const char *exec_path, const float epsilon,
const float threshold) {
char *ref_file_path = sdkFindFilePath(ref_file, exec_path);
if (ref_file_path == NULL) {
printf(
"CheckRenderD3D9::PPMvsPPM unable to find <%s> in <%s> Aborting "
"comparison!\n",
ref_file, exec_path);
printf(">>> Check info.xml and [project//data] folder <%s> <<<\n",
ref_file);
printf("Aborting comparison!\n");
printf(" FAILURE!\n");
return false;
}
return (sdkComparePPM(src_file, ref_file_path, epsilon, threshold, true) ==
true);
};
HRESULT CheckRenderD3D9::BackbufferToPPM(IDirect3DDevice9 *pDevice,
const char *zFileName) {
IDirect3DSurface9 *pSurface = NULL;
if (FAILED(
pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pSurface))) {
printf("Unable to get the back buffer. Aborting...\n");
return E_FAIL;
}
// D3DXSaveSurfaceToFile("C:\\bing.dds",D3DXIFF_DDS,pSurface,NULL,NULL);
HRESULT hr = S_OK;
hr = SurfaceToPPM(pDevice, pSurface, zFileName);
pSurface->Release();
return hr;
}
HRESULT CheckRenderD3D9::SurfaceToPPM(IDirect3DDevice9 *pDevice,
IDirect3DSurface9 *pSurface,
const char *zFileName) {
D3DSURFACE_DESC pDesc;
pSurface->GetDesc(&pDesc);
// $$ For now only support common 8bit formats. TODO: support for more
// complex formats via conversion?
if (!(pDesc.Format == D3DFMT_A8R8G8B8 || pDesc.Format == D3DFMT_X8R8G8B8)) {
return E_INVALIDARG;
}
IDirect3DTexture9 *pTargetTex = NULL;
if (FAILED(pDevice->CreateTexture(pDesc.Width, pDesc.Height, 1,
D3DUSAGE_DYNAMIC, pDesc.Format,
D3DPOOL_SYSTEMMEM, &pTargetTex, NULL))) {
printf("Unable to create texture for surface transfer! Aborting...\n");
return E_FAIL;
}
IDirect3DSurface9 *pTargetSurface = NULL;
if (FAILED(pTargetTex->GetSurfaceLevel(0, &pTargetSurface))) {
printf("Unable to get surface for surface transfer! Aborting...\n");
return E_FAIL;
}
// This is required because we cannot lock a D3DPOOL_DEAULT surface directly.
// So, we copy to our sysmem surface.
if (FAILED(pDevice->GetRenderTargetData(pSurface, pTargetSurface))) {
printf(
"Unable to GetRenderTargetData() for surface transfer! Aborting...\n");
return E_FAIL;
}
D3DLOCKED_RECT lockedRect;
HRESULT hr = pTargetSurface->LockRect(&lockedRect, NULL, 0);
// Need to convert from dx pitch to pitch=width
//
// $ PPM is BGR and not RGB it seems. Saved image looks "funny" in viewer(red
// and blue swapped), but since ref will be dumped using same method, this is
// ok.
// however, if we want the saved image to be properly colored, then we
// can swizzle the color bytes here.
unsigned char *pPPMData = new unsigned char[pDesc.Width * pDesc.Height * 4];
for (unsigned int iHeight = 0; iHeight < pDesc.Height; iHeight++) {
#if 1 // swizzle to implment RGB to BGR conversion.
for (unsigned int iWidth = 0; iWidth < pDesc.Width; iWidth++) {
DWORD color = *(DWORD *)((unsigned char *)(lockedRect.pBits) +
iHeight * lockedRect.Pitch + iWidth * 4);
// R<->B, [7:0] <-> [23:16], swizzle
color = ((color & 0xFF) << 16) | (color & 0xFF00) |
((color & 0xFF0000) >> 16) | (color & 0xFF000000);
memcpy(&(pPPMData[(iHeight * pDesc.Width + iWidth) * 4]),
(unsigned char *)&color, 4);
}
#else
memcpy(&(pPPMData[iHeight * pDesc.Width * 4]),
(unsigned char *)(lockedRect.pBits) + iHeight * lockedRect.Pitch,
pDesc.Width * 4);
#endif
}
pTargetSurface->UnlockRect();
// Prepends the PPM header info and bumps byte data afterwards
sdkSavePPM4ub(zFileName, pPPMData, pDesc.Width, pDesc.Height);
delete[] pPPMData;
pTargetSurface->Release();
pTargetTex->Release();
return S_OK;
}

View File

@ -1,54 +0,0 @@
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#ifndef _RENDERCHECK_D3D9_H_
#define _RENDERCHECK_D3D9_H_
#include <assert.h>
#include <d3d9.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
class CheckRenderD3D9 {
public:
CheckRenderD3D9() {}
static HRESULT BackbufferToPPM(IDirect3DDevice9 *pDevice,
const char *zFileName);
static HRESULT SurfaceToPPM(IDirect3DDevice9 *pDevice,
IDirect3DSurface9 *pSurface,
const char *zFileName);
static bool PPMvsPPM(const char *src_file, const char *ref_file,
const char *exec_path, const float epsilon,
const float threshold = 0.0f);
};
#endif

View File

@ -15,30 +15,36 @@ endif()
include_directories(../../../Common)
if(WIN32)
find_package(DirectX)
# Source file
# Add target for simpleD3D11
add_executable(simpleD3D11
simpleD3D11.cpp
sinewave_cuda.cu
../../../Common/rendercheck_d3d11.cpp
)
if(${DirectX_FOUND})
target_compile_options(simpleD3D11 PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
# Source file
# Add target for simpleD3D11
add_executable(simpleD3D11 simpleD3D11.cpp sinewave_cuda.cu)
target_compile_features(simpleD3D11 PRIVATE cxx_std_17 cuda_std_17)
target_compile_options(simpleD3D11 PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
set_target_properties(simpleD3D11 PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_compile_features(simpleD3D11 PRIVATE cxx_std_17 cuda_std_17)
target_include_directories(simpleD3D11 PRIVATE
${CUDAToolkit_INCLUDE_DIRS}
)
set_target_properties(simpleD3D11 PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(simpleD3D11 PRIVATE
d3d11
dxgi
dxguid
d3dcompiler
)
target_link_libraries(simpleD3D11 PRIVATE
DirectX::D3D11
)
add_custom_command(TARGET simpleD3D11 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/data
${CMAKE_CURRENT_BINARY_DIR}/data
)
else()
message(STATUS "DirectX not found - will not build sample 'simpleD3D11'")
endif()
add_custom_command(TARGET simpleD3D11 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/data
${CMAKE_CURRENT_BINARY_DIR}/data
)
else()
message(STATUS "Sample 'simpleD3D11' is Windows-only - skipping")
endif()

View File

@ -15,35 +15,38 @@ endif()
include_directories(../../../Common)
if(WIN32)
find_package(DirectX)
# Source file
# Add target for simpleD3D11Texture
add_executable(simpleD3D11Texture
simpleD3D11Texture.cpp
../../../Common/rendercheck_d3d11.cpp
texture_2d.cu
texture_3d.cu
texture_cube.cu
)
if(${DirectX_FOUND})
target_compile_options(simpleD3D11Texture PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
# Source file
# Add target for simpleD3D11Texture
add_executable(simpleD3D11Texture
simpleD3D11Texture.cpp
texture_2d.cu
texture_3d.cu
texture_cube.cu
)
target_compile_features(simpleD3D11Texture PRIVATE cxx_std_17 cuda_std_17)
target_compile_options(simpleD3D11Texture PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
set_target_properties(simpleD3D11Texture PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_compile_features(simpleD3D11Texture PRIVATE cxx_std_17 cuda_std_17)
target_include_directories(simpleD3D11Texture PRIVATE
${CUDAToolkit_INCLUDE_DIRS}
)
set_target_properties(simpleD3D11Texture PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(simpleD3D11Texture PRIVATE
d3d11
dxgi
dxguid
d3dcompiler
)
target_link_libraries(simpleD3D11Texture PRIVATE
DirectX::D3D11
)
add_custom_command(TARGET simpleD3D11Texture POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/data
${CMAKE_CURRENT_BINARY_DIR}/data
)
else()
message(STATUS "DirectX not found - will not build sample 'simpleD3D11Texture'")
endif()
add_custom_command(TARGET simpleD3D11Texture POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/data
${CMAKE_CURRENT_BINARY_DIR}/data
)
else()
message(STATUS "Sample 'simpleD3D11Texture' is Windows-only - skipping")
endif()

View File

@ -15,38 +15,40 @@ endif()
include_directories(../../../Common)
if(WIN32)
find_package(DirectX)
# Source file
# Add target for simpleD3D12
add_executable(simpleD3D12 WIN32
DX12CudaSample.cpp
Main.cpp
Win32Application.cpp
simpleD3D12.cpp
stdafx.cpp
sinewave_cuda.cu
)
if(${DirectX_FOUND})
target_compile_options(simpleD3D12 PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
# Source file
# Add target for simpleD3D12
add_executable(simpleD3D12
DX12CudaSample.cpp
Main.cpp
Win32Application.cpp
simpleD3D12.cpp
stdafx.cpp
sinewave_cuda.cu
)
target_compile_features(simpleD3D12 PRIVATE cxx_std_17 cuda_std_17)
target_compile_options(simpleD3D12 PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--extended-lambda>)
set_target_properties(simpleD3D12 PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_compile_features(simpleD3D12 PRIVATE cxx_std_17 cuda_std_17)
target_include_directories(simpleD3D12 PRIVATE
${CUDAToolkit_INCLUDE_DIRS}
)
set_target_properties(simpleD3D12 PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(simpleD3D12 PRIVATE
d3d12
dxgi
dxguid
d3dcompiler
)
target_link_libraries(simpleD3D12 PRIVATE
DirectX::D3D12
)
add_custom_command(TARGET simpleD3D12 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/shaders.hlsl
${CMAKE_CURRENT_BINARY_DIR}/shaders.hlsl
)
add_custom_command(TARGET simpleD3D11 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_file
${CMAKE_CURRENT_SOURCE_DIR}/shaders.hlsl
${CMAKE_CURRENT_BINARY_DIR}/shaders.hlsl
)
else()
message(STATUS "DirectX not found - will not build sample 'simpleD3D12'")
endif()
else()
message(STATUS "Sample 'simpleD3D12' is Windows-only - will not build")
endif()