Skip to content

Commit 7307a69

Browse files
committed
save work - UI shaders update
1 parent ac4e041 commit 7307a69

File tree

8 files changed

+63
-50
lines changed

8 files changed

+63
-50
lines changed

include/nbl/system/ISystem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class NBL_API2 ISystem : public core::IReferenceCounted
146146
}
147147

148148
void unmountBuiltins();
149+
bool areBuiltinsMounted() const;
149150

150151
//
151152
struct SystemInfo

src/nbl/ext/ImGui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ get_filename_component(_OUTPUT_DIRECTORY_SOURCE_ "${CMAKE_CURRENT_BINARY_DIR}/sr
3232
get_filename_component(_OUTPUT_DIRECTORY_HEADER_ "${CMAKE_CURRENT_BINARY_DIR}/include" ABSOLUTE)
3333

3434
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "common.hlsl")
35+
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "psinput.hlsl")
3536
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "vertex.hlsl") # (*) -> this we could precompile [no resources for which set/binding Ixs could be adjusted] but I'm not going to mix stuff
3637
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "fragment.hlsl") # (*) -> but this we could not since we let users to provide external descriptor set layout + ImGUI textures & sampler state set/binding Ixs (for pipeline layout) at runtime
3738

src/nbl/ext/ImGui/ImGui.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ namespace nbl::ext::imgui
133133
constexpr std::string_view NBL_ARCHIVE_ALIAS = "nbl/ext/imgui/shaders";
134134

135135
auto system = smart_refctd_ptr<system::ISystem>(creationParams.assetManager->getSystem()); //! proxy the system, we will touch it gently
136+
assert(system->areBuiltinsMounted()); //! we assume user has all Nabla builtins mounted, but we won't check it at release
137+
136138
auto archive = make_smart_refctd_ptr<nbl::ext::imgui::builtin::CArchive>(smart_refctd_ptr<system::ILogger>(creationParams.utilities->getLogger())); //! we should never assume user will mount our internal archive since its the extension and not user's job to do it, hence we mount only to compile our extension sources then unmount the archive
137139
auto compiler = make_smart_refctd_ptr<CHLSLCompiler>(smart_refctd_ptr(system)); //! note we are out of default logical device's compiler set scope so also a few special steps are required to compile our extension shaders to SPIRV
138140
auto includeFinder = make_smart_refctd_ptr<IShaderCompiler::CIncludeFinder>(smart_refctd_ptr(system));

src/nbl/ext/ImGui/shaders/common.hlsl

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,27 @@
1-
#ifdef __HLSL_VERSION
2-
struct VSInput
3-
{
4-
[[vk::location(0)]] float2 position : POSITION;
5-
[[vk::location(1)]] float2 uv : TEXCOORD0;
6-
[[vk::location(2)]] float4 color : COLOR0;
7-
};
8-
9-
struct PSInput
1+
2+
namespace nbl::hlsl
3+
{
4+
struct emulated_snorm16_t2
105
{
11-
float4 position : SV_Position;
12-
float2 uv : TEXCOORD0;
13-
float4 color : COLOR0;
14-
uint drawID : SV_InstanceID;
15-
float clip[4] : SV_ClipDistance;
6+
uint32_t packed;
167
};
8+
}
179

10+
namespace nbl::ext::imgui
11+
{
1812
struct PushConstants
1913
{
2014
uint64_t elementBDA;
2115
uint64_t elementCount;
22-
float2 scale;
23-
float2 translate;
24-
float4 viewport;
25-
};
26-
27-
#else
28-
struct PushConstants
29-
{
30-
uint64_t elementBDA;
31-
uint64_t elementCount;
32-
float scale[2];
33-
float translate[2];
34-
float viewport[4];
16+
nbl::hlsl::float32_t2 scale;
17+
nbl::hlsl::float32_t2 translate;
18+
nbl::hlsl::float32_t4 viewport;
3519
};
36-
#endif // __HLSL_VERSION
3720

38-
struct emulated_snorm16_t2
39-
{
40-
#ifdef __HLSL_VERSION
41-
float32_t2 unpack() // returns in NDC [-1, 1] range
21+
struct PerObjectData
4222
{
43-
return clamp(float32_t2(x, y) / 32767.0f, -1.f, +1.f);
44-
}
45-
#endif
46-
47-
int16_t x, y;
48-
};
49-
50-
struct PerObjectData
51-
{
52-
emulated_snorm16_t2 aabbMin, aabbMax;
53-
uint16_t texId : 14;
54-
uint16_t samplerIx : 2;
55-
};
23+
nbl::hlsl::emulated_snorm16_t2 aabbMin, aabbMax;
24+
uint32_t texId : 26;
25+
uint32_t samplerIx : 6;
26+
};
27+
}

