Skip to content

Commit c59679b

Browse files
committed
add dxc compile option for dxc extension.
1 parent 7d7e334 commit c59679b

File tree

1 file changed

+53
-17
lines changed

1 file changed

+53
-17
lines changed

extensions/dxc.hpp

+53-17
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,45 @@
1515

1616
namespace wrapper::directx12::extensions
1717
{
18+
enum class dxc_compile_option : uint32
19+
{
20+
none = 0,
21+
debug = (1 << 0),
22+
hlsl2021 = (1 << 1)
23+
};
24+
25+
inline dxc_compile_option operator|(dxc_compile_option lhs, dxc_compile_option rhs)
26+
{
27+
return static_cast<dxc_compile_option>(static_cast<uint32>(lhs) | static_cast<uint32>(rhs));
28+
}
29+
30+
inline dxc_compile_option operator&(dxc_compile_option lhs, dxc_compile_option rhs)
31+
{
32+
return static_cast<dxc_compile_option>(static_cast<uint32>(lhs) & static_cast<uint32>(rhs));
33+
}
34+
35+
inline std::vector<const wchar_t*> build_compile_arguments_from_compile_option(dxc_compile_option compile_option)
36+
{
37+
std::vector<const wchar_t*> arguments;
38+
39+
if ((compile_option & dxc_compile_option::debug) != dxc_compile_option::none)
40+
{
41+
arguments.push_back(L"-Od");
42+
}
43+
44+
if ((compile_option & dxc_compile_option::hlsl2021) != dxc_compile_option::none)
45+
{
46+
arguments.push_back(L"-HV 2021");
47+
}
48+
49+
return arguments;
50+
}
1851

19-
inline shader_code compile_from_source_using_dxc(const std::string& source, const std::wstring& filename,
20-
const std::wstring& entry, const std::wstring& version, const std::vector<std::pair<std::wstring, std::wstring>>& macros = {})
52+
inline shader_code compile_from_source_using_dxc(
53+
const std::string& source, const std::wstring& filename,
54+
const std::wstring& entry, const std::wstring& version,
55+
const dxc_compile_option& compile_option = dxc_compile_option::none,
56+
const std::vector<std::pair<std::wstring, std::wstring>>& macros = {})
2157
{
2258
ComPtr<IDxcIncludeHandler> include;
2359
ComPtr<IDxcCompiler> compiler;
@@ -42,11 +78,7 @@ namespace wrapper::directx12::extensions
4278
for (const auto& macro : macros)
4379
defines.push_back({ macro.first.c_str(), macro.second.c_str() });
4480

45-
std::vector<const wchar_t*> arguments = {
46-
#ifdef _DEBUG
47-
L"-Od"
48-
#endif
49-
};
81+
std::vector<const wchar_t*> arguments = build_compile_arguments_from_compile_option(compile_option);
5082

5183
compiler->Compile(encoding_blob.Get(), filename.c_str(), entry.c_str(),
5284
version.c_str(), arguments.data(), static_cast<uint32>(arguments.size()),
@@ -77,7 +109,9 @@ namespace wrapper::directx12::extensions
77109
}
78110

79111
inline shader_code compile_from_source_using_dxc(const std::string& source, const std::string& filename,
80-
const std::string& entry, const std::string& version, const std::vector<std::pair<std::string, std::string>>& macros = {})
112+
const std::string& entry, const std::string& version,
113+
const dxc_compile_option& compile_option = dxc_compile_option::none,
114+
const std::vector<std::pair<std::string, std::string>>& macros = {})
81115
{
82116
std::vector<std::pair<std::wstring, std::wstring>> wmacros = {};
83117

@@ -92,12 +126,15 @@ namespace wrapper::directx12::extensions
92126
multi_bytes_string_to_wide_string(filename),
93127
multi_bytes_string_to_wide_string(entry),
94128
multi_bytes_string_to_wide_string(version),
129+
compile_option,
95130
wmacros
96131
);
97132
}
98133

99-
inline shader_code compile_from_file_using_dxc(const std::wstring& filename, const std::wstring& entry,
100-
const std::wstring& version, const std::vector<std::pair<std::wstring, std::wstring>>& macros = {})
134+
inline shader_code compile_from_file_using_dxc(
135+
const std::wstring& filename, const std::wstring& entry, const std::wstring& version,
136+
const dxc_compile_option& compile_option = dxc_compile_option::none,
137+
const std::vector<std::pair<std::wstring, std::wstring>>& macros = {})
101138
{
102139
ComPtr<IDxcIncludeHandler> include;
103140
ComPtr<IDxcCompiler> compiler;
@@ -121,11 +158,7 @@ namespace wrapper::directx12::extensions
121158
for (const auto& macro : macros)
122159
defines.push_back({ macro.first.c_str(), macro.second.c_str() });
123160

124-
std::vector<const wchar_t*> arguments = {
125-
#ifdef _DEBUG
126-
L"-Od"
127-
#endif
128-
};
161+
std::vector<const wchar_t*> arguments = build_compile_arguments_from_compile_option(compile_option);
129162

130163
compiler->Compile(encoding_blob.Get(), filename.c_str(), entry.c_str(),
131164
version.c_str(), arguments.data(), static_cast<uint32>(arguments.size()),
@@ -157,8 +190,10 @@ namespace wrapper::directx12::extensions
157190
return shader_code(code);
158191
}
159192

160-
inline shader_code compile_from_file_using_dxc(const std::string& filename, const std::string& entry,
161-
const std::string& version, const std::vector<std::pair<std::string, std::string>>& macros = {})
193+
inline shader_code compile_from_file_using_dxc(
194+
const std::string& filename, const std::string& entry, const std::string& version,
195+
const dxc_compile_option& compile_option = dxc_compile_option::none,
196+
const std::vector<std::pair<std::string, std::string>>& macros = {})
162197
{
163198
std::vector<std::pair<std::wstring, std::wstring>> wmacros = {};
164199

@@ -172,6 +207,7 @@ namespace wrapper::directx12::extensions
172207
multi_bytes_string_to_wide_string(filename),
173208
multi_bytes_string_to_wide_string(entry),
174209
multi_bytes_string_to_wide_string(version),
210+
compile_option,
175211
wmacros
176212
);
177213
}

0 commit comments

Comments
 (0)