Skip to content

Commit 640e6a3

Browse files
committed
Load shaders and create the pipeline for full screen triagnle
1 parent 5d63d04 commit 640e6a3

File tree

2 files changed

+60
-14
lines changed

2 files changed

+60
-14
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (C) 2024-2024 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
5+
#pragma wave shader_stage(fragment)
6+
7+
// vertex shader is provided by the fullScreenTriangle extension
8+
#include <nbl/builtin/hlsl/ext/FullScreenTriangle/SVertexAttributes.hlsl>
9+
using namespace nbl::hlsl::ext::FullScreenTriangle;
10+
11+
[[vk::combinedImageSampler]] [[vk::binding(0, 3)]] Texture2D texture;
12+
[[vk::combinedImageSampler]] [[vk::binding(0, 3)]] SamplerState samplerState;
13+
14+
[[vk::location(0)]] float32_t4 main(SVertexAttributes vxAttr) : SV_Target0
15+
{
16+
return texture.Sample(samplerState, vxAttr.uv);
17+
}

26_Autoexposure/main.cpp

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "nbl/video/surface/CSurfaceVulkan.h"
88
#include "nbl/asset/interchange/IAssetLoader.h"
9+
#include "nbl/ext/FullScreenTriangle/FullScreenTriangle.h"
10+
911

1012
using namespace nbl;
1113
using namespace core;
@@ -107,9 +109,11 @@ class AutoexposureApp final : public examples::SimpleWindowedApplication, public
107109

108110
auto queue = getGraphicsQueue();
109111

110-
// init the surface and create the swapchain
112+
// Gather swapchain resources
113+
std::unique_ptr<CDefaultSwapchainFramebuffers> scResources;
114+
ISwapchain::SCreationParams swapchainParams;
111115
{
112-
ISwapchain::SCreationParams swapchainParams = { .surface = smart_refctd_ptr<ISurface>(m_surface->getSurface()) };
116+
swapchainParams = { .surface = smart_refctd_ptr<ISurface>(m_surface->getSurface()) };
113117
// Need to choose a surface format
114118
if (!swapchainParams.deduceFormat(m_physicalDevice))
115119
return logFail("Could not choose a Surface Format for the Swapchain!");
@@ -142,29 +146,53 @@ class AutoexposureApp final : public examples::SimpleWindowedApplication, public
142146
},
143147
IGPURenderpass::SCreationParams::DependenciesEnd
144148
};
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);
146150
if (!scResources->getRenderpass())
147151
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!");
150152
}
151153

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));
160184
const IGPUShader::SSpecInfo fragSpec = {
161185
.entryPoint = "main",
162186
.shader = fragmentShader.get()
163187
};
164188
m_pipeline = fsTriProtoPPln.createPipeline(fragSpec, layout.get(), scResources->getRenderpass());
165189
if (!m_pipeline)
166190
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!");
168196

169197
// need resetttable commandbuffers for the upload utility
170198
{
@@ -326,6 +354,7 @@ class AutoexposureApp final : public examples::SimpleWindowedApplication, public
326354
std::array<smart_refctd_ptr<IGPUDescriptorSet>, ISwapchain::MaxImages> m_descriptorSets;
327355
smart_refctd_ptr<IGPUCommandPool> m_cmdPool;
328356
std::array<smart_refctd_ptr<IGPUCommandBuffer>, ISwapchain::MaxImages> m_cmdBufs;
357+
smart_refctd_ptr<IGPUGraphicsPipeline> m_pipeline;
329358

330359
// window
331360
smart_refctd_ptr<IWindow> m_window;

0 commit comments

Comments
 (0)