Skip to content

Commit a347562

Browse files
author
devsh
committed
note down embedding TODOs for arek
1 parent 846d2fd commit a347562

File tree

4 files changed

+70
-8
lines changed

4 files changed

+70
-8
lines changed

09_GeometryCreator/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "common.hpp"
66

7+
// TODO: Arek, we should have a `nbl::examples` class inheriting from `application_templates::MonoAssetManagerAndBuiltinResourceApplication` which
8+
// during `onAppInitialized` also mounts correct `common/include/nbl/examples` and `common/src/nbl/examples` as folder or builtin
79
class GeometryCreatorApp final : public MonoWindowApplication, public application_templates::MonoAssetManagerAndBuiltinResourceApplication
810
{
911
using device_base_t = MonoWindowApplication;
@@ -55,6 +57,10 @@ class GeometryCreatorApp final : public MonoWindowApplication, public applicatio
5557
.addtionalBufferOwnershipFamilies = addtionalBufferOwnershipFamilies
5658
},patch
5759
);
60+
61+
// TODO: this is plain wrong Arek
62+
auto commonArchive = make_smart_refctd_ptr<system::CMountDirectoryArchive>(localInputCWD/"app_resources",smart_refctd_ptr(m_logger),m_system.get());
63+
m_system->mount(make_smart_refctd_ptr<system::CMountDirectoryArchive>(localInputCWD/"../common/src/nbl/examples",smart_refctd_ptr(m_logger),m_system.get()),"nbl/examples");
5864

5965
auto scRes = static_cast<CDefaultSwapchainFramebuffers*>(m_surface->getSwapchainResources());
6066
m_renderer = CSimpleDebugRenderer::create(m_assetMgr.get(),scRes->getRenderpass(),0,m_scene.get());

