|
3 | 3 | // For conditions of distribution and use, see copyright notice in nabla.h |
4 | 4 | #include "common.hpp" |
5 | 5 |
|
| 6 | +#include "nbl/this_example/builtin/build/spirv/keys.hpp" |
| 7 | + |
6 | 8 | #include "nbl/ext/FullScreenTriangle/FullScreenTriangle.h" |
7 | 9 | #include "nbl/builtin/hlsl/indirect_commands.hlsl" |
8 | 10 |
|
@@ -106,95 +108,42 @@ class RaytracingPipelineApp final : public SimpleWindowedApplication, public Bui |
106 | 108 | if (!asset_base_t::onAppInitialized(smart_refctd_ptr(system))) |
107 | 109 | return false; |
108 | 110 |
|
109 | | - smart_refctd_ptr<IShaderCompiler::CCache> shaderReadCache = nullptr; |
110 | | - smart_refctd_ptr<IShaderCompiler::CCache> shaderWriteCache = core::make_smart_refctd_ptr<IShaderCompiler::CCache>(); |
111 | | - auto shaderCachePath = localOutputCWD / "main_pipeline_shader_cache.bin"; |
112 | | - |
113 | | - { |
114 | | - core::smart_refctd_ptr<system::IFile> shaderReadCacheFile; |
115 | | - { |
116 | | - system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future; |
117 | | - m_system->createFile(future, shaderCachePath.c_str(), system::IFile::ECF_READ); |
118 | | - if (future.wait()) |
119 | | - { |
120 | | - future.acquire().move_into(shaderReadCacheFile); |
121 | | - if (shaderReadCacheFile) |
122 | | - { |
123 | | - const size_t size = shaderReadCacheFile->getSize(); |
124 | | - if (size > 0ull) |
125 | | - { |
126 | | - std::vector<uint8_t> contents(size); |
127 | | - system::IFile::success_t succ; |
128 | | - shaderReadCacheFile->read(succ, contents.data(), 0, size); |
129 | | - if (succ) |
130 | | - shaderReadCache = IShaderCompiler::CCache::deserialize(contents); |
131 | | - } |
132 | | - } |
133 | | - } |
134 | | - else |
135 | | - m_logger->log("Failed Openning Shader Cache File.", ILogger::ELL_ERROR); |
136 | | - } |
137 | | - |
138 | | - } |
139 | | - |
140 | 111 | // Load Custom Shader |
141 | | - auto loadCompileAndCreateShader = [&](const std::string& relPath) -> smart_refctd_ptr<IShader> |
| 112 | + auto loadPrecompiledShader = [&]<core::StringLiteral ShaderKey>() -> smart_refctd_ptr<IShader> |
142 | 113 | { |
143 | 114 | IAssetLoader::SAssetLoadParams lp = {}; |
144 | 115 | lp.logger = m_logger.get(); |
145 | | - lp.workingDirectory = ""; // virtual root |
146 | | - auto assetBundle = m_assetMgr->getAsset(relPath, lp); |
| 116 | + lp.workingDirectory = "app_resources"; // virtual root |
| 117 | + auto key = nbl::this_example::builtin::build::get_spirv_key<ShaderKey>(m_device.get()); |
| 118 | + auto assetBundle = m_assetMgr->getAsset(key.data(), lp); |
147 | 119 | const auto assets = assetBundle.getContents(); |
148 | 120 | if (assets.empty()) |
149 | 121 | return nullptr; |
150 | 122 |
|
151 | 123 | // lets go straight from ICPUSpecializedShader to IGPUSpecializedShader |
152 | | - auto sourceRaw = IAsset::castDown<IShader>(assets[0]); |
153 | | - if (!sourceRaw) |
| 124 | + auto shader = IAsset::castDown<IShader>(assets[0]); |
| 125 | + if (!shader) |
| 126 | + { |
| 127 | + m_logger->log("Failed to load a precompiled shader.", ILogger::ELL_ERROR); |
154 | 128 | return nullptr; |
| 129 | + } |
155 | 130 |
|
156 | | - return m_device->compileShader({ sourceRaw.get(), nullptr, shaderReadCache.get(), shaderWriteCache.get() }); |
| 131 | + return shader; |
157 | 132 | }; |
158 | 133 |
|
159 | 134 | // load shaders |
160 | | - const auto raygenShader = loadCompileAndCreateShader("app_resources/raytrace.rgen.hlsl"); |
161 | | - const auto closestHitShader = loadCompileAndCreateShader("app_resources/raytrace.rchit.hlsl"); |
162 | | - const auto proceduralClosestHitShader = loadCompileAndCreateShader("app_resources/raytrace_procedural.rchit.hlsl"); |
163 | | - const auto intersectionHitShader = loadCompileAndCreateShader("app_resources/raytrace.rint.hlsl"); |
164 | | - const auto anyHitShaderColorPayload = loadCompileAndCreateShader("app_resources/raytrace.rahit.hlsl"); |
165 | | - const auto anyHitShaderShadowPayload = loadCompileAndCreateShader("app_resources/raytrace_shadow.rahit.hlsl"); |
166 | | - const auto missShader = loadCompileAndCreateShader("app_resources/raytrace.rmiss.hlsl"); |
167 | | - const auto missShadowShader = loadCompileAndCreateShader("app_resources/raytrace_shadow.rmiss.hlsl"); |
168 | | - const auto directionalLightCallShader = loadCompileAndCreateShader("app_resources/light_directional.rcall.hlsl"); |
169 | | - const auto pointLightCallShader = loadCompileAndCreateShader("app_resources/light_point.rcall.hlsl"); |
170 | | - const auto spotLightCallShader = loadCompileAndCreateShader("app_resources/light_spot.rcall.hlsl"); |
171 | | - const auto fragmentShader = loadCompileAndCreateShader("app_resources/present.frag.hlsl"); |
172 | | - |
173 | | - core::smart_refctd_ptr<system::IFile> shaderWriteCacheFile; |
174 | | - { |
175 | | - system::ISystem::future_t<core::smart_refctd_ptr<system::IFile>> future; |
176 | | - m_system->deleteFile(shaderCachePath); // temp solution instead of trimming, to make sure we won't have corrupted json |
177 | | - m_system->createFile(future, shaderCachePath.c_str(), system::IFile::ECF_WRITE); |
178 | | - if (future.wait()) |
179 | | - { |
180 | | - future.acquire().move_into(shaderWriteCacheFile); |
181 | | - if (shaderWriteCacheFile) |
182 | | - { |
183 | | - auto serializedCache = shaderWriteCache->serialize(); |
184 | | - if (shaderWriteCacheFile) |
185 | | - { |
186 | | - system::IFile::success_t succ; |
187 | | - shaderWriteCacheFile->write(succ, serializedCache->getPointer(), 0, serializedCache->getSize()); |
188 | | - if (!succ) |
189 | | - m_logger->log("Failed Writing To Shader Cache File.", ILogger::ELL_ERROR); |
190 | | - } |
191 | | - } |
192 | | - else |
193 | | - m_logger->log("Failed Creating Shader Cache File.", ILogger::ELL_ERROR); |
194 | | - } |
195 | | - else |
196 | | - m_logger->log("Failed Creating Shader Cache File.", ILogger::ELL_ERROR); |
197 | | - } |
| 135 | + const auto raygenShader = loadPrecompiledShader.operator()<"raytrace_rgen">(); // "app_resources/raytrace.rgen.hlsl" |
| 136 | + const auto closestHitShader = loadPrecompiledShader.operator()<"raytrace_rchit">(); // "app_resources/raytrace.rchit.hlsl" |
| 137 | + const auto proceduralClosestHitShader = loadPrecompiledShader.operator()<"raytrace_procedural_rchit">(); // "app_resources/raytrace_procedural.rchit.hlsl" |
| 138 | + const auto intersectionHitShader = loadPrecompiledShader.operator()<"raytrace_rint">(); // "app_resources/raytrace.rint.hlsl" |
| 139 | + const auto anyHitShaderColorPayload = loadPrecompiledShader.operator()<"raytrace_rahit">(); // "app_resources/raytrace.rahit.hlsl" |
| 140 | + const auto anyHitShaderShadowPayload = loadPrecompiledShader.operator()<"raytrace_shadow_rahit">(); // "app_resources/raytrace_shadow.rahit.hlsl" |
| 141 | + const auto missShader = loadPrecompiledShader.operator()<"raytrace_rmiss">(); // "app_resources/raytrace.rmiss.hlsl" |
| 142 | + const auto missShadowShader = loadPrecompiledShader.operator()<"raytrace_shadow_rmiss">(); // "app_resources/raytrace_shadow.rmiss.hlsl" |
| 143 | + const auto directionalLightCallShader = loadPrecompiledShader.operator()<"light_directional_rcall">(); // "app_resources/light_directional.rcall.hlsl" |
| 144 | + const auto pointLightCallShader = loadPrecompiledShader.operator()<"light_point_rcall">(); // "app_resources/light_point.rcall.hlsl" |
| 145 | + const auto spotLightCallShader = loadPrecompiledShader.operator()<"light_spot_rcall">(); // "app_resources/light_spot.rcall.hlsl" |
| 146 | + const auto fragmentShader = loadPrecompiledShader.operator()<"present_frag">(); // "app_resources/present.frag.hlsl" |
198 | 147 |
|
199 | 148 | m_semaphore = m_device->createSemaphore(m_realFrameIx); |
200 | 149 | if (!m_semaphore) |
|
0 commit comments