diff --git a/vkplayer.cpp b/vkplayer.cpp index 610852f..afcdc81 100644 --- a/vkplayer.cpp +++ b/vkplayer.cpp @@ -53,6 +53,7 @@ struct DecoderImage VkDeviceMemory image_memory; // todo: deduplicate shared parameters VkDeviceSize memory_offset_plane0, memory_offset_plane1; + VkDeviceSize stride0, stride1; VkImageView image_view; unsigned char *pMappedData; }; @@ -130,6 +131,13 @@ void CreateSoftwareImage(VkInstance inst, VulkanDevice &dev, DecoderImage &image VkCommandBuffer cbuf = dev.CreateCommandBuffer(); VulkanTexture::SetImageLayout(cbuf, image.image, VK_IMAGE_LAYOUT_PREINITIALIZED, VK_IMAGE_LAYOUT_GENERAL, { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 }); dev.FlushCommandBuffer(cbuf,dev.defautQueue); + VkImageSubresource plane = {VK_IMAGE_ASPECT_PLANE_0_BIT}; + VkSubresourceLayout layout = {}; + vkGetImageSubresourceLayout(dev.device, image.image, &plane, &layout); + image.stride0 = layout.rowPitch; + plane.aspectMask = VK_IMAGE_ASPECT_PLANE_1_BIT; + vkGetImageSubresourceLayout(dev.device, image.image, &plane, &layout); + image.stride1 = layout.rowPitch; } #define MAX_DECODER_FRAMES 4 @@ -192,13 +200,14 @@ static void *DecoderThread(void*) idx++; DecoderImage &img = gFF.images[idx & 3]; // todo: wait fence? - memcpy(img.pMappedData + img.memory_offset_plane0 , frame->data[0], frame->linesize[0] * frame->height); + for(int i = 0; i < frame->height; i++) + memcpy(img.pMappedData + img.memory_offset_plane0 + img.stride0 * i, frame->data[0] + frame->linesize[0]*i, frame->linesize[0]); // ffmpeg cannot NV12???? for(int i = 0; i < frame->height / 2; i++) for(int j = 0; j < frame->linesize[1]; j++) { - *(img.pMappedData + img.memory_offset_plane1 + frame->linesize[1]*2*i +j * 2) = *(frame->data[1] + frame->linesize[1]* i + j); - *(img.pMappedData + img.memory_offset_plane1 + frame->linesize[1]*2*i +j * 2+1) = *(frame->data[2] + frame->linesize[2]* i + j); + *(img.pMappedData + img.memory_offset_plane1 + img.stride1*i +j * 2) = *(frame->data[1] + frame->linesize[1]* i + j); + *(img.pMappedData + img.memory_offset_plane1 + img.stride1*i +j * 2+1) = *(frame->data[2] + frame->linesize[2]* i + j); } //memcpy(img.pMappedData + img.memory_offset_plane1 , frame->data[1], frame->linesize[1] * frame->height/2); //assert(!frame->data[2]);