Skip to content

Commit 2590ba0

Browse files
committed
Removed duplicate list of required arguments
1 parent ecb40ce commit 2590ba0

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

include/nbl/asset/utils/CHLSLCompiler.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class NBL_API2 CHLSLCompiler final : public IShaderCompiler
3232

3333
struct SOptions : IShaderCompiler::SCompilerOptions
3434
{
35-
// TODO: Add extra dxc options
3635
std::span<const std::string> dxcOptions;
3736
IShader::E_CONTENT_TYPE getCodeContentType() const override { return IShader::E_CONTENT_TYPE::ECT_HLSL; };
3837
};
@@ -55,7 +54,17 @@ class NBL_API2 CHLSLCompiler final : public IShaderCompiler
5554
std::string preprocessShader(std::string&& code, IShader::E_SHADER_STAGE& stage, std::vector<std::string>& dxc_compile_flags_override, const SPreprocessorOptions& preprocessOptions) const;
5655

5756
void insertIntoStart(std::string& code, std::ostringstream&& ins) const override;
58-
57+
constexpr static inline const wchar_t* RequiredArguments[] = {
58+
L"-spirv",
59+
L"-Zpr",
60+
L"-enable-16bit-types",
61+
L"-fvk-use-scalar-layout",
62+
L"-Wno-c++11-extensions",
63+
L"-Wno-c++1z-extensions",
64+
L"-Wno-gnu-static-float-init",
65+
L"-fspv-target-env=vulkan1.3"
66+
};
67+
constexpr static inline uint32_t RequiredArgumentCount = 8;
5968

6069
protected:
6170
// This can't be a unique_ptr due to it being an undefined type

src/nbl/asset/utils/CHLSLCompiler.cpp

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,34 +101,23 @@ static void try_upgrade_shader_stage(std::vector<std::wstring> &arguments) {
101101

102102

103103
static void add_required_arguments_if_not_present(std::vector<std::wstring>& arguments, system::logger_opt_ptr &logger) {
104-
constexpr int required_arg_size = 8;
105-
std::wstring required_arguments[] = {
106-
L"-spirv",
107-
L"-Zpr",
108-
L"-enable-16bit-types",
109-
L"-fvk-use-scalar-layout",
110-
L"-Wno-c++11-extensions",
111-
L"-Wno-c++1z-extensions",
112-
L"-Wno-gnu-static-float-init",
113-
L"-fspv-target-env=vulkan1.3"
114-
};
115-
bool found_arg_flags[required_arg_size]{};
104+
bool found_arg_flags[CHLSLCompiler::RequiredArgumentCount]{};
116105
int argc = arguments.size();
117106
for (int i = 0; i < argc; i++)
118107
{
119-
for (int j = 0; j < required_arg_size; j++)
108+
for (int j = 0; j < CHLSLCompiler::RequiredArgumentCount; j++)
120109
{
121-
if (arguments[i] == required_arguments[j]) {
110+
if (arguments[i] == CHLSLCompiler::RequiredArguments[j]) {
122111
found_arg_flags[j] = true;
123112
break;
124113
}
125114
}
126115
}
127-
for (int j = 0; j < required_arg_size; j++)
116+
for (int j = 0; j < CHLSLCompiler::RequiredArgumentCount; j++)
128117
{
129118
if (!found_arg_flags[j]) {
130-
logger.log("Required compile flag not found %ls. This flag will be force enabled as it is required by Nabla.", system::ILogger::ELL_WARNING, required_arguments[j]);
131-
arguments.push_back(required_arguments[j]);
119+
logger.log("Required compile flag not found %ls. This flag will be force enabled as it is required by Nabla.", system::ILogger::ELL_WARNING, CHLSLCompiler::RequiredArguments[j]);
120+
arguments.push_back(CHLSLCompiler::RequiredArguments[j]);
132121
}
133122
}
134123
}
@@ -348,17 +337,11 @@ core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV(const char* cod
348337
}
349338
else { //lastly default arguments
350339
arguments = {
351-
L"-spirv",
352340
L"-HV", L"202x",
353341
L"-T", targetProfile.c_str(),
354-
L"-Zpr", // Packs matrices in row-major order by default
355-
L"-enable-16bit-types",
356-
L"-fvk-use-scalar-layout",
357-
L"-Wno-c++11-extensions",
358-
L"-Wno-c++1z-extensions",
359-
L"-Wno-gnu-static-float-init",
360-
L"-fspv-target-env=vulkan1.3"
361342
};
343+
for (size_t i = 0; i < RequiredArgumentCount; i++)
344+
arguments.push_back(RequiredArguments[i]);
362345
// If a custom SPIR-V optimizer is specified, use that instead of DXC's spirv-opt.
363346
// This is how we can get more optimizer options.
364347
//

0 commit comments

Comments
 (0)