Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
Vulkan render to OpenGL texture
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Antonio Ospite
Vulkan render to OpenGL texture
Commits
711743ad
Commit
711743ad
authored
3 years ago
by
Sascha Willems
Browse files
Options
Downloads
Patches
Plain Diff
Refactoring
parent
24158377
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/texturesparseresidency/texturesparseresidency.cpp
+26
-55
26 additions, 55 deletions
examples/texturesparseresidency/texturesparseresidency.cpp
examples/texturesparseresidency/texturesparseresidency.h
+1
-0
1 addition, 0 deletions
examples/texturesparseresidency/texturesparseresidency.h
with
27 additions
and
55 deletions
examples/texturesparseresidency/texturesparseresidency.cpp
+
26
−
55
View file @
711743ad
...
@@ -195,7 +195,7 @@ void VulkanExample::prepareSparseTexture(uint32_t width, uint32_t height, uint32
...
@@ -195,7 +195,7 @@ void VulkanExample::prepareSparseTexture(uint32_t width, uint32_t height, uint32
texture
.
device
=
vulkanDevice
->
logicalDevice
;
texture
.
device
=
vulkanDevice
->
logicalDevice
;
texture
.
width
=
width
;
texture
.
width
=
width
;
texture
.
height
=
height
;
texture
.
height
=
height
;
texture
.
mipLevels
=
floor
(
log2
(
std
::
max
(
width
,
height
)))
+
1
;
texture
.
mipLevels
=
static_cast
<
uint32_t
>
(
floor
(
log2
(
std
::
max
(
width
,
height
)))
+
1
)
;
texture
.
layerCount
=
layerCount
;
texture
.
layerCount
=
layerCount
;
texture
.
format
=
format
;
texture
.
format
=
format
;
...
@@ -708,24 +708,12 @@ void VulkanExample::render()
...
@@ -708,24 +708,12 @@ void VulkanExample::render()
}
}
}
}
void
VulkanExample
::
uploadContent
(
VirtualTexturePage
page
,
VkImage
image
)
// Fills a buffer with random colors
void
VulkanExample
::
randomPattern
(
uint8_t
*
buffer
,
uint32_t
width
,
uint32_t
height
)
{
{
// Generate some random image data and upload as a buffer
const
size_t
bufferSize
=
4
*
page
.
extent
.
width
*
page
.
extent
.
height
;
vks
::
Buffer
imageBuffer
;
VK_CHECK_RESULT
(
vulkanDevice
->
createBuffer
(
VK_BUFFER_USAGE_TRANSFER_SRC_BIT
,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
&
imageBuffer
,
bufferSize
));
imageBuffer
.
map
();
// Fill buffer with random colors
std
::
random_device
rd
;
std
::
random_device
rd
;
std
::
mt19937
rndEngine
(
rd
());
std
::
mt19937
rndEngine
(
rd
());
std
::
uniform_int_distribution
<
uint32_t
>
rndDist
(
0
,
255
);
std
::
uniform_int_distribution
<
uint32_t
>
rndDist
(
0
,
255
);
uint8_t
*
data
=
(
uint8_t
*
)
imageBuffer
.
mapped
;
uint8_t
rndVal
[
4
]
=
{
0
,
0
,
0
,
0
};
uint8_t
rndVal
[
4
]
=
{
0
,
0
,
0
,
0
};
while
(
rndVal
[
0
]
+
rndVal
[
1
]
+
rndVal
[
2
]
<
10
)
{
while
(
rndVal
[
0
]
+
rndVal
[
1
]
+
rndVal
[
2
]
<
10
)
{
rndVal
[
0
]
=
(
uint8_t
)
rndDist
(
rndEngine
);
rndVal
[
0
]
=
(
uint8_t
)
rndDist
(
rndEngine
);
...
@@ -733,18 +721,31 @@ void VulkanExample::uploadContent(VirtualTexturePage page, VkImage image)
...
@@ -733,18 +721,31 @@ void VulkanExample::uploadContent(VirtualTexturePage page, VkImage image)
rndVal
[
2
]
=
(
uint8_t
)
rndDist
(
rndEngine
);
rndVal
[
2
]
=
(
uint8_t
)
rndDist
(
rndEngine
);
}
}
rndVal
[
3
]
=
255
;
rndVal
[
3
]
=
255
;
for
(
uint32_t
y
=
0
;
y
<
height
;
y
++
)
{
for
(
uint32_t
y
=
0
;
y
<
page
.
extent
.
height
;
y
++
)
for
(
uint32_t
x
=
0
;
x
<
width
;
x
++
)
{
{
for
(
uint32_t
c
=
0
;
c
<
4
;
c
++
,
++
buffer
)
{
for
(
uint32_t
x
=
0
;
x
<
page
.
extent
.
width
;
x
++
)
*
buffer
=
rndVal
[
c
];
{
}
for
(
uint32_t
c
=
0
;
c
<
4
;
c
++
,
++
data
)
{
*
data
=
rndVal
[
c
];
}
}
}
}
}
}
void
VulkanExample
::
uploadContent
(
VirtualTexturePage
page
,
VkImage
image
)
{
// Generate some random image data and upload as a buffer
const
size_t
bufferSize
=
4
*
page
.
extent
.
width
*
page
.
extent
.
height
;
vks
::
Buffer
imageBuffer
;
VK_CHECK_RESULT
(
vulkanDevice
->
createBuffer
(
VK_BUFFER_USAGE_TRANSFER_SRC_BIT
,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
&
imageBuffer
,
bufferSize
));
imageBuffer
.
map
();
uint8_t
*
data
=
(
uint8_t
*
)
imageBuffer
.
mapped
;
randomPattern
(
data
,
page
.
extent
.
height
,
page
.
extent
.
width
);
VkCommandBuffer
copyCmd
=
vulkanDevice
->
createCommandBuffer
(
VK_COMMAND_BUFFER_LEVEL_PRIMARY
,
true
);
VkCommandBuffer
copyCmd
=
vulkanDevice
->
createCommandBuffer
(
VK_COMMAND_BUFFER_LEVEL_PRIMARY
,
true
);
vks
::
tools
::
setImageLayout
(
copyCmd
,
image
,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
,
texture
.
subRange
,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
,
VK_PIPELINE_STAGE_TRANSFER_BIT
);
vks
::
tools
::
setImageLayout
(
copyCmd
,
image
,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
,
texture
.
subRange
,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
,
VK_PIPELINE_STAGE_TRANSFER_BIT
);
VkBufferImageCopy
region
{};
VkBufferImageCopy
region
{};
...
@@ -821,7 +822,6 @@ void VulkanExample::fillMipTail()
...
@@ -821,7 +822,6 @@ void VulkanExample::fillMipTail()
const
uint32_t
width
=
std
::
max
(
texture
.
width
>>
i
,
1u
);
const
uint32_t
width
=
std
::
max
(
texture
.
width
>>
i
,
1u
);
const
uint32_t
height
=
std
::
max
(
texture
.
height
>>
i
,
1u
);
const
uint32_t
height
=
std
::
max
(
texture
.
height
>>
i
,
1u
);
const
uint32_t
depth
=
1
;
// Generate some random image data and upload as a buffer
// Generate some random image data and upload as a buffer
const
size_t
bufferSize
=
4
*
width
*
height
;
const
size_t
bufferSize
=
4
*
width
*
height
;
...
@@ -839,36 +839,7 @@ void VulkanExample::fillMipTail()
...
@@ -839,36 +839,7 @@ void VulkanExample::fillMipTail()
std
::
mt19937
rndEngine
(
rd
());
std
::
mt19937
rndEngine
(
rd
());
std
::
uniform_int_distribution
<
uint32_t
>
rndDist
(
0
,
255
);
std
::
uniform_int_distribution
<
uint32_t
>
rndDist
(
0
,
255
);
uint8_t
*
data
=
(
uint8_t
*
)
imageBuffer
.
mapped
;
uint8_t
*
data
=
(
uint8_t
*
)
imageBuffer
.
mapped
;
uint8_t
rndVal
[
4
]
=
{
0
,
0
,
0
,
0
};
randomPattern
(
data
,
width
,
height
);
while
(
rndVal
[
0
]
+
rndVal
[
1
]
+
rndVal
[
2
]
<
10
)
{
rndVal
[
0
]
=
(
uint8_t
)
rndDist
(
rndEngine
);
rndVal
[
1
]
=
(
uint8_t
)
rndDist
(
rndEngine
);
rndVal
[
2
]
=
(
uint8_t
)
rndDist
(
rndEngine
);
}
rndVal
[
3
]
=
255
;
switch
(
mipLevel
)
{
case
0
:
rndVal
[
0
]
=
rndVal
[
1
]
=
rndVal
[
2
]
=
255
;
break
;
case
1
:
rndVal
[
0
]
=
rndVal
[
1
]
=
rndVal
[
2
]
=
200
;
break
;
case
2
:
rndVal
[
0
]
=
rndVal
[
1
]
=
rndVal
[
2
]
=
150
;
break
;
}
for
(
uint32_t
y
=
0
;
y
<
height
;
y
++
)
{
for
(
uint32_t
x
=
0
;
x
<
width
;
x
++
)
{
for
(
uint32_t
c
=
0
;
c
<
4
;
c
++
,
++
data
)
{
*
data
=
rndVal
[
c
];
}
}
}
VkCommandBuffer
copyCmd
=
vulkanDevice
->
createCommandBuffer
(
VK_COMMAND_BUFFER_LEVEL_PRIMARY
,
true
);
VkCommandBuffer
copyCmd
=
vulkanDevice
->
createCommandBuffer
(
VK_COMMAND_BUFFER_LEVEL_PRIMARY
,
true
);
vks
::
tools
::
setImageLayout
(
copyCmd
,
texture
.
image
,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
,
texture
.
subRange
,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
,
VK_PIPELINE_STAGE_TRANSFER_BIT
);
vks
::
tools
::
setImageLayout
(
copyCmd
,
texture
.
image
,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
,
texture
.
subRange
,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
,
VK_PIPELINE_STAGE_TRANSFER_BIT
);
...
@@ -877,7 +848,7 @@ void VulkanExample::fillMipTail()
...
@@ -877,7 +848,7 @@ void VulkanExample::fillMipTail()
region
.
imageSubresource
.
layerCount
=
1
;
region
.
imageSubresource
.
layerCount
=
1
;
region
.
imageSubresource
.
mipLevel
=
i
;
region
.
imageSubresource
.
mipLevel
=
i
;
region
.
imageOffset
=
{};
region
.
imageOffset
=
{};
region
.
imageExtent
=
{
width
,
height
,
depth
};
region
.
imageExtent
=
{
width
,
height
,
1
};
vkCmdCopyBufferToImage
(
copyCmd
,
imageBuffer
.
buffer
,
texture
.
image
,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
,
1
,
&
region
);
vkCmdCopyBufferToImage
(
copyCmd
,
imageBuffer
.
buffer
,
texture
.
image
,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
,
1
,
&
region
);
vks
::
tools
::
setImageLayout
(
copyCmd
,
texture
.
image
,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
,
texture
.
subRange
,
VK_PIPELINE_STAGE_TRANSFER_BIT
,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
);
vks
::
tools
::
setImageLayout
(
copyCmd
,
texture
.
image
,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
,
texture
.
subRange
,
VK_PIPELINE_STAGE_TRANSFER_BIT
,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
);
vulkanDevice
->
flushCommandBuffer
(
copyCmd
,
queue
);
vulkanDevice
->
flushCommandBuffer
(
copyCmd
,
queue
);
...
...
This diff is collapsed.
Click to expand it.
examples/texturesparseresidency/texturesparseresidency.h
+
1
−
0
View file @
711743ad
...
@@ -101,6 +101,7 @@ public:
...
@@ -101,6 +101,7 @@ public:
~
VulkanExample
();
~
VulkanExample
();
virtual
void
getEnabledFeatures
();
virtual
void
getEnabledFeatures
();
glm
::
uvec3
alignedDivision
(
const
VkExtent3D
&
extent
,
const
VkExtent3D
&
granularity
);
glm
::
uvec3
alignedDivision
(
const
VkExtent3D
&
extent
,
const
VkExtent3D
&
granularity
);
void
randomPattern
(
uint8_t
*
buffer
,
uint32_t
width
,
uint32_t
height
);
void
prepareSparseTexture
(
uint32_t
width
,
uint32_t
height
,
uint32_t
layerCount
,
VkFormat
format
);
void
prepareSparseTexture
(
uint32_t
width
,
uint32_t
height
,
uint32_t
layerCount
,
VkFormat
format
);
// @todo: move to dtor of texture
// @todo: move to dtor of texture
void
destroyTextureImage
(
SparseTexture
texture
);
void
destroyTextureImage
(
SparseTexture
texture
);
...
...
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