-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathUtils.h
More file actions
196 lines (173 loc) · 7.61 KB
/
Utils.h
File metadata and controls
196 lines (173 loc) · 7.61 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
* Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#pragma once
#include <Platform.h>
#include <GraphicsAPI/GraphicsAPI.h>
#include <vector>
#include <string>
#define RETURN_IF_STATUS_FAILED(x) \
do { \
KickstartRT::Status sts##__COUNTER__ = (x); \
if (sts##__COUNTER__ != KickstartRT::Status::OK) return sts##__COUNTER__;\
} while (0)
namespace KickstartRT_NativeLayer
{
template <typename ... Args>
inline std::wstring DebugName(const std::wstring& fmt, Args ... args)
{
int len = std::swprintf(nullptr, 0, fmt.c_str(), args ...);
// todo - not quite right for linux. Returns a negative
if (len <= 0)
len = 256;
std::vector<wchar_t> buf(len + 1);
std::swprintf(&buf[0], len + 1, fmt.c_str(), args ...);
const std::wstring sWrk(L"KS:");
return sWrk + buf.data();
};
template <>
inline std::wstring DebugName(const std::wstring& str)
{
return std::wstring(L"KS:") + str;
}
template <typename ... Args>
inline std::string DebugName(const std::string& fmt, Args ... args)
{
size_t len = std::snprintf(nullptr, 0, fmt.c_str(), args ...);
std::vector<char> buf(len + 1);
std::snprintf(&buf[0], len + 1, fmt.c_str(), args ...);
const std::string sWrk("KS:");
return sWrk + buf.data();
};
template <>
inline std::string DebugName(const std::string& str)
{
return std::string("KS:") + str;
}
inline const char* GetString(DenoisingContextInput::DenoisingMethod method) {
switch (method) {
case DenoisingContextInput::DenoisingMethod::NRD_Reblur:
return "NRD_Reblur";
case DenoisingContextInput::DenoisingMethod::NRD_Relax:
return "NRD_Relax";
case DenoisingContextInput::DenoisingMethod::NRD_Sigma:
return "NRD_Sigma";
default:
return "Unknown";
}
}
inline const char* GetString(DenoisingContextInput::SignalType signalType) {
switch (signalType) {
case DenoisingContextInput::SignalType::Specular:
return "Specular";
case DenoisingContextInput::SignalType::Diffuse:
return "Diffuse";
case DenoisingContextInput::SignalType::SpecularAndDiffuse:
return "SpecularAndDiffuse";
case DenoisingContextInput::SignalType::DiffuseOcclusion:
return "DiffuseOcclusion";
case DenoisingContextInput::SignalType::Shadow:
return "Shadow";
case DenoisingContextInput::SignalType::MultiShadow:
return "MultiShadow";
default:
return "Unknown";
}
}
namespace Utils {
void LogGeometryInput(const BVHTask::GeometryInput* input);
bool CheckInputTextureState(GraphicsAPI::CommandList* cmdList, const RenderTask::ShaderResourceTex* inputTex, GraphicsAPI::ResourceState::State expectedState);
bool CheckInputTextureState(GraphicsAPI::CommandList* cmdList, const RenderTask::UnorderedAccessTex* inputTex, GraphicsAPI::ResourceState::State expectedState);
};
namespace GraphicsAPI {
struct TexValidator {
TexValidator(const char* debugName, const RenderTask::UnorderedAccessTex& uaTex) :m_debugName(debugName) {
#if defined(GRAPHICS_API_D3D12)
m_format = Resource::GetResourceFormat(uaTex.uavDesc.Format);
m_isNull = uaTex.resource == nullptr;
#elif defined(GRAPHICS_API_VK)
m_format = Resource::GetResourceFormat(uaTex.format);
m_isNull = uaTex.image == 0;
#endif
m_formatType = Resource::GetFormatType(m_format);
m_channelCount = Resource::GetChannelCount(m_format);
};
TexValidator(const char* debugName, const RenderTask::ShaderResourceTex& srvTex) :m_debugName(debugName) {
#if defined(GRAPHICS_API_D3D12)
m_format = Resource::GetResourceFormat(srvTex.srvDesc.Format);
m_isNull = srvTex.resource == nullptr;
#elif defined(GRAPHICS_API_VK)
m_format = Resource::GetResourceFormat(srvTex.format);
m_isNull = srvTex.image == 0;
#endif
m_formatType = Resource::GetFormatType(m_format);
m_channelCount = Resource::GetChannelCount(m_format);
};
TexValidator(const char* debugName, const RenderTask::CombinedAccessTex& tex) :m_debugName(debugName) {
#if defined(GRAPHICS_API_D3D12)
m_format = Resource::GetResourceFormat(tex.srvDesc.Format);
m_isNull = tex.resource == nullptr;
#elif defined(GRAPHICS_API_VK)
m_format = Resource::GetResourceFormat(tex.format);
m_isNull = tex.image == 0;
#endif
m_formatType = Resource::GetFormatType(m_format);
m_channelCount = Resource::GetChannelCount(m_format);
};
bool IsNull() const { return m_isNull; }
Status AssertIsNotNull() const {
if (m_isNull) {
Log::Fatal(L"Unexpected (%s) to be set", m_debugName);
return Status::ERROR_INVALID_PARAM;
}
return Status::OK;
}
Status AssertChannelCount(std::initializer_list<uint32_t> counts) const {
if (!IsAnyOf(m_channelCount, counts)) {
Log::Fatal(L"Unexpected channel count. Has (%d) channels.", m_channelCount);
return Status::ERROR_INVALID_PARAM;
}
return Status::OK;
}
template<class... TArgs>
Status AssertFormatType(std::initializer_list<Resource::FormatType> formats) const {
if (!IsAnyOf(m_formatType, formats)) {
Log::Fatal(L"Unexpected format type. Is (%d)", m_formatType);
return Status::ERROR_INVALID_PARAM;
}
return Status::OK;
}
private:
template<class T>
bool IsAnyOf(T object, std::initializer_list<T> list) const {
for (auto l : list) {
if (object == l) return true;
}
return false;
}
const char* m_debugName;
bool m_isNull;
Resource::Format m_format;
Resource::FormatType m_formatType;
uint32_t m_channelCount;
};
};
};