Skip to content

Commit a47d343

Browse files
DXCompiler: replaced ExtraDefinitions parameter with Preamble
1 parent 6c258b3 commit a47d343

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static constexpr char VulkanDefine[] =
6363
"# define METAL 1\n"
6464
"#endif\n"
6565
#endif
66-
;
66+
"\n";
6767

6868
std::vector<uint32_t> CompileShaderDXC(const ShaderCreateInfo& ShaderCI,
6969
const ShaderVkImpl::CreateInfo& VkShaderCI)

Graphics/ShaderTools/include/DXCompiler.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -85,7 +85,7 @@ class IDXCompiler
8585

8686
virtual void Compile(const ShaderCreateInfo& ShaderCI,
8787
ShaderVersion ShaderModel,
88-
const char* ExtraDefinitions,
88+
const char* Preamble,
8989
IDxcBlob** ppByteCodeBlob,
9090
std::vector<uint32_t>* pByteCode,
9191
IDataBlob** ppCompilerOutput) noexcept(false) = 0;

Graphics/ShaderTools/include/HLSLUtils.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -39,8 +39,7 @@
3939
namespace Diligent
4040
{
4141

42-
String BuildHLSLSourceString(const ShaderCreateInfo& ShaderCI,
43-
const char* ExtraDefinitions = nullptr) noexcept(false);
42+
String BuildHLSLSourceString(const ShaderCreateInfo& ShaderCI) noexcept(false);
4443

4544
String GetHLSLProfileString(SHADER_TYPE ShaderType, ShaderVersion ShaderModel);
4645

@@ -56,8 +55,8 @@ void HandleHLSLCompilerResult(bool CompilationSucceeded,
5655

5756
if (ppOutputLog != nullptr)
5857
{
59-
const auto ShaderSourceLen = ShaderSource.length();
60-
auto pOutputLogBlob = DataBlobImpl::Create(ShaderSourceLen + 1 + CompilerMsgLen + 1);
58+
const size_t ShaderSourceLen = ShaderSource.length();
59+
RefCntAutoPtr<DataBlobImpl> pOutputLogBlob = DataBlobImpl::Create(ShaderSourceLen + 1 + CompilerMsgLen + 1);
6160

6261
char* log = pOutputLogBlob->GetDataPtr<char>();
6362

Graphics/ShaderTools/src/DXCompiler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class DXCompilerImpl final : public IDXCompiler
105105

106106
virtual void Compile(const ShaderCreateInfo& ShaderCI,
107107
ShaderVersion ShaderModel,
108-
const char* ExtraDefinitions,
108+
const char* Preamble,
109109
IDxcBlob** ppByteCodeBlob,
110110
std::vector<uint32_t>* pByteCode,
111111
IDataBlob** ppCompilerOutput) noexcept(false) override final;
@@ -688,7 +688,7 @@ void DXCompilerImpl::GetD3D12ShaderReflection(IDxcBlob* pShaderBy
688688

689689
void DXCompilerImpl::Compile(const ShaderCreateInfo& ShaderCI,
690690
ShaderVersion ShaderModel,
691-
const char* ExtraDefinitions,
691+
const char* Preamble,
692692
IDxcBlob** ppByteCodeBlob,
693693
std::vector<uint32_t>* pByteCode,
694694
IDataBlob** ppCompilerOutput) noexcept(false)
@@ -781,7 +781,8 @@ void DXCompilerImpl::Compile(const ShaderCreateInfo& ShaderCI,
781781

782782
IDXCompiler::CompileAttribs CA;
783783

784-
const String Source = BuildHLSLSourceString(ShaderCI, ExtraDefinitions);
784+
String Source{Preamble != nullptr ? Preamble : ""};
785+
Source.append(BuildHLSLSourceString(ShaderCI));
785786

786787
DxcDefine Defines[] = {{L"DXCOMPILER", L"1"}};
787788

Graphics/ShaderTools/src/HLSLUtils.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -43,17 +43,13 @@ static constexpr char g_HLSLDefinitions[] =
4343
// clang-format on
4444

4545

46-
String BuildHLSLSourceString(const ShaderCreateInfo& ShaderCI,
47-
const char* ExtraDefinitions) noexcept(false)
46+
String BuildHLSLSourceString(const ShaderCreateInfo& ShaderCI) noexcept(false)
4847
{
4948
String HLSLSource;
5049

5150
HLSLSource.append(g_HLSLDefinitions);
5251
AppendShaderTypeDefinitions(HLSLSource, ShaderCI.Desc.ShaderType);
5352

54-
if (ExtraDefinitions != nullptr)
55-
HLSLSource += ExtraDefinitions;
56-
5753
if (ShaderCI.Macros)
5854
{
5955
HLSLSource += '\n';

0 commit comments

Comments
 (0)