|
4 | 4 |
|
5 | 5 | // I've moved out a tiny part of this example into a shared header for reuse, please open and read it. |
6 | 6 | #include "nbl/examples/examples.hpp" |
| 7 | +#include "nbl/this_example/builtin/build/spirv/keys.hpp" |
7 | 8 |
|
8 | 9 | using namespace nbl; |
9 | 10 | using namespace nbl::core; |
@@ -189,7 +190,7 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul |
189 | 190 | for (uint32_t imageIdx = 0; imageIdx < IMAGE_CNT; ++imageIdx) |
190 | 191 | { |
191 | 192 | const auto imagePathToLoad = imagesToLoad[imageIdx]; |
192 | | - auto cpuImage = loadFistAssetInBundle<ICPUImage>(imagePathToLoad); |
| 193 | + auto cpuImage = loadImageAsset(imagePathToLoad); |
193 | 194 | if (!cpuImage) |
194 | 195 | logFailAndTerminate("Failed to load image from path %s",ILogger::ELL_ERROR,imagePathToLoad); |
195 | 196 |
|
@@ -279,17 +280,10 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul |
279 | 280 | } |
280 | 281 |
|
281 | 282 | // LOAD SHADER FROM FILE |
282 | | - smart_refctd_ptr<IShader> source; |
283 | | - { |
284 | | - source = loadFistAssetInBundle<IShader>("../app_resources/comp_shader.hlsl"); |
285 | | - } |
| 283 | + smart_refctd_ptr<IShader> shader = loadPreCompiledShader<"comp_shader">(); // "../app_resources/comp_shader.hlsl" |
286 | 284 |
|
287 | | - if (!source) |
288 | | - logFailAndTerminate("Could not create a CPU shader!"); |
289 | | - |
290 | | - core::smart_refctd_ptr<IShader> shader = m_device->compileShader({ source.get() }); |
291 | | - if(!shader) |
292 | | - logFailAndTerminate("Could not compile shader to spirv!"); |
| 285 | + if (!shader) |
| 286 | + logFailAndTerminate("Could not load the precompiled shader!"); |
293 | 287 |
|
294 | 288 | // CREATE COMPUTE PIPELINE |
295 | 289 | SPushConstantRange pc[1]; |
@@ -534,21 +528,39 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul |
534 | 528 |
|
535 | 529 | return false; |
536 | 530 | } |
537 | | - |
538 | | - template<typename AssetType> |
539 | | - core::smart_refctd_ptr<AssetType> loadFistAssetInBundle(const std::string& path) |
| 531 | + |
| 532 | + core::smart_refctd_ptr<ICPUImage> loadImageAsset(const std::string& path) |
540 | 533 | { |
541 | 534 | IAssetLoader::SAssetLoadParams lp; |
542 | 535 | SAssetBundle bundle = m_assetMgr->getAsset(path, lp); |
543 | 536 | if (bundle.getContents().empty()) |
544 | | - logFailAndTerminate("Couldn't load an asset.",ILogger::ELL_ERROR); |
| 537 | + logFailAndTerminate("Couldn't load an image.",ILogger::ELL_ERROR); |
545 | 538 |
|
546 | | - auto asset = IAsset::castDown<AssetType>(bundle.getContents()[0]); |
| 539 | + auto asset = IAsset::castDown<ICPUImage>(bundle.getContents()[0]); |
547 | 540 | if (!asset) |
548 | 541 | logFailAndTerminate("Incorrect asset loaded.",ILogger::ELL_ERROR); |
549 | 542 |
|
550 | 543 | return asset; |
551 | 544 | } |
| 545 | + |
| 546 | + template<core::StringLiteral ShaderKey> |
| 547 | + core::smart_refctd_ptr<IShader> loadPreCompiledShader() |
| 548 | + { |
| 549 | + IAssetLoader::SAssetLoadParams lp; |
| 550 | + lp.logger = m_logger.get(); |
| 551 | + lp.workingDirectory = "app_resources"; |
| 552 | + |
| 553 | + auto key = nbl::this_example::builtin::build::get_spirv_key<ShaderKey>(m_device.get()); |
| 554 | + SAssetBundle bundle = m_assetMgr->getAsset(key.data(), lp); |
| 555 | + if (bundle.getContents().empty()) |
| 556 | + logFailAndTerminate("Couldn't load a shader.", ILogger::ELL_ERROR); |
| 557 | + |
| 558 | + auto asset = IAsset::castDown<IShader>(bundle.getContents()[0]); |
| 559 | + if (!asset) |
| 560 | + logFailAndTerminate("Incorrect asset loaded.", ILogger::ELL_ERROR); |
| 561 | + |
| 562 | + return asset; |
| 563 | + } |
552 | 564 | }; |
553 | 565 |
|
554 | 566 | NBL_MAIN_FUNC(StagingAndMultipleQueuesApp) |
0 commit comments