src/nbl/ext/ImGui/shaders/fragment.hlsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#endif
2424

2525
#include "common.hlsl"
26+
#include "psinput.hlsl"
27+
28+
using namespace nbl::ext::imgui;
2629

2730
[[vk::push_constant]] struct PushConstants pc;
2831

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
#ifdef __HLSL_VERSION
3+
namespace nbl::ext::imgui
4+
{
5+
struct PSInput
6+
{
7+
float32_t4 position : SV_Position;
8+
float32_t2 uv : TEXCOORD0;
9+
float32_t4 color : COLOR0;
10+
float32_t4 clip : SV_ClipDistance;
11+
uint drawID : SV_InstanceID;
12+
};
13+
}
14+
#endif // __HLSL_VERSION

src/nbl/ext/ImGui/shaders/vertex.hlsl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
#include "nbl/builtin/hlsl/glsl_compat/core.hlsl"
12
#include "common.hlsl"
3+
#include "psinput.hlsl"
24

35
[[vk::push_constant]] struct PushConstants pc;
46

7+
struct VSInput
8+
{
9+
[[vk::location(0)]] float2 position : POSITION;
10+
[[vk::location(1)]] float2 uv : TEXCOORD0;
11+
[[vk::location(2)]] float4 color : COLOR0;
12+
};
13+
514
/*
615
we use Indirect Indexed draw call to render whole GUI, note we do a cross
716
platform trick and use base instance index as replacement for gl_DrawID
@@ -20,8 +29,8 @@ PSInput VSMain(VSInput input, uint drawID : SV_InstanceID)
2029

2130
// NDC [-1, 1] range
2231
output.position = float4(input.position * pc.scale + pc.translate, 0, 1);
23-
const float2 vMin = self.aabbMin.unpack();
24-
const float2 vMax = self.aabbMax.unpack();
32+
const float32_t2 vMin = nbl::hlsl::unpackSnorm2x16(self.aabbMin.packed);
33+
const float32_t2 vMax = nbl::hlsl::unpackSnorm2x16(self.aabbMax.packed);
2534

2635
// clip planes calculations, axis aligned
2736
output.clip[0] = output.position.x - vMin.x;

src/nbl/system/ISystem.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,11 @@ bool ISystem::ICaller::flushMapping(IFile* file, size_t offset, size_t size)
312312
return retval;
313313
}
314314

315-
void ISystem::unmountBuiltins() {
315+
void ISystem::unmountBuiltins() {
316316

317317
auto removeByKey = [&, this](const char* s) {
318318
auto range = m_cachedArchiveFiles.findRange(s);
319+
319320
std::vector<core::smart_refctd_ptr<IFileArchive>> items_to_remove = {}; //is it always just 1 item?
320321
for (auto it = range.begin(); it != range.end(); ++it)
321322
{
@@ -326,8 +327,18 @@ void ISystem::unmountBuiltins() {
326327
m_cachedArchiveFiles.removeObject(items_to_remove[i], s);
327328
}
328329
};
329-
removeByKey("nbl/builtin");
330+
331+
removeByKey("nbl");
330332
removeByKey("spirv");
331333
removeByKey("boost");
332-
334+
}
335+
336+
bool ISystem::areBuiltinsMounted() const
337+
{
338+
// TODO: we need to span our keys and reuse accross this cpp to not DRY
339+
for (const auto& it : { "nbl", "spirv", "boost" })
340+
if (m_cachedArchiveFiles.findRange(it).empty())
341+
return false;
342+
343+
return true;
333344
}

0 commit comments

Comments
 (0)