Allocate some reconstruction source

This commit is contained in:
mittorn 2024-10-30 04:01:05 +03:00
parent 5c6c01e266
commit b4eca34dfc

View file

@ -263,6 +263,59 @@ static void SetupFFMpeg(VkInstance inst, VulkanDevice &dev, unsigned int width,
// decoder outputs frames mapped to random VkImage from decoder pool
// reconstruction source frames match decoder frame index (but not image index)
#define RECONSTRUCTION_SOURCE_FRAMES 4
struct ReconsructionSource
{
VkImage image;
VkDeviceMemory image_memory;
VkImageView image_view;
unsigned char *pMappedData;
};
static struct
{
ReconsructionSource sources[RECONSTRUCTION_SOURCE_FRAMES];
unsigned int frame_idx;
FILE *reconstructionStream;
// todo: separate thread
// todo: separate queue family if needed
// todo: staging buffer when linear not supported
} gReconstruction;
void SetupReconstructionImages(VulkanDevice &dev, VkFormat format, unsigned int width, unsigned int height)
{
for(int i = 0; i < RECONSTRUCTION_SOURCE_FRAMES; i++)
{
ReconsructionSource &image = gReconstruction.sources[i];
CallWith(Image2dInfo(VK_IMAGE_USAGE_SAMPLED_BIT, format, width, height,
$(tiling) = VK_IMAGE_TILING_LINEAR,
$(initialLayout) = VK_IMAGE_LAYOUT_UNDEFINED ),
vkCreateImage(dev.device, &ref,NULL, &image.image));
VkMemoryRequirements mem_reqs;
vkGetImageMemoryRequirements(dev.device, image.image, &mem_reqs);
VkMemoryAllocateInfo info = AllocateInfo(mem_reqs.size);
dev.GetMemoryType(mem_reqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, &info.memoryTypeIndex);
vkAllocateMemory(dev.device, &info, NULL, &image.image_memory);
vkMapMemory(dev.device, image.image_memory, 0, mem_reqs.size, 0, (void**)&image.pMappedData);
vkBindImageMemory(dev.device, image.image, image.image_memory, 0);
CallWith($M(VkImageViewCreateInfo{VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO},
$(image) = image.image, $(viewType) = VK_IMAGE_VIEW_TYPE_2D,
$(format) = format,
$(subresourceRange) = SubresourceRange()),
vkCreateImageView(dev.device, &ref, NULL, &image.image_view));
}
gReconstruction.reconstructionStream = fopen("reconstruction.bin", "rb");
}
int ReadReconstructionFrame()
{
uint32_t length = 0;
ReconsructionSource &image = gReconstruction.sources[++gReconstruction.frame_idx & 3];
fread(&length, sizeof(int), 1, gReconstruction.reconstructionStream);
fread(image.pMappedData, 1, length, gReconstruction.reconstructionStream);
return gReconstruction.frame_idx;
}
// if separate reconstruction disabled, each decoder/reconstruction source combo generates command buffer for each swapchain image
// separate reconstruction:
// reconstruction target frame index always match reconstruction source frames
@ -517,6 +570,7 @@ struct GraphicsApplication
int rheight_out = 1080; // fov
int rwidth_in = 1920; // /2
int rheight_in = 1080; // /2
SetupReconstructionImages(dev, VK_FORMAT_R4G4B4A4_UNORM_PACK16, rwidth_in, rheight_in);
CreateWindow("demo", width, height, false);
CreateSwapchain(width,height, !compute);