Skip to content

Commit 6e76442

Browse files
authored
Fix TextVideoMemBlitter staging buffer issue. (#3419)
* Fix TextVideoMemBlitter staging buffer issue, and broken vkFlushMappedMemoryRange. * Merge flush and reset. * Rename flush_and_reset() to flush(_reset=true).
1 parent dd49a57 commit 6e76442

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

src/renderer_vk.cpp

+8-14
Original file line numberDiff line numberDiff line change
@@ -4454,15 +4454,14 @@ VK_IMPORT_DEVICE
44544454
return createHostBuffer(_size, flags, _buffer, _memory, _data);
44554455
}
44564456

4457-
StagingBufferVK allocFromScratchStagingBuffer(uint32_t _size, uint32_t _align, const void* _data = NULL, bool _tryScratch = true)
4457+
StagingBufferVK allocFromScratchStagingBuffer(uint32_t _size, uint32_t _align, const void* _data = NULL)
44584458
{
44594459
BGFX_PROFILER_SCOPE("allocFromScratchStagingBuffer", kColorResource);
44604460

44614461
StagingBufferVK result;
44624462
ScratchBufferVK &scratch = m_scratchStagingBuffer[m_cmd.m_currentFrameInFlight];
44634463

4464-
if (_tryScratch
4465-
&& _size <= BGFX_CONFIG_MAX_STAGING_SIZE_FOR_SCRATCH_BUFFER)
4464+
if (_size <= BGFX_CONFIG_MAX_STAGING_SIZE_FOR_SCRATCH_BUFFER)
44664465
{
44674466
const uint32_t scratchOffset = scratch.alloc(_size, _align);
44684467

@@ -4734,18 +4733,12 @@ VK_DESTROY
47344733

47354734
void ScratchBufferVK::destroy()
47364735
{
4737-
reset();
4738-
47394736
vkUnmapMemory(s_renderVK->m_device, m_deviceMem);
47404737

47414738
s_renderVK->release(m_buffer);
47424739
s_renderVK->release(m_deviceMem);
47434740
}
47444741

4745-
void ScratchBufferVK::reset()
4746-
{
4747-
m_pos = 0;
4748-
}
47494742

47504743
uint32_t ScratchBufferVK::alloc(uint32_t _size, uint32_t _minAlign)
47514744
{
@@ -4775,7 +4768,7 @@ VK_DESTROY
47754768
}
47764769

47774770

4778-
void ScratchBufferVK::flush()
4771+
void ScratchBufferVK::flush(bool _reset)
47794772
{
47804773
const VkPhysicalDeviceLimits& deviceLimits = s_renderVK->m_deviceProperties.limits;
47814774
VkDevice device = s_renderVK->m_device;
@@ -4790,6 +4783,10 @@ VK_DESTROY
47904783
range.offset = 0;
47914784
range.size = size;
47924785
VK_CHECK(vkFlushMappedMemoryRanges(device, 1, &range) );
4786+
4787+
if (_reset) {
4788+
m_pos = 0;
4789+
}
47934790
}
47944791

47954792
void BufferVK::create(VkCommandBuffer _commandBuffer, uint32_t _size, void* _data, uint16_t _flags, bool _vertex, uint32_t _stride)
@@ -4840,7 +4837,7 @@ VK_DESTROY
48404837
BGFX_PROFILER_SCOPE("BufferVK::update", kColorFrame);
48414838
BX_UNUSED(_discard);
48424839

4843-
StagingBufferVK stagingBuffer = s_renderVK->allocFromScratchStagingBuffer(_size, 8, _data, !_discard);
4840+
StagingBufferVK stagingBuffer = s_renderVK->allocFromScratchStagingBuffer(_size, 8, _data);
48444841

48454842
VkBufferCopy region;
48464843
region.srcOffset = stagingBuffer.m_offset;
@@ -8502,10 +8499,7 @@ VK_DESTROY
85028499
const uint64_t f3 = BGFX_STATE_BLEND_INV_FACTOR<<4;
85038500

85048501
ScratchBufferVK& scratchBuffer = m_scratchBuffer[m_cmd.m_currentFrameInFlight];
8505-
scratchBuffer.reset();
8506-
85078502
ScratchBufferVK& scratchStagingBuffer = m_scratchStagingBuffer[m_cmd.m_currentFrameInFlight];
8508-
scratchStagingBuffer.reset();
85098503

85108504
setMemoryBarrier(
85118505
m_commandBuffer

src/renderer_vk.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,9 @@ VK_DESTROY_FUNC(DescriptorSet);
398398
void createUniform(uint32_t _size, uint32_t _count);
399399
void createStaging(uint32_t _size);
400400
void destroy();
401-
void reset();
402401
uint32_t alloc(uint32_t _size, uint32_t _minAlign = 1);
403402
uint32_t write(const void* _data, uint32_t _size, uint32_t _minAlign = 1);
404-
void flush();
403+
void flush(bool _reset = true);
405404

406405
VkBuffer m_buffer;
407406
VkDeviceMemory m_deviceMem;

0 commit comments

Comments
 (0)