Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
VkCV Framework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vulkan2021
VkCV Framework
Merge requests
!74
Resolve "Mesh Shader Implementation"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Mesh Shader Implementation"
87-mesh-shader-implementation
into
develop
Overview
1
Commits
47
Pipelines
39
Changes
276
Merged
Ghost User
requested to merge
87-mesh-shader-implementation
into
develop
3 years ago
Overview
1
Commits
47
Pipelines
39
Changes
6
Expand
Closes
#87 (closed)
Edited
3 years ago
by
Tobias Frisch
0
0
Merge request reports
Compare
version 18
version 38
67865802
3 years ago
version 37
f6a34061
3 years ago
version 36
6a489a08
3 years ago
version 35
5f182098
3 years ago
version 34
094d81a8
3 years ago
version 33
d7ea5c20
3 years ago
version 32
2c47c965
3 years ago
version 31
7ae0c95d
3 years ago
version 30
25fdb8d3
3 years ago
version 29
ff82fe73
3 years ago
version 28
8fe90478
3 years ago
version 27
85228f00
3 years ago
version 26
c84586d6
3 years ago
version 25
8048598a
3 years ago
version 24
11ad08b1
3 years ago
version 23
fa3e41c6
3 years ago
version 22
a557caeb
3 years ago
version 21
e4952916
3 years ago
version 20
e411dc41
3 years ago
version 19
9f2a390b
3 years ago
version 18
03b69290
3 years ago
version 17
704482d6
3 years ago
version 16
3d918289
3 years ago
version 15
55937807
3 years ago
version 14
60ab534c
3 years ago
version 13
60ab534c
3 years ago
version 12
4d5ec8ef
3 years ago
version 11
1df2d12b
3 years ago
version 10
caf7997f
3 years ago
version 9
1ce5fe8c
3 years ago
version 8
03c441fa
3 years ago
version 7
074ee4e5
3 years ago
version 6
99b22389
3 years ago
version 5
f22dffcd
3 years ago
version 4
ddf3936a
3 years ago
version 3
19356f9a
3 years ago
version 2
682504ad
3 years ago
version 1
ba27891a
3 years ago
develop (base)
and
version 20
latest version
38e22ec2
47 commits,
3 years ago
version 38
67865802
46 commits,
3 years ago
version 37
f6a34061
45 commits,
3 years ago
version 36
6a489a08
43 commits,
3 years ago
version 35
5f182098
42 commits,
3 years ago
version 34
094d81a8
41 commits,
3 years ago
version 33
d7ea5c20
40 commits,
3 years ago
version 32
2c47c965
39 commits,
3 years ago
version 31
7ae0c95d
38 commits,
3 years ago
version 30
25fdb8d3
34 commits,
3 years ago
version 29
ff82fe73
33 commits,
3 years ago
version 28
8fe90478
32 commits,
3 years ago
version 27
85228f00
31 commits,
3 years ago
version 26
c84586d6
30 commits,
3 years ago
version 25
8048598a
29 commits,
3 years ago
version 24
11ad08b1
28 commits,
3 years ago
version 23
fa3e41c6
27 commits,
3 years ago
version 22
a557caeb
26 commits,
3 years ago
version 21
e4952916
25 commits,
3 years ago
version 20
e411dc41
24 commits,
3 years ago
version 19
9f2a390b
21 commits,
3 years ago
version 18
03b69290
20 commits,
3 years ago
version 17
704482d6
19 commits,
3 years ago
version 16
3d918289
18 commits,
3 years ago
version 15
55937807
17 commits,
3 years ago
version 14
60ab534c
16 commits,
3 years ago
version 13
60ab534c
16 commits,
3 years ago
version 12
4d5ec8ef
15 commits,
3 years ago
version 11
1df2d12b
13 commits,
3 years ago
version 10
caf7997f
12 commits,
3 years ago
version 9
1ce5fe8c
11 commits,
3 years ago
version 8
03c441fa
10 commits,
3 years ago
version 7
074ee4e5
9 commits,
3 years ago
version 6
99b22389
7 commits,
3 years ago
version 5
f22dffcd
6 commits,
3 years ago
version 4
ddf3936a
5 commits,
3 years ago
version 3
19356f9a
4 commits,
3 years ago
version 2
682504ad
3 commits,
3 years ago
version 1
ba27891a
2 commits,
3 years ago
Show latest version
6 files
+
173
−
174
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
Search (e.g. *.vue) (Ctrl+P)
modules/scene/include/vkcv/scene/Meshlet.hpp
0 → 100644
+
161
−
0
Options
#pragma once
#include
<vector>
#include
<Map>
#include
<glm/glm.hpp>
namespace
vkcv
::
scene
{
struct
Vertex
{
glm
::
vec3
position
;
float
padding0
;
glm
::
vec3
normal
;
float
padding1
;
};
struct
Meshlet
{
uint32_t
vertexOffset
;
uint32_t
vertexCount
;
uint32_t
indexOffset
;
uint32_t
indexCount
;
};
struct
MeshShaderModelData
{
std
::
vector
<
Vertex
>
vertices
;
std
::
vector
<
uint32_t
>
localIndices
;
std
::
vector
<
Meshlet
>
meshlets
;
};
std
::
vector
<
Vertex
>
convertToVertices
(
const
std
::
vector
<
uint8_t
>&
vertexData
,
const
uint64_t
vertexCount
,
const
vkcv
::
asset
::
VertexAttribute
&
positionAttribute
,
const
vkcv
::
asset
::
VertexAttribute
&
normalAttribute
)
{
assert
(
positionAttribute
.
type
==
vkcv
::
asset
::
PrimitiveType
::
POSITION
);
assert
(
normalAttribute
.
type
==
vkcv
::
asset
::
PrimitiveType
::
NORMAL
);
std
::
vector
<
Vertex
>
vertices
;
vertices
.
reserve
(
vertexCount
);
const
size_t
positionStepSize
=
positionAttribute
.
stride
==
0
?
sizeof
(
glm
::
vec3
)
:
positionAttribute
.
stride
;
const
size_t
normalStepSize
=
normalAttribute
.
stride
==
0
?
sizeof
(
glm
::
vec3
)
:
normalAttribute
.
stride
;
for
(
int
i
=
0
;
i
<
vertexCount
;
i
++
)
{
Vertex
v
;
const
size_t
positionOffset
=
positionAttribute
.
offset
+
positionStepSize
*
i
;
const
size_t
normalOffset
=
normalAttribute
.
offset
+
normalStepSize
*
i
;
v
.
position
=
*
reinterpret_cast
<
const
glm
::
vec3
*>
(
&
(
vertexData
[
positionOffset
]));
v
.
normal
=
*
reinterpret_cast
<
const
glm
::
vec3
*>
(
&
(
vertexData
[
normalOffset
]));
vertices
.
push_back
(
v
);
}
return
vertices
;
}
MeshShaderModelData
createMeshShaderModelData
(
const
std
::
vector
<
Vertex
>&
inVertices
,
const
std
::
vector
<
uint32_t
>&
inIndices
)
{
MeshShaderModelData
data
;
size_t
currentIndex
=
0
;
const
size_t
maxVerticesPerMeshlet
=
64
;
const
size_t
maxIndicesPerMeshlet
=
126
*
3
;
bool
indicesAreLeft
=
true
;
while
(
indicesAreLeft
)
{
Meshlet
meshlet
;
meshlet
.
indexCount
=
0
;
meshlet
.
vertexCount
=
0
;
meshlet
.
indexOffset
=
data
.
localIndices
.
size
();
meshlet
.
vertexOffset
=
data
.
vertices
.
size
();
std
::
map
<
uint32_t
,
uint32_t
>
globalToLocalIndexMap
;
std
::
vector
<
uint32_t
>
globalIndicesOrdered
;
while
(
true
)
{
indicesAreLeft
=
currentIndex
+
1
<=
inIndices
.
size
();
if
(
!
indicesAreLeft
)
{
break
;
}
bool
enoughSpaceForIndices
=
meshlet
.
indexCount
+
3
<
maxIndicesPerMeshlet
;
if
(
!
enoughSpaceForIndices
)
{
break
;
}
size_t
vertexCountToAdd
=
0
;
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
const
uint32_t
globalIndex
=
inIndices
[
currentIndex
+
i
];
const
bool
containsVertex
=
globalToLocalIndexMap
.
find
(
globalIndex
)
!=
globalToLocalIndexMap
.
end
();
if
(
!
containsVertex
)
{
vertexCountToAdd
++
;
}
}
bool
enoughSpaceForVertices
=
meshlet
.
vertexCount
+
vertexCountToAdd
<
maxVerticesPerMeshlet
;
if
(
!
enoughSpaceForVertices
)
{
break
;
}
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
const
uint32_t
globalIndex
=
inIndices
[
currentIndex
+
i
];
uint32_t
localIndex
;
const
bool
indexAlreadyExists
=
globalToLocalIndexMap
.
find
(
globalIndex
)
!=
globalToLocalIndexMap
.
end
();
if
(
indexAlreadyExists
)
{
localIndex
=
globalToLocalIndexMap
[
globalIndex
];
}
else
{
localIndex
=
globalToLocalIndexMap
.
size
();
globalToLocalIndexMap
[
globalIndex
]
=
localIndex
;
globalIndicesOrdered
.
push_back
(
globalIndex
);
}
data
.
localIndices
.
push_back
(
localIndex
);
}
meshlet
.
indexCount
+=
3
;
currentIndex
+=
3
;
meshlet
.
vertexCount
+=
vertexCountToAdd
;
}
for
(
const
uint32_t
globalIndex
:
globalIndicesOrdered
)
{
const
Vertex
v
=
inVertices
[
globalIndex
];
data
.
vertices
.
push_back
(
v
);
}
data
.
meshlets
.
push_back
(
meshlet
);
}
return
data
;
}
std
::
vector
<
uint32_t
>
assetLoaderIndicesTo32BitIndices
(
const
std
::
vector
<
uint8_t
>&
indexData
,
vkcv
::
asset
::
IndexType
indexType
)
{
std
::
vector
<
uint32_t
>
indices
;
if
(
indexType
==
vkcv
::
asset
::
IndexType
::
UINT16
)
{
for
(
int
i
=
0
;
i
<
indexData
.
size
();
i
+=
2
)
{
const
uint16_t
index16Bit
=
*
reinterpret_cast
<
const
uint16_t
*>
(
&
(
indexData
[
i
]));
const
uint32_t
index32Bit
=
static_cast
<
uint32_t
>
(
index16Bit
);
indices
.
push_back
(
index32Bit
);
}
}
else
if
(
indexType
==
vkcv
::
asset
::
IndexType
::
UINT32
)
{
for
(
int
i
=
0
;
i
<
indexData
.
size
();
i
+=
4
)
{
const
uint32_t
index32Bit
=
*
reinterpret_cast
<
const
uint32_t
*>
(
&
(
indexData
[
i
]));
indices
.
push_back
(
index32Bit
);
}
}
else
{
vkcv_log
(
vkcv
::
LogLevel
::
ERROR
,
"Unsupported index type"
);
}
return
indices
;
}
}
\ No newline at end of file
Loading