Skip to content

Commit 312ca61

Browse files
committed
pull Matt and resolve conflicts
2 parents c9f610f + fcae0b4 commit 312ca61

File tree

98 files changed

+3280
-3178
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+3280
-3178
lines changed

02_HelloCompute/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ class HelloComputeApp final : public nbl::application_templates::MonoSystemMonoL
9494
// The convention is that an `ICPU` object represents a potentially Mutable (and in the past, Serializable) recipe for creating an `IGPU` object, and later examples will show automated systems for doing that.
9595
// The Assets always form a Directed Acyclic Graph and our type system enforces that property at compile time (i.e. an `IBuffer` cannot reference an `IImageView` even indirectly).
9696
// Another reason for the 1:1 pairing of types is that one can use a CPU-to-GPU associative cache (asset manager has a default one) and use the pointers to the CPU objects as UUIDs.
97-
// The ICPUShader is just a mutable container for source code (can be high level like HLSL needing compilation to SPIR-V or SPIR-V itself) held in an `nbl::asset::ICPUBuffer`.
97+
// The IShader is just a mutable container for source code (can be high level like HLSL needing compilation to SPIR-V or SPIR-V itself) held in an `nbl::asset::ICPUBuffer`.
9898
// They can be created: from buffers of code, by compilation from some other source code, or loaded from files (next example will do that).
99-
smart_refctd_ptr<nbl::asset::ICPUShader> cpuShader;
99+
smart_refctd_ptr<nbl::asset::IShader> cpuShader;
100100
{
101101
// Normally we'd use the ISystem and the IAssetManager to load shaders flexibly from (virtual) files for ease of development (syntax highlighting and Intellisense),
102102
// but I want to show the full process of assembling a shader from raw source code at least once.
@@ -138,7 +138,7 @@ class HelloComputeApp final : public nbl::application_templates::MonoSystemMonoL
138138
}
139139

140140
// Note how each ILogicalDevice method takes a smart-pointer r-value, so that the GPU objects refcount their dependencies
141-
smart_refctd_ptr<nbl::video::IGPUShader> shader = device->createShader(cpuShader.get());
141+
smart_refctd_ptr<IShader> shader = device->compileShader({.source = cpuShader.get()});
142142
if (!shader)
143143
return logFail("Failed to create a GPU Shader, seems the Driver doesn't like the SPIR-V we're feeding it!\n");
144144

03_DeviceSelectionAndSharedSources/Testers.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class IntrospectionTesterBase
2424
const std::string m_functionToTestName = "";
2525

2626
protected:
27-
static std::pair<smart_refctd_ptr<ICPUShader>, smart_refctd_ptr<const CSPIRVIntrospector::CStageIntrospectionData>> compileHLSLShaderAndTestIntrospection(
27+
static std::pair<smart_refctd_ptr<IShader>, smart_refctd_ptr<const CSPIRVIntrospector::CStageIntrospectionData>> compileHLSLShaderAndTestIntrospection(
2828
video::IPhysicalDevice* physicalDevice, video::ILogicalDevice* device, system::ILogger* logger, asset::IAssetManager* assetMgr, const std::string& shaderPath, CSPIRVIntrospector& introspector)
2929
{
3030
IAssetLoader::SAssetLoadParams lp = {};
@@ -33,15 +33,18 @@ class IntrospectionTesterBase
3333
// this time we load a shader directly from a file
3434
auto assetBundle = assetMgr->getAsset(shaderPath, lp);
3535
const auto assets = assetBundle.getContents();
36-
if (assets.empty())
36+
const auto* metadata = assetBundle.getMetadata();
37+
if (assets.empty() || assetBundle.getAssetType() != IAsset::ET_SHADER)
3738
{
3839
logFail(logger, "Could not load shader!");
3940
assert(0);
4041
}
42+
const auto hlslMetadata = static_cast<const CHLSLMetadata*>(metadata);
43+
const auto shaderStage = hlslMetadata->shaderStages->front();
4144

4245
// It would be super weird if loading a shader from a file produced more than 1 asset
4346
assert(assets.size() == 1);
44-
smart_refctd_ptr<ICPUShader> source = IAsset::castDown<ICPUShader>(assets[0]);
47+
smart_refctd_ptr<IShader> source = IAsset::castDown<IShader>(assets[0]);
4548

4649
smart_refctd_ptr<const CSPIRVIntrospector::CStageIntrospectionData> introspection;
4750
{
@@ -53,7 +56,7 @@ class IntrospectionTesterBase
5356
// The Shader Asset Loaders deduce the stage from the file extension,
5457
// if the extension is generic (.glsl or .hlsl) the stage is unknown.
5558
// But it can still be overriden from within the source with a `#pragma shader_stage`
56-
options.stage = source->getStage() == IShader::E_SHADER_STAGE::ESS_COMPUTE ? source->getStage() : IShader::E_SHADER_STAGE::ESS_VERTEX; // TODO: do smth with it
59+
options.stage = shaderStage == IShader::E_SHADER_STAGE::ESS_COMPUTE ? shaderStage : IShader::E_SHADER_STAGE::ESS_VERTEX; // TODO: do smth with it
5760
options.targetSpirvVersion = device->getPhysicalDevice()->getLimits().spirvVersion;
5861
// we need to perform an unoptimized compilation with source debug info or we'll lose names of variable sin the introspection
5962
options.spirvOptimizer = nullptr;
@@ -186,7 +189,7 @@ class PredefinedLayoutTester final : public IntrospectionTesterBase
186189
constexpr uint32_t MERGE_TEST_SHADERS_CNT = mergeTestShadersPaths.size();
187190

188191
CSPIRVIntrospector introspector[MERGE_TEST_SHADERS_CNT];
189-
smart_refctd_ptr<ICPUShader> sources[MERGE_TEST_SHADERS_CNT];
192+
smart_refctd_ptr<IShader> sources[MERGE_TEST_SHADERS_CNT];
190193

191194
for (uint32_t i = 0u; i < MERGE_TEST_SHADERS_CNT; ++i)
192195
{
@@ -201,7 +204,7 @@ class PredefinedLayoutTester final : public IntrospectionTesterBase
201204
.binding = 0,
202205
.type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
203206
.createFlags = ICPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
204-
.stageFlags = ICPUShader::E_SHADER_STAGE::ESS_COMPUTE,
207+
.stageFlags = IShader::E_SHADER_STAGE::ESS_COMPUTE,
205208
.count = 1,
206209
.immutableSamplers = nullptr
207210
}
@@ -213,15 +216,15 @@ class PredefinedLayoutTester final : public IntrospectionTesterBase
213216
.binding = 0,
214217
.type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
215218
.createFlags = ICPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
216-
.stageFlags = ICPUShader::E_SHADER_STAGE::ESS_COMPUTE,
219+
.stageFlags = IShader::E_SHADER_STAGE::ESS_COMPUTE,
217220
.count = 1,
218221
.immutableSamplers = nullptr
219222
},
220223
{
221224
.binding = 1,
222225
.type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
223226
.createFlags = ICPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
224-
.stageFlags = ICPUShader::E_SHADER_STAGE::ESS_COMPUTE,
227+
.stageFlags = IShader::E_SHADER_STAGE::ESS_COMPUTE,
225228
.count = 2,
226229
.immutableSamplers = nullptr
227230
}
@@ -251,9 +254,9 @@ class PredefinedLayoutTester final : public IntrospectionTesterBase
251254
bool pplnCreationSuccess[MERGE_TEST_SHADERS_CNT];
252255
for (uint32_t i = 0u; i < MERGE_TEST_SHADERS_CNT; ++i)
253256
{
254-
ICPUShader::SSpecInfo specInfo;
257+
ICPUPipelineBase::SShaderSpecInfo specInfo;
255258
specInfo.entryPoint = "main";
256-
specInfo.shader = sources[i].get();
259+
specInfo.shader = sources[i];
257260
pplnCreationSuccess[i] = static_cast<bool>(introspector[i].createApproximateComputePipelineFromIntrospection(specInfo, core::smart_refctd_ptr<ICPUPipelineLayout>(predefinedPplnLayout)));
258261
}
259262

03_DeviceSelectionAndSharedSources/main.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
44

5-
#include "nbl/application_templates/MonoDeviceApplication.hpp"
6-
#include "nbl/application_templates/MonoAssetManagerAndBuiltinResourceApplication.hpp"
7-
#include "CommonPCH/PCH.hpp"
5+
#include "nbl/examples/examples.hpp"
6+
// TODO: why isn't this in `nabla.h` ?
7+
#include "nbl/asset/metadata/CHLSLMetadata.h"
88

99
using namespace nbl;
1010
using namespace core;
@@ -60,9 +60,9 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
6060
//shaderIntrospection->debugPrint(m_logger.get());
6161

6262
// We've now skipped the manual creation of a descriptor set layout, pipeline layout
63-
ICPUShader::SSpecInfo specInfo;
63+
ICPUPipelineBase::SShaderSpecInfo specInfo;
6464
specInfo.entryPoint = "main";
65-
specInfo.shader = source.get();
65+
specInfo.shader = source;
6666

6767
smart_refctd_ptr<nbl::asset::ICPUComputePipeline> cpuPipeline = introspector.createApproximateComputePipelineFromIntrospection(specInfo);
6868

@@ -236,7 +236,7 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
236236
// Whether to keep invoking the above. In this example because its headless GPU compute, we do all the work in the app initialization.
237237
bool keepRunning() override { return false; }
238238

239-
std::pair<smart_refctd_ptr<ICPUShader>, smart_refctd_ptr<const CSPIRVIntrospector::CStageIntrospectionData>> compileShaderAndTestIntrospection(
239+
std::pair<smart_refctd_ptr<IShader>, smart_refctd_ptr<const CSPIRVIntrospector::CStageIntrospectionData>> compileShaderAndTestIntrospection(
240240
const std::string& shaderPath, CSPIRVIntrospector& introspector)
241241
{
242242
IAssetLoader::SAssetLoadParams lp = {};
@@ -245,15 +245,19 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
245245
// this time we load a shader directly from a file
246246
auto assetBundle = m_assetMgr->getAsset(shaderPath, lp);
247247
const auto assets = assetBundle.getContents();
248-
if (assets.empty())
248+
if (assets.empty() || assetBundle.getAssetType() != IAsset::ET_SHADER)
249249
{
250250
logFail("Could not load shader!");
251251
assert(0);
252252
}
253253

254+
const auto* metadata = assetBundle.getMetadata();
255+
const auto hlslMetadata = static_cast<const CHLSLMetadata*>(metadata);
256+
const auto shaderStage = hlslMetadata->shaderStages->front();
257+
254258
// It would be super weird if loading a shader from a file produced more than 1 asset
255259
assert(assets.size() == 1);
256-
smart_refctd_ptr<ICPUShader> source = IAsset::castDown<ICPUShader>(assets[0]);
260+
smart_refctd_ptr<IShader> source = IAsset::castDown<IShader>(assets[0]);
257261

258262
smart_refctd_ptr<const CSPIRVIntrospector::CStageIntrospectionData> introspection;
259263
{
@@ -265,7 +269,7 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
265269
// The Shader Asset Loaders deduce the stage from the file extension,
266270
// if the extension is generic (.glsl or .hlsl) the stage is unknown.
267271
// But it can still be overriden from within the source with a `#pragma shader_stage`
268-
options.stage = source->getStage() == IShader::E_SHADER_STAGE::ESS_COMPUTE ? source->getStage() : IShader::E_SHADER_STAGE::ESS_VERTEX; // TODO: do smth with it
272+
options.stage = shaderStage == IShader::E_SHADER_STAGE::ESS_COMPUTE ? shaderStage : IShader::E_SHADER_STAGE::ESS_VERTEX; // TODO: do smth with it
269273
options.targetSpirvVersion = m_device->getPhysicalDevice()->getLimits().spirvVersion;
270274
// we need to perform an unoptimized compilation with source debug info or we'll lose names of variable sin the introspection
271275
options.spirvOptimizer = nullptr;
@@ -277,7 +281,7 @@ class DeviceSelectionAndSharedSourcesApp final : public application_templates::M
277281
options.preprocessorOptions.includeFinder = compilerSet->getShaderCompiler(source->getContentType())->getDefaultIncludeFinder();
278282

279283
auto spirvUnspecialized = compilerSet->compileToSPIRV(source.get(), options);
280-
const CSPIRVIntrospector::CStageIntrospectionData::SParams inspctParams = { .entryPoint = "main", .shader = spirvUnspecialized };
284+
const CSPIRVIntrospector::CStageIntrospectionData::SParams inspctParams = { .entryPoint = "main", .shader = spirvUnspecialized, .stage = shaderStage };
281285

282286
introspection = introspector.introspect(inspctParams);
283287
introspection->debugPrint(m_logger.get());

05_StreamingAndBufferDeviceAddressApp/app_resources/shader.comp.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ template<typename capability_traits=nbl::hlsl::jit::device_capabilities_traits>
1010
void dummyTraitTest() {}
1111

1212
[numthreads(WorkgroupSize,1,1)]
13+
[shader("compute")]
1314
void main(uint32_t3 ID : SV_DispatchThreadID)
1415
{
1516
dummyTraitTest();

05_StreamingAndBufferDeviceAddressApp/main.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class StreamingAndBufferDeviceAddressApp final : public application_templates::M
9191
return false;
9292

9393
// this time we load a shader directly from a file
94-
smart_refctd_ptr<IGPUShader> shader;
94+
smart_refctd_ptr<IShader> shader;
9595
{
9696
IAssetLoader::SAssetLoadParams lp = {};
9797
lp.logger = m_logger.get();
@@ -102,14 +102,10 @@ class StreamingAndBufferDeviceAddressApp final : public application_templates::M
102102
return logFail("Could not load shader!");
103103

104104
// lets go straight from ICPUSpecializedShader to IGPUSpecializedShader
105-
auto source = IAsset::castDown<ICPUShader>(assets[0]);
105+
const auto shaderSource = IAsset::castDown<IShader>(assets[0]);
106+
shader = m_device->compileShader({shaderSource.get()});
106107
// The down-cast should not fail!
107-
assert(source);
108-
109-
// this time we skip the use of the asset converter since the ICPUShader->IGPUShader path is quick and simple
110-
shader = m_device->createShader(source.get());
111-
if (!shader)
112-
return logFail("Creation of a GPU Shader to from CPU Shader source failed!");
108+
assert(shader);
113109
}
114110

115111
// The StreamingTransientDataBuffers are actually composed on top of another useful utility called `CAsyncSingleBufferSubAllocator`
@@ -139,6 +135,7 @@ class StreamingAndBufferDeviceAddressApp final : public application_templates::M
139135
IGPUComputePipeline::SCreationParams params = {};
140136
params.layout = layout.get();
141137
params.shader.shader = shader.get();
138+
params.shader.entryPoint = "main";
142139
if (!m_device->createComputePipelines(nullptr,{&params,1},&m_pipeline))
143140
return logFail("Failed to create compute pipeline!\n");
144141
}

07_StagingAndMultipleQueues/main.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
// For conditions of distribution and use, see copyright notice in nabla.h
44

55
// I've moved out a tiny part of this example into a shared header for reuse, please open and read it.
6-
7-
#include "nbl/application_templates/BasicMultiQueueApplication.hpp"
8-
#include "nbl/application_templates/MonoAssetManagerAndBuiltinResourceApplication.hpp"
9-
10-
// get asset converter
11-
#include "CommonPCH/PCH.hpp"
6+
#include "nbl/examples/examples.hpp"
127

138
using namespace nbl;
149
using namespace core;
@@ -246,15 +241,15 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
246241
.binding = 0,
247242
.type = nbl::asset::IDescriptor::E_TYPE::ET_SAMPLED_IMAGE,
248243
.createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
249-
.stageFlags = IGPUShader::E_SHADER_STAGE::ESS_COMPUTE,
244+
.stageFlags = IShader::E_SHADER_STAGE::ESS_COMPUTE,
250245
.count = 1,
251246
.immutableSamplers = nullptr
252247
},
253248
{
254249
.binding = 1,
255250
.type = nbl::asset::IDescriptor::E_TYPE::ET_STORAGE_BUFFER,
256251
.createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_NONE,
257-
.stageFlags = IGPUShader::E_SHADER_STAGE::ESS_COMPUTE,
252+
.stageFlags = IShader::E_SHADER_STAGE::ESS_COMPUTE,
258253
.count = 1,
259254
.immutableSamplers = nullptr
260255
}
@@ -281,18 +276,17 @@ class StagingAndMultipleQueuesApp final : public application_templates::BasicMul
281276
}
282277

283278
// LOAD SHADER FROM FILE
284-
smart_refctd_ptr<ICPUShader> source;
279+
smart_refctd_ptr<IShader> source;
285280
{
286-
source = loadFistAssetInBundle<ICPUShader>("../app_resources/comp_shader.hlsl");
287-
source->setShaderStage(IShader::E_SHADER_STAGE::ESS_COMPUTE); // can also be done via a #pragma in the shader
281+
source = loadFistAssetInBundle<IShader>("../app_resources/comp_shader.hlsl");
288282
}
289283

290284
if (!source)
291285
logFailAndTerminate("Could not create a CPU shader!");
292286

293-
core::smart_refctd_ptr<IGPUShader> shader = m_device->createShader(source.get());
287+
core::smart_refctd_ptr<IShader> shader = m_device->compileShader({ source.get() });
294288
if(!shader)
295-
logFailAndTerminate("Could not create a GPU shader!");
289+
logFailAndTerminate("Could not compile shader to spirv!");
296290

297291
// CREATE COMPUTE PIPELINE
298292
SPushConstantRange pc[1];

08_HelloSwapchain/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (C) 2018-2024 - DevSH Graphics Programming Sp. z O.O.
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
4-
#include "SimpleWindowedApplication.hpp"
4+
#include "nbl/examples/examples.hpp"
55

66
//
77
#include "nbl/video/surface/CSurfaceVulkan.h"

09_GeometryCreator/include/common.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#ifndef _NBL_THIS_EXAMPLE_COMMON_H_INCLUDED_
22
#define _NBL_THIS_EXAMPLE_COMMON_H_INCLUDED_
33

4-
#include <nabla.h>
5-
64
// TODO: @AnastaZIuk do we even make that explicit?
75
#include "nbl/examples/PCH.hpp"
86

@@ -14,6 +12,6 @@ using namespace asset;
1412
using namespace ui;
1513
using namespace video;
1614
using namespace scene;
17-
using namespace examples;
15+
using namespace nbl::examples;
1816

1917
#endif // __NBL_THIS_EXAMPLE_COMMON_H_INCLUDED__

0 commit comments

Comments
 (0)