Skip to content

Commit 4d04bcc

Browse files
authored
Merge pull request #132 from leegao/bc6
Fix BC6h staging buffer size calculation to use the correct texel str…
2 parents 0309dd8 + 2198a9e commit 4d04bcc

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/vulkan/wrapper/artifacts.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void RecordBCnArtifacts(struct wrapper_device* device, VkFormat original_format,
5555
};
5656
VkResult result = WCHECK(MapMemory2KHR((VkDevice) device, &mapInfoSrc, &srcData));
5757
if (result != VK_SUCCESS) {
58-
WLOGE("ERROR: Failed to map srcBuffer memory: %d", result);
58+
WLOGE("Failed to map srcBuffer memory: %d", result);
5959
} else {
6060
int w = region->bufferRowLength ? region->bufferRowLength : region->imageExtent.width;
6161
int h = region->bufferImageHeight ? region->bufferImageHeight : region->imageExtent.height;
@@ -75,16 +75,27 @@ void RecordBCnArtifacts(struct wrapper_device* device, VkFormat original_format,
7575
} else if (wbuf->memory == VK_NULL_HANDLE) {
7676
WLOGE("dstBuffer not bound, skipping (decode_id=%d)", decode_id);
7777
} else {
78+
// Invalidate the memory to be visible to the host in case this was decoded via the compute shader
79+
VkMappedMemoryRange flushRange = {
80+
.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
81+
.memory = wbuf->memory,
82+
.offset = 0,
83+
.size = VK_WHOLE_SIZE,
84+
};
85+
VkResult result = WCHECK(InvalidateMappedMemoryRanges((VkDevice) device, 1, &flushRange));
86+
if (result != VK_SUCCESS) {
87+
WLOGE("Failed to flush dstBuffer memory: %d", result);
88+
}
7889
void* dstData;
7990
VkMemoryMapInfoKHR mapInfoSrc = {
8091
.sType = VK_STRUCTURE_TYPE_MEMORY_MAP_INFO_KHR,
8192
.memory = wbuf->memory,
8293
.offset = 0,
8394
.size = VK_WHOLE_SIZE,
8495
};
85-
VkResult result = WCHECK(MapMemory2KHR((VkDevice) device, &mapInfoSrc, &dstData));
96+
result = WCHECK(MapMemory2KHR((VkDevice) device, &mapInfoSrc, &dstData));
8697
if (result != VK_SUCCESS) {
87-
WLOGE("ERROR: Failed to map dstBuffer memory: %d", result);
98+
WLOGE("Failed to map dstBuffer memory: %d", result);
8899
} else {
89100
int block_size = get_bc_target_size(device->physical, original_format);
90101
auto fd = open_log_file("_dst.dat", original_format, decode_id, "wb");

src/vulkan/wrapper/wrapper_device.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ static VkResult HostSideDecompression(
13921392
wrapper_buffer* srcBuffer,
13931393
VkDeviceMemory dstMemory,
13941394
const VkBufferImageCopy* region,
1395-
VkFormat dstFormat
1395+
VkFormat in_format
13961396
) {
13971397
// Map the source buffer
13981398
void* srcData;
@@ -1413,9 +1413,8 @@ static VkResult HostSideDecompression(
14131413
VkMemoryMapInfoKHR mapInfoDst = {
14141414
.sType = VK_STRUCTURE_TYPE_MEMORY_MAP_INFO_KHR,
14151415
.memory = dstMemory,
1416-
.offset = 0, // Assuming dstMemory is large enough to hold the decompressed
1417-
// TODO: FIX THIS for non rgba8 data
1418-
.size = region->imageExtent.width * region->imageExtent.height * 4, // 4 bytes per pixel for RGBA
1416+
.offset = 0,
1417+
.size = region->imageExtent.width * region->imageExtent.height * get_bc_target_size(_device->physical, in_format),
14191418
};
14201419
result = WCHECK(MapMemory2KHR((VkDevice) _device, &mapInfoDst, &dstData));
14211420
if (result != VK_SUCCESS) {
@@ -1424,7 +1423,7 @@ static VkResult HostSideDecompression(
14241423

14251424
// Decompress the data from srcData to dstData
14261425
BCnDecompression(
1427-
dstFormat,
1426+
in_format,
14281427
srcData,
14291428
dstData,
14301429
region
@@ -1838,7 +1837,7 @@ WRAPPER_CmdCopyBufferToImage(VkCommandBuffer commandBuffer,
18381837
if (!use_image_view) {
18391838
result = CreateStagingBuffer(
18401839
_device,
1841-
region->imageExtent.width * region->imageExtent.height * region->imageExtent.depth * 4,
1840+
region->imageExtent.width * region->imageExtent.height * get_bc_target_size(_device->physical, wimg->original_format),
18421841
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
18431842
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
18441843
&stagingBuffer, &stagingBufferMemory);
@@ -1848,6 +1847,7 @@ WRAPPER_CmdCopyBufferToImage(VkCommandBuffer commandBuffer,
18481847
}
18491848

18501849
// TODO: track these using the fence/semaphore for the submitted queue
1850+
// This should be safe to do now with the queue synchronization, check with vvl
18511851
WLOGD("Tracking new staging buffer for image %d", wimg->obj_id);
18521852
TRACK_STAGING(_device, BUFFER, stagingBuffer, wimg);
18531853
TRACK_STAGING(_device, DEVICE_MEMORY, stagingBufferMemory, wimg);

0 commit comments

Comments
 (0)