1 /* 2 * Copyright 2016 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can 5 * be found in the LICENSE file. 6 * 7 */ 8 9 #pragma once 10 11 // 12 // 13 // 14 15 #include <vulkan/vulkan.h> 16 17 // 18 // 19 // 20 21 #include <stdint.h> 22 #include <stdbool.h> 23 24 // 25 // 26 // 27 28 #include "hs_vk_target.h" 29 30 // 31 // Create a HotSort instance from a specific vendor, architecture and 32 // key/val size target. 33 // 34 35 struct hs_vk * 36 hs_vk_create(struct hs_vk_target const * const target, 37 VkDevice device, 38 VkAllocationCallbacks const * allocator, 39 VkPipelineCache pipeline_cache); 40 41 // 42 // Resources will be disposed of with the same device and allocator 43 // used for creation. 44 // 45 46 void 47 hs_vk_release(struct hs_vk * const hs); 48 49 // 50 // Allocate a thread local descriptor set for the vin and vout 51 // VkBuffers. Note that HotSort uses only one descriptor set. 52 // 53 // Don't forget to return the descriptor set back to the same pool 54 // with vkFreeDescriptorSets(). 55 // 56 57 VkDescriptorSet 58 hs_vk_ds_alloc(struct hs_vk const * const hs, VkDescriptorPool desc_pool); 59 60 // 61 // Explicitly bind the descriptor set describing the 'vin' and 'vout' 62 // buffers to the command buffer before calling 'hs_vk_sort()'. 63 // 64 // If 'vout' is VK_NULL_HANDLE then the sort will be performed in 65 // place. 66 // 67 // FIXME -- do we want to expose a set index? 68 // 69 // FIXME -- do we want to allow specialization of the buffer bindings 70 // or sets? 71 // 72 73 void 74 hs_vk_ds_bind(struct hs_vk const * const hs, 75 VkDescriptorSet hs_ds, 76 VkCommandBuffer cb, 77 VkBuffer vin, 78 VkBuffer vout); 79 80 // 81 // Explicitly reveal what padding of maximum valued keys will be 82 // applied to the input and output buffers. 83 // 84 // count : input number of keys 85 // count_padded_in : adjusted count of keys in vin[] buffer 86 // count_padded_out : adjusted count of keys in vout[] buffer 87 // 88 // Instead of implicitly padding the buffers, HotSort requires this 89 // explicit step to support use cases like: 90 // 91 // - writing past the end of the vin[] buffer 92 // - dynamically allocating a vout[] buffer before sorting 93 // 94 95 void 96 hs_vk_pad(struct hs_vk const * const hs, 97 uint32_t const count, 98 uint32_t * const count_padded_in, 99 uint32_t * const count_padded_out); 100 101 // 102 // Append commands to the command buffer that when enqueued will sort 103 // the keys in the 'vin' buffer and store them in the 'vout' buffer. 104 // 105 // If 'vout' is VK_NULL_HANDLE then the sort will be performed in 106 // place. 107 // 108 // Pipeline barriers should be applied both before and after invoking 109 // this function. 110 // 111 // Note that the algorithm *may* perform transfer operations on the 112 // buffers before executing a compute shader. 113 // 114 // The algorithm ends with a single compute shader. 115 // 116 117 void 118 hs_vk_sort(struct hs_vk const * const hs, 119 VkCommandBuffer cb, 120 VkBuffer vin, 121 VkPipelineStageFlags const vin_src_stage, 122 VkAccessFlagBits const vin_src_access, 123 VkBuffer vout, 124 VkPipelineStageFlags const vout_src_stage, 125 VkAccessFlagBits const vout_src_access, 126 uint32_t const count, 127 uint32_t const count_padded_in, 128 uint32_t const count_padded_out, 129 bool const linearize); 130 131 // 132 // 133 // 134