mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-10-23 21:28:17 +08:00
add and update samples for CUDA 11.6
This commit is contained in:
46
Samples/5_Domain_Specific/simpleD3D10Texture/Makefile
Normal file
46
Samples/5_Domain_Specific/simpleD3D10Texture/Makefile
Normal file
@@ -0,0 +1,46 @@
|
||||
################################################################################
|
||||
# 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.
|
||||
#
|
||||
################################################################################
|
||||
#
|
||||
# Makefile project only supported on Mac OS X and Linux Platforms)
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# Target rules
|
||||
all: build
|
||||
|
||||
build:
|
||||
$(info >>> WARNING - simpleD3D10Texture is not supported on Linux - waiving sample <<<)
|
||||
|
||||
run: build
|
||||
|
||||
testrun: build
|
||||
|
||||
clean:
|
||||
|
||||
clobber: clean
|
||||
49
Samples/5_Domain_Specific/simpleD3D10Texture/README.md
Normal file
49
Samples/5_Domain_Specific/simpleD3D10Texture/README.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# simpleD3D10Texture - Simple D3D10 Texture
|
||||
|
||||
## Description
|
||||
|
||||
Simple program which demonstrates how to interoperate CUDA with Direct3D10 Texture. The program creates a number of D3D10 Textures (2D, 3D, and CubeMap) which are generated from CUDA kernels. Direct3D then renders the results on the screen. A Direct3D10 Capable device is required.
|
||||
|
||||
## Key Concepts
|
||||
|
||||
Graphics Interop, Texture
|
||||
|
||||
## Supported SM Architectures
|
||||
|
||||
[SM 3.5 ](https://developer.nvidia.com/cuda-gpus) [SM 3.7 ](https://developer.nvidia.com/cuda-gpus) [SM 5.0 ](https://developer.nvidia.com/cuda-gpus) [SM 5.2 ](https://developer.nvidia.com/cuda-gpus) [SM 5.3 ](https://developer.nvidia.com/cuda-gpus) [SM 6.0 ](https://developer.nvidia.com/cuda-gpus) [SM 6.1 ](https://developer.nvidia.com/cuda-gpus) [SM 7.0 ](https://developer.nvidia.com/cuda-gpus) [SM 7.2 ](https://developer.nvidia.com/cuda-gpus) [SM 7.5 ](https://developer.nvidia.com/cuda-gpus) [SM 8.0 ](https://developer.nvidia.com/cuda-gpus) [SM 8.6 ](https://developer.nvidia.com/cuda-gpus) [SM 8.7 ](https://developer.nvidia.com/cuda-gpus)
|
||||
|
||||
## Supported OSes
|
||||
|
||||
Windows
|
||||
|
||||
## Supported CPU Architecture
|
||||
|
||||
x86_64
|
||||
|
||||
## CUDA APIs involved
|
||||
|
||||
### [CUDA Runtime API](http://docs.nvidia.com/cuda/cuda-runtime-api/index.html)
|
||||
cudaMemset, cudaFree, cudaGraphicsMapResources, cudaGraphicsUnregisterResource, cudaGetDeviceCount, cudaMallocPitch, cudaMalloc, cudaGraphicsSubResourceGetMappedArray, cudaGetLastError, cudaGraphicsUnmapResources, cudaGetErrorString, cudaGetDeviceProperties
|
||||
|
||||
## Dependencies needed to build/run
|
||||
[DirectX](../../README.md#directx)
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Download and install the [CUDA Toolkit 11.6](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
|
||||
Make sure the dependencies mentioned in [Dependencies]() section above are installed.
|
||||
|
||||
## Build and Run
|
||||
|
||||
### Windows
|
||||
The Windows samples are built using the Visual Studio IDE. Solution files (.sln) are provided for each supported version of Visual Studio, using the format:
|
||||
```
|
||||
*_vs<version>.sln - for Visual Studio <version>
|
||||
```
|
||||
Each individual sample has its own set of solution files in its directory:
|
||||
|
||||
To build/examine all the samples at once, the complete solution files should be used. To build/examine a single sample, the individual sample solution files should be used.
|
||||
> **Note:** Some samples require that the Microsoft DirectX SDK (June 2010 or newer) be installed and that the VC++ directory paths are properly set up (**Tools > Options...**). Check DirectX Dependencies section for details."
|
||||
|
||||
## References (for more details)
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,970 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
/* This example demonstrates how to use the CUDA Direct3D bindings to
|
||||
* transfer data between CUDA and DX9 2D, CubeMap, and Volume Textures.
|
||||
*/
|
||||
|
||||
#pragma warning(disable : 4312)
|
||||
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
|
||||
// This header inclues all the necessary D3D10 and CUDA includes
|
||||
#include <dynlink_d3d10.h>
|
||||
#include <cuda_runtime_api.h>
|
||||
#include <cuda_d3d10_interop.h>
|
||||
|
||||
// includes, project
|
||||
#include <rendercheck_d3d10.h>
|
||||
#include <helper_cuda.h> // helper functions for CUDA error checking and initialization
|
||||
|
||||
#define MAX_EPSILON 10
|
||||
|
||||
static char *SDK_name = "simpleD3D10Texture";
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Global variables
|
||||
//-----------------------------------------------------------------------------
|
||||
IDXGIAdapter *g_pCudaCapableAdapter = NULL; // Adapter to use
|
||||
ID3D10Device *g_pd3dDevice = NULL; // Our rendering device
|
||||
IDXGISwapChain *g_pSwapChain = NULL; // The swap chain of the window
|
||||
ID3D10RenderTargetView *g_pSwapChainRTV =
|
||||
NULL; // The Render target view on the swap chain ( used for clear)
|
||||
ID3D10RasterizerState *g_pRasterState = NULL;
|
||||
|
||||
ID3D10InputLayout *g_pInputLayout = NULL;
|
||||
ID3D10Effect *g_pSimpleEffect = NULL;
|
||||
ID3D10EffectTechnique *g_pSimpleTechnique = NULL;
|
||||
ID3D10EffectVectorVariable *g_pvQuadRect = NULL;
|
||||
ID3D10EffectScalarVariable *g_pUseCase = NULL;
|
||||
ID3D10EffectShaderResourceVariable *g_pTexture2D = NULL;
|
||||
ID3D10EffectShaderResourceVariable *g_pTexture3D = NULL;
|
||||
ID3D10EffectShaderResourceVariable *g_pTextureCube = NULL;
|
||||
|
||||
static const char g_simpleEffectSrc[] =
|
||||
"float4 g_vQuadRect; \n"
|
||||
"int g_UseCase; \n"
|
||||
"Texture2D g_Texture2D; \n"
|
||||
"Texture3D g_Texture3D; \n"
|
||||
"TextureCube g_TextureCube; \n"
|
||||
"\n"
|
||||
"SamplerState samLinear{ \n"
|
||||
" Filter = MIN_MAG_LINEAR_MIP_POINT; \n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct Fragment{ \n"
|
||||
" float4 Pos : SV_POSITION;\n"
|
||||
" float3 Tex : TEXCOORD0; };\n"
|
||||
"\n"
|
||||
"Fragment VS( uint vertexId : SV_VertexID )\n"
|
||||
"{\n"
|
||||
" Fragment f;\n"
|
||||
" f.Tex = float3( 0.f, 0.f, 0.f); \n"
|
||||
" if (vertexId == 1) f.Tex.x = 1.f; \n"
|
||||
" else if (vertexId == 2) f.Tex.y = 1.f; \n"
|
||||
" else if (vertexId == 3) f.Tex.xy = float2(1.f, 1.f); \n"
|
||||
" \n"
|
||||
" f.Pos = float4( g_vQuadRect.xy + f.Tex * g_vQuadRect.zw, 0, 1);\n"
|
||||
" \n"
|
||||
" if (g_UseCase == 1) { \n"
|
||||
" if (vertexId == 1) f.Tex.z = 0.5f; \n"
|
||||
" else if (vertexId == 2) f.Tex.z = 0.5f; \n"
|
||||
" else if (vertexId == 3) f.Tex.z = 1.f; \n"
|
||||
" } \n"
|
||||
" else if (g_UseCase >= 2) { \n"
|
||||
" f.Tex.xy = f.Tex.xy * 2.f - 1.f; \n"
|
||||
" } \n"
|
||||
" return f;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"float4 PS( Fragment f ) : SV_Target\n"
|
||||
"{\n"
|
||||
" if (g_UseCase == 0) return g_Texture2D.Sample( samLinear, f.Tex.xy ); "
|
||||
"\n"
|
||||
" else if (g_UseCase == 1) return g_Texture3D.Sample( samLinear, f.Tex "
|
||||
"); \n"
|
||||
" else if (g_UseCase == 2) return g_TextureCube.Sample( samLinear, "
|
||||
"float3(f.Tex.xy, 1.0) ); \n"
|
||||
" else if (g_UseCase == 3) return g_TextureCube.Sample( samLinear, "
|
||||
"float3(f.Tex.xy, -1.0) ); \n"
|
||||
" else if (g_UseCase == 4) return g_TextureCube.Sample( samLinear, "
|
||||
"float3(1.0, f.Tex.xy) ); \n"
|
||||
" else if (g_UseCase == 5) return g_TextureCube.Sample( samLinear, "
|
||||
"float3(-1.0, f.Tex.xy) ); \n"
|
||||
" else if (g_UseCase == 6) return g_TextureCube.Sample( samLinear, "
|
||||
"float3(f.Tex.x, 1.0, f.Tex.y) ); \n"
|
||||
" else if (g_UseCase == 7) return g_TextureCube.Sample( samLinear, "
|
||||
"float3(f.Tex.x, -1.0, f.Tex.y) ); \n"
|
||||
" else return float4(f.Tex, 1);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"technique10 Render\n"
|
||||
"{\n"
|
||||
" pass P0\n"
|
||||
" {\n"
|
||||
" SetVertexShader( CompileShader( vs_4_0, VS() ) );\n"
|
||||
" SetGeometryShader( NULL );\n"
|
||||
" SetPixelShader( CompileShader( ps_4_0, PS() ) );\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n";
|
||||
|
||||
// testing/tracing function used pervasively in tests. if the condition is
|
||||
// unsatisfied
|
||||
// then spew and fail the function immediately (doing no cleanup)
|
||||
#define AssertOrQuit(x) \
|
||||
if (!(x)) { \
|
||||
fprintf(stdout, "Assert unsatisfied in %s at %s:%d\n", __FUNCTION__, \
|
||||
__FILE__, __LINE__); \
|
||||
return 1; \
|
||||
}
|
||||
|
||||
bool g_bDone = false;
|
||||
bool g_bPassed = true;
|
||||
|
||||
const unsigned int g_WindowWidth = 720;
|
||||
const unsigned int g_WindowHeight = 720;
|
||||
|
||||
int g_iFrameToCompare = 10;
|
||||
|
||||
int *pArgc = NULL;
|
||||
char **pArgv = NULL;
|
||||
|
||||
// Data structure for 2D texture shared between DX10 and CUDA
|
||||
struct {
|
||||
ID3D10Texture2D *pTexture;
|
||||
ID3D10ShaderResourceView *pSRView;
|
||||
cudaGraphicsResource *cudaResource;
|
||||
void *cudaLinearMemory;
|
||||
size_t pitch;
|
||||
int width;
|
||||
int height;
|
||||
} g_texture_2d;
|
||||
|
||||
// Data structure for volume textures shared between DX10 and CUDA
|
||||
struct {
|
||||
ID3D10Texture3D *pTexture;
|
||||
ID3D10ShaderResourceView *pSRView;
|
||||
cudaGraphicsResource *cudaResource;
|
||||
void *cudaLinearMemory;
|
||||
size_t pitch;
|
||||
int width;
|
||||
int height;
|
||||
int depth;
|
||||
} g_texture_3d;
|
||||
|
||||
// Data structure for cube texture shared between DX10 and CUDA
|
||||
struct {
|
||||
ID3D10Texture2D *pTexture;
|
||||
ID3D10ShaderResourceView *pSRView;
|
||||
cudaGraphicsResource *cudaResource;
|
||||
void *cudaLinearMemory;
|
||||
size_t pitch;
|
||||
int size;
|
||||
} g_texture_cube;
|
||||
|
||||
// The CUDA kernel launchers that get called
|
||||
extern "C" {
|
||||
bool cuda_texture_2d(void *surface, size_t width, size_t height, size_t pitch,
|
||||
float t);
|
||||
bool cuda_texture_3d(void *surface, int width, int height, int depth,
|
||||
size_t pitch, size_t pitchslice, float t);
|
||||
bool cuda_texture_cube(void *surface, int width, int height, size_t pitch,
|
||||
int face, float t);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
HRESULT InitD3D(HWND hWnd);
|
||||
HRESULT InitTextures();
|
||||
|
||||
void RunKernels();
|
||||
void DrawScene();
|
||||
void Cleanup();
|
||||
void Render();
|
||||
|
||||
LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
#define NAME_LEN 512
|
||||
|
||||
bool findCUDADevice() {
|
||||
int nGraphicsGPU = 0;
|
||||
int deviceCount = 0;
|
||||
bool bFoundGraphics = false;
|
||||
char devname[NAME_LEN];
|
||||
|
||||
// This function call returns 0 if there are no CUDA capable devices.
|
||||
cudaError_t error_id = cudaGetDeviceCount(&deviceCount);
|
||||
|
||||
if (error_id != cudaSuccess) {
|
||||
printf("cudaGetDeviceCount returned %d\n-> %s\n", (int)error_id,
|
||||
cudaGetErrorString(error_id));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (deviceCount == 0) {
|
||||
printf("> There are no device(s) supporting CUDA\n");
|
||||
return false;
|
||||
} else {
|
||||
printf("> Found %d CUDA Capable Device(s)\n", deviceCount);
|
||||
}
|
||||
|
||||
// Get CUDA device properties
|
||||
cudaDeviceProp deviceProp;
|
||||
|
||||
for (int dev = 0; dev < deviceCount; ++dev) {
|
||||
cudaGetDeviceProperties(&deviceProp, dev);
|
||||
STRCPY(devname, NAME_LEN, deviceProp.name);
|
||||
printf("> GPU %d: %s\n", dev, devname);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool findDXDevice(char *dev_name) {
|
||||
HRESULT hr = S_OK;
|
||||
cudaError cuStatus;
|
||||
|
||||
// Iterate through the candidate adapters
|
||||
IDXGIFactory *pFactory;
|
||||
hr = sFnPtr_CreateDXGIFactory(__uuidof(IDXGIFactory), (void **)(&pFactory));
|
||||
|
||||
if (!SUCCEEDED(hr)) {
|
||||
printf("> No DXGI Factory created.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
UINT adapter = 0;
|
||||
|
||||
for (; !g_pCudaCapableAdapter; ++adapter) {
|
||||
// Get a candidate DXGI adapter
|
||||
IDXGIAdapter *pAdapter = NULL;
|
||||
hr = pFactory->EnumAdapters(adapter, &pAdapter);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
break; // no compatible adapters found
|
||||
}
|
||||
|
||||
// Query to see if there exists a corresponding compute device
|
||||
int cuDevice;
|
||||
cuStatus = cudaD3D10GetDevice(&cuDevice, pAdapter);
|
||||
printLastCudaError("cudaD3D10GetDevice failed"); // This prints and resets
|
||||
// the cudaError to
|
||||
// cudaSuccess
|
||||
|
||||
if (cudaSuccess == cuStatus) {
|
||||
// If so, mark it as the one against which to create our d3d10 device
|
||||
g_pCudaCapableAdapter = pAdapter;
|
||||
g_pCudaCapableAdapter->AddRef();
|
||||
}
|
||||
|
||||
pAdapter->Release();
|
||||
}
|
||||
|
||||
printf("> Found %d D3D10 Adapater(s).\n", (int)adapter);
|
||||
|
||||
pFactory->Release();
|
||||
|
||||
if (!g_pCudaCapableAdapter) {
|
||||
printf("> Found 0 D3D10 Adapater(s) /w Compute capability.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
DXGI_ADAPTER_DESC adapterDesc;
|
||||
g_pCudaCapableAdapter->GetDesc(&adapterDesc);
|
||||
wcstombs_s(NULL, dev_name, 256, adapterDesc.Description, 128);
|
||||
|
||||
printf("> Found 1 D3D10 Adapater(s) /w Compute capability.\n");
|
||||
printf("> %s\n", dev_name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Program main
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main(int argc, char *argv[]) {
|
||||
char device_name[256];
|
||||
char *ref_file = NULL;
|
||||
|
||||
pArgc = &argc;
|
||||
pArgv = argv;
|
||||
|
||||
printf("[%s] - Starting...\n", SDK_name);
|
||||
|
||||
if (!findCUDADevice()) // Search for CUDA GPU
|
||||
{
|
||||
printf("> CUDA Device NOT found on \"%s\".. Exiting.\n", device_name);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
// Search for D3D API (locate drivers, does not mean device is found)
|
||||
if (!dynlinkLoadD3D10API()) {
|
||||
printf("> D3D10 API libraries NOT found on.. Exiting.\n");
|
||||
dynlinkUnloadD3D10API();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
if (!findDXDevice(device_name)) { // Search for D3D Hardware Device
|
||||
printf("> D3D10 Graphics Device NOT found.. Exiting.\n");
|
||||
dynlinkUnloadD3D10API();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
// command line options
|
||||
if (argc > 1) {
|
||||
// automatied build testing harness
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "file"))
|
||||
getCmdLineArgumentString(argc, (const char **)argv, "file", &ref_file);
|
||||
}
|
||||
|
||||
//
|
||||
// create window
|
||||
//
|
||||
// Register the window class
|
||||
#if 1
|
||||
WNDCLASSEX wc = {sizeof(WNDCLASSEX),
|
||||
CS_CLASSDC,
|
||||
MsgProc,
|
||||
0L,
|
||||
0L,
|
||||
GetModuleHandle(NULL),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
"CUDA SDK",
|
||||
NULL};
|
||||
RegisterClassEx(&wc);
|
||||
|
||||
// Create the application's window
|
||||
int xBorder = ::GetSystemMetrics(SM_CXSIZEFRAME);
|
||||
int yMenu = ::GetSystemMetrics(SM_CYMENU);
|
||||
int yBorder = ::GetSystemMetrics(SM_CYSIZEFRAME);
|
||||
HWND hWnd = CreateWindow(
|
||||
wc.lpszClassName, "CUDA/D3D10 Texture InterOP", WS_OVERLAPPEDWINDOW, 0, 0,
|
||||
g_WindowWidth + 2 * xBorder, g_WindowHeight + 2 * yBorder + yMenu, NULL,
|
||||
NULL, wc.hInstance, NULL);
|
||||
#else
|
||||
static WNDCLASSEX wc = {
|
||||
sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
|
||||
GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
|
||||
"CudaD3D9Tex", NULL};
|
||||
RegisterClassEx(&wc);
|
||||
HWND hWnd = CreateWindow("CudaD3D9Tex", "CUDA D3D9 Texture Interop",
|
||||
WS_OVERLAPPEDWINDOW, 0, 0, 800, 320,
|
||||
GetDesktopWindow(), NULL, wc.hInstance, NULL);
|
||||
#endif
|
||||
|
||||
ShowWindow(hWnd, SW_SHOWDEFAULT);
|
||||
UpdateWindow(hWnd);
|
||||
|
||||
// Initialize Direct3D
|
||||
if (SUCCEEDED(InitD3D(hWnd)) && SUCCEEDED(InitTextures())) {
|
||||
// 2D
|
||||
// register the Direct3D resources that we'll use
|
||||
// we'll read to and write from g_texture_2d, so don't set any special map
|
||||
// flags for it
|
||||
cudaGraphicsD3D10RegisterResource(&g_texture_2d.cudaResource,
|
||||
g_texture_2d.pTexture,
|
||||
cudaGraphicsRegisterFlagsNone);
|
||||
getLastCudaError("cudaGraphicsD3D10RegisterResource (g_texture_2d) failed");
|
||||
// cuda cannot write into the texture directly : the texture is seen as a
|
||||
// cudaArray and can only be mapped as a texture
|
||||
// Create a buffer so that cuda can write into it
|
||||
// pixel fmt is DXGI_FORMAT_R32G32B32A32_FLOAT
|
||||
cudaMallocPitch(&g_texture_2d.cudaLinearMemory, &g_texture_2d.pitch,
|
||||
g_texture_2d.width * sizeof(float) * 4,
|
||||
g_texture_2d.height);
|
||||
getLastCudaError("cudaMallocPitch (g_texture_2d) failed");
|
||||
cudaMemset(g_texture_2d.cudaLinearMemory, 1,
|
||||
g_texture_2d.pitch * g_texture_2d.height);
|
||||
|
||||
// CUBE
|
||||
cudaGraphicsD3D10RegisterResource(&g_texture_cube.cudaResource,
|
||||
g_texture_cube.pTexture,
|
||||
cudaGraphicsRegisterFlagsNone);
|
||||
getLastCudaError(
|
||||
"cudaGraphicsD3D10RegisterResource (g_texture_cube) failed");
|
||||
// create the buffer. pixel fmt is DXGI_FORMAT_R8G8B8A8_SNORM
|
||||
cudaMallocPitch(&g_texture_cube.cudaLinearMemory, &g_texture_cube.pitch,
|
||||
g_texture_cube.size * 4, g_texture_cube.size);
|
||||
getLastCudaError("cudaMallocPitch (g_texture_cube) failed");
|
||||
cudaMemset(g_texture_cube.cudaLinearMemory, 1,
|
||||
g_texture_cube.pitch * g_texture_cube.size);
|
||||
getLastCudaError("cudaMemset (g_texture_cube) failed");
|
||||
|
||||
// 3D
|
||||
cudaGraphicsD3D10RegisterResource(&g_texture_3d.cudaResource,
|
||||
g_texture_3d.pTexture,
|
||||
cudaGraphicsRegisterFlagsNone);
|
||||
getLastCudaError("cudaGraphicsD3D10RegisterResource (g_texture_3d) failed");
|
||||
// create the buffer. pixel fmt is DXGI_FORMAT_R8G8B8A8_SNORM
|
||||
// cudaMallocPitch(&g_texture_3d.cudaLinearMemory, &g_texture_3d.pitch,
|
||||
// g_texture_3d.width * 4, g_texture_3d.height * g_texture_3d.depth);
|
||||
cudaMalloc(
|
||||
&g_texture_3d.cudaLinearMemory,
|
||||
g_texture_3d.width * 4 * g_texture_3d.height * g_texture_3d.depth);
|
||||
g_texture_3d.pitch = g_texture_3d.width * 4;
|
||||
getLastCudaError("cudaMallocPitch (g_texture_3d) failed");
|
||||
cudaMemset(g_texture_3d.cudaLinearMemory, 1,
|
||||
g_texture_3d.pitch * g_texture_3d.height * g_texture_3d.depth);
|
||||
getLastCudaError("cudaMemset (g_texture_3d) failed");
|
||||
} else {
|
||||
printf("> WARNING: No D3D10 Device found.\n");
|
||||
g_bPassed = true;
|
||||
exit(g_bPassed ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
|
||||
//
|
||||
// the main loop
|
||||
//
|
||||
while (false == g_bDone) {
|
||||
Render();
|
||||
|
||||
//
|
||||
// handle I/O
|
||||
//
|
||||
MSG msg;
|
||||
ZeroMemory(&msg, sizeof(msg));
|
||||
|
||||
while (msg.message != WM_QUIT) {
|
||||
if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
} else {
|
||||
Render();
|
||||
|
||||
if (ref_file) {
|
||||
for (int count = 0; count < g_iFrameToCompare; count++) {
|
||||
Render();
|
||||
}
|
||||
|
||||
const char *cur_image_path = "simpleD3D10Texture.ppm";
|
||||
|
||||
// Save a reference of our current test run image
|
||||
CheckRenderD3D10::ActiveRenderTargetToPPM(g_pd3dDevice,
|
||||
cur_image_path);
|
||||
|
||||
// compare to offical reference image, printing PASS or FAIL.
|
||||
g_bPassed = CheckRenderD3D10::PPMvsPPM(cur_image_path, ref_file,
|
||||
argv[0], MAX_EPSILON, 0.15f);
|
||||
|
||||
g_bDone = true;
|
||||
|
||||
Cleanup();
|
||||
|
||||
PostQuitMessage(0);
|
||||
} else {
|
||||
g_bPassed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Release D3D Library (after message loop)
|
||||
dynlinkUnloadD3D10API();
|
||||
|
||||
// Unregister windows class
|
||||
UnregisterClass(wc.lpszClassName, wc.hInstance);
|
||||
|
||||
//
|
||||
// and exit
|
||||
//
|
||||
printf("> %s running on %s exiting...\n", SDK_name, device_name);
|
||||
|
||||
exit(g_bPassed ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: InitD3D()
|
||||
// Desc: Initializes Direct3D
|
||||
//-----------------------------------------------------------------------------
|
||||
HRESULT InitD3D(HWND hWnd) {
|
||||
// Set up the structure used to create the device and swapchain
|
||||
DXGI_SWAP_CHAIN_DESC sd;
|
||||
ZeroMemory(&sd, sizeof(sd));
|
||||
sd.BufferCount = 1;
|
||||
sd.BufferDesc.Width = g_WindowWidth;
|
||||
sd.BufferDesc.Height = g_WindowHeight;
|
||||
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
sd.BufferDesc.RefreshRate.Numerator = 60;
|
||||
sd.BufferDesc.RefreshRate.Denominator = 1;
|
||||
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
sd.OutputWindow = hWnd;
|
||||
sd.SampleDesc.Count = 1;
|
||||
sd.SampleDesc.Quality = 0;
|
||||
sd.Windowed = TRUE;
|
||||
|
||||
// Create device and swapchain
|
||||
HRESULT hr = sFnPtr_D3D10CreateDeviceAndSwapChain(
|
||||
g_pCudaCapableAdapter, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0,
|
||||
D3D10_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice);
|
||||
AssertOrQuit(SUCCEEDED(hr));
|
||||
g_pCudaCapableAdapter->Release();
|
||||
|
||||
// Create a render target view of the swapchain
|
||||
ID3D10Texture2D *pBuffer;
|
||||
hr =
|
||||
g_pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID *)&pBuffer);
|
||||
AssertOrQuit(SUCCEEDED(hr));
|
||||
|
||||
hr = g_pd3dDevice->CreateRenderTargetView(pBuffer, NULL, &g_pSwapChainRTV);
|
||||
AssertOrQuit(SUCCEEDED(hr));
|
||||
pBuffer->Release();
|
||||
|
||||
g_pd3dDevice->OMSetRenderTargets(1, &g_pSwapChainRTV, NULL);
|
||||
|
||||
// Setup the viewport
|
||||
D3D10_VIEWPORT vp;
|
||||
vp.Width = g_WindowWidth;
|
||||
vp.Height = g_WindowHeight;
|
||||
vp.MinDepth = 0.0f;
|
||||
vp.MaxDepth = 1.0f;
|
||||
vp.TopLeftX = 0;
|
||||
vp.TopLeftY = 0;
|
||||
g_pd3dDevice->RSSetViewports(1, &vp);
|
||||
|
||||
// Setup the effect
|
||||
{
|
||||
ID3D10Blob *pCompiledEffect;
|
||||
ID3D10Blob *pErrors = NULL;
|
||||
hr = sFnPtr_D3D10CompileEffectFromMemory((void *)g_simpleEffectSrc,
|
||||
sizeof(g_simpleEffectSrc), NULL,
|
||||
NULL, // pDefines
|
||||
NULL, // pIncludes
|
||||
0, // HLSL flags
|
||||
0, // FXFlags
|
||||
&pCompiledEffect, &pErrors);
|
||||
|
||||
if (pErrors) {
|
||||
LPVOID l_pError = NULL;
|
||||
l_pError = pErrors->GetBufferPointer(); // then cast to a char* to see it
|
||||
// in the locals window
|
||||
fprintf(stdout, "Compilation error: \n %s", (char *)l_pError);
|
||||
}
|
||||
|
||||
AssertOrQuit(SUCCEEDED(hr));
|
||||
|
||||
hr = sFnPtr_D3D10CreateEffectFromMemory(
|
||||
pCompiledEffect->GetBufferPointer(), pCompiledEffect->GetBufferSize(),
|
||||
0, // FXFlags
|
||||
g_pd3dDevice, NULL, &g_pSimpleEffect);
|
||||
pCompiledEffect->Release();
|
||||
|
||||
g_pSimpleTechnique = g_pSimpleEffect->GetTechniqueByName("Render");
|
||||
|
||||
g_pvQuadRect =
|
||||
g_pSimpleEffect->GetVariableByName("g_vQuadRect")->AsVector();
|
||||
g_pUseCase = g_pSimpleEffect->GetVariableByName("g_UseCase")->AsScalar();
|
||||
|
||||
g_pTexture2D =
|
||||
g_pSimpleEffect->GetVariableByName("g_Texture2D")->AsShaderResource();
|
||||
g_pTexture3D =
|
||||
g_pSimpleEffect->GetVariableByName("g_Texture3D")->AsShaderResource();
|
||||
g_pTextureCube =
|
||||
g_pSimpleEffect->GetVariableByName("g_TextureCube")->AsShaderResource();
|
||||
|
||||
// Setup no Input Layout
|
||||
g_pd3dDevice->IASetInputLayout(0);
|
||||
g_pd3dDevice->IASetPrimitiveTopology(
|
||||
D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
||||
}
|
||||
|
||||
D3D10_RASTERIZER_DESC rasterizerState;
|
||||
rasterizerState.FillMode = D3D10_FILL_SOLID;
|
||||
rasterizerState.CullMode = D3D10_CULL_FRONT;
|
||||
rasterizerState.FrontCounterClockwise = false;
|
||||
rasterizerState.DepthBias = false;
|
||||
rasterizerState.DepthBiasClamp = 0;
|
||||
rasterizerState.SlopeScaledDepthBias = 0;
|
||||
rasterizerState.DepthClipEnable = false;
|
||||
rasterizerState.ScissorEnable = false;
|
||||
rasterizerState.MultisampleEnable = false;
|
||||
rasterizerState.AntialiasedLineEnable = false;
|
||||
g_pd3dDevice->CreateRasterizerState(&rasterizerState, &g_pRasterState);
|
||||
g_pd3dDevice->RSSetState(g_pRasterState);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: InitTextures()
|
||||
// Desc: Initializes Direct3D Textures (allocation and initialization)
|
||||
//-----------------------------------------------------------------------------
|
||||
HRESULT InitTextures() {
|
||||
//
|
||||
// create the D3D resources we'll be using
|
||||
//
|
||||
// 2D texture
|
||||
{
|
||||
g_texture_2d.width = 256;
|
||||
g_texture_2d.height = 256;
|
||||
|
||||
D3D10_TEXTURE2D_DESC desc;
|
||||
ZeroMemory(&desc, sizeof(D3D10_TEXTURE2D_DESC));
|
||||
desc.Width = g_texture_2d.width;
|
||||
desc.Height = g_texture_2d.height;
|
||||
desc.MipLevels = 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Usage = D3D10_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
|
||||
|
||||
if (FAILED(
|
||||
g_pd3dDevice->CreateTexture2D(&desc, NULL, &g_texture_2d.pTexture)))
|
||||
return E_FAIL;
|
||||
|
||||
if (FAILED(g_pd3dDevice->CreateShaderResourceView(
|
||||
g_texture_2d.pTexture, NULL, &g_texture_2d.pSRView)))
|
||||
return E_FAIL;
|
||||
|
||||
g_pTexture2D->SetResource(g_texture_2d.pSRView);
|
||||
}
|
||||
|
||||
// 3D texture
|
||||
{
|
||||
g_texture_3d.width = 64;
|
||||
g_texture_3d.height = 64;
|
||||
g_texture_3d.depth = 64;
|
||||
|
||||
D3D10_TEXTURE3D_DESC desc;
|
||||
ZeroMemory(&desc, sizeof(D3D10_TEXTURE3D_DESC));
|
||||
desc.Width = g_texture_3d.width;
|
||||
desc.Height = g_texture_3d.height;
|
||||
desc.Depth = g_texture_3d.depth;
|
||||
desc.MipLevels = 1;
|
||||
desc.Format = DXGI_FORMAT_R8G8B8A8_SNORM;
|
||||
desc.Usage = D3D10_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
|
||||
|
||||
if (FAILED(
|
||||
g_pd3dDevice->CreateTexture3D(&desc, NULL, &g_texture_3d.pTexture)))
|
||||
return E_FAIL;
|
||||
|
||||
if (FAILED(g_pd3dDevice->CreateShaderResourceView(
|
||||
g_texture_3d.pTexture, NULL, &g_texture_3d.pSRView)))
|
||||
return E_FAIL;
|
||||
|
||||
g_pTexture3D->SetResource(g_texture_3d.pSRView);
|
||||
}
|
||||
|
||||
// cube texture
|
||||
{
|
||||
g_texture_cube.size = 64;
|
||||
|
||||
D3D10_TEXTURE2D_DESC desc;
|
||||
ZeroMemory(&desc, sizeof(D3D10_TEXTURE2D_DESC));
|
||||
desc.Width = g_texture_cube.size;
|
||||
desc.Height = g_texture_cube.size;
|
||||
desc.MipLevels = 1;
|
||||
desc.ArraySize = 6;
|
||||
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Usage = D3D10_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
|
||||
desc.MiscFlags = D3D10_RESOURCE_MISC_TEXTURECUBE;
|
||||
|
||||
if (FAILED(g_pd3dDevice->CreateTexture2D(&desc, NULL,
|
||||
&g_texture_cube.pTexture)))
|
||||
return E_FAIL;
|
||||
|
||||
D3D10_SHADER_RESOURCE_VIEW_DESC SRVDesc;
|
||||
ZeroMemory(&SRVDesc, sizeof(SRVDesc));
|
||||
SRVDesc.Format = desc.Format;
|
||||
SRVDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURECUBE;
|
||||
SRVDesc.TextureCube.MipLevels = desc.MipLevels;
|
||||
SRVDesc.TextureCube.MostDetailedMip = 0;
|
||||
|
||||
if (FAILED(g_pd3dDevice->CreateShaderResourceView(
|
||||
g_texture_cube.pTexture, &SRVDesc, &g_texture_cube.pSRView)))
|
||||
return E_FAIL;
|
||||
|
||||
g_pTextureCube->SetResource(g_texture_cube.pSRView);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//! Run the Cuda part of the computation
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void RunKernels() {
|
||||
static float t = 0.0f;
|
||||
|
||||
// populate the 2d texture
|
||||
{
|
||||
cudaArray *cuArray;
|
||||
cudaGraphicsSubResourceGetMappedArray(&cuArray, g_texture_2d.cudaResource,
|
||||
0, 0);
|
||||
getLastCudaError(
|
||||
"cudaGraphicsSubResourceGetMappedArray (cuda_texture_2d) failed");
|
||||
|
||||
// kick off the kernel and send the staging buffer cudaLinearMemory as an
|
||||
// argument to allow the kernel to write to it
|
||||
cuda_texture_2d(g_texture_2d.cudaLinearMemory, g_texture_2d.width,
|
||||
g_texture_2d.height, g_texture_2d.pitch, t);
|
||||
getLastCudaError("cuda_texture_2d failed");
|
||||
|
||||
// then we want to copy cudaLinearMemory to the D3D texture, via its mapped
|
||||
// form : cudaArray
|
||||
cudaMemcpy2DToArray(
|
||||
cuArray, // dst array
|
||||
0, 0, // offset
|
||||
g_texture_2d.cudaLinearMemory, g_texture_2d.pitch, // src
|
||||
g_texture_2d.width * 4 * sizeof(float), g_texture_2d.height, // extent
|
||||
cudaMemcpyDeviceToDevice); // kind
|
||||
getLastCudaError("cudaMemcpy2DToArray failed");
|
||||
}
|
||||
// populate the volume texture
|
||||
{
|
||||
size_t pitchSlice = g_texture_3d.pitch * g_texture_3d.height;
|
||||
cudaArray *cuArray;
|
||||
cudaGraphicsSubResourceGetMappedArray(&cuArray, g_texture_3d.cudaResource,
|
||||
0, 0);
|
||||
getLastCudaError(
|
||||
"cudaGraphicsSubResourceGetMappedArray (cuda_texture_3d) failed");
|
||||
|
||||
// kick off the kernel and send the staging buffer cudaLinearMemory as an
|
||||
// argument to allow the kernel to write to it
|
||||
cuda_texture_3d(g_texture_3d.cudaLinearMemory, g_texture_3d.width,
|
||||
g_texture_3d.height, g_texture_3d.depth, g_texture_3d.pitch,
|
||||
pitchSlice, t);
|
||||
getLastCudaError("cuda_texture_3d failed");
|
||||
|
||||
// then we want to copy cudaLinearMemory to the D3D texture, via its mapped
|
||||
// form : cudaArray
|
||||
struct cudaMemcpy3DParms memcpyParams = {0};
|
||||
memcpyParams.dstArray = cuArray;
|
||||
memcpyParams.srcPtr.ptr = g_texture_3d.cudaLinearMemory;
|
||||
memcpyParams.srcPtr.pitch = g_texture_3d.pitch;
|
||||
memcpyParams.srcPtr.xsize = g_texture_3d.width;
|
||||
memcpyParams.srcPtr.ysize = g_texture_3d.height;
|
||||
memcpyParams.extent.width = g_texture_3d.width;
|
||||
memcpyParams.extent.height = g_texture_3d.height;
|
||||
memcpyParams.extent.depth = g_texture_3d.depth;
|
||||
memcpyParams.kind = cudaMemcpyDeviceToDevice;
|
||||
cudaMemcpy3D(&memcpyParams);
|
||||
getLastCudaError("cudaMemcpy3D failed");
|
||||
}
|
||||
|
||||
// populate the faces of the cube map
|
||||
for (int face = 0; face < 6; ++face) {
|
||||
cudaArray *cuArray;
|
||||
cudaGraphicsSubResourceGetMappedArray(&cuArray, g_texture_cube.cudaResource,
|
||||
face, 0);
|
||||
getLastCudaError(
|
||||
"cudaGraphicsSubResourceGetMappedArray (cuda_texture_cube) failed");
|
||||
|
||||
// kick off the kernel and send the staging buffer cudaLinearMemory as an
|
||||
// argument to allow the kernel to write to it
|
||||
cuda_texture_cube(g_texture_cube.cudaLinearMemory, g_texture_cube.size,
|
||||
g_texture_cube.size, g_texture_cube.pitch, face, t);
|
||||
getLastCudaError("cuda_texture_cube failed");
|
||||
|
||||
// then we want to copy cudaLinearMemory to the D3D texture, via its mapped
|
||||
// form : cudaArray
|
||||
cudaMemcpy2DToArray(cuArray, // dst array
|
||||
0, 0, // offset
|
||||
g_texture_cube.cudaLinearMemory,
|
||||
g_texture_cube.pitch, // src
|
||||
g_texture_cube.size * 4, g_texture_cube.size, // extent
|
||||
cudaMemcpyDeviceToDevice); // kind
|
||||
getLastCudaError("cudaMemcpy2DToArray failed");
|
||||
}
|
||||
|
||||
t += 0.01f;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//! Draw the final result on the screen
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void DrawScene() {
|
||||
// Clear the backbuffer to a black color
|
||||
float ClearColor[4] = {0.5f, 0.5f, 0.6f, 1.0f};
|
||||
g_pd3dDevice->ClearRenderTargetView(g_pSwapChainRTV, ClearColor);
|
||||
|
||||
//
|
||||
// draw the 2d texture
|
||||
//
|
||||
g_pUseCase->SetInt(0);
|
||||
float quadRect[4] = {-0.9f, -0.9f, 0.7f, 0.7f};
|
||||
g_pvQuadRect->SetFloatVector((float *)&quadRect);
|
||||
g_pSimpleTechnique->GetPassByIndex(0)->Apply(0);
|
||||
g_pd3dDevice->Draw(4, 0);
|
||||
|
||||
//
|
||||
// draw a slice the 3d texture
|
||||
//
|
||||
g_pUseCase->SetInt(1);
|
||||
quadRect[1] = 0.1f;
|
||||
g_pvQuadRect->SetFloatVector((float *)&quadRect);
|
||||
g_pSimpleTechnique->GetPassByIndex(0)->Apply(0);
|
||||
g_pd3dDevice->Draw(4, 0);
|
||||
|
||||
//
|
||||
// draw the 6 faces of the cube texture
|
||||
//
|
||||
float faceRect[4] = {-0.1f, -0.9f, 0.5f, 0.5f};
|
||||
|
||||
for (int f = 0; f < 6; f++) {
|
||||
if (f == 3) {
|
||||
faceRect[0] += 0.55f;
|
||||
faceRect[1] = -0.9f;
|
||||
}
|
||||
|
||||
g_pUseCase->SetInt(2 + f);
|
||||
g_pvQuadRect->SetFloatVector((float *)&faceRect);
|
||||
g_pSimpleTechnique->GetPassByIndex(0)->Apply(0);
|
||||
g_pd3dDevice->Draw(4, 0);
|
||||
faceRect[1] += 0.6f;
|
||||
}
|
||||
|
||||
// Present the backbuffer contents to the display
|
||||
g_pSwapChain->Present(0, 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: Cleanup()
|
||||
// Desc: Releases all previously initialized objects
|
||||
//-----------------------------------------------------------------------------
|
||||
void Cleanup() {
|
||||
// unregister the Cuda resources
|
||||
cudaGraphicsUnregisterResource(g_texture_2d.cudaResource);
|
||||
getLastCudaError("cudaGraphicsUnregisterResource (g_texture_2d) failed");
|
||||
cudaFree(g_texture_2d.cudaLinearMemory);
|
||||
getLastCudaError("cudaFree (g_texture_2d) failed");
|
||||
|
||||
cudaGraphicsUnregisterResource(g_texture_cube.cudaResource);
|
||||
getLastCudaError("cudaGraphicsUnregisterResource (g_texture_cube) failed");
|
||||
cudaFree(g_texture_cube.cudaLinearMemory);
|
||||
getLastCudaError("cudaFree (g_texture_2d) failed");
|
||||
|
||||
cudaGraphicsUnregisterResource(g_texture_3d.cudaResource);
|
||||
getLastCudaError("cudaGraphicsUnregisterResource (g_texture_3d) failed");
|
||||
cudaFree(g_texture_3d.cudaLinearMemory);
|
||||
getLastCudaError("cudaFree (g_texture_2d) failed");
|
||||
|
||||
//
|
||||
// clean up Direct3D
|
||||
//
|
||||
{
|
||||
// release the resources we created
|
||||
g_texture_2d.pSRView->Release();
|
||||
g_texture_2d.pTexture->Release();
|
||||
g_texture_cube.pSRView->Release();
|
||||
g_texture_cube.pTexture->Release();
|
||||
g_texture_3d.pSRView->Release();
|
||||
g_texture_3d.pTexture->Release();
|
||||
|
||||
if (g_pInputLayout != NULL) g_pInputLayout->Release();
|
||||
|
||||
if (g_pSimpleEffect != NULL) g_pSimpleEffect->Release();
|
||||
|
||||
if (g_pSwapChainRTV != NULL) g_pSwapChainRTV->Release();
|
||||
|
||||
if (g_pSwapChain != NULL) g_pSwapChain->Release();
|
||||
|
||||
if (g_pd3dDevice != NULL) g_pd3dDevice->Release();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: Render()
|
||||
// Desc: Launches the CUDA kernels to fill in the texture data
|
||||
//-----------------------------------------------------------------------------
|
||||
void Render() {
|
||||
//
|
||||
// map the resources we've registered so we can access them in Cuda
|
||||
// - it is most efficient to map and unmap all resources in a single call,
|
||||
// and to have the map/unmap calls be the boundary between using the GPU
|
||||
// for Direct3D and Cuda
|
||||
//
|
||||
static bool doit = true;
|
||||
|
||||
if (doit) {
|
||||
doit = true;
|
||||
cudaStream_t stream = 0;
|
||||
const int nbResources = 3;
|
||||
cudaGraphicsResource *ppResources[nbResources] = {
|
||||
g_texture_2d.cudaResource, g_texture_3d.cudaResource,
|
||||
g_texture_cube.cudaResource,
|
||||
};
|
||||
cudaGraphicsMapResources(nbResources, ppResources, stream);
|
||||
getLastCudaError("cudaGraphicsMapResources(3) failed");
|
||||
|
||||
//
|
||||
// run kernels which will populate the contents of those textures
|
||||
//
|
||||
RunKernels();
|
||||
|
||||
//
|
||||
// unmap the resources
|
||||
//
|
||||
cudaGraphicsUnmapResources(nbResources, ppResources, stream);
|
||||
getLastCudaError("cudaGraphicsUnmapResources(3) failed");
|
||||
}
|
||||
|
||||
//
|
||||
// draw the scene using them
|
||||
//
|
||||
DrawScene();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: MsgProc()
|
||||
// Desc: The window's message handler
|
||||
//-----------------------------------------------------------------------------
|
||||
static LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam,
|
||||
LPARAM lParam) {
|
||||
switch (msg) {
|
||||
case WM_KEYDOWN:
|
||||
if (wParam == VK_ESCAPE) {
|
||||
g_bDone = true;
|
||||
Cleanup();
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
g_bDone = true;
|
||||
Cleanup();
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
|
||||
case WM_PAINT:
|
||||
ValidateRect(hWnd, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2017
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "simpleD3D10Texture", "simpleD3D10Texture_vs2017.vcxproj", "{997E0757-EA74-4A4E-A0FC-47D8C8831A15}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.Build.0 = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.ActiveCfg = Release|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,116 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<CUDAPropsPath Condition="'$(CUDAPropsPath)'==''">$(VCTargetsPath)\BuildCustomizations</CUDAPropsPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{997E0757-EA74-4A4E-A0FC-47D8C8831A15}</ProjectGuid>
|
||||
<RootNamespace>simpleD3D10Texture_vs2017</RootNamespace>
|
||||
<ProjectName>simpleD3D10Texture</ProjectName>
|
||||
<CudaToolkitCustomDir />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(WindowsTargetPlatformVersion)'==''">
|
||||
<LatestTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</LatestTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion Condition="'$(WindowsTargetPlatformVersion)' == ''">$(LatestTargetPlatformVersion)</WindowsTargetPlatformVersion>
|
||||
<TargetPlatformVersion>$(WindowsTargetPlatformVersion)</TargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup>
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.6.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IntDir>$(Platform)/$(Configuration)/</IntDir>
|
||||
<IncludePath>$(IncludePath)</IncludePath>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Platform)'=='x64'">
|
||||
<OutDir>../../../bin/win64/$(Configuration)/</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>./;$(CudaToolkitDir)/include;../../../Common;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>cudart_static.lib;d3d10.lib;d3dcompiler.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(CudaToolkitLibDir);</AdditionalLibraryDirectories>
|
||||
<OutputFile>$(OutDir)/simpleD3D10Texture.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_35,sm_35;compute_37,sm_37;compute_50,sm_50;compute_52,sm_52;compute_60,sm_60;compute_61,sm_61;compute_70,sm_70;compute_75,sm_75;compute_80,sm_80;compute_86,sm_86;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" --threads 0 </AdditionalOptions>
|
||||
<Include>./;../../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MTd</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MT</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="simpleD3D10Texture.cpp" />
|
||||
<CudaCompile Include="texture_2d.cu" />
|
||||
<CudaCompile Include="texture_3d.cu" />
|
||||
<CudaCompile Include="texture_cube.cu" />
|
||||
<ClCompile Include="..\..\..\Common\rendercheck_d3d10.cpp" />
|
||||
<ClInclude Include="..\..\..\Common\rendercheck_d3d10.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.6.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2019
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "simpleD3D10Texture", "simpleD3D10Texture_vs2019.vcxproj", "{997E0757-EA74-4A4E-A0FC-47D8C8831A15}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.Build.0 = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.ActiveCfg = Release|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,112 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<CUDAPropsPath Condition="'$(CUDAPropsPath)'==''">$(VCTargetsPath)\BuildCustomizations</CUDAPropsPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{997E0757-EA74-4A4E-A0FC-47D8C8831A15}</ProjectGuid>
|
||||
<RootNamespace>simpleD3D10Texture_vs2019</RootNamespace>
|
||||
<ProjectName>simpleD3D10Texture</ProjectName>
|
||||
<CudaToolkitCustomDir />
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup>
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.6.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IntDir>$(Platform)/$(Configuration)/</IntDir>
|
||||
<IncludePath>$(IncludePath)</IncludePath>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Platform)'=='x64'">
|
||||
<OutDir>../../../bin/win64/$(Configuration)/</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>./;$(CudaToolkitDir)/include;../../../Common;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>cudart_static.lib;d3d10.lib;d3dcompiler.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(CudaToolkitLibDir);</AdditionalLibraryDirectories>
|
||||
<OutputFile>$(OutDir)/simpleD3D10Texture.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_35,sm_35;compute_37,sm_37;compute_50,sm_50;compute_52,sm_52;compute_60,sm_60;compute_61,sm_61;compute_70,sm_70;compute_75,sm_75;compute_80,sm_80;compute_86,sm_86;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" --threads 0 </AdditionalOptions>
|
||||
<Include>./;../../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MTd</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MT</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="simpleD3D10Texture.cpp" />
|
||||
<CudaCompile Include="texture_2d.cu" />
|
||||
<CudaCompile Include="texture_3d.cu" />
|
||||
<CudaCompile Include="texture_cube.cu" />
|
||||
<ClCompile Include="..\..\..\Common\rendercheck_d3d10.cpp" />
|
||||
<ClInclude Include="..\..\..\Common\rendercheck_d3d10.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.6.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2022
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "simpleD3D10Texture", "simpleD3D10Texture_vs2022.vcxproj", "{997E0757-EA74-4A4E-A0FC-47D8C8831A15}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Debug|x64.Build.0 = Debug|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.ActiveCfg = Release|x64
|
||||
{997E0757-EA74-4A4E-A0FC-47D8C8831A15}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,112 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<CUDAPropsPath Condition="'$(CUDAPropsPath)'==''">$(VCTargetsPath)\BuildCustomizations</CUDAPropsPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{997E0757-EA74-4A4E-A0FC-47D8C8831A15}</ProjectGuid>
|
||||
<RootNamespace>simpleD3D10Texture_vs2022</RootNamespace>
|
||||
<ProjectName>simpleD3D10Texture</ProjectName>
|
||||
<CudaToolkitCustomDir />
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup>
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.6.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IntDir>$(Platform)/$(Configuration)/</IntDir>
|
||||
<IncludePath>$(IncludePath)</IncludePath>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Platform)'=='x64'">
|
||||
<OutDir>../../../bin/win64/$(Configuration)/</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN32;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>./;$(CudaToolkitDir)/include;../../../Common;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>cudart_static.lib;d3d10.lib;d3dcompiler.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(CudaToolkitLibDir);</AdditionalLibraryDirectories>
|
||||
<OutputFile>$(OutDir)/simpleD3D10Texture.exe</OutputFile>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<CodeGeneration>compute_35,sm_35;compute_37,sm_37;compute_50,sm_50;compute_52,sm_52;compute_60,sm_60;compute_61,sm_61;compute_70,sm_70;compute_75,sm_75;compute_80,sm_80;compute_86,sm_86;</CodeGeneration>
|
||||
<AdditionalOptions>-Xcompiler "/wd 4819" --threads 0 </AdditionalOptions>
|
||||
<Include>./;../../../Common</Include>
|
||||
<Defines>WIN32</Defines>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MTd</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
<CudaCompile>
|
||||
<Runtime>MT</Runtime>
|
||||
<TargetMachinePlatform>64</TargetMachinePlatform>
|
||||
</CudaCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="simpleD3D10Texture.cpp" />
|
||||
<CudaCompile Include="texture_2d.cu" />
|
||||
<CudaCompile Include="texture_3d.cu" />
|
||||
<CudaCompile Include="texture_cube.cu" />
|
||||
<ClCompile Include="..\..\..\Common\rendercheck_d3d10.cpp" />
|
||||
<ClInclude Include="..\..\..\Common\rendercheck_d3d10.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="$(CUDAPropsPath)\CUDA 11.6.targets" />
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
78
Samples/5_Domain_Specific/simpleD3D10Texture/texture_2d.cu
Normal file
78
Samples/5_Domain_Specific/simpleD3D10Texture/texture_2d.cu
Normal file
@@ -0,0 +1,78 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define PI 3.1415926536f
|
||||
|
||||
/*
|
||||
* Paint a 2D texture with a moving red/green hatch pattern on a
|
||||
* strobing blue background. Note that this kernel reads to and
|
||||
* writes from the texture, hence why this texture was not mapped
|
||||
* as WriteDiscard.
|
||||
*/
|
||||
__global__ void cuda_kernel_texture_2d(unsigned char *surface, int width,
|
||||
int height, size_t pitch, float t) {
|
||||
int x = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int y = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
float *pixel;
|
||||
|
||||
// in the case where, due to quantization into grids, we have
|
||||
// more threads than pixels, skip the threads which don't
|
||||
// correspond to valid pixels
|
||||
if (x >= width || y >= height) return;
|
||||
|
||||
// get a pointer to the pixel at (x,y)
|
||||
pixel = (float *)(surface + y * pitch) + 4 * x;
|
||||
|
||||
// populate it
|
||||
float value_x = 0.5f + 0.5f * cos(t + 10.0f * ((2.0f * x) / width - 1.0f));
|
||||
float value_y = 0.5f + 0.5f * cos(t + 10.0f * ((2.0f * y) / height - 1.0f));
|
||||
pixel[0] = 0.5 * pixel[0] + 0.5 * pow(value_x, 3.0f); // red
|
||||
pixel[1] = 0.5 * pixel[1] + 0.5 * pow(value_y, 3.0f); // green
|
||||
pixel[2] = 0.5f + 0.5f * cos(t); // blue
|
||||
pixel[3] = 1; // alpha
|
||||
}
|
||||
|
||||
extern "C" void cuda_texture_2d(void *surface, int width, int height,
|
||||
size_t pitch, float t) {
|
||||
cudaError_t error = cudaSuccess;
|
||||
|
||||
dim3 Db = dim3(16, 16); // block dimensions are fixed to be 256 threads
|
||||
dim3 Dg = dim3((width + Db.x - 1) / Db.x, (height + Db.y - 1) / Db.y);
|
||||
|
||||
cuda_kernel_texture_2d<<<Dg, Db>>>((unsigned char *)surface, width, height,
|
||||
pitch, t);
|
||||
|
||||
error = cudaGetLastError();
|
||||
|
||||
if (error != cudaSuccess) {
|
||||
printf("cuda_kernel_texture_2d() failed to launch error = %d\n", error);
|
||||
}
|
||||
}
|
||||
76
Samples/5_Domain_Specific/simpleD3D10Texture/texture_3d.cu
Normal file
76
Samples/5_Domain_Specific/simpleD3D10Texture/texture_3d.cu
Normal file
@@ -0,0 +1,76 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Paint a 3D texture with a gradient in X (blue) and Z (green), and have every
|
||||
* other Z slice have full red.
|
||||
*/
|
||||
__global__ void cuda_kernel_texture_3d(unsigned char *surface, int width,
|
||||
int height, int depth, size_t pitch,
|
||||
size_t pitchSlice, float t) {
|
||||
int x = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int y = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
|
||||
// in the case where, due to quantization into grids, we have
|
||||
// more threads than pixels, skip the threads which don't
|
||||
// correspond to valid pixels
|
||||
if (x >= width || y >= height) return;
|
||||
|
||||
// walk across the Z slices of this texture. it should be noted that
|
||||
// this is far from optimal data access.
|
||||
for (int z = 0; z < depth; ++z) {
|
||||
// get a pointer to this pixel
|
||||
unsigned char *pixel = surface + z * pitchSlice + y * pitch + 4 * x;
|
||||
pixel[0] = (unsigned char)(255.f * (0.5f + 0.5f *
|
||||
cos(t + (x * x + y * y + z * z) * 0.0001f * 3.14f))); // red
|
||||
pixel[1] = (unsigned char)(255.f * (0.5f + 0.5f *
|
||||
sin(t + (x * x + y * y + z * z) * 0.0001f * 3.14f))); // green
|
||||
pixel[2] = (unsigned char)0; // blue
|
||||
pixel[3] = 255; // alpha
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void cuda_texture_3d(void *surface, int width, int height, int depth,
|
||||
size_t pitch, size_t pitchSlice, float t) {
|
||||
cudaError_t error = cudaSuccess;
|
||||
|
||||
dim3 Db = dim3(16, 16); // block dimensions are fixed to be 256 threads
|
||||
dim3 Dg = dim3((width + Db.x - 1) / Db.x, (height + Db.y - 1) / Db.y);
|
||||
|
||||
cuda_kernel_texture_3d<<<Dg, Db>>>((unsigned char *)surface, width, height,
|
||||
depth, pitch, pitchSlice, t);
|
||||
|
||||
error = cudaGetLastError();
|
||||
|
||||
if (error != cudaSuccess) {
|
||||
printf("cuda_kernel_texture_3d() failed to launch error = %d\n", error);
|
||||
}
|
||||
}
|
||||
91
Samples/5_Domain_Specific/simpleD3D10Texture/texture_cube.cu
Normal file
91
Samples/5_Domain_Specific/simpleD3D10Texture/texture_cube.cu
Normal file
@@ -0,0 +1,91 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define PI 3.1415926536f
|
||||
|
||||
/*
|
||||
* Paint a 2D surface with a moving bulls-eye pattern. The "face" parameter
|
||||
* selects
|
||||
* between 6 different colors to use. We will use a different color on each
|
||||
* face of a
|
||||
* cube map.
|
||||
*/
|
||||
__global__ void cuda_kernel_texture_cube(char *surface, int width, int height,
|
||||
size_t pitch, int face, float t) {
|
||||
int x = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int y = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
unsigned char *pixel;
|
||||
|
||||
// in the case where, due to quantization into grids, we have
|
||||
// more threads than pixels, skip the threads which don't
|
||||
// correspond to valid pixels
|
||||
if (x >= width || y >= height) return;
|
||||
|
||||
// get a pointer to this pixel
|
||||
pixel = (unsigned char *)(surface + y * pitch) + 4 * x;
|
||||
|
||||
// populate it
|
||||
float theta_x = (2.0f * x) / width - 1.0f;
|
||||
float theta_y = (2.0f * y) / height - 1.0f;
|
||||
float theta = 2.0f * PI * sqrt(theta_x * theta_x + theta_y * theta_y);
|
||||
unsigned char value = 255 * (0.6f + 0.4f * cos(theta + t));
|
||||
|
||||
pixel[3] = 255; // alpha
|
||||
|
||||
if (face % 2) {
|
||||
pixel[0] = // blue
|
||||
pixel[1] = // green
|
||||
pixel[2] = 0.5; // red
|
||||
pixel[face / 2] = value;
|
||||
} else {
|
||||
pixel[0] = // blue
|
||||
pixel[1] = // green
|
||||
pixel[2] = value; // red
|
||||
pixel[face / 2] = 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void cuda_texture_cube(void *surface, int width, int height,
|
||||
size_t pitch, int face, float t) {
|
||||
cudaError_t error = cudaSuccess;
|
||||
|
||||
dim3 Db = dim3(16, 16); // block dimensions are fixed to be 256 threads
|
||||
dim3 Dg = dim3((width + Db.x - 1) / Db.x, (height + Db.y - 1) / Db.y);
|
||||
|
||||
cuda_kernel_texture_cube<<<Dg, Db>>>((char *)surface, width, height, pitch,
|
||||
face, t);
|
||||
|
||||
error = cudaGetLastError();
|
||||
|
||||
if (error != cudaSuccess) {
|
||||
printf("cuda_kernel_texture_cube() failed to launch error = %d\n", error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user