Skip to content

Commit c4f4470

Browse files
committed
update shaders
1 parent 7307a69 commit c4f4470

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

src/nbl/ext/ImGui/ImGui.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ using namespace nbl::video;
1616
using namespace nbl::core;
1717
using namespace nbl::asset;
1818
using namespace nbl::ui;
19+
using namespace nbl::hlsl;
1920

2021
namespace nbl::ext::imgui
2122
{
@@ -1165,16 +1166,19 @@ namespace nbl::ext::imgui
11651166

11661167
auto packSnorm16 = [](float ndc) -> int16_t
11671168
{
1168-
return std::round<int16_t>(std::clamp(ndc, -1.0f, 1.0f) * 32767.0f); // TODO: ok encodePixels<asset::EF_R16_SNORM, double>(void* _pix, const double* _input) but iirc we have issues with our encode/decode utils
1169+
return std::round<int16_t>(std::clamp(ndc, -1.0f, 1.0f) * 32767.0f);
1170+
};
1171+
1172+
auto packToUint32 = [](uint16_t x, uint16_t y) -> uint32_t
1173+
{
1174+
return (static_cast<uint32_t>(x) << 16) | static_cast<uint32_t>(y);
11691175
};
11701176

11711177
const auto vMin = trs.toNDC(core::vector2df_SIMD(scissor.offset.x, scissor.offset.y));
11721178
const auto vMax = trs.toNDC(core::vector2df_SIMD(scissor.offset.x + scissor.extent.width, scissor.offset.y + scissor.extent.height));
11731179

1174-
element->aabbMin.x = packSnorm16(vMin.x);
1175-
element->aabbMin.y = packSnorm16(vMin.y);
1176-
element->aabbMax.x = packSnorm16(vMax.x);
1177-
element->aabbMax.y = packSnorm16(vMax.y);
1180+
element->aabbMin = packToUint32(packSnorm16(vMin.x), packSnorm16(vMin.y));
1181+
element->aabbMax = packToUint32(packSnorm16(vMax.x), packSnorm16(vMax.y));
11781182
element->texId = pcmd->TextureId.textureID;
11791183
element->samplerIx = pcmd->TextureId.samplerIx;
11801184
}

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
2-
namespace nbl::hlsl
3-
{
4-
struct emulated_snorm16_t2
5-
{
6-
uint32_t packed;
7-
};
8-
}
1+
#include "nbl/builtin/hlsl/glsl_compat/core.hlsl"
92

10-
namespace nbl::ext::imgui
3+
namespace nbl
4+
{
5+
namespace ext
6+
{
7+
namespace imgui
118
{
129
struct PushConstants
1310
{
@@ -20,8 +17,10 @@ namespace nbl::ext::imgui
2017

2118
struct PerObjectData
2219
{
23-
nbl::hlsl::emulated_snorm16_t2 aabbMin, aabbMax;
20+
uint32_t aabbMin, aabbMax; //! snorm16_t2 packed as [uint16_t, uint16_t]
2421
uint32_t texId : 26;
2522
uint32_t samplerIx : 6;
2623
};
2724
}
25+
}
26+
}
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
21
#ifdef __HLSL_VERSION
3-
namespace nbl::ext::imgui
2+
namespace nbl
3+
{
4+
namespace ext
5+
{
6+
namespace imgui
47
{
58
struct PSInput
69
{
@@ -11,4 +14,6 @@ namespace nbl::ext::imgui
1114
uint drawID : SV_InstanceID;
1215
};
1316
}
14-
#endif // __HLSL_VERSION
17+
}
18+
}
19+
#endif // __HLSL_VERSION

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#include "nbl/builtin/hlsl/glsl_compat/core.hlsl"
21
#include "common.hlsl"
32
#include "psinput.hlsl"
43

5-
[[vk::push_constant]] struct PushConstants pc;
4+
[[vk::push_constant]] struct nbl::ext::imgui::PushConstants pc;
65

76
struct VSInput
87
{
@@ -17,20 +16,21 @@ struct VSInput
1716
to request per object data with BDA
1817
*/
1918

20-
PSInput VSMain(VSInput input, uint drawID : SV_InstanceID)
19+
nbl::ext::imgui::PSInput VSMain(VSInput input, uint drawID : SV_InstanceID)
2120
{
22-
PSInput output;
21+
nbl::ext::imgui::PSInput output;
2322
output.color = input.color;
2423
output.uv = input.uv;
2524
output.drawID = drawID;
2625

2726
// BDA for requesting object data
28-
const PerObjectData self = vk::RawBufferLoad<PerObjectData>(pc.elementBDA + sizeof(PerObjectData)* drawID);
27+
const nbl::ext::imgui::PerObjectData self = vk::RawBufferLoad<nbl::ext::imgui::PerObjectData>(pc.elementBDA + sizeof(nbl::ext::imgui::PerObjectData)* drawID);
2928

3029
// NDC [-1, 1] range
3130
output.position = float4(input.position * pc.scale + pc.translate, 0, 1);
32-
const float32_t2 vMin = nbl::hlsl::unpackSnorm2x16(self.aabbMin.packed);
33-
const float32_t2 vMax = nbl::hlsl::unpackSnorm2x16(self.aabbMax.packed);
31+
32+
const float32_t2 vMin = nbl::hlsl::glsl::unpackSnorm2x16(self.aabbMin);
33+
const float32_t2 vMax = nbl::hlsl::glsl::unpackSnorm2x16(self.aabbMax);
3434

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

0 commit comments

Comments
 (0)