common/include/nbl/examples/geometry/CSimpleDebugRenderer.hpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted
2121
using namespace nbl::asset; \
2222
using namespace nbl::video
2323
public:
24-
//
25-
constexpr static inline auto DescriptorCount = 255;
2624
//
2725
struct SViewParams
2826
{
@@ -85,7 +83,7 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted
8583
{
8684
EXPOSE_NABLA_NAMESPACES;
8785

88-
if (!!renderpass)
86+
if (!renderpass)
8987
return nullptr;
9088
auto device = const_cast<ILogicalDevice*>(renderpass->getOriginDevice());
9189
auto logger = device->getLogger();
@@ -100,9 +98,10 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted
10098
smart_refctd_ptr<IShader> shader;
10199
{
102100
const auto bundle = assMan->getAsset("nbl/examples/geometry/shaders/unified.hlsl",{});
101+
// TODO: Arek
103102
//const auto bundle = assMan->getAsset("nbl/examples/geometry/shaders/unified.spv",{});
104103
const auto contents = bundle.getContents();
105-
if (bundle.getAssetType()!=IAsset::ET_SHADER || contents.empty())
104+
if (contents.empty() || bundle.getAssetType()!=IAsset::ET_SHADER)
106105
return nullptr;
107106
shader = IAsset::castDown<IShader>(contents[0]);
108107
if (!shader)
@@ -124,7 +123,7 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted
124123
// some geometries may not have particular attributes
125124
.createFlags = IGPUDescriptorSetLayout::SBinding::E_CREATE_FLAGS::ECF_PARTIALLY_BOUND_BIT,
126125
.stageFlags = IShader::E_SHADER_STAGE::ESS_VERTEX|IShader::E_SHADER_STAGE::ESS_FRAGMENT,
127-
.count = DescriptorCount
126+
.count = SInstance::SPushConstants::DescriptorCount
128127
}
129128
};
130129
dsLayout = device->createDescriptorSetLayout(bindings);
@@ -164,9 +163,9 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted
164163
smart_refctd_ptr<IGPUGraphicsPipeline> pipelines[PipelineType::Count] = {};
165164
{
166165
IGPUGraphicsPipeline::SCreationParams params[PipelineType::Count] = {};
167-
params[PipelineType::BasicTriangleList].vertexShader = {.shader=shader.get(),.entryPoint="BasicTriangleListVS"};
166+
params[PipelineType::BasicTriangleList].vertexShader = {.shader=shader.get(),.entryPoint="BasicVS"};
168167
params[PipelineType::BasicTriangleList].fragmentShader = {.shader=shader.get(),.entryPoint="BasicFS"};
169-
params[PipelineType::BasicTriangleFan].vertexShader = {.shader=shader.get(),.entryPoint="BasicTriangleFanVS"};
168+
params[PipelineType::BasicTriangleFan].vertexShader = {.shader=shader.get(),.entryPoint="BasicVS"};
170169
params[PipelineType::BasicTriangleFan].fragmentShader = {.shader=shader.get(),.entryPoint="BasicFS"};
171170
params[PipelineType::Cone].vertexShader = {.shader=shader.get(),.entryPoint="ConeVS"};
172171
params[PipelineType::Cone].fragmentShader = {.shader=shader.get(),.entryPoint="ConeFS"};
@@ -206,7 +205,7 @@ class CSimpleDebugRenderer final : public core::IReferenceCounted
206205
auto allocateUTB = [device,&infos](const IGeometry<const IGPUBuffer>::SDataView& view)->uint8_t
207206
{
208207
if (!view)
209-
return DescriptorCount;
208+
return SInstance::SPushConstants::DescriptorCount;
210209
const auto retval = infos.size();
211210
infos.emplace_back().desc = device->createBufferView(view.src, view.composed.format);
212211
return retval;

common/include/nbl/examples/geometry/SPushConstants.hlsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ struct SInstanceMatrices
2222

2323
struct SPushConstants
2424
{
25+
// no idea if DXC still has this bug with Push Constant static variables
26+
#ifndef __HLSL_VERSiON
27+
NBL_CONSTEXPR_STATIC_INLINE uint32_t DescriptorCount = 255;
28+
#endif
29+
2530
SInstanceMatrices matrices;
2631
uint32_t positionView : 11;
2732
uint32_t normalView : 10;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
#include "nbl/examples/geometry/SPushConstants.hlsl"
3+
using namespace nbl::hlsl;
4+
using namespace nbl::hlsl::examples::geometry_creator_scene;
5+
6+
// for dat sweet programmable pulling
7+
[[vk::binding(0)]] Buffer<float32_t4> utbs[/*SPushConstants::DescriptorCount*/255];
8+
9+
//
10+
[[vk::push_constant]] SPushConstants pc;
11+
12+
//
13+
struct SInterpolants
14+
{
15+
float32_t4 position : SV_Position;
16+
float32_t3 color : COLOR0;
17+
};
18+
#include "nbl/builtin/hlsl/math/linalg/fast_affine.hlsl"
19+
20+
//
21+
SInterpolants BasicVS()
22+
{
23+
const float32_t3 position = utbs[pc.positionView].xyz;
24+
25+
SInterpolants output;
26+
output.position = math::linalg::promoted_mul(pc.matrices.worldViewProj,position);
27+
output.color = mul(pc.matrices.normalMat,utbs[pc.normalView].xyz)*0.5+promote<float32_t3>(0.5f);
28+
return output;
29+
}
30+
float32_t4 BasicFS(SInterpolants input) : SV_Target0
31+
{
32+
return float32_t4(input.color,1.f);
33+
}
34+
35+
// TODO: do smooth normals on the cone
36+
SInterpolants ConeVS()
37+
{
38+
const float32_t3 position = utbs[pc.positionView].xyz;
39+
40+
SInterpolants output;
41+
output.position = math::linalg::promoted_mul(pc.matrices.worldViewProj,position);
42+
output.color = mul(inverse(transpose(pc.matrices.normalMat)),position);
43+
return output;
44+
}
45+
float32_t4 ConeFS(SInterpolants input) : SV_Target0
46+
{
47+
const float32_t2x3 dViewPos_dScreen = float32_t2x3(
48+
ddx(input.color),
49+
ddy(input.color)
50+
);
51+
return float32_t4(normalize(cross(X,Y))*0.5f+promote<float32_t3>(0.5f),1.f);
52+
}

0 commit comments

Comments
 (0)