Skip to content

Commit 2656b21

Browse files
rearrange binding order and add index buffer descriptor
1 parent e29e083 commit 2656b21

File tree

1 file changed

+59
-30
lines changed

1 file changed

+59
-30
lines changed

include/nbl/builtin/glsl/virtual_geometry/descriptors.glsl

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@
55
#ifndef _NBL_BUILTIN_GLSL_VIRTUAL_GEOMETRY_DESCRIPTORS_INCLUDED_
66
#define _NBL_BUILTIN_GLSL_VIRTUAL_GEOMETRY_DESCRIPTORS_INCLUDED_
77

8+
9+
810
#ifndef _NBL_VG_USE_SSBO
911

12+
1013
#ifndef _NBL_VG_DESCRIPTOR_SET
1114
#define _NBL_VG_DESCRIPTOR_SET 0
1215
#endif
16+
17+
#ifndef _NBL_VG_UINT_BUFFERS
18+
#define _NBL_VG_UINT_BUFFERS_BINDING 0
19+
#define _NBL_VG_UINT_BUFFERS_COUNT 1
20+
#endif
1321
#ifndef _NBL_VG_FLOAT_BUFFERS
1422
#define _NBL_VG_FLOAT_BUFFERS_BINDING 1
1523
#define _NBL_VG_FLOAT_BUFFERS_COUNT 15
@@ -18,76 +26,97 @@
1826
#define _NBL_VG_INT_BUFFERS_BINDING 2
1927
#define _NBL_VG_INT_BUFFERS_COUNT 0
2028
#endif
21-
#ifndef _NBL_VG_UINT_BUFFERS
22-
#define _NBL_VG_UINT_BUFFERS_BINDING 3
23-
#define _NBL_VG_UINT_BUFFERS_COUNT 0
24-
#endif
2529

30+
#if _NBL_VG_UINT_BUFFERS_COUNT
31+
layout(set = _NBL_VG_DESCRIPTOR_SET, binding = _NBL_VG_UINT_BUFFERS_BINDING) uniform usamplerBuffer MeshPackedDataUintSample[_NBL_VG_UINT_BUFFERS_COUNT];
32+
uvec3 nbl_glsl_VG_fetchTriangle(in uint baseVertex)
33+
{
34+
return texelFetch(MeshPackedDataUintSample[_NBL_VG_UINT_BUFFERS_COUNT-1u],baseVertex).xyz;
35+
}
36+
#endif
2637
#if _NBL_VG_FLOAT_BUFFERS_COUNT
2738
layout(set = _NBL_VG_DESCRIPTOR_SET, binding = _NBL_VG_FLOAT_BUFFERS_BINDING) uniform samplerBuffer MeshPackedDataFloatSample[_NBL_VG_FLOAT_BUFFERS_COUNT];
2839
#endif
2940
#if _NBL_VG_INT_BUFFERS_COUNT
3041
layout(set = _NBL_VG_DESCRIPTOR_SET, binding = _NBL_VG_INT_BUFFERS_BINDING) uniform isamplerBuffer MeshPackedDataIntSample[_NBL_VG_INT_BUFFERS_COUNT];
3142
#endif
32-
#if _NBL_VG_UINT_BUFFERS_COUNT
33-
layout(set = _NBL_VG_DESCRIPTOR_SET, binding = _NBL_VG_UINT_BUFFERS_BINDING) uniform usamplerBuffer MeshPackedDataUintSample[_NBL_VG_UINT_BUFFERS_COUNT];
34-
#endif
43+
3544

3645
#else // _NBL_VG_USE_SSBO
3746

47+
3848
#ifndef _NBL_VG_SSBO_DESCRIPTOR_SET
3949
#define _NBL_VG_SSBO_DESCRIPTOR_SET 0
4050
#endif
41-
#ifndef _NBL_VG_USE_SSBO_UVEC4
42-
#ifndef _NBL_VG_SSBO_UVEC4_BINDING
43-
#define _NBL_VG_SSBO_UVEC4_BINDING 0
51+
52+
#ifndef _NBL_VG_USE_SSBO_UINT
53+
#ifndef _NBL_VG_SSBO_UINT_BINDING
54+
#define _NBL_VG_SSBO_UINT_BINDING 0
55+
#endif
56+
#endif
57+
#ifndef _NBL_VG_USE_SSBO_UVEC2
58+
#ifndef _NBL_VG_SSBO_UVEC2_BINDING
59+
#define _NBL_VG_SSBO_UVEC2_BINDING 1
4460
#endif
4561
#endif
4662
#ifndef _NBL_VG_USE_SSBO_UVEC3
4763
#ifndef _NBL_VG_SSBO_UVEC3_BINDING
48-
#define _NBL_VG_SSBO_UVEC3_BINDING 1
64+
#define _NBL_VG_SSBO_UVEC3_BINDING 2
4965
#endif
5066
#endif
51-
#ifndef _NBL_VG_USE_SSBO_UVEC2
52-
#ifndef _NBL_VG_SSBO_UVEC2_BINDING
53-
#define _NBL_VG_SSBO_UVEC2_BINDING 2
67+
#ifndef _NBL_VG_USE_SSBO_UVEC4
68+
#ifndef _NBL_VG_SSBO_UVEC4_BINDING
69+
#define _NBL_VG_SSBO_UVEC4_BINDING 3
5470
#endif
5571
#endif
56-
#ifndef _NBL_VG_USE_SSBO_UINT
57-
#ifndef _NBL_VG_SSBO_UINT_BINDING
58-
#define _NBL_VG_SSBO_UINT_BINDING 3
72+
#ifndef _NBL_VG_USE_SSBO_INDEX
73+
#ifndef _NBL_VG_SSBO_INDEX_BINDING
74+
#define _NBL_VG_SSBO_INDEX_BINDING 4
5975
#endif
6076
#endif
6177

62-
#ifdef _NBL_VG_USE_SSBO_UVEC4
63-
layout(set = _NBL_VG_SSBO_DESCRIPTOR_SET, binding = _NBL_VG_SSBO_UVEC4_BINDING, std430) readonly buffer MeshPackedDataAsUvec4
78+
#ifdef _NBL_VG_USE_SSBO_UINT
79+
layout(set = _NBL_VG_SSBO_DESCRIPTOR_SET, binding = _NBL_VG_SSBO_UINT_BINDING, std430) readonly buffer MeshPackedDataAsUint
6480
{
65-
uvec4 attribData[];
66-
} meshPackedDataUvec4Buffer;
81+
uint attribData[];
82+
} meshPackedDataUintBuffer;
83+
#endif
84+
#ifdef _NBL_VG_USE_SSBO_UVEC2
85+
layout(set = _NBL_VG_SSBO_DESCRIPTOR_SET, binding = _NBL_VG_SSBO_UVEC2_BINDING, std430) readonly buffer MeshPackedDataAsUvec2
86+
{
87+
uvec2 attribData[];
88+
} meshPackedDataUvec2Buffer;
6789
#endif
6890
#ifdef _NBL_VG_USE_SSBO_UVEC3
6991
struct Packed_uvec3_t
7092
{
71-
uint x,y,z;
93+
uint x, y, z;
7294
};
7395
layout(set = _NBL_VG_SSBO_DESCRIPTOR_SET, binding = _NBL_VG_SSBO_UVEC3_BINDING, std430) readonly buffer MeshPackedDataAsUvec3
7496
{
7597
Packed_uvec3_t attribData[];
7698
} meshPackedDataUvec3Buffer;
7799
#endif
78-
#ifdef _NBL_VG_USE_SSBO_UVEC2
79-
layout(set = _NBL_VG_SSBO_DESCRIPTOR_SET, binding = _NBL_VG_SSBO_UVEC2_BINDING, std430) readonly buffer MeshPackedDataAsUvec2
100+
#ifdef _NBL_VG_USE_SSBO_UVEC4
101+
layout(set = _NBL_VG_SSBO_DESCRIPTOR_SET, binding = _NBL_VG_SSBO_UVEC4_BINDING, std430) readonly buffer MeshPackedDataAsUvec4
80102
{
81-
uvec2 attribData[];
82-
} meshPackedDataUvec2Buffer;
103+
uvec4 attribData[];
104+
} meshPackedDataUvec4Buffer;
83105
#endif
84-
#ifdef _NBL_VG_USE_SSBO_UINT
85-
layout(set = _NBL_VG_SSBO_DESCRIPTOR_SET, binding = _NBL_VG_SSBO_UINT_BINDING, std430) readonly buffer MeshPackedDataAsUint
106+
#ifdef _NBL_VG_USE_SSBO_INDEX
107+
layout(set = _NBL_VG_SSBO_DESCRIPTOR_SET, binding = _NBL_VG_SSBO_INDEX_BINDING, std430) readonly buffer TrianglePackedData
86108
{
87-
uint attribData[];
88-
} meshPackedDataUintBuffer;
109+
u16vec3 indices[];
110+
} trianglePackedData;
111+
uvec3 nbl_glsl_VG_fetchTriangle(in uint baseTriangle)
112+
{
113+
return uvec3(trianglePackedData.indices[baseTriangle]);
114+
}
89115
#endif
90116

117+
91118
#endif // _NBL_VG_USE_SSBO
92119

120+
121+
93122
#endif // _NBL_BUILTIN_GLSL_VIRTUAL_GEOMETRY_DESCRIPTORS_INCLUDED_

0 commit comments

Comments
 (0)