19 #include "shared/shared.h"
23 #define TR_PARTICLE_MAX_NUM MAX_PARTICLES
24 #define TR_BEAM_MAX_NUM MAX_ENTITIES
25 #define TR_SPRITE_MAX_NUM MAX_ENTITIES
26 #define TR_VERTEX_MAX_NUM (TR_PARTICLE_MAX_NUM + TR_BEAM_MAX_NUM + TR_SPRITE_MAX_NUM) * 4
27 #define TR_INDEX_MAX_NUM (TR_PARTICLE_MAX_NUM + TR_BEAM_MAX_NUM + TR_SPRITE_MAX_NUM) * 6
28 #define TR_POSITION_SIZE 3 * sizeof(float)
29 #define TR_COLOR_SIZE 4 * sizeof(float)
30 #define TR_SPRITE_INFO_SIZE 2 * sizeof(float)
32 #define TR_BLAS_BUILD_FLAGS VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_NV | \
33 VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_NV
88 static void write_beam_geometry(
const float* view_matrix,
const entity_t* entities,
int entity_num);
89 static void write_sprite_geometry(
const float* view_matrix,
const entity_t* entities,
int entity_num);
106 color.u32 = pcolor->u32;
110 for (
int i = 0; i < 3; i++)
111 color_f32[i] = hdr_factor * ((
float)
color.u8[i] / 255.0);
124 const size_t particle_data_size = particle_vertex_position_max_size + particle_color_size;
128 const size_t beam_data_size = beam_vertex_position_max_size + beam_color_size;
132 const size_t sprite_data_size = sprite_vertex_position_max_size + sprite_info_size;
135 transparency.host_frame_size = particle_data_size + beam_data_size + sprite_data_size;
179 for (
int i = 0; i < entity_num; i++)
181 if (entities[i].flags & RF_BEAM)
183 else if ((entities[i].model & 0x80000000) == 0)
186 if (model && model->type == MOD_SPRITE)
203 transparency.vertex_position_host_offset = host_buffer_offset;
204 transparency.particle_color_host_offset = host_buffer_offset + particle_vertices_size + beam_vertices_size + sprite_vertices_size;
267 const vec3_t view_y = { view_matrix[1], view_matrix[5], view_matrix[9] };
278 const particle_t* particle =
particles + i;
281 particle_colors[3] = particle->alpha;
282 particle_colors = particle_colors + 4;
285 VectorCopy(particle->origin,
origin);
288 VectorSubtract(view_origin,
origin, z_axis);
293 CrossProduct(z_axis, view_y, x_axis);
294 CrossProduct(x_axis, z_axis, y_axis);
296 const float size_factor = pow(particle->alpha, 0.05f);
297 if (particle->radius == 0.f)
299 VectorScale(y_axis, particle_size * size_factor, y_axis);
300 VectorScale(x_axis, particle_size * size_factor, x_axis);
304 VectorScale(y_axis, particle->radius, y_axis);
305 VectorScale(x_axis, particle->radius, x_axis);
309 VectorSubtract(
origin, x_axis, temp);
310 VectorAdd(temp, y_axis, vertex_positions[0]);
312 VectorAdd(
origin, x_axis, temp);
313 VectorAdd(temp, y_axis, vertex_positions[1]);
315 VectorAdd(
origin, x_axis, temp);
316 VectorSubtract(temp, y_axis, vertex_positions[2]);
318 VectorSubtract(
origin, x_axis, temp);
319 VectorSubtract(temp, y_axis, vertex_positions[3]);
321 vertex_positions += 4;
330 const vec3_t view_y = { view_matrix[1], view_matrix[5], view_matrix[9] };
339 const size_t beam_vertex_offset =
transparency.vertex_position_host_offset + particle_vertex_data_size;
342 vec3_t* vertex_positions = (vec3_t*)(
transparency.mapped_host_buffer + beam_vertex_offset);
345 for (
int i = 0; i < entity_num; i++)
347 if ((entities[i].flags & RF_BEAM) == 0)
350 const entity_t* beam = entities + i;
353 beam_colors[3] = beam->alpha;
354 beam_colors = beam_colors + 4;
358 VectorCopy(beam->oldorigin, begin);
359 VectorCopy(beam->origin, end);
362 VectorSubtract(end, begin, to_end);
365 VectorCopy(to_end, norm_dir);
367 VectorMA(begin, -5.f, norm_dir, begin);
368 VectorMA(end, 5.f, norm_dir, end);
371 VectorSubtract(view_origin, begin, to_view);
374 CrossProduct(to_end, to_view, x_axis);
376 VectorScale(x_axis, beam_width, x_axis);
378 VectorSubtract(end, x_axis, vertex_positions[0]);
379 VectorAdd(end, x_axis, vertex_positions[1]);
380 VectorAdd(begin, x_axis, vertex_positions[2]);
381 VectorSubtract(begin, x_axis, vertex_positions[3]);
382 vertex_positions += 4;
390 const entity_t* a = *(
void**)_a;
391 const entity_t* b = *(
void**)_b;
393 if (a->origin[0] < b->origin[0])
return -1;
394 if (a->origin[0] > b->origin[0])
return 1;
395 if (a->origin[1] < b->origin[1])
return -1;
396 if (a->origin[1] > b->origin[1])
return 1;
397 if (a->origin[2] < b->origin[2])
return -1;
398 if (a->origin[2] > b->origin[2])
return 1;
399 if (a->oldorigin[0] < b->oldorigin[0])
return -1;
400 if (a->oldorigin[0] > b->oldorigin[0])
return 1;
401 if (a->oldorigin[1] < b->oldorigin[1])
return -1;
402 if (a->oldorigin[1] > b->oldorigin[1])
return 1;
403 if (a->oldorigin[2] < b->oldorigin[2])
return -1;
404 if (a->oldorigin[2] > b->oldorigin[2])
return 1;
410 vec3_t dir, norm_dir;
411 VectorSubtract(end, begin, dir);
412 VectorCopy(dir, norm_dir);
415 vec3_t
up = { 0.f, 0.f, 1.f };
416 vec3_t left = { 1.f, 0.f, 0.f };
417 if (fabsf(norm_dir[2]) < 0.9f)
419 CrossProduct(
up, norm_dir, left);
421 CrossProduct(norm_dir, left,
up);
426 CrossProduct(norm_dir, left,
up);
428 CrossProduct(
up, norm_dir, left);
433 vec3_t vertices[6] = {
435 { 0.866f, -0.5f, 0.f },
436 { -0.866f, -0.5f, 0.f },
438 { -0.866f, 0.5f, 1.f },
439 { 0.866f, 0.5f, 1.f },
442 const int indices[18] = {
451 for (
int vert = 0; vert < 6; vert++)
454 VectorCopy(begin, transformed);
455 VectorMA(transformed, vertices[vert][0] * radius,
up, transformed);
456 VectorMA(transformed, vertices[vert][1] * radius, left, transformed);
457 VectorMA(transformed, vertices[vert][2], dir, transformed);
458 VectorCopy(transformed, vertices[vert]);
461 for (
int tri = 0; tri < 6; tri++)
463 if (*num_lights >= max_lights)
466 int i0 = indices[tri * 3 + 0];
467 int i1 = indices[tri * 3 + 1];
468 int i2 = indices[tri * 3 + 2];
472 VectorCopy(vertices[i0], light->
positions + 0);
473 VectorCopy(vertices[i1], light->
positions + 3);
474 VectorCopy(vertices[i2], light->
positions + 6);
497 if (hdr_factor <= 0.f)
504 for (
int i = 0; i < num_entites; i++)
509 if ((entities[i].flags & RF_BEAM) != 0)
510 beams[num_beams++] = entities + i;
518 for (
int i = 0; i < num_beams; i++)
520 if (*num_lights >= max_lights)
523 const entity_t* beam = beams[i];
527 VectorCopy(beam->oldorigin, begin);
528 VectorCopy(beam->origin, end);
531 VectorSubtract(end, begin, to_end);
534 VectorCopy(to_end, norm_dir);
536 VectorMA(begin, -5.f, norm_dir, begin);
537 VectorMA(end, 5.f, norm_dir, end);
551 const vec3_t view_x = { view_matrix[0], view_matrix[4], view_matrix[8] };
552 const vec3_t view_y = { view_matrix[1], view_matrix[5], view_matrix[9] };
553 const vec3_t world_y = { 0.f, 0.f, 1.f };
560 const size_t sprite_vertex_offset =
transparency.vertex_position_host_offset + particle_vertex_data_size + beam_vertex_data_size;
563 vec3_t* vertex_positions = (vec3_t*)(
transparency.mapped_host_buffer + sprite_vertex_offset);
566 int sprite_count = 0;
567 for (
int i = 0; i < entity_num; i++)
569 const entity_t *e = entities + i;
571 if (e->model & 0x80000000)
575 if (!model || model->type != MOD_SPRITE)
578 mspriteframe_t *frame = &model->spriteframes[e->frame % model->numframes];
582 sprite_info[1] = *(uint32_t*)&e->alpha;
593 VectorSubtract(view_origin, e->origin, to_camera);
596 CrossProduct(world_y, to_camera, cyl_x);
599 VectorScale(cyl_x, frame->origin_x, left);
600 VectorScale(cyl_x, frame->origin_x - frame->width,
right);
602 VectorScale(world_y, -frame->origin_y, down);
603 VectorScale(world_y, frame->height - frame->origin_y,
up);
607 VectorScale(view_x, frame->origin_x, left);
608 VectorScale(view_x, frame->origin_x - frame->width,
right);
610 if (model->sprite_vertical)
612 VectorScale(world_y, -frame->origin_y, down);
613 VectorScale(world_y, frame->height - frame->origin_y,
up);
617 VectorScale(view_y, -frame->origin_y, down);
618 VectorScale(view_y, frame->height - frame->origin_y,
up);
622 VectorAdd3(e->origin, down, left, vertex_positions[0]);
623 VectorAdd3(e->origin,
up, left, vertex_positions[1]);
624 VectorAdd3(e->origin,
up,
right, vertex_positions[2]);
625 VectorAdd3(e->origin, down,
right, vertex_positions[3]);
627 vertex_positions += 4;
642 const VkBufferCopy vertices = {
648 const VkBufferCopy paritcle_colors = {
654 const VkBufferCopy beam_colors = {
660 const VkBufferCopy sprite_infos = {
670 1, &paritcle_colors);
680 transparency.transfer_barriers[i].sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
681 transparency.transfer_barriers[i].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
682 transparency.transfer_barriers[i].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
683 transparency.transfer_barriers[i].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
684 transparency.transfer_barriers[i].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
690 transparency.transfer_barriers[1].size = paritcle_colors.size;
692 transparency.transfer_barriers[2].size = beam_colors.size;
694 transparency.transfer_barriers[3].size = sprite_infos.size;
702 vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
705 const VkGeometryTrianglesNV triangles = {
706 .sType = VK_STRUCTURE_TYPE_GEOMETRY_TRIANGLES_NV,
710 .vertexFormat = VK_FORMAT_R32G32B32_SFLOAT,
713 .indexType = VK_INDEX_TYPE_UINT16
716 const VkGeometryAABBNV aabbs = {
717 .sType = VK_STRUCTURE_TYPE_GEOMETRY_AABB_NV
720 const VkGeometryDataNV geometry_data = {
721 .triangles = triangles,
725 const VkGeometryNV geometry = {
726 .sType = VK_STRUCTURE_TYPE_GEOMETRY_NV,
727 .geometryType = VK_GEOMETRY_TYPE_TRIANGLES_NV,
728 .geometry = geometry_data
731 const VkAccelerationStructureInfoNV info = {
732 .sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_INFO_NV,
733 .type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_NV,
737 .pGeometries = &geometry
743 qvkCmdBuildAccelerationStructureNV(command_buffer, &info, VK_NULL_HANDLE, 0, update,
752 const VkGeometryTrianglesNV triangles = {
753 .sType = VK_STRUCTURE_TYPE_GEOMETRY_TRIANGLES_NV,
757 .vertexFormat = VK_FORMAT_R32G32B32_SFLOAT,
761 .indexType = VK_INDEX_TYPE_UINT16
764 const VkGeometryAABBNV aabbs = {
765 .sType = VK_STRUCTURE_TYPE_GEOMETRY_AABB_NV
768 const VkGeometryDataNV geometry_data = {
769 .triangles = triangles,
773 const VkGeometryNV geometry = {
774 .sType = VK_STRUCTURE_TYPE_GEOMETRY_NV,
775 .geometryType = VK_GEOMETRY_TYPE_TRIANGLES_NV,
776 .geometry = geometry_data
779 const VkAccelerationStructureInfoNV info = {
780 .sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_INFO_NV,
781 .type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_NV,
785 .pGeometries = &geometry
792 qvkCmdBuildAccelerationStructureNV(command_buffer, &info, VK_NULL_HANDLE, 0, update,
802 const VkGeometryTrianglesNV triangles = {
803 .sType = VK_STRUCTURE_TYPE_GEOMETRY_TRIANGLES_NV,
807 .vertexFormat = VK_FORMAT_R32G32B32_SFLOAT,
808 .vertexOffset =
transparency.sprite_vertex_device_offset,
811 .indexType = VK_INDEX_TYPE_UINT16
814 const VkGeometryAABBNV aabbs = {
815 .sType = VK_STRUCTURE_TYPE_GEOMETRY_AABB_NV
818 const VkGeometryDataNV geometry_data = {
819 .triangles = triangles,
823 const VkGeometryNV geometry = {
824 .sType = VK_STRUCTURE_TYPE_GEOMETRY_NV,
825 .geometryType = VK_GEOMETRY_TYPE_TRIANGLES_NV,
826 .geometry = geometry_data
829 const VkAccelerationStructureInfoNV info = {
830 .sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_INFO_NV,
831 .type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_NV,
835 .pGeometries = &geometry
841 qvkCmdBuildAccelerationStructureNV(command_buffer, &info, VK_NULL_HANDLE, 0, update,
848 VkAccelerationStructureMemoryRequirementsInfoNV scratch_requirements_info = {
849 .sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_NV,
850 .type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV,
851 .accelerationStructure = blas
854 VkMemoryRequirements2 build_memory_requirements = { 0 };
855 build_memory_requirements.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2;
856 qvkGetAccelerationStructureMemoryRequirementsNV(
qvk.
device, &scratch_requirements_info,
857 &build_memory_requirements);
859 scratch_requirements_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV;
861 VkMemoryRequirements2 update_memory_requirements = { 0 };
862 update_memory_requirements.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2;
863 qvkGetAccelerationStructureMemoryRequirementsNV(
qvk.
device, &scratch_requirements_info,
864 &update_memory_requirements);
866 const uint64_t build_size = build_memory_requirements.memoryRequirements.size;
867 const uint64_t update_size = update_memory_requirements.memoryRequirements.size;
869 return max(build_size, update_size);
878 transparency.beam_scratch_device_offset = particle_scratch_size;
881 const VkBufferCreateInfo host_buffer_info = {
882 .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
884 .usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT
887 const VkBufferCreateInfo scratch_buffer_info = {
888 .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
889 .size = particle_scratch_size + beam_scratch_size + sprite_scratch_size,
890 .usage = VK_BUFFER_USAGE_RAY_TRACING_BIT_NV
893 const VkBufferCreateInfo buffer_info = {
894 .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
896 .usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
899 const VkBufferCreateInfo index_buffer_info = {
900 .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
902 .usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
905 const VkBufferCreateInfo particle_color_buffer_info = {
906 .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
908 .usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
911 const VkBufferCreateInfo beam_color_buffer_info = {
912 .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
914 .usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
917 const VkBufferCreateInfo sprite_info_buffer_info = {
918 .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
920 .usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
936 VkMemoryRequirements host_buffer_requirements;
939 const VkMemoryPropertyFlags host_flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT |
940 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
942 const uint32_t host_memory_type =
get_memory_type(host_buffer_requirements.memoryTypeBits, host_flags);
944 const VkMemoryAllocateInfo host_memory_allocate_info = {
945 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
946 .allocationSize = host_buffer_requirements.size,
947 .memoryTypeIndex = host_memory_type
954 const VkBuffer device_buffers[] = {
963 const VkMemoryPropertyFlags device_flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
964 uint32_t memory_types[
LENGTH(device_buffers)];
965 VkMemoryRequirements requirements[
LENGTH(device_buffers)];
967 VkMemoryAllocateInfo memory_allocate_info = { .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
969 for (
size_t i = 0; i <
LENGTH(device_buffers); i++)
971 vkGetBufferMemoryRequirements(
qvk.
device, device_buffers[i], &requirements[i]);
972 memory_types[i] =
get_memory_type(requirements[i].memoryTypeBits, device_flags);
973 memory_allocate_info.allocationSize += requirements[i].size + ((i == 0) ? 0 : requirements[i].alignment);
977 for (
size_t i = 1; i <
LENGTH(device_buffers); i++)
979 if (memory_types[i] != memory_types[0])
983 memory_allocate_info.memoryTypeIndex = memory_types[0];
986 #ifdef VKPT_DEVICE_GROUPS
987 VkMemoryAllocateFlagsInfoKHR mem_alloc_flags = {
988 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO_KHR,
989 .flags = VK_MEMORY_ALLOCATE_DEVICE_MASK_BIT_KHR,
994 memory_allocate_info.pNext = &mem_alloc_flags;
1001 VkBindBufferMemoryInfo bindings[
LENGTH(device_buffers) + 1] = { 0 };
1003 bindings[0].sType = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO;
1006 bindings[0].memoryOffset = 0;
1009 for (
size_t i = 0; i <
LENGTH(device_buffers); i++)
1011 VkBindBufferMemoryInfo* binding = bindings + i + 1;
1013 binding->sType = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO;
1014 binding->buffer = device_buffers[i];
1017 offset =
align(offset, requirements[i].alignment);
1018 binding->memoryOffset = offset;
1019 offset += requirements[i].size;
1034 const VkGeometryTrianglesNV geometry_triangles = {
1035 .sType = VK_STRUCTURE_TYPE_GEOMETRY_TRIANGLES_NV,
1037 .vertexFormat = VK_FORMAT_R32G32B32_SFLOAT,
1039 .indexType = VK_INDEX_TYPE_UINT16
1042 const VkGeometryAABBNV geometry_aabbs = {
1043 .sType = VK_STRUCTURE_TYPE_GEOMETRY_AABB_NV
1046 const VkGeometryDataNV geometry_data = {
1047 .triangles = geometry_triangles,
1048 .aabbs = geometry_aabbs
1051 const VkGeometryNV geometry = {
1052 .sType = VK_STRUCTURE_TYPE_GEOMETRY_NV,
1053 .geometryType = VK_GEOMETRY_TYPE_TRIANGLES_NV,
1054 .geometry = geometry_data
1057 const VkAccelerationStructureInfoNV info = {
1058 .sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_INFO_NV,
1059 .type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_NV,
1062 .pGeometries = &geometry
1065 const VkAccelerationStructureCreateInfoNV blas_info = {
1066 .sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_NV,
1077 const VkAccelerationStructureMemoryRequirementsInfoNV blas_requirements_info = {
1078 .sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_NV,
1079 .type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV,
1083 VkMemoryRequirements2 blas_memory_requirements = { 0 };
1084 blas_memory_requirements.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2;
1085 qvkGetAccelerationStructureMemoryRequirementsNV(
qvk.
device, &blas_requirements_info,
1086 &blas_memory_requirements);
1088 VkMemoryRequirements mem_req = blas_memory_requirements.memoryRequirements;
1089 size_t beam_memory_offset =
align(mem_req.size, mem_req.alignment);
1090 mem_req.size += beam_memory_offset;
1092 size_t sprite_memory_offset =
align(mem_req.size, mem_req.alignment);
1093 mem_req.size += sprite_memory_offset;
1097 VkBindAccelerationStructureMemoryInfoNV bindings[3] = { 0 };
1099 bindings[0].sType = VK_STRUCTURE_TYPE_BIND_ACCELERATION_STRUCTURE_MEMORY_INFO_NV;
1100 bindings[0].accelerationStructure =
transparency.particle_blas;
1102 bindings[1].sType = VK_STRUCTURE_TYPE_BIND_ACCELERATION_STRUCTURE_MEMORY_INFO_NV;
1103 bindings[1].accelerationStructure =
transparency.beam_blas;
1105 bindings[1].memoryOffset = beam_memory_offset;
1106 bindings[2].sType = VK_STRUCTURE_TYPE_BIND_ACCELERATION_STRUCTURE_MEMORY_INFO_NV;
1107 bindings[2].accelerationStructure =
transparency.sprite_blas;
1109 bindings[2].memoryOffset = sprite_memory_offset;
1116 const VkBufferViewCreateInfo particle_color_view_info = {
1117 .sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO,
1119 .format = VK_FORMAT_R32G32B32A32_SFLOAT,
1123 const VkBufferViewCreateInfo beam_color_view_info = {
1124 .sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO,
1126 .format = VK_FORMAT_R32G32B32A32_SFLOAT,
1130 const VkBufferViewCreateInfo sprite_info_view_info = {
1131 .sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO,
1133 .format = VK_FORMAT_R32G32_UINT,
1137 _VK(vkCreateBufferView(
qvk.
device, &particle_color_view_info, NULL,
1140 _VK(vkCreateBufferView(
qvk.
device, &beam_color_view_info, NULL,
1143 _VK(vkCreateBufferView(
qvk.
device, &sprite_info_view_info, NULL,
1149 uint16_t* indices = (uint16_t*)
transparency.mapped_host_buffer;
1153 uint16_t* quad = indices + i * 6;
1155 const uint16_t base_vertex = i * 4;
1156 quad[0] = base_vertex + 0;
1157 quad[1] = base_vertex + 1;
1158 quad[2] = base_vertex + 2;
1159 quad[3] = base_vertex + 2;
1160 quad[4] = base_vertex + 3;
1161 quad[5] = base_vertex + 0;
1166 const VkBufferMemoryBarrier pre_barrier = {
1167 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
1169 .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
1170 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
1171 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
1173 .size = VK_WHOLE_SIZE
1176 vkCmdPipelineBarrier(cmd_buf, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
1177 0, 0, NULL, 1, &pre_barrier, 0, NULL);
1179 const VkBufferCopy region = {
1185 const VkBufferMemoryBarrier post_barrier = {
1186 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
1187 .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
1188 .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT,
1189 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
1190 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
1192 .size = VK_WHOLE_SIZE
1195 vkCmdPipelineBarrier(cmd_buf, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
1196 0, 0, NULL, 1, &post_barrier, 0, NULL);