Repository navigation
Expand file tree
/
Copy pathscene_shader_macros.cpp
More file actions
98 lines (85 loc) · 3.64 KB
/
Copy pathscene_shader_macros.cpp
File metadata and controls
98 lines (85 loc) · 3.64 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
/*
* Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/
//
// Builds Slang `-D` macro lists for shared and scene-optimal shader compiles.
// Consumes `SceneFeatureSet` from scene_feature_detection and is called from the path
// tracer and rasterizer before `SlangCompiler::compileFile()`.
//
#include "scene_shader_macros.hpp"
#include <array>
namespace nvvkgltf {
namespace {
// Push `name=0` or `name=1` so optimal recompiles do not rely on header defaults alone.
void pushExplicit(std::vector<std::pair<std::string, std::string>>& macros, const char* name, bool used)
{
macros.push_back({name, used ? "1" : "0"});
}
struct FeatureMacro
{
SceneFeatureSet::Feature feature;
const char* macro;
};
constexpr std::array<FeatureMacro, SceneFeatureSet::kExtensionFeatureCount> kPathTracerFeatureMacros{{
{SceneFeatureSet::eTransmission, "GLTF_USE_TRANSMISSION"},
{SceneFeatureSet::eVolume, "GLTF_USE_VOLUME"},
{SceneFeatureSet::eScatter, "GLTF_USE_SCATTER"},
{SceneFeatureSet::eClearcoat, "GLTF_USE_CLEARCOAT"},
{SceneFeatureSet::eIridescence, "GLTF_USE_IRIDESCENCE"},
{SceneFeatureSet::eAnisotropy, "GLTF_USE_ANISOTROPY"},
{SceneFeatureSet::eSheen, "GLTF_USE_SHEEN"},
{SceneFeatureSet::eDispersion, "GLTF_USE_DISPERSION"},
{SceneFeatureSet::eDiffuseTransmission, "GLTF_USE_DIFFUSE_TRANSMISSION"},
{SceneFeatureSet::eRetroreflection, "GLTF_USE_RETROREFLECTION"},
{SceneFeatureSet::eUnlit, "GLTF_USE_UNLIT"},
{SceneFeatureSet::eSpecular, "GLTF_USE_SPECULAR"},
{SceneFeatureSet::eIor, "GLTF_USE_IOR"},
{SceneFeatureSet::eSpecularGlossiness, "GLTF_USE_SPECULAR_GLOSSINESS"},
{SceneFeatureSet::eTextureTransform, "GLTF_USE_TEXTURE_TRANSFORM"},
}};
} // namespace
void applyCommonShaderMacros(nvslang::SlangCompiler& compiler)
{
#if defined(USE_DLSS)
compiler.addMacro({"HAS_DLSS_MOTION", "1"});
#endif
}
void appendPathTracerOptimalMacros(std::vector<std::pair<std::string, std::string>>& macros, const SceneFeatureSet& features)
{
for(const FeatureMacro& entry : kPathTracerFeatureMacros)
{
pushExplicit(macros, entry.macro, features.has(entry.feature));
}
}
void appendPathTracerDlssShaderMacro(std::vector<std::pair<std::string, std::string>>& macros, const SceneFeatureSet& features, bool dlssActive)
{
// Two independent, runtime-driven compile gates (both refreshed every frame, independent of
// optimal mode):
// USE_GUIDE_SHADER : guide-buffer capture (albedo/normal/etc.). Needed by DLSS, OptiX and OIDN,
// so it follows eDlssGuide == dlssGuideRequired() (any of them active).
// USE_DLSS_SHADER : DLSS's guide captures, on the frames DLSS renders (PathTracer::makeVariantKey;
// with OptiX or OIDN also on, frame 0 only). Its guide writes still follow the
// per-frame ePtUseDlss flag, off while DLSS is loading.
#if defined(USE_DLSS) || defined(USE_OPTIX_DENOISER) || defined(USE_OIDN_DENOISER)
const bool useGuideShader = features.has(SceneFeatureSet::eDlssGuide);
#else
const bool useGuideShader = false;
#endif
#if defined(USE_DLSS)
const bool useDlssShader = dlssActive;
#else
const bool useDlssShader = false;
#endif
pushExplicit(macros, "USE_GUIDE_SHADER", useGuideShader);
pushExplicit(macros, "USE_DLSS_SHADER", useDlssShader);
}
} // namespace nvvkgltf