1093 VkImageCreateInfo img_info = {
1094 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
1100 .imageType = VK_IMAGE_TYPE_2D,
1101 .format = VK_FORMAT_UNDEFINED,
1104 .samples = VK_SAMPLE_COUNT_1_BIT,
1105 .tiling = VK_IMAGE_TILING_OPTIMAL,
1106 .usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT
1107 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT
1108 | VK_IMAGE_USAGE_SAMPLED_BIT,
1109 .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
1111 .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
1114 VkImageViewCreateInfo img_view_info = {
1115 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1116 .viewType = VK_IMAGE_VIEW_TYPE_2D,
1117 .format = VK_FORMAT_UNDEFINED,
1118 .subresourceRange = {
1119 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
1122 .baseArrayLayer = 0,
1126 VK_COMPONENT_SWIZZLE_R,
1127 VK_COMPONENT_SWIZZLE_G,
1128 VK_COMPONENT_SWIZZLE_B,
1129 VK_COMPONENT_SWIZZLE_A
1133 #ifdef VKPT_DEVICE_GROUPS
1139 uint32_t new_image_num = 0;
1140 size_t total_size = 0;
1141 for(
int i = 0; i < MAX_RIMAGES; i++) {
1144 if (
tex_images[i] != VK_NULL_HANDLE || !q_img->registration_sequence || q_img->pix_data == NULL)
1147 img_info.extent.width = q_img->upload_width;
1148 img_info.extent.height = q_img->upload_height;
1149 img_info.mipLevels =
get_num_miplevels(q_img->upload_width, q_img->upload_height);
1150 img_info.format = q_img->is_srgb ? VK_FORMAT_R8G8B8A8_SRGB : VK_FORMAT_R8G8B8A8_UNORM;
1155 VkMemoryRequirements mem_req;
1158 assert(!(mem_req.alignment & (mem_req.alignment - 1)));
1159 total_size += mem_req.alignment - 1;
1160 total_size &= ~(mem_req.alignment - 1);
1161 total_size += mem_req.size;
1164 image_memory->
size = mem_req.size;
1165 image_memory->
alignment = mem_req.alignment;
1171 bind_info->sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO;
1173 bind_info->memory = image_memory->
memory;
1179 if (new_image_num == 0)
1184 buffer_create(&buf_img_upload, total_size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
1185 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
1189 char *staging_buffer =
buffer_map(&buf_img_upload);
1192 for(
int i = 0; i < MAX_RIMAGES; i++) {
1198 int num_mip_levels =
get_num_miplevels(q_img->upload_width, q_img->upload_height);
1200 VkMemoryRequirements mem_req;
1203 assert(!(mem_req.alignment & (mem_req.alignment - 1)));
1204 offset += mem_req.alignment - 1;
1205 offset &= ~(mem_req.alignment - 1);
1207 uint32_t wd = q_img->upload_width;
1208 uint32_t ht = q_img->upload_height;
1210 VkImageSubresourceRange subresource_range = {
1211 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
1213 .levelCount = num_mip_levels,
1214 .baseArrayLayer = 0,
1220 .subresourceRange = subresource_range,
1222 .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
1223 .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
1224 .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
1228 memcpy(staging_buffer + offset, q_img->pix_data, wd * ht * 4);
1230 VkBufferImageCopy cpy_info = {
1231 .bufferOffset = offset,
1232 .imageSubresource = {
1233 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
1235 .baseArrayLayer = 0,
1238 .imageOffset = { 0, 0, 0 },
1239 .imageExtent = { wd, ht, 1 }
1243 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cpy_info);
1246 subresource_range.levelCount = 1;
1248 for (
int mip = 1; mip < num_mip_levels; mip++)
1250 subresource_range.baseMipLevel = mip - 1;
1254 .subresourceRange = subresource_range,
1255 .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
1256 .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
1257 .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1258 .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1261 int nwd = (wd > 1) ? (wd >> 1) : wd;
1262 int nht = (ht > 1) ? (ht >> 1) : ht;
1264 VkImageBlit region = {
1266 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
1267 .mipLevel = mip - 1,
1268 .baseArrayLayer = 0,
1276 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
1278 .baseArrayLayer = 0,
1288 tex_images[i], VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1289 tex_images[i], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1293 subresource_range.baseMipLevel = mip - 1;
1297 .subresourceRange = subresource_range,
1298 .srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
1299 .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
1300 .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1301 .newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
1308 subresource_range.baseMipLevel = num_mip_levels - 1;
1312 .subresourceRange = subresource_range,
1313 .srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
1314 .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
1315 .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1316 .newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
1320 img_view_info.subresourceRange.levelCount = num_mip_levels;
1321 img_view_info.format = q_img->is_srgb ? VK_FORMAT_R8G8B8A8_SRGB : VK_FORMAT_R8G8B8A8_UNORM;
1325 offset += mem_req.size;
1329 staging_buffer = NULL;
1337 const uint32_t unused_index = unused_resources->
buffer_num++;
1338 unused_resources->
buffers[unused_index] = buf_img_upload.
buffer;