Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
Unterteilungsalgorithmen
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kai Westerkamp
Unterteilungsalgorithmen
Commits
5ed828b4
Commit
5ed828b4
authored
Sep 26, 2016
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite buildNeighborsMap to use GPU
parent
2117bcae
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
172 additions
and
20 deletions
+172
-20
subdivision.cpp
QTProject/subdivision.cpp
+171
-3
subdivision.h
QTProject/subdivision.h
+1
-0
triangle.cpp
QTProject/triangle.cpp
+0
-16
triangle.h
QTProject/triangle.h
+0
-1
No files found.
QTProject/subdivision.cpp
View file @
5ed828b4
...
@@ -152,11 +152,9 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
...
@@ -152,11 +152,9 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
qCDebug
(
log_timing
)
<<
"building Triangles:"
<<
formatTimeMeasurement
(
subTimer
.
elapsed
());
qCDebug
(
log_timing
)
<<
"building Triangles:"
<<
formatTimeMeasurement
(
subTimer
.
elapsed
());
subTimer
.
restart
();
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
;
QMap
<
Triangle
,
Triangle
::
Neighbors
>
neighbors
;
QVector
<
Triangle
>
all_triangles
=
triangles
+
triangles_regular
;
QVector
<
Triangle
>
all_triangles
=
triangles
+
triangles_regular
;
buildNeighborsMap
(
all_triangles
,
neighbors
);
buildNeighborsMap
(
vb
,
all_triangles
,
neighbors
);
qCDebug
(
log_timing
)
<<
"building neighbors map:"
<<
formatTimeMeasurement
(
subTimer
.
elapsed
());
subTimer
.
restart
();
subTimer
.
restart
();
precomputeEdgeTable
(
tables
,
triangles
,
neighbors
,
(
unsigned
int
)
vb
.
length
());
precomputeEdgeTable
(
tables
,
triangles
,
neighbors
,
(
unsigned
int
)
vb
.
length
());
...
@@ -175,6 +173,176 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
...
@@ -175,6 +173,176 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
return
tables
;
return
tables
;
}
}
void
Subdivision
::
buildNeighborsMap
(
QVector
<
Vertex
>
&
vb
,
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
)
{
QTime
timer
;
timer
.
start
();
qCDebug
(
log_timing
)
<<
"buildNeighborsMap_gpu started"
;
QTime
subTimer
;
subTimer
.
start
();
GLuint
vb_handle
;
f
->
glGenBuffers
(
1
,
&
vb_handle
);
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
vb_handle
);
f
->
glBufferData
(
GL_SHADER_STORAGE_BUFFER
,
vb
.
size
()
*
sizeof
(
Vertex
),
vb
.
data
(),
GL_DYNAMIC_DRAW
);
GLuint
ib_handle
;
f
->
glGenBuffers
(
1
,
&
ib_handle
);
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
ib_handle
);
f
->
glBufferData
(
GL_SHADER_STORAGE_BUFFER
,
triangles
.
size
()
*
3
*
sizeof
(
GLuint
),
NULL
,
GL_DYNAMIC_DRAW
);
GLuint
*
ptr
=
(
GLuint
*
)
f
->
glMapBuffer
(
GL_SHADER_STORAGE_BUFFER
,
GL_WRITE_ONLY
);
qDebug
()
<<
vb
.
size
();
for
(
int
i
=
0
;
i
<
triangles
.
size
();
i
++
)
{
ptr
[
3
*
i
+
0
]
=
triangles
[
i
].
u_idx
();
ptr
[
3
*
i
+
1
]
=
triangles
[
i
].
v_idx
();
ptr
[
3
*
i
+
2
]
=
triangles
[
i
].
w_idx
();
}
f
->
glUnmapBuffer
(
GL_SHADER_STORAGE_BUFFER
);
GLuint
offset_handle
;
f
->
glGenBuffers
(
1
,
&
offset_handle
);
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
offset_handle
);
f
->
glBufferData
(
GL_SHADER_STORAGE_BUFFER
,
2
*
sizeof
(
GLuint
),
NULL
,
GL_DYNAMIC_DRAW
);
GLuint
output_handle
;
f
->
glGenBuffers
(
1
,
&
output_handle
);
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
output_handle
);
f
->
glBufferData
(
GL_SHADER_STORAGE_BUFFER
,
triangles
.
size
()
*
3
*
sizeof
(
GLint
),
NULL
,
GL_DYNAMIC_DRAW
);
GLint
*
output_ptr
=
(
GLint
*
)
f
->
glMapBuffer
(
GL_SHADER_STORAGE_BUFFER
,
GL_WRITE_ONLY
);
memset
(
output_ptr
,
(
GLint
)
-
1
,
triangles
.
size
()
*
3
*
sizeof
(
GLint
));
f
->
glUnmapBuffer
(
GL_SHADER_STORAGE_BUFFER
);
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
0
);
qCDebug
(
log_timing
)
<<
"Copying to GPU:"
<<
formatTimeMeasurement
(
subTimer
.
elapsed
());
subTimer
.
restart
();
neighborsShader
->
bind
();
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
0
,
vb_handle
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
1
,
ib_handle
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
2
,
offset_handle
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
3
,
output_handle
);
GLuint
offset_in
=
0
;
GLuint
offset_search
=
0
;
while
(
offset_in
<=
(
unsigned
)
triangles
.
size
()
||
offset_search
<=
(
unsigned
)
triangles
.
size
())
{
if
(
offset_search
>
(
unsigned
)
triangles
.
size
())
{
offset_in
+=
128
;
offset_search
=
0
;
}
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
offset_handle
);
GLuint
*
offset_ptr
=
(
GLuint
*
)
f
->
glMapBuffer
(
GL_SHADER_STORAGE_BUFFER
,
GL_WRITE_ONLY
);
offset_ptr
[
0
]
=
offset_in
;
offset_ptr
[
1
]
=
offset_search
;
f
->
glUnmapBuffer
(
GL_SHADER_STORAGE_BUFFER
);
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
0
);
qDebug
()
<<
"dispatching with offset"
<<
offset_in
<<
offset_search
;
f
->
glDispatchCompute
(
128
,
32
,
1
);
offset_search
+=
128
*
32
;
}
f
->
glMemoryBarrier
(
GL_SHADER_STORAGE_BARRIER_BIT
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
0
,
0
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
1
,
0
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
2
,
0
);
f
->
glBindBufferBase
(
GL_SHADER_STORAGE_BUFFER
,
3
,
0
);
neighborsShader
->
release
();
qCDebug
(
log_timing
)
<<
"Running shader:"
<<
formatTimeMeasurement
(
subTimer
.
elapsed
());
subTimer
.
restart
();
f
->
glBindBuffer
(
GL_SHADER_STORAGE_BUFFER
,
output_handle
);
GLint
*
out_ptr
=
(
GLint
*
)
f
->
glMapBuffer
(
GL_SHADER_STORAGE_BUFFER
,
GL_READ_ONLY
);
bool
valid
=
true
;
for
(
int
i
=
0
;
i
<
3
*
triangles
.
length
();
i
++
)
{
if
(
out_ptr
[
i
]
<
0
||
out_ptr
[
i
]
>=
triangles
.
length
())
{
qCWarning
(
log_subdiv
)
<<
"Invalid neighbor:"
<<
i
<<
out_ptr
[
i
];
valid
=
false
;
}
}
if
(
valid
)
{
for
(
int
i
=
0
;
i
<
triangles
.
length
();
i
++
)
{
Triangle
::
Neighbors
ns
;
GLint
other
=
out_ptr
[
3
*
i
+
0
];
ns
.
uv
.
triangle
=
&
(
triangles
[
other
]);
if
(
out_ptr
[
3
*
other
+
0
]
==
i
)
{
ns
.
uv
.
edge
.
name
=
Triangle
::
Edge
::
Name
::
uv
;
ns
.
uv
.
edge
.
a
=
ns
.
uv
.
triangle
->
u_idx
();
ns
.
uv
.
edge
.
b
=
ns
.
uv
.
triangle
->
v_idx
();
ns
.
uv
.
edge
.
c
=
ns
.
uv
.
triangle
->
w_idx
();
}
else
if
(
out_ptr
[
3
*
other
+
1
]
==
i
)
{
ns
.
uv
.
edge
.
name
=
Triangle
::
Edge
::
Name
::
vw
;
ns
.
uv
.
edge
.
a
=
ns
.
uv
.
triangle
->
v_idx
();
ns
.
uv
.
edge
.
b
=
ns
.
uv
.
triangle
->
w_idx
();
ns
.
uv
.
edge
.
c
=
ns
.
uv
.
triangle
->
u_idx
();
}
else
if
(
out_ptr
[
3
*
other
+
2
]
==
i
)
{
ns
.
uv
.
edge
.
name
=
Triangle
::
Edge
::
Name
::
wu
;
ns
.
uv
.
edge
.
a
=
ns
.
uv
.
triangle
->
w_idx
();
ns
.
uv
.
edge
.
b
=
ns
.
uv
.
triangle
->
u_idx
();
ns
.
uv
.
edge
.
c
=
ns
.
uv
.
triangle
->
v_idx
();
}
other
=
out_ptr
[
3
*
i
+
1
];
ns
.
vw
.
triangle
=
&
(
triangles
[
other
]);
if
(
out_ptr
[
3
*
other
+
0
]
==
i
)
{
ns
.
vw
.
edge
.
name
=
Triangle
::
Edge
::
Name
::
uv
;
ns
.
vw
.
edge
.
a
=
ns
.
vw
.
triangle
->
u_idx
();
ns
.
vw
.
edge
.
b
=
ns
.
vw
.
triangle
->
v_idx
();
ns
.
vw
.
edge
.
c
=
ns
.
vw
.
triangle
->
w_idx
();
}
else
if
(
out_ptr
[
3
*
other
+
1
]
==
i
)
{
ns
.
vw
.
edge
.
name
=
Triangle
::
Edge
::
Name
::
vw
;
ns
.
vw
.
edge
.
a
=
ns
.
vw
.
triangle
->
v_idx
();
ns
.
vw
.
edge
.
b
=
ns
.
vw
.
triangle
->
w_idx
();
ns
.
vw
.
edge
.
c
=
ns
.
vw
.
triangle
->
u_idx
();
}
else
if
(
out_ptr
[
3
*
other
+
2
]
==
i
)
{
ns
.
vw
.
edge
.
name
=
Triangle
::
Edge
::
Name
::
wu
;
ns
.
vw
.
edge
.
a
=
ns
.
vw
.
triangle
->
w_idx
();
ns
.
vw
.
edge
.
b
=
ns
.
vw
.
triangle
->
u_idx
();
ns
.
vw
.
edge
.
c
=
ns
.
vw
.
triangle
->
v_idx
();
}
other
=
out_ptr
[
3
*
i
+
2
];
ns
.
wu
.
triangle
=
&
(
triangles
[
other
]);
if
(
out_ptr
[
3
*
other
+
0
]
==
i
)
{
ns
.
wu
.
edge
.
name
=
Triangle
::
Edge
::
Name
::
uv
;
ns
.
wu
.
edge
.
a
=
ns
.
wu
.
triangle
->
u_idx
();
ns
.
wu
.
edge
.
b
=
ns
.
wu
.
triangle
->
v_idx
();
ns
.
wu
.
edge
.
c
=
ns
.
wu
.
triangle
->
w_idx
();
}
else
if
(
out_ptr
[
3
*
other
+
1
]
==
i
)
{
ns
.
wu
.
edge
.
name
=
Triangle
::
Edge
::
Name
::
vw
;
ns
.
wu
.
edge
.
a
=
ns
.
wu
.
triangle
->
v_idx
();
ns
.
wu
.
edge
.
b
=
ns
.
wu
.
triangle
->
w_idx
();
ns
.
wu
.
edge
.
c
=
ns
.
wu
.
triangle
->
u_idx
();
}
else
if
(
out_ptr
[
3
*
other
+
2
]
==
i
)
{
ns
.
wu
.
edge
.
name
=
Triangle
::
Edge
::
Name
::
wu
;
ns
.
wu
.
edge
.
a
=
ns
.
wu
.
triangle
->
w_idx
();
ns
.
wu
.
edge
.
b
=
ns
.
wu
.
triangle
->
u_idx
();
ns
.
wu
.
edge
.
c
=
ns
.
wu
.
triangle
->
v_idx
();
}
neighbors
.
insert
(
triangles
[
i
],
ns
);
}
}
f
->
glUnmapBuffer
(
GL_SHADER_STORAGE_BUFFER
);
qCDebug
(
log_timing
)
<<
"Building map:"
<<
formatTimeMeasurement
(
subTimer
.
elapsed
());
f
->
glDeleteBuffers
(
1
,
&
vb_handle
);
f
->
glDeleteBuffers
(
1
,
&
ib_handle
);
f
->
glDeleteBuffers
(
1
,
&
output_handle
);
qCDebug
(
log_timing
)
<<
"buildNeighborsMap_gpu done:"
<<
formatTimeMeasurement
(
timer
.
elapsed
());
}
void
Subdivision
::
precomputeEdgeTable
(
Subdivision
::
Tables
&
tables
,
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
,
unsigned
int
offset
)
{
void
Subdivision
::
precomputeEdgeTable
(
Subdivision
::
Tables
&
tables
,
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
,
unsigned
int
offset
)
{
//compute edge table
//compute edge table
//Format: first two entries: edge vertices. last two entries: distant vertices.
//Format: first two entries: edge vertices. last two entries: distant vertices.
...
...
QTProject/subdivision.h
View file @
5ed828b4
...
@@ -58,6 +58,7 @@ private:
...
@@ -58,6 +58,7 @@ private:
QOpenGLShaderProgram
*
initComputeShaderProgram
(
QString
&
source
);
QOpenGLShaderProgram
*
initComputeShaderProgram
(
QString
&
source
);
Tables
precomputeTables
(
Input
input
);
Tables
precomputeTables
(
Input
input
);
void
buildNeighborsMap
(
QVector
<
Vertex
>
&
vb
,
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
);
void
precomputeEdgeTable
(
Subdivision
::
Tables
&
tables
,
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
,
unsigned
int
offset
);
void
precomputeEdgeTable
(
Subdivision
::
Tables
&
tables
,
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
,
unsigned
int
offset
);
void
precomputeVertexTable
(
Subdivision
::
Tables
&
tables
,
Input
&
input
,
QMap
<
unsigned
int
,
unsigned
int
>
&
modified_vertices
);
void
precomputeVertexTable
(
Subdivision
::
Tables
&
tables
,
Input
&
input
,
QMap
<
unsigned
int
,
unsigned
int
>
&
modified_vertices
);
void
updateIndexBuffer
(
QVector
<
unsigned
int
>
&
index_buffer
,
QMap
<
unsigned
int
,
unsigned
int
>
map
);
void
updateIndexBuffer
(
QVector
<
unsigned
int
>
&
index_buffer
,
QMap
<
unsigned
int
,
unsigned
int
>
map
);
...
...
QTProject/triangle.cpp
View file @
5ed828b4
...
@@ -225,22 +225,6 @@ void insert_neighbor(QMap<Triangle, Triangle::Neighbors> &neighbors, const Trian
...
@@ -225,22 +225,6 @@ void insert_neighbor(QMap<Triangle, Triangle::Neighbors> &neighbors, const Trian
neighbors
.
insert
(
triangle_a
,
ns
);
neighbors
.
insert
(
triangle_a
,
ns
);
}
}
void
buildNeighborsMap
(
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
)
{
Triangle
::
Edge
edge_a
,
edge_b
;
for
(
int
i
=
0
;
i
<
triangles
.
length
();
i
++
){
Triangle
*
triangle_a
=
&
triangles
[
i
];
for
(
int
j
=
i
+
1
;
j
<
triangles
.
length
();
j
++
){
Triangle
*
triangle_b
=
&
triangles
[
j
];
if
(
triangle_a
->
get_shared_edge
(
*
triangle_b
,
edge_a
,
edge_b
))
{
insert_neighbor
(
neighbors
,
*
triangle_a
,
edge_a
,
triangle_b
,
edge_b
);
insert_neighbor
(
neighbors
,
*
triangle_b
,
edge_b
,
triangle_a
,
edge_a
);
}
}
}
}
QDebug
operator
<<
(
QDebug
d
,
const
Triangle
&
triangle
)
{
QDebug
operator
<<
(
QDebug
d
,
const
Triangle
&
triangle
)
{
QDebugStateSaver
saver
(
d
);
QDebugStateSaver
saver
(
d
);
d
.
nospace
()
<<
"Triangle("
<<
triangle
.
u_idx
()
<<
", "
<<
triangle
.
v_idx
()
<<
", "
<<
triangle
.
w_idx
()
<<
"; "
<<
triangle
.
u
().
pos
<<
", "
<<
triangle
.
v
().
pos
<<
", "
<<
triangle
.
w
().
pos
<<
")"
;
d
.
nospace
()
<<
"Triangle("
<<
triangle
.
u_idx
()
<<
", "
<<
triangle
.
v_idx
()
<<
", "
<<
triangle
.
w_idx
()
<<
"; "
<<
triangle
.
u
().
pos
<<
", "
<<
triangle
.
v
().
pos
<<
", "
<<
triangle
.
w
().
pos
<<
")"
;
...
...
QTProject/triangle.h
View file @
5ed828b4
...
@@ -73,7 +73,6 @@ class Triangle {
...
@@ -73,7 +73,6 @@ class Triangle {
Triangle
::
Edge
::
Name
rotate_edge_name
(
Triangle
::
Edge
::
Name
edge
);
Triangle
::
Edge
::
Name
rotate_edge_name
(
Triangle
::
Edge
::
Name
edge
);
void
ibToTriangles
(
QVector
<
Vertex
>
*
vb
,
QVector
<
unsigned
int
>
&
ib
,
QVector
<
Triangle
>
&
triangles
);
void
ibToTriangles
(
QVector
<
Vertex
>
*
vb
,
QVector
<
unsigned
int
>
&
ib
,
QVector
<
Triangle
>
&
triangles
);
void
buildNeighborsMap
(
QVector
<
Triangle
>
&
triangles
,
QMap
<
Triangle
,
Triangle
::
Neighbors
>
&
neighbors
);
QDebug
operator
<<
(
QDebug
d
,
const
Triangle
&
triangle
);
QDebug
operator
<<
(
QDebug
d
,
const
Triangle
&
triangle
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment