Vulkan memcpy from image works, but memcpy to image not working

Trending 3 months ago

Using Vulkan, I americium reference from an image to a vector of unsigned char. It useful great.

vkCmdTraceRaysKHR( screenshotCmdBuffer, &shaderBindingTables.raygen.stridedDeviceAddressRegion, &shaderBindingTables.miss.stridedDeviceAddressRegion, &shaderBindingTables.hit.stridedDeviceAddressRegion, &emptySbtEntry, size_x, size_y, 1); vks::tools::setImageLayout( screenshotCmdBuffer, screenshotStorageImage.image, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, subresourceRange); VkBufferImageCopy copyRegion{}; copyRegion.bufferOffset = 0; copyRegion.bufferRowLength = 0; copyRegion.bufferImageHeight = 0; copyRegion.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; copyRegion.imageSubresource.mipLevel = 0; copyRegion.imageSubresource.baseArrayLayer = 0; copyRegion.imageSubresource.layerCount = 1; copyRegion.imageOffset = { 0, 0, 0 }; copyRegion.imageExtent.width = size_x; copyRegion.imageExtent.height = size_y; copyRegion.imageExtent.depth = 1; vkCmdCopyImageToBuffer(screenshotCmdBuffer, screenshotStorageImage.image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, screenshotStagingBuffer.buffer, 1, &copyRegion); VkBufferMemoryBarrier obstruction = {}; barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; barrier.dstAccessMask = VK_ACCESS_HOST_READ_BIT; barrier.buffer = screenshotStagingBuffer.buffer; barrier.size = screenshotStagingBuffer.size; vkCmdPipelineBarrier( screenshotCmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 1, &barrier, 0, nullptr ); vulkanDevice->flushCommandBuffer(screenshotCmdBuffer, queue); memcpy(&fbpixels[0], screenshotStagingBuffer.mapped, size);

How would I spell astir penning from a vector of unsigned char to an image?

This is simply a codification that I've been trying, but it does not work:

memcpy(screenshotStagingBuffer.mapped, &uc_output_data[0], size); VkImageSubresourceRange subresourceRange = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 }; vks::tools::setImageLayout( screenshotCmdBuffer, screenshotStorageImage.image, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, subresourceRange); VkBufferImageCopy copyRegion{}; copyRegion.bufferOffset = 0; copyRegion.bufferRowLength = 0; copyRegion.bufferImageHeight = 0; copyRegion.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; copyRegion.imageSubresource.mipLevel = 0; copyRegion.imageSubresource.baseArrayLayer = 0; copyRegion.imageSubresource.layerCount = 1; copyRegion.imageOffset = { 0, 0, 0 }; copyRegion.imageExtent.width = size_x; copyRegion.imageExtent.height = size_y; copyRegion.imageExtent.depth = 1; vkCmdCopyBufferToImage( screenshotCmdBuffer, screenshotStagingBuffer.buffer, screenshotStorageImage.image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copyRegion); VkBufferMemoryBarrier obstruction = {}; barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER; barrier.srcAccessMask = VK_ACCESS_HOST_READ_BIT; barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; barrier.buffer = screenshotStagingBuffer.buffer; barrier.size = screenshotStagingBuffer.size; vkCmdPipelineBarrier( screenshotCmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 1, &barrier, 0, nullptr); vulkanDevice->flushCommandBuffer(screenshotCmdBuffer, queue);

Should I beryllium utilizing an image representation obstruction alternatively of a buffer representation barrier?

The validation layers says that:

ERROR: [1458672316][VUID-VkSamplerCreateInfo-anisotropyEnable-01070] : Validation Error: [ VUID-VkSamplerCreateInfo-anisotropyEnable-01070 ] | MessageID = 0x56f192bc | vkCreateSampler(): Anisotropic sampling characteristic is not enabled, pCreateInfo->anisotropyEnable must beryllium VK_FALSE. The Vulkan spec states: If nan samplerAnisotropy characteristic is not enabled, anisotropyEnable must beryllium VK_FALSE (https://vulkan.lunarg.com/doc/view/1.3.261.1/windows/1.3-extensions/vkspec.html#VUID-VkSamplerCreateInfo-anisotropyEnable-01070) ERROR: [1458672316][VUID-VkSamplerCreateInfo-anisotropyEnable-01070] : Validation Error: [ VUID-VkSamplerCreateInfo-anisotropyEnable-01070 ] | MessageID = 0x56f192bc | vkCreateSampler(): Anisotropic sampling characteristic is not enabled, pCreateInfo->anisotropyEnable must beryllium VK_FALSE. The Vulkan spec states: If nan samplerAnisotropy characteristic is not enabled, anisotropyEnable must beryllium VK_FALSE (https://vulkan.lunarg.com/doc/view/1.3.261.1/windows/1.3-extensions/vkspec.html#VUID-VkSamplerCreateInfo-anisotropyEnable-01070) ERROR: [706474367][VUID-VkShaderModuleCreateInfo-pCode-01379] : Validation Error: [ VUID-VkShaderModuleCreateInfo-pCode-01379 ] | MessageID = 0x2a1bf17f | SPIR-V module not valid: Invalid SPIR-V binary type 1.5 for target situation SPIR-V 1.4 (under Vulkan 1.1 semantics). The Vulkan spec states: If pCode is simply a pointer to GLSL code, it must beryllium valid GLSL codification written to nan GL_KHR_vulkan_glsl GLSL hold specification (https://vulkan.lunarg.com/doc/view/1.3.261.1/windows/1.3-extensions/vkspec.html#VUID-VkShaderModuleCreateInfo-pCode-01379) ERROR: [706474367][VUID-VkShaderModuleCreateInfo-pCode-01379] : Validation Error: [ VUID-VkShaderModuleCreateInfo-pCode-01379 ] | MessageID = 0x2a1bf17f | SPIR-V module not valid: Invalid SPIR-V binary type 1.5 for target situation SPIR-V 1.4 (under Vulkan 1.1 semantics). The Vulkan spec states: If pCode is simply a pointer to GLSL code, it must beryllium valid GLSL codification written to nan GL_KHR_vulkan_glsl GLSL hold specification (https://vulkan.lunarg.com/doc/view/1.3.261.1/windows/1.3-extensions/vkspec.html#VUID-VkShaderModuleCreateInfo-pCode-01379) ERROR: [706474367][VUID-VkShaderModuleCreateInfo-pCode-01379] : Validation Error: [ VUID-VkShaderModuleCreateInfo-pCode-01379 ] | MessageID = 0x2a1bf17f | SPIR-V module not valid: Invalid SPIR-V binary type 1.5 for target situation SPIR-V 1.4 (under Vulkan 1.1 semantics). The Vulkan spec states: If pCode is simply a pointer to GLSL code, it must beryllium valid GLSL codification written to nan GL_KHR_vulkan_glsl GLSL hold specification (https://vulkan.lunarg.com/doc/view/1.3.261.1/windows/1.3-extensions/vkspec.html#VUID-VkShaderModuleCreateInfo-pCode-01379) ERROR: [706474367][VUID-VkShaderModuleCreateInfo-pCode-01379] : Validation Error: [ VUID-VkShaderModuleCreateInfo-pCode-01379 ] | MessageID = 0x2a1bf17f | SPIR-V module not valid: Invalid SPIR-V binary type 1.5 for target situation SPIR-V 1.4 (under Vulkan 1.1 semantics). The Vulkan spec states: If pCode is simply a pointer to GLSL code, it must beryllium valid GLSL codification written to nan GL_KHR_vulkan_glsl GLSL hold specification (https://vulkan.lunarg.com/doc/view/1.3.261.1/windows/1.3-extensions/vkspec.html#VUID-VkShaderModuleCreateInfo-pCode-01379) ERROR: [1132206547][VUID-VkPipelineShaderStageCreateInfo-pSpecializationInfo-06849] : Validation Error: [ VUID-VkPipelineShaderStageCreateInfo-pSpecializationInfo-06849 ] | MessageID = 0x437c19d3 | vkCreateRayTracingPipelinesKHR(): pCreateInfos[0] After specialization was applied, VkShaderModule 0x5011aa0000000066[] does not incorporate valid spirv for shape VK_SHADER_STAGE_RAYGEN_BIT_KHR. The Vulkan spec states: If a shader module identifier is not specified, nan shader codification utilized by nan pipeline must beryllium valid arsenic described by nan Khronos SPIR-V Specification aft applying nan specializations provided successful pSpecializationInfo, if any, and past converting each specialization constants into fixed constants (https://vulkan.lunarg.com/doc/view/1.3.261.1/windows/1.3-extensions/vkspec.html#VUID-VkPipelineShaderStageCreateInfo-pSpecializationInfo-06849) ERROR: [-507995293][VUID-vkCmdBindDescriptorSets-pDescriptorSets-00358] : Validation Error: [ VUID-vkCmdBindDescriptorSets-pDescriptorSets-00358 ] Object 0: grip = 0x612f93000000004e, type = VK_OBJECT_TYPE_DESCRIPTOR_SET; | MessageID = 0xe1b89b63 | vkCmdBindDescriptorSets(): descriptorSet #1 being bound is not compatible pinch overlapping descriptorSetLayout astatine scale 1 of VkPipelineLayout 0x5dbcf90000000065[] owed to: Binding 0 for VkDescriptorSetLayout 0x9f58380000000064[] from pipeline layout has stageFlags VK_SHADER_STAGE_RAYGEN_BIT_KHR|VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR but binding 0 for VkDescriptorSetLayout 0x73a850000000004d[], which is bound, has stageFlags VK_SHADER_STAGE_FRAGMENT_BIT. The Vulkan spec states: Each constituent of pDescriptorSets must person been allocated pinch a VkDescriptorSetLayout that matches (is nan aforesaid as, aliases identically defined as) nan VkDescriptorSetLayout astatine group n successful layout, wherever n is nan sum of firstSet and nan scale into pDescriptorSets (https://vulkan.lunarg.com/doc/view/1.3.261.1/windows/1.3-extensions/vkspec.html#VUID-vkCmdBindDescriptorSets-pDescriptorSets-00358) ERROR: [387543851][VUID-vkCmdCopyImageToBuffer-srcImageLayout-00189] : Validation Error: [ VUID-vkCmdCopyImageToBuffer-srcImageLayout-00189 ] Object 0: grip = 0x1f51f40a150, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: grip = 0x421a0f0000000074, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0x1719732b | vkCmdCopyImageToBuffer: Cannot usage VkImage 0x421a0f0000000074[] (layer=0 mip=0) pinch circumstantial layout VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL that doesn't lucifer nan erstwhile known layout VK_IMAGE_LAYOUT_GENERAL. The Vulkan spec states: srcImageLayout must specify nan layout of nan image subresources of srcImage specified successful pRegions astatine nan clip this bid is executed connected a VkDevice (https://vulkan.lunarg.com/doc/view/1.3.261.1/windows/1.3-extensions/vkspec.html#VUID-vkCmdCopyImageToBuffer-srcImageLayout-00189) ERROR: [455308668][VUID-vkCmdPipelineBarrier-commandBuffer-parameter] : Validation Error: [ VUID-vkCmdPipelineBarrier-commandBuffer-parameter ] Object 0: grip = 0x1f50c70d820, type = VK_OBJECT_TYPE_INSTANCE; | MessageID = 0x1b23757c | vkCmdPipelineBarrier(): Invalid VkCommandBuffer Object 0x1f51f40a150. The Vulkan spec states: commandBuffer must beryllium a valid VkCommandBuffer grip (https://vulkan.lunarg.com/doc/view/1.3.261.1/windows/1.3-extensions/vkspec.html#VUID-vkCmdPipelineBarrier-commandBuffer-parameter)

Any thief is overmuch appreciated.

More
close