|
6 | 6 |
|
7 | 7 | #include "nbl/video/surface/CSurfaceVulkan.h"
|
8 | 8 | #include "nbl/asset/interchange/IAssetLoader.h"
|
| 9 | +#include "nbl/ext/FullScreenTriangle/FullScreenTriangle.h" |
| 10 | + |
9 | 11 |
|
10 | 12 | using namespace nbl;
|
11 | 13 | using namespace core;
|
@@ -107,9 +109,11 @@ class AutoexposureApp final : public examples::SimpleWindowedApplication, public
|
107 | 109 |
|
108 | 110 | auto queue = getGraphicsQueue();
|
109 | 111 |
|
110 |
| - // init the surface and create the swapchain |
| 112 | + // Gather swapchain resources |
| 113 | + std::unique_ptr<CDefaultSwapchainFramebuffers> scResources; |
| 114 | + ISwapchain::SCreationParams swapchainParams; |
111 | 115 | {
|
112 |
| - ISwapchain::SCreationParams swapchainParams = { .surface = smart_refctd_ptr<ISurface>(m_surface->getSurface()) }; |
| 116 | + swapchainParams = { .surface = smart_refctd_ptr<ISurface>(m_surface->getSurface()) }; |
113 | 117 | // Need to choose a surface format
|
114 | 118 | if (!swapchainParams.deduceFormat(m_physicalDevice))
|
115 | 119 | return logFail("Could not choose a Surface Format for the Swapchain!");
|
@@ -142,29 +146,53 @@ class AutoexposureApp final : public examples::SimpleWindowedApplication, public
|
142 | 146 | },
|
143 | 147 | IGPURenderpass::SCreationParams::DependenciesEnd
|
144 | 148 | };
|
145 |
| - auto scResources = std::make_unique<CDefaultSwapchainFramebuffers>(m_device.get(), swapchainParams.surfaceFormat.format, dependencies); |
| 149 | + scResources = std::make_unique<CDefaultSwapchainFramebuffers>(m_device.get(), swapchainParams.surfaceFormat.format, dependencies); |
146 | 150 | if (!scResources->getRenderpass())
|
147 | 151 | return logFail("Failed to create Renderpass!");
|
148 |
| - if (!m_surface || !m_surface->init(queue, std::move(scResources), swapchainParams.sharedParams)) |
149 |
| - return logFail("Could not create Window & Surface or initialize the Surface!"); |
150 | 152 | }
|
151 | 153 |
|
152 |
| - // Now create the pipeline |
153 |
| - /* { |
154 |
| - const asset::SPushConstantRange range = { |
155 |
| - .stageFlags = IShader::E_SHADER_STAGE::ESS_FRAGMENT, |
156 |
| - .offset = 0, |
157 |
| - .size = sizeof(push_constants_t) |
158 |
| - }; |
159 |
| - auto layout = m_device->createPipelineLayout({ &range,1 }, nullptr, nullptr, nullptr, core::smart_refctd_ptr(dsLayout)); |
| 154 | + // Load the shaders and create the pipeline |
| 155 | + { |
| 156 | + // Load FSTri Shader |
| 157 | + ext::FullScreenTriangle::ProtoPipeline fsTriProtoPPln(m_assetMgr.get(), m_device.get(), m_logger.get()); |
| 158 | + if (!fsTriProtoPPln) |
| 159 | + return logFail("Failed to create Full Screen Triangle protopipeline or load its vertex shader!"); |
| 160 | + |
| 161 | + // Load Custom Shader |
| 162 | + auto loadCompileAndCreateShader = [&](const std::string& relPath) -> smart_refctd_ptr<IGPUShader> |
| 163 | + { |
| 164 | + IAssetLoader::SAssetLoadParams lp = {}; |
| 165 | + lp.logger = m_logger.get(); |
| 166 | + lp.workingDirectory = ""; // virtual root |
| 167 | + auto assetBundle = m_assetMgr->getAsset(relPath, lp); |
| 168 | + const auto assets = assetBundle.getContents(); |
| 169 | + if (assets.empty()) |
| 170 | + return nullptr; |
| 171 | + |
| 172 | + // lets go straight from ICPUSpecializedShader to IGPUSpecializedShader |
| 173 | + auto source = IAsset::castDown<ICPUShader>(assets[0]); |
| 174 | + if (!source) |
| 175 | + return nullptr; |
| 176 | + |
| 177 | + return m_device->createShader(source.get()); |
| 178 | + }; |
| 179 | + auto fragmentShader = loadCompileAndCreateShader("app_resources/present.frag.hlsl"); |
| 180 | + if (!fragmentShader) |
| 181 | + return logFail("Failed to Load and Compile Fragment Shader!"); |
| 182 | + |
| 183 | + auto layout = m_device->createPipelineLayout({}, nullptr, nullptr, nullptr, core::smart_refctd_ptr(dsLayout)); |
160 | 184 | const IGPUShader::SSpecInfo fragSpec = {
|
161 | 185 | .entryPoint = "main",
|
162 | 186 | .shader = fragmentShader.get()
|
163 | 187 | };
|
164 | 188 | m_pipeline = fsTriProtoPPln.createPipeline(fragSpec, layout.get(), scResources->getRenderpass());
|
165 | 189 | if (!m_pipeline)
|
166 | 190 | return logFail("Could not create Graphics Pipeline!");
|
167 |
| - }*/ |
| 191 | + } |
| 192 | + |
| 193 | + // Init the surface and create the swapchain |
| 194 | + if (!m_surface || !m_surface->init(queue, std::move(scResources), swapchainParams.sharedParams)) |
| 195 | + return logFail("Could not create Window & Surface or initialize the Surface!"); |
168 | 196 |
|
169 | 197 | // need resetttable commandbuffers for the upload utility
|
170 | 198 | {
|
@@ -326,6 +354,7 @@ class AutoexposureApp final : public examples::SimpleWindowedApplication, public
|
326 | 354 | std::array<smart_refctd_ptr<IGPUDescriptorSet>, ISwapchain::MaxImages> m_descriptorSets;
|
327 | 355 | smart_refctd_ptr<IGPUCommandPool> m_cmdPool;
|
328 | 356 | std::array<smart_refctd_ptr<IGPUCommandBuffer>, ISwapchain::MaxImages> m_cmdBufs;
|
| 357 | + smart_refctd_ptr<IGPUGraphicsPipeline> m_pipeline; |
329 | 358 |
|
330 | 359 | // window
|
331 | 360 | smart_refctd_ptr<IWindow> m_window;
|
|
0 commit comments