Skip to content

Commit 6be5146

Browse files
committed
Add and update samples for cuda 10.2 support
1 parent 489d9f7 commit 6be5146

File tree

305 files changed

+78239
-518
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

305 files changed

+78239
-518
lines changed

Common/dynlink_d3d11.h

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
2+
*
3+
* Redistribution and use in source and binary forms, with or without
4+
* modification, are permitted provided that the following conditions
5+
* are met:
6+
* * Redistributions of source code must retain the above copyright
7+
* notice, this list of conditions and the following disclaimer.
8+
* * Redistributions in binary form must reproduce the above copyright
9+
* notice, this list of conditions and the following disclaimer in the
10+
* documentation and/or other materials provided with the distribution.
11+
* * Neither the name of NVIDIA CORPORATION nor the names of its
12+
* contributors may be used to endorse or promote products derived
13+
* from this software without specific prior written permission.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
16+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
19+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
28+
//--------------------------------------------------------------------------------------
29+
// File: dynlink_d3d11.h
30+
//
31+
// Shortcut macros and functions for using DX objects
32+
//
33+
// Copyright (c) Microsoft Corporation. All rights reserved
34+
//--------------------------------------------------------------------------------------
35+
36+
#ifndef _DYNLINK_D3D11_H_
37+
#define _DYNLINK_D3D11_H_
38+
39+
// Standard Windows includes
40+
#include <windows.h>
41+
#include <initguid.h>
42+
#include <assert.h>
43+
#include <wchar.h>
44+
#include <mmsystem.h>
45+
#include <commctrl.h> // for InitCommonControls()
46+
#include <shellapi.h> // for ExtractIcon()
47+
#include <new.h> // for placement new
48+
#include <shlobj.h>
49+
#include <math.h>
50+
#include <limits.h>
51+
#include <stdio.h>
52+
53+
// CRT's memory leak detection
54+
#if defined(DEBUG) || defined(_DEBUG)
55+
#include <crtdbg.h>
56+
#endif
57+
58+
// Direct3D10 includes
59+
#include <dxgi.h>
60+
#include <d3d11.h>
61+
// #include <..\Samples\C++\Effects11\Inc\d3dx11effect.h>
62+
63+
// XInput includes
64+
#include <xinput.h>
65+
66+
// strsafe.h deprecates old unsecure string functions. If you
67+
// really do not want to it to (not recommended), then uncomment the next line
68+
//#define STRSAFE_NO_DEPRECATE
69+
70+
#ifndef STRSAFE_NO_DEPRECATE
71+
#pragma deprecated("strncpy")
72+
#pragma deprecated("wcsncpy")
73+
#pragma deprecated("_tcsncpy")
74+
#pragma deprecated("wcsncat")
75+
#pragma deprecated("strncat")
76+
#pragma deprecated("_tcsncat")
77+
#endif
78+
79+
#pragma warning( disable : 4996 ) // disable deprecated warning
80+
#include <strsafe.h>
81+
#pragma warning( default : 4996 )
82+
83+
typedef HRESULT(WINAPI *LPCREATEDXGIFACTORY)(REFIID, void **);
84+
typedef HRESULT(WINAPI *LPD3D11CREATEDEVICEANDSWAPCHAIN)(__in_opt IDXGIAdapter *pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, UINT Flags, __in_ecount_opt(FeatureLevels) CONST D3D_FEATURE_LEVEL *pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, __in_opt CONST DXGI_SWAP_CHAIN_DESC *pSwapChainDesc, __out_opt IDXGISwapChain **ppSwapChain, __out_opt ID3D11Device **ppDevice, __out_opt D3D_FEATURE_LEVEL *pFeatureLevel, __out_opt ID3D11DeviceContext **ppImmediateContext);
85+
typedef HRESULT(WINAPI *LPD3D11CREATEDEVICE)(IDXGIAdapter *, D3D_DRIVER_TYPE, HMODULE, UINT32, D3D_FEATURE_LEVEL *, UINT, UINT32, ID3D11Device **, D3D_FEATURE_LEVEL *, ID3D11DeviceContext **);
86+
87+
static HMODULE s_hModDXGI = NULL;
88+
static LPCREATEDXGIFACTORY sFnPtr_CreateDXGIFactory = NULL;
89+
static HMODULE s_hModD3D11 = NULL;
90+
static LPD3D11CREATEDEVICE sFnPtr_D3D11CreateDevice = NULL;
91+
static LPD3D11CREATEDEVICEANDSWAPCHAIN sFnPtr_D3D11CreateDeviceAndSwapChain = NULL;
92+
93+
// unload the D3D10 DLLs
94+
static bool dynlinkUnloadD3D11API(void)
95+
{
96+
if (s_hModDXGI)
97+
{
98+
FreeLibrary(s_hModDXGI);
99+
s_hModDXGI = NULL;
100+
}
101+
102+
if (s_hModD3D11)
103+
{
104+
FreeLibrary(s_hModD3D11);
105+
s_hModD3D11 = NULL;
106+
}
107+
108+
return true;
109+
}
110+
111+
// Dynamically load the D3D11 DLLs loaded and map the function pointers
112+
static bool dynlinkLoadD3D11API(void)
113+
{
114+
// If both modules are non-NULL, this function has already been called. Note
115+
// that this doesn't guarantee that all ProcAddresses were found.
116+
if (s_hModD3D11 != NULL && s_hModDXGI != NULL)
117+
{
118+
return true;
119+
}
120+
121+
#if 1
122+
// This may fail if Direct3D 11 isn't installed
123+
s_hModD3D11 = LoadLibrary("d3d11.dll");
124+
125+
if (s_hModD3D11 != NULL)
126+
{
127+
sFnPtr_D3D11CreateDevice = (LPD3D11CREATEDEVICE)GetProcAddress(s_hModD3D11, "D3D11CreateDevice");
128+
sFnPtr_D3D11CreateDeviceAndSwapChain = (LPD3D11CREATEDEVICEANDSWAPCHAIN)GetProcAddress(s_hModD3D11, "D3D11CreateDeviceAndSwapChain");
129+
}
130+
else
131+
{
132+
printf("\nLoad d3d11.dll failed\n");
133+
fflush(0);
134+
}
135+
136+
if (!sFnPtr_CreateDXGIFactory)
137+
{
138+
s_hModDXGI = LoadLibrary("dxgi.dll");
139+
140+
if (s_hModDXGI)
141+
{
142+
sFnPtr_CreateDXGIFactory = (LPCREATEDXGIFACTORY)GetProcAddress(s_hModDXGI, "CreateDXGIFactory1");
143+
}
144+
145+
return (s_hModDXGI != NULL) && (s_hModD3D11 != NULL);
146+
}
147+
148+
return (s_hModD3D11 != NULL);
149+
#else
150+
sFnPtr_D3D11CreateDevice = (LPD3D11CREATEDEVICE)D3D11CreateDeviceAndSwapChain;
151+
sFnPtr_D3D11CreateDeviceAndSwapChain = (LPD3D11CREATEDEVICEANDSWAPCHAIN)D3D11CreateDeviceAndSwapChain;
152+
//sFnPtr_D3DX11CreateEffectFromMemory = ( LPD3DX11CREATEEFFECTFROMMEMORY )D3DX11CreateEffectFromMemory;
153+
sFnPtr_D3DX11CompileFromMemory = (LPD3DX11COMPILEFROMMEMORY)D3DX11CompileFromMemory;
154+
sFnPtr_CreateDXGIFactory = (LPCREATEDXGIFACTORY)CreateDXGIFactory;
155+
return true;
156+
#endif
157+
return true;
158+
}
159+
160+
#endif

0 commit comments

Comments
 (0)