forked from NVIDIA-RTX/RTXNTC-Library
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphicsResources.cpp
More file actions
99 lines (84 loc) · 3.46 KB
/
GraphicsResources.cpp
File metadata and controls
99 lines (84 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#include "GraphicsResources.h"
#include "CoopVecWeightConverter.h"
#include <libntc/ntc.h>
namespace ntc
{
GraphicsResources::GraphicsResources(ContextParameters const& params)
: m_allocator(params.pAllocator)
, m_graphicsApi(params.graphicsApi)
{
if (params.graphicsApi == GraphicsAPI::D3D12)
{
#if NTC_WITH_DX12
m_d3d12Device = static_cast<ID3D12Device*>(params.d3d12Device);
if (params.enableCooperativeVector)
{
CoopVecWeightConverter::IsDX12CoopVecSupported(this, m_coopVecSupported);
}
#endif
}
else if (params.graphicsApi == GraphicsAPI::Vulkan)
{
#if NTC_WITH_VULKAN
m_vulkanInstance = static_cast<VkInstance>(params.vkInstance);
m_vulkanPhysicalDevice = static_cast<VkPhysicalDevice>(params.vkPhysicalDevice);
m_vulkanDevice = static_cast<VkDevice>(params.vkDevice);
m_vulkanLoader = new (m_allocator->Allocate(sizeof(VulkanDynamicLoader))) VulkanDynamicLoader();
PFN_vkGetInstanceProcAddr const vkGetInstanceProcAddr =
m_vulkanLoader->getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
if (vkGetInstanceProcAddr)
{
#define LOAD_INSTANCE_FN(name) pfn_##name = (PFN_##name)vkGetInstanceProcAddr(m_vulkanInstance, #name)
LOAD_INSTANCE_FN(vkGetPhysicalDeviceCooperativeVectorPropertiesNV);
#undef LOAD_INSTANCE_FN
}
PFN_vkGetDeviceProcAddr const vkGetDeviceProcAddr =
m_vulkanLoader->getProcAddress<PFN_vkGetDeviceProcAddr>("vkGetDeviceProcAddr");
if (vkGetDeviceProcAddr)
{
#define LOAD_DEVICE_FN(name) pfn_##name = (PFN_##name)vkGetDeviceProcAddr(m_vulkanDevice, #name)
LOAD_DEVICE_FN(vkCmdConvertCooperativeVectorMatrixNV);
LOAD_DEVICE_FN(vkCmdCopyBuffer);
LOAD_DEVICE_FN(vkCmdDecompressMemoryNV);
LOAD_DEVICE_FN(vkConvertCooperativeVectorMatrixNV);
LOAD_DEVICE_FN(vkGetBufferDeviceAddress);
#undef LOAD_DEVICE_FN
}
PFN_vkGetPhysicalDeviceProperties const vkGetPhysicalDeviceProperties =
m_vulkanLoader->getProcAddress<PFN_vkGetPhysicalDeviceProperties>("vkGetPhysicalDeviceProperties");
if (m_vulkanPhysicalDevice && vkGetPhysicalDeviceProperties)
{
vkGetPhysicalDeviceProperties(m_vulkanPhysicalDevice, &m_vulkanPhysicalDeviceProperties);
}
if (params.enableCooperativeVector)
{
CoopVecWeightConverter::IsVkCoopVecSupported(this, m_coopVecSupported);
}
#endif
}
if (!params.enableCooperativeVector)
m_coopVecSupported = false;
}
GraphicsResources::~GraphicsResources()
{
#if NTC_WITH_VULKAN
if (m_vulkanLoader)
{
m_vulkanLoader->~DynamicLoader();
m_allocator->Deallocate(m_vulkanLoader, sizeof(VulkanDynamicLoader));
m_vulkanLoader = nullptr;
}
#endif
}
}