Image creation functions update.
This commit is contained in:
parent
1e74933a47
commit
d110d15a06
|
|
@ -736,8 +736,8 @@ void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *
|
||||||
Vk_Image& vk_image = vk_resources.images[tr.scratchImage[client]->index];
|
Vk_Image& vk_image = vk_resources.images[tr.scratchImage[client]->index];
|
||||||
vkDestroyImage(vk.device, vk_image.image, nullptr);
|
vkDestroyImage(vk.device, vk_image.image, nullptr);
|
||||||
vkDestroyImageView(vk.device, vk_image.image_view, nullptr);
|
vkDestroyImageView(vk.device, vk_image.image_view, nullptr);
|
||||||
vk_image.image = vk_create_cinematic_image(cols, rows, vk_image.image_view);
|
vk_image.image = vk_create_image(cols, rows, vk_image.image_view);
|
||||||
vk_update_cinematic_image(vk_image.image, cols, rows, data);
|
vk_upload_image_data(vk_image.image, cols, rows, data);
|
||||||
|
|
||||||
VkDescriptorImageInfo image_info;
|
VkDescriptorImageInfo image_info;
|
||||||
image_info.sampler = vk.sampler;
|
image_info.sampler = vk.sampler;
|
||||||
|
|
@ -765,7 +765,7 @@ void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *
|
||||||
|
|
||||||
// VULKAN
|
// VULKAN
|
||||||
const Vk_Image& vk_image = vk_resources.images[tr.scratchImage[client]->index];
|
const Vk_Image& vk_image = vk_resources.images[tr.scratchImage[client]->index];
|
||||||
vk_update_cinematic_image(vk_image.image, cols, rows, data);
|
vk_upload_image_data(vk_image.image, cols, rows, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -777,7 +777,8 @@ image_t *R_CreateImage( const char *name, const byte *pic, int width, int height
|
||||||
|
|
||||||
// VULKAN
|
// VULKAN
|
||||||
Vk_Image& vk_image = vk_resources.images[image->index];
|
Vk_Image& vk_image = vk_resources.images[image->index];
|
||||||
vk_image.image = vk_create_texture(pic, width, height, vk_image.image_view);
|
vk_image.image = vk_create_image(width, height, vk_image.image_view);
|
||||||
|
vk_upload_image_data(vk_image.image, width, height, pic);
|
||||||
vk_image.descriptor_set = vk_create_descriptor_set(vk_image.image_view);
|
vk_image.descriptor_set = vk_create_descriptor_set(vk_image.image_view);
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
|
|
|
||||||
|
|
@ -816,10 +816,24 @@ void vk_create_instance(HWND hwnd) {
|
||||||
return module;
|
return module;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern unsigned char single_texture_vert_spv[];
|
||||||
|
extern long long single_texture_vert_spv_size;
|
||||||
vk.single_texture_vs = create_shader_module(single_texture_vert_spv, single_texture_vert_spv_size);
|
vk.single_texture_vs = create_shader_module(single_texture_vert_spv, single_texture_vert_spv_size);
|
||||||
|
|
||||||
|
extern unsigned char single_texture_frag_spv[];
|
||||||
|
extern long long single_texture_frag_spv_size;
|
||||||
vk.single_texture_fs = create_shader_module(single_texture_frag_spv, single_texture_frag_spv_size);
|
vk.single_texture_fs = create_shader_module(single_texture_frag_spv, single_texture_frag_spv_size);
|
||||||
|
|
||||||
|
extern unsigned char multi_texture_vert_spv[];
|
||||||
|
extern long long multi_texture_vert_spv_size;
|
||||||
vk.multi_texture_vs = create_shader_module(multi_texture_vert_spv, multi_texture_vert_spv_size);
|
vk.multi_texture_vs = create_shader_module(multi_texture_vert_spv, multi_texture_vert_spv_size);
|
||||||
|
|
||||||
|
extern unsigned char multi_texture_mul_frag_spv[];
|
||||||
|
extern long long multi_texture_mul_frag_spv_size;
|
||||||
vk.multi_texture_mul_fs = create_shader_module(multi_texture_mul_frag_spv, multi_texture_mul_frag_spv_size);
|
vk.multi_texture_mul_fs = create_shader_module(multi_texture_mul_frag_spv, multi_texture_mul_frag_spv_size);
|
||||||
|
|
||||||
|
extern unsigned char multi_texture_add_frag_spv[];
|
||||||
|
extern long long multi_texture_add_frag_spv_size;
|
||||||
vk.multi_texture_add_fs = create_shader_module(multi_texture_add_frag_spv, multi_texture_add_frag_spv_size);
|
vk.multi_texture_add_fs = create_shader_module(multi_texture_add_frag_spv, multi_texture_add_frag_spv_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -964,21 +978,15 @@ static void record_buffer_memory_barrier(VkCommandBuffer cb, VkBuffer buffer,
|
||||||
vkCmdPipelineBarrier(cb, src_stages, dst_stages, 0, 0, nullptr, 1, &barrier, 0, nullptr);
|
vkCmdPipelineBarrier(cb, src_stages, dst_stages, 0, 0, nullptr, 1, &barrier, 0, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
VkImage vk_create_texture(const uint8_t* rgba_pixels, int image_width, int image_height, VkImageView& image_view) {
|
VkImage vk_create_image(int width, int height, VkImageView& image_view) {
|
||||||
int image_size = image_width * image_height * 4;
|
|
||||||
|
|
||||||
ensure_staging_buffer_allocation(image_size);
|
|
||||||
Com_Memcpy(vk_resources.staging_buffer_ptr, rgba_pixels, image_size);
|
|
||||||
|
|
||||||
// create texture image
|
|
||||||
VkImageCreateInfo desc;
|
VkImageCreateInfo desc;
|
||||||
desc.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
desc.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||||
desc.pNext = nullptr;
|
desc.pNext = nullptr;
|
||||||
desc.flags = 0;
|
desc.flags = 0;
|
||||||
desc.imageType = VK_IMAGE_TYPE_2D;
|
desc.imageType = VK_IMAGE_TYPE_2D;
|
||||||
desc.format = VK_FORMAT_R8G8B8A8_UNORM;
|
desc.format = VK_FORMAT_R8G8B8A8_UNORM;
|
||||||
desc.extent.width = image_width;
|
desc.extent.width = width;
|
||||||
desc.extent.height = image_height;
|
desc.extent.height = height;
|
||||||
desc.extent.depth = 1;
|
desc.extent.depth = 1;
|
||||||
desc.mipLevels = 1;
|
desc.mipLevels = 1;
|
||||||
desc.arrayLayers = 1;
|
desc.arrayLayers = 1;
|
||||||
|
|
@ -990,70 +998,14 @@ VkImage vk_create_texture(const uint8_t* rgba_pixels, int image_width, int image
|
||||||
desc.pQueueFamilyIndices = nullptr;
|
desc.pQueueFamilyIndices = nullptr;
|
||||||
desc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
desc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
|
||||||
VkImage texture_image;
|
|
||||||
VK_CHECK(vkCreateImage(vk.device, &desc, nullptr, &texture_image));
|
|
||||||
allocate_and_bind_image_memory(texture_image);
|
|
||||||
|
|
||||||
// copy buffer's content to texture
|
|
||||||
record_and_run_commands(vk.command_pool, vk.queue,
|
|
||||||
[&texture_image, &image_width, &image_height](VkCommandBuffer command_buffer) {
|
|
||||||
|
|
||||||
record_buffer_memory_barrier(command_buffer, vk_resources.staging_buffer,
|
|
||||||
VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
||||||
VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT);
|
|
||||||
|
|
||||||
record_image_layout_transition(command_buffer, texture_image, VK_FORMAT_R8G8B8A8_UNORM,
|
|
||||||
0, VK_IMAGE_LAYOUT_UNDEFINED, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
|
||||||
|
|
||||||
VkBufferImageCopy region;
|
|
||||||
region.bufferOffset = 0;
|
|
||||||
region.bufferRowLength = 0;
|
|
||||||
region.bufferImageHeight = 0;
|
|
||||||
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
||||||
region.imageSubresource.mipLevel = 0;
|
|
||||||
region.imageSubresource.baseArrayLayer = 0;
|
|
||||||
region.imageSubresource.layerCount = 1;
|
|
||||||
region.imageOffset = VkOffset3D{ 0, 0, 0 };
|
|
||||||
region.imageExtent = VkExtent3D{ (uint32_t)image_width, (uint32_t)image_height, 1 };
|
|
||||||
|
|
||||||
vkCmdCopyBufferToImage(command_buffer, vk_resources.staging_buffer, texture_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
|
|
||||||
|
|
||||||
record_image_layout_transition(command_buffer, texture_image, VK_FORMAT_R8G8B8A8_UNORM,
|
|
||||||
VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
|
||||||
});
|
|
||||||
|
|
||||||
image_view = create_image_view(texture_image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT);
|
|
||||||
return texture_image;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkImage vk_create_cinematic_image(int width, int height, VkImageView& image_view) {
|
|
||||||
VkImageCreateInfo image_desc;
|
|
||||||
image_desc.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
|
||||||
image_desc.pNext = nullptr;
|
|
||||||
image_desc.flags = 0;
|
|
||||||
image_desc.imageType = VK_IMAGE_TYPE_2D;
|
|
||||||
image_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
|
|
||||||
image_desc.extent.width = width;
|
|
||||||
image_desc.extent.height = height;
|
|
||||||
image_desc.extent.depth = 1;
|
|
||||||
image_desc.mipLevels = 1;
|
|
||||||
image_desc.arrayLayers = 1;
|
|
||||||
image_desc.samples = VK_SAMPLE_COUNT_1_BIT;
|
|
||||||
image_desc.tiling = VK_IMAGE_TILING_OPTIMAL;
|
|
||||||
image_desc.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
|
|
||||||
image_desc.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
|
||||||
image_desc.queueFamilyIndexCount = 0;
|
|
||||||
image_desc.pQueueFamilyIndices = nullptr;
|
|
||||||
image_desc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
||||||
|
|
||||||
VkImage image;
|
VkImage image;
|
||||||
VK_CHECK(vkCreateImage(vk.device, &image_desc, nullptr, &image));
|
VK_CHECK(vkCreateImage(vk.device, &desc, nullptr, &image));
|
||||||
allocate_and_bind_image_memory(image);
|
allocate_and_bind_image_memory(image);
|
||||||
image_view = create_image_view(image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT);
|
image_view = create_image_view(image, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vk_update_cinematic_image(VkImage image, int width, int height, const uint8_t* rgba_pixels) {
|
void vk_upload_image_data(VkImage image, int width, int height, const uint8_t* rgba_pixels) {
|
||||||
VkDeviceSize size = width * height * 4;
|
VkDeviceSize size = width * height * 4;
|
||||||
|
|
||||||
ensure_staging_buffer_allocation(size);
|
ensure_staging_buffer_allocation(size);
|
||||||
|
|
|
||||||
|
|
@ -61,9 +61,8 @@ void vk_destroy_resources(); // destroys Vk_Resources resources
|
||||||
//
|
//
|
||||||
// Resources allocation.
|
// Resources allocation.
|
||||||
//
|
//
|
||||||
VkImage vk_create_texture(const uint8_t* rgba_pixels, int width, int height, VkImageView& image_view);
|
VkImage vk_create_image(int width, int height, VkImageView& image_view);
|
||||||
VkImage vk_create_cinematic_image(int width, int height, VkImageView& image_view);
|
void vk_upload_image_data(VkImage image, int width, int height, const uint8_t* rgba_pixels);
|
||||||
void vk_update_cinematic_image(VkImage image, int width, int height, const uint8_t* rgba_pixels);
|
|
||||||
VkPipeline vk_find_pipeline(const Vk_Pipeline_Desc& desc);
|
VkPipeline vk_find_pipeline(const Vk_Pipeline_Desc& desc);
|
||||||
VkDescriptorSet vk_create_descriptor_set(VkImageView image_view);
|
VkDescriptorSet vk_create_descriptor_set(VkImageView image_view);
|
||||||
|
|
||||||
|
|
@ -79,23 +78,6 @@ void vk_bind_stage_specific_resources(VkPipeline pipeline, bool multitexture, bo
|
||||||
void vk_begin_frame();
|
void vk_begin_frame();
|
||||||
void vk_end_frame();
|
void vk_end_frame();
|
||||||
|
|
||||||
|
|
||||||
// Shaders.
|
|
||||||
extern unsigned char single_texture_vert_spv[];
|
|
||||||
extern long long single_texture_vert_spv_size;
|
|
||||||
|
|
||||||
extern unsigned char single_texture_frag_spv[];
|
|
||||||
extern long long single_texture_frag_spv_size;
|
|
||||||
|
|
||||||
extern unsigned char multi_texture_vert_spv[];
|
|
||||||
extern long long multi_texture_vert_spv_size;
|
|
||||||
|
|
||||||
extern unsigned char multi_texture_add_frag_spv[];
|
|
||||||
extern long long multi_texture_add_frag_spv_size;
|
|
||||||
|
|
||||||
extern unsigned char multi_texture_mul_frag_spv[];
|
|
||||||
extern long long multi_texture_mul_frag_spv_size;
|
|
||||||
|
|
||||||
// Vulkan specific structures used by the engine.
|
// Vulkan specific structures used by the engine.
|
||||||
struct Vk_Instance {
|
struct Vk_Instance {
|
||||||
VkInstance instance = VK_NULL_HANDLE;
|
VkInstance instance = VK_NULL_HANDLE;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user