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
Commits
8e9ce68e
Verified
Commit
8e9ce68e
authored
2 years ago
by
Tobias Frisch
Browse files
Options
Downloads
Patches
Plain Diff
Implement optimization via resizable-bar support
Signed-off-by:
Tobias Frisch
<
tfrisch@uni-koblenz.de
>
parent
1eb3389f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/vkcv/BufferManager.cpp
+88
-18
88 additions, 18 deletions
src/vkcv/BufferManager.cpp
src/vkcv/BufferManager.hpp
+1
-0
1 addition, 0 deletions
src/vkcv/BufferManager.hpp
with
89 additions
and
18 deletions
src/vkcv/BufferManager.cpp
+
88
−
18
View file @
8e9ce68e
...
@@ -15,9 +15,55 @@ namespace vkcv {
...
@@ -15,9 +15,55 @@ namespace vkcv {
if
(
!
HandleManager
<
BufferEntry
,
BufferHandle
>::
init
(
core
))
{
if
(
!
HandleManager
<
BufferEntry
,
BufferHandle
>::
init
(
core
))
{
return
false
;
return
false
;
}
}
const
vma
::
Allocator
&
allocator
=
getCore
().
getContext
().
getAllocator
();
const
auto
&
memoryProperties
=
allocator
.
getMemoryProperties
();
const
auto
&
heaps
=
memoryProperties
->
memoryHeaps
;
std
::
vector
<
vk
::
MemoryPropertyFlags
>
heapMemoryFlags
;
heapMemoryFlags
.
resize
(
heaps
.
size
());
for
(
const
auto
&
type
:
memoryProperties
->
memoryTypes
)
{
if
(
type
.
heapIndex
>=
heaps
.
size
())
{
continue
;
}
heapMemoryFlags
[
type
.
heapIndex
]
|=
type
.
propertyFlags
;
}
vk
::
DeviceSize
maxDeviceHeapSize
=
0
;
uint32_t
deviceHeapIndex
=
0
;
for
(
uint32_t
i
=
0
;
i
<
heaps
.
size
();
i
++
)
{
if
(
!
(
heaps
[
i
].
flags
&
vk
::
MemoryHeapFlagBits
::
eDeviceLocal
))
{
continue
;
}
if
(
!
(
heapMemoryFlags
[
i
]
&
vk
::
MemoryPropertyFlagBits
::
eDeviceLocal
))
{
continue
;
}
if
(
heaps
[
i
].
size
<
maxDeviceHeapSize
)
{
continue
;
}
maxDeviceHeapSize
=
heaps
[
i
].
size
;
deviceHeapIndex
=
i
;
}
if
(
heapMemoryFlags
[
deviceHeapIndex
]
&
vk
::
MemoryPropertyFlagBits
::
eHostVisible
)
{
m_resizableBar
=
true
;
}
else
{
m_resizableBar
=
false
;
}
m_stagingBuffer
=
createBuffer
(
TypeGuard
(
1
),
BufferType
::
STAGING
,
m_stagingBuffer
=
createBuffer
(
BufferMemoryType
::
HOST_VISIBLE
,
1024
*
1024
,
false
);
TypeGuard
(
1
),
BufferType
::
STAGING
,
BufferMemoryType
::
HOST_VISIBLE
,
1024
*
1024
,
false
);
return
true
;
return
true
;
}
}
...
@@ -44,7 +90,9 @@ namespace vkcv {
...
@@ -44,7 +90,9 @@ namespace vkcv {
}
}
BufferManager
::
BufferManager
()
noexcept
:
BufferManager
::
BufferManager
()
noexcept
:
HandleManager
<
BufferEntry
,
BufferHandle
>
(),
m_stagingBuffer
(
BufferHandle
())
{}
HandleManager
<
BufferEntry
,
BufferHandle
>
(),
m_resizableBar
(
false
),
m_stagingBuffer
(
BufferHandle
())
{}
BufferManager
::~
BufferManager
()
noexcept
{
BufferManager
::~
BufferManager
()
noexcept
{
clear
();
clear
();
...
@@ -67,15 +115,15 @@ namespace vkcv {
...
@@ -67,15 +115,15 @@ namespace vkcv {
usageFlags
=
vk
::
BufferUsageFlagBits
::
eStorageBuffer
;
usageFlags
=
vk
::
BufferUsageFlagBits
::
eStorageBuffer
;
break
;
break
;
case
BufferType
::
STAGING
:
case
BufferType
::
STAGING
:
usageFlags
=
usageFlags
=
vk
::
BufferUsageFlagBits
::
eTransferSrc
vk
::
BufferUsageFlagBits
::
eTransferSrc
|
vk
::
BufferUsageFlagBits
::
eTransferDst
;
|
vk
::
BufferUsageFlagBits
::
eTransferDst
;
break
;
break
;
case
BufferType
::
INDEX
:
case
BufferType
::
INDEX
:
usageFlags
=
vk
::
BufferUsageFlagBits
::
eIndexBuffer
;
usageFlags
=
vk
::
BufferUsageFlagBits
::
eIndexBuffer
;
break
;
break
;
case
BufferType
::
INDIRECT
:
case
BufferType
::
INDIRECT
:
usageFlags
=
usageFlags
=
vk
::
BufferUsageFlagBits
::
eStorageBuffer
vk
::
BufferUsageFlagBits
::
eStorageBuffer
|
vk
::
BufferUsageFlagBits
::
eIndirectBuffer
;
|
vk
::
BufferUsageFlagBits
::
eIndirectBuffer
;
break
;
break
;
default:
default:
vkcv_log
(
LogLevel
::
WARNING
,
"Unknown buffer type"
);
vkcv_log
(
LogLevel
::
WARNING
,
"Unknown buffer type"
);
...
@@ -92,20 +140,16 @@ namespace vkcv {
...
@@ -92,20 +140,16 @@ namespace vkcv {
const
vma
::
Allocator
&
allocator
=
getCore
().
getContext
().
getAllocator
();
const
vma
::
Allocator
&
allocator
=
getCore
().
getContext
().
getAllocator
();
vk
::
MemoryPropertyFlags
memoryTypeFlags
;
vma
::
MemoryUsage
memoryUsage
;
vma
::
MemoryUsage
memoryUsage
;
bool
mappable
=
false
;
bool
mappable
=
false
;
switch
(
memoryType
)
{
switch
(
memoryType
)
{
case
BufferMemoryType
::
DEVICE_LOCAL
:
case
BufferMemoryType
::
DEVICE_LOCAL
:
memoryTypeFlags
=
vk
::
MemoryPropertyFlagBits
::
eDeviceLocal
;
memoryUsage
=
vma
::
MemoryUsage
::
eAutoPreferDevice
;
memoryUsage
=
vma
::
MemoryUsage
::
eGpuOnly
;
mappable
=
false
;
mappable
=
false
;
break
;
break
;
case
BufferMemoryType
::
HOST_VISIBLE
:
case
BufferMemoryType
::
HOST_VISIBLE
:
memoryTypeFlags
=
vk
::
MemoryPropertyFlagBits
::
eHostVisible
memoryUsage
=
vma
::
MemoryUsage
::
eAutoPreferHost
;
|
vk
::
MemoryPropertyFlagBits
::
eHostCoherent
;
memoryUsage
=
vma
::
MemoryUsage
::
eCpuOnly
;
mappable
=
true
;
mappable
=
true
;
break
;
break
;
default:
default:
...
@@ -114,18 +158,44 @@ namespace vkcv {
...
@@ -114,18 +158,44 @@ namespace vkcv {
mappable
=
false
;
mappable
=
false
;
break
;
break
;
}
}
if
(
type
==
BufferType
::
STAGING
)
{
vma
::
AllocationCreateFlags
allocationCreateFlags
;
memoryUsage
=
vma
::
MemoryUsage
::
eCpuToGpu
;
if
(
mappable
)
{
if
(
type
==
vkcv
::
BufferType
::
STAGING
)
{
allocationCreateFlags
=
vma
::
AllocationCreateFlagBits
::
eHostAccessSequentialWrite
;
}
else
{
allocationCreateFlags
=
vma
::
AllocationCreateFlagBits
::
eHostAccessRandom
;
}
}
else
if
((
m_resizableBar
)
&&
(
memoryType
==
BufferMemoryType
::
DEVICE_LOCAL
))
{
allocationCreateFlags
=
vma
::
AllocationCreateFlagBits
::
eHostAccessAllowTransferInstead
|
vma
::
AllocationCreateFlagBits
::
eHostAccessSequentialWrite
;
}
}
auto
bufferAllocation
=
allocator
.
createBuffer
(
auto
bufferAllocation
=
allocator
.
createBuffer
(
vk
::
BufferCreateInfo
(
createFlags
,
size
,
usageFlags
),
vk
::
BufferCreateInfo
(
createFlags
,
size
,
usageFlags
),
vma
::
AllocationCreateInfo
(
vma
::
AllocationCreateFlags
(),
memoryUsage
,
memoryTypeFlags
,
vma
::
AllocationCreateInfo
(
memoryTypeFlags
,
0
,
vma
::
Pool
(),
nullptr
));
allocationCreateFlags
,
memoryUsage
,
vk
::
MemoryPropertyFlags
(),
vk
::
MemoryPropertyFlags
(),
0
,
vma
::
Pool
(),
nullptr
)
);
vk
::
Buffer
buffer
=
bufferAllocation
.
first
;
vk
::
Buffer
buffer
=
bufferAllocation
.
first
;
vma
::
Allocation
allocation
=
bufferAllocation
.
second
;
vma
::
Allocation
allocation
=
bufferAllocation
.
second
;
const
vk
::
MemoryPropertyFlags
finalMemoryFlags
=
allocator
.
getAllocationMemoryProperties
(
allocation
);
if
(
vk
::
MemoryPropertyFlagBits
::
eHostVisible
&
finalMemoryFlags
)
{
mappable
=
true
;
}
return
add
({
typeGuard
,
type
,
memoryType
,
size
,
buffer
,
allocation
,
mappable
});
return
add
({
typeGuard
,
type
,
memoryType
,
size
,
buffer
,
allocation
,
mappable
});
}
}
...
...
This diff is collapsed.
Click to expand it.
src/vkcv/BufferManager.hpp
+
1
−
0
View file @
8e9ce68e
...
@@ -37,6 +37,7 @@ namespace vkcv {
...
@@ -37,6 +37,7 @@ namespace vkcv {
friend
class
Core
;
friend
class
Core
;
private:
private:
bool
m_resizableBar
;
BufferHandle
m_stagingBuffer
;
BufferHandle
m_stagingBuffer
;
bool
init
(
Core
&
core
)
override
;
bool
init
(
Core
&
core
)
override
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment