}
#define HKEY(obj) ((uint64_t)(obj))
-#define FIND_SWAPCHAIN_DATA(obj) ((struct swapchain_data *)find_object_data(HKEY(obj)))
-#define FIND_CMD_BUFFER_DATA(obj) ((struct command_buffer_data *)find_object_data(HKEY(obj)))
-#define FIND_DEVICE_DATA(obj) ((struct device_data *)find_object_data(HKEY(obj)))
-#define FIND_QUEUE_DATA(obj) ((struct queue_data *)find_object_data(HKEY(obj)))
-#define FIND_PHYSICAL_DEVICE_DATA(obj) ((struct instance_data *)find_object_data(HKEY(obj)))
-#define FIND_INSTANCE_DATA(obj) ((struct instance_data *)find_object_data(HKEY(obj)))
+#define FIND(type, obj) ((type *)find_object_data(HKEY(obj)))
+
static void *find_object_data(uint64_t obj)
{
simple_mtx_lock(&vk_object_to_data_mutex);
const VkAllocationCallbacks* pAllocator,
VkSwapchainKHR* pSwapchain)
{
- struct device_data *device_data = FIND_DEVICE_DATA(device);
+ struct device_data *device_data = FIND(struct device_data, device);
VkResult result = device_data->vtable.CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
if (result != VK_SUCCESS) return result;
VkSwapchainKHR swapchain,
const VkAllocationCallbacks* pAllocator)
{
- struct swapchain_data *swapchain_data = FIND_SWAPCHAIN_DATA(swapchain);
+ struct swapchain_data *swapchain_data =
+ FIND(struct swapchain_data, swapchain);
shutdown_swapchain_data(swapchain_data);
swapchain_data->device->vtable.DestroySwapchainKHR(device, swapchain, pAllocator);
VkQueue queue,
const VkPresentInfoKHR* pPresentInfo)
{
- struct queue_data *queue_data = FIND_QUEUE_DATA(queue);
+ struct queue_data *queue_data = FIND(struct queue_data, queue);
struct device_data *device_data = queue_data->device;
struct instance_data *instance_data = device_data->instance;
uint32_t query_results[OVERLAY_QUERY_COUNT];
if (instance_data->params.no_display) {
for (uint32_t i = 0; i < pPresentInfo->swapchainCount; i++) {
VkSwapchainKHR swapchain = pPresentInfo->pSwapchains[i];
- struct swapchain_data *swapchain_data = FIND_SWAPCHAIN_DATA(swapchain);
+ struct swapchain_data *swapchain_data =
+ FIND(struct swapchain_data, swapchain);
before_present(swapchain_data,
pPresentInfo->pWaitSemaphores,
} else {
for (uint32_t i = 0; i < pPresentInfo->swapchainCount; i++) {
VkSwapchainKHR swapchain = pPresentInfo->pSwapchains[i];
- struct swapchain_data *swapchain_data = FIND_SWAPCHAIN_DATA(swapchain);
+ struct swapchain_data *swapchain_data =
+ FIND(struct swapchain_data, swapchain);
VkPresentInfoKHR present_info = *pPresentInfo;
present_info.swapchainCount = 1;
present_info.pSwapchains = &swapchain;
VkFence fence,
uint32_t* pImageIndex)
{
- struct swapchain_data *swapchain_data = FIND_SWAPCHAIN_DATA(swapchain);
+ struct swapchain_data *swapchain_data =
+ FIND(struct swapchain_data, swapchain);
struct device_data *device_data = swapchain_data->device;
uint64_t ts0 = os_time_get();
const VkAcquireNextImageInfoKHR* pAcquireInfo,
uint32_t* pImageIndex)
{
- struct swapchain_data *swapchain_data = FIND_SWAPCHAIN_DATA(pAcquireInfo->swapchain);
+ struct swapchain_data *swapchain_data =
+ FIND(struct swapchain_data, pAcquireInfo->swapchain);
struct device_data *device_data = swapchain_data->device;
uint64_t ts0 = os_time_get();
uint32_t firstVertex,
uint32_t firstInstance)
{
- struct command_buffer_data *cmd_buffer_data = FIND_CMD_BUFFER_DATA(commandBuffer);
+ struct command_buffer_data *cmd_buffer_data =
+ FIND(struct command_buffer_data, commandBuffer);
cmd_buffer_data->stats.stats[OVERLAY_PARAM_ENABLED_draw]++;
struct device_data *device_data = cmd_buffer_data->device;
device_data->vtable.CmdDraw(commandBuffer, vertexCount, instanceCount,
int32_t vertexOffset,
uint32_t firstInstance)
{
- struct command_buffer_data *cmd_buffer_data = FIND_CMD_BUFFER_DATA(commandBuffer);
+ struct command_buffer_data *cmd_buffer_data =
+ FIND(struct command_buffer_data, commandBuffer);
cmd_buffer_data->stats.stats[OVERLAY_PARAM_ENABLED_draw_indexed]++;
struct device_data *device_data = cmd_buffer_data->device;
device_data->vtable.CmdDrawIndexed(commandBuffer, indexCount, instanceCount,
uint32_t drawCount,
uint32_t stride)
{
- struct command_buffer_data *cmd_buffer_data = FIND_CMD_BUFFER_DATA(commandBuffer);
+ struct command_buffer_data *cmd_buffer_data =
+ FIND(struct command_buffer_data, commandBuffer);
cmd_buffer_data->stats.stats[OVERLAY_PARAM_ENABLED_draw_indirect]++;
struct device_data *device_data = cmd_buffer_data->device;
device_data->vtable.CmdDrawIndirect(commandBuffer, buffer, offset, drawCount, stride);
uint32_t drawCount,
uint32_t stride)
{
- struct command_buffer_data *cmd_buffer_data = FIND_CMD_BUFFER_DATA(commandBuffer);
+ struct command_buffer_data *cmd_buffer_data =
+ FIND(struct command_buffer_data, commandBuffer);
cmd_buffer_data->stats.stats[OVERLAY_PARAM_ENABLED_draw_indexed_indirect]++;
struct device_data *device_data = cmd_buffer_data->device;
device_data->vtable.CmdDrawIndexedIndirect(commandBuffer, buffer, offset, drawCount, stride);
uint32_t maxDrawCount,
uint32_t stride)
{
- struct command_buffer_data *cmd_buffer_data = FIND_CMD_BUFFER_DATA(commandBuffer);
+ struct command_buffer_data *cmd_buffer_data =
+ FIND(struct command_buffer_data, commandBuffer);
cmd_buffer_data->stats.stats[OVERLAY_PARAM_ENABLED_draw_indirect_count]++;
struct device_data *device_data = cmd_buffer_data->device;
device_data->vtable.CmdDrawIndirectCountKHR(commandBuffer, buffer, offset,
uint32_t maxDrawCount,
uint32_t stride)
{
- struct command_buffer_data *cmd_buffer_data = FIND_CMD_BUFFER_DATA(commandBuffer);
+ struct command_buffer_data *cmd_buffer_data =
+ FIND(struct command_buffer_data, commandBuffer);
cmd_buffer_data->stats.stats[OVERLAY_PARAM_ENABLED_draw_indexed_indirect_count]++;
struct device_data *device_data = cmd_buffer_data->device;
device_data->vtable.CmdDrawIndexedIndirectCountKHR(commandBuffer, buffer, offset,
uint32_t groupCountY,
uint32_t groupCountZ)
{
- struct command_buffer_data *cmd_buffer_data = FIND_CMD_BUFFER_DATA(commandBuffer);
+ struct command_buffer_data *cmd_buffer_data =
+ FIND(struct command_buffer_data, commandBuffer);
cmd_buffer_data->stats.stats[OVERLAY_PARAM_ENABLED_dispatch]++;
struct device_data *device_data = cmd_buffer_data->device;
device_data->vtable.CmdDispatch(commandBuffer, groupCountX, groupCountY, groupCountZ);
VkBuffer buffer,
VkDeviceSize offset)
{
- struct command_buffer_data *cmd_buffer_data = FIND_CMD_BUFFER_DATA(commandBuffer);
+ struct command_buffer_data *cmd_buffer_data =
+ FIND(struct command_buffer_data, commandBuffer);
cmd_buffer_data->stats.stats[OVERLAY_PARAM_ENABLED_dispatch_indirect]++;
struct device_data *device_data = cmd_buffer_data->device;
device_data->vtable.CmdDispatchIndirect(commandBuffer, buffer, offset);
VkPipelineBindPoint pipelineBindPoint,
VkPipeline pipeline)
{
- struct command_buffer_data *cmd_buffer_data = FIND_CMD_BUFFER_DATA(commandBuffer);
+ struct command_buffer_data *cmd_buffer_data =
+ FIND(struct command_buffer_data, commandBuffer);
switch (pipelineBindPoint) {
case VK_PIPELINE_BIND_POINT_GRAPHICS: cmd_buffer_data->stats.stats[OVERLAY_PARAM_ENABLED_pipeline_graphics]++; break;
case VK_PIPELINE_BIND_POINT_COMPUTE: cmd_buffer_data->stats.stats[OVERLAY_PARAM_ENABLED_pipeline_compute]++; break;
VkCommandBuffer commandBuffer,
const VkCommandBufferBeginInfo* pBeginInfo)
{
- struct command_buffer_data *cmd_buffer_data = FIND_CMD_BUFFER_DATA(commandBuffer);
+ struct command_buffer_data *cmd_buffer_data =
+ FIND(struct command_buffer_data, commandBuffer);
struct device_data *device_data = cmd_buffer_data->device;
memset(&cmd_buffer_data->stats, 0, sizeof(cmd_buffer_data->stats));
static VkResult overlay_EndCommandBuffer(
VkCommandBuffer commandBuffer)
{
- struct command_buffer_data *cmd_buffer_data = FIND_CMD_BUFFER_DATA(commandBuffer);
+ struct command_buffer_data *cmd_buffer_data =
+ FIND(struct command_buffer_data, commandBuffer);
struct device_data *device_data = cmd_buffer_data->device;
if (cmd_buffer_data->timestamp_query_pool) {
VkCommandBuffer commandBuffer,
VkCommandBufferResetFlags flags)
{
- struct command_buffer_data *cmd_buffer_data = FIND_CMD_BUFFER_DATA(commandBuffer);
+ struct command_buffer_data *cmd_buffer_data =
+ FIND(struct command_buffer_data, commandBuffer);
struct device_data *device_data = cmd_buffer_data->device;
memset(&cmd_buffer_data->stats, 0, sizeof(cmd_buffer_data->stats));
uint32_t commandBufferCount,
const VkCommandBuffer* pCommandBuffers)
{
- struct command_buffer_data *cmd_buffer_data = FIND_CMD_BUFFER_DATA(commandBuffer);
+ struct command_buffer_data *cmd_buffer_data =
+ FIND(struct command_buffer_data, commandBuffer);
struct device_data *device_data = cmd_buffer_data->device;
/* Add the stats of the executed command buffers to the primary one. */
for (uint32_t c = 0; c < commandBufferCount; c++) {
- struct command_buffer_data *sec_cmd_buffer_data = FIND_CMD_BUFFER_DATA(pCommandBuffers[c]);
+ struct command_buffer_data *sec_cmd_buffer_data =
+ FIND(struct command_buffer_data, pCommandBuffers[c]);
for (uint32_t s = 0; s < OVERLAY_PARAM_ENABLED_MAX; s++)
cmd_buffer_data->stats.stats[s] += sec_cmd_buffer_data->stats.stats[s];
const VkCommandBufferAllocateInfo* pAllocateInfo,
VkCommandBuffer* pCommandBuffers)
{
- struct device_data *device_data = FIND_DEVICE_DATA(device);
+ struct device_data *device_data = FIND(struct device_data, device);
VkResult result =
device_data->vtable.AllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers);
if (result != VK_SUCCESS)
uint32_t commandBufferCount,
const VkCommandBuffer* pCommandBuffers)
{
- struct device_data *device_data = FIND_DEVICE_DATA(device);
+ struct device_data *device_data = FIND(struct device_data, device);
for (uint32_t i = 0; i < commandBufferCount; i++) {
struct command_buffer_data *cmd_buffer_data =
- FIND_CMD_BUFFER_DATA(pCommandBuffers[i]);
+ FIND(struct command_buffer_data, pCommandBuffers[i]);
+
/* It is legal to free a NULL command buffer*/
if (!cmd_buffer_data)
continue;
const VkSubmitInfo* pSubmits,
VkFence fence)
{
- struct queue_data *queue_data = FIND_QUEUE_DATA(queue);
+ struct queue_data *queue_data = FIND(struct queue_data, queue);
struct device_data *device_data = queue_data->device;
device_data->frame_stats.stats[OVERLAY_PARAM_ENABLED_submit]++;
for (uint32_t s = 0; s < submitCount; s++) {
for (uint32_t c = 0; c < pSubmits[s].commandBufferCount; c++) {
struct command_buffer_data *cmd_buffer_data =
- FIND_CMD_BUFFER_DATA(pSubmits[s].pCommandBuffers[c]);
+ FIND(struct command_buffer_data, pSubmits[s].pCommandBuffers[c]);
/* Merge the submitted command buffer stats into the device. */
for (uint32_t st = 0; st < OVERLAY_PARAM_ENABLED_MAX; st++)
const VkAllocationCallbacks* pAllocator,
VkDevice* pDevice)
{
- struct instance_data *instance_data = FIND_PHYSICAL_DEVICE_DATA(physicalDevice);
+ struct instance_data *instance_data =
+ FIND(struct instance_data, physicalDevice);
VkLayerDeviceCreateInfo *chain_info =
get_device_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
VkDevice device,
const VkAllocationCallbacks* pAllocator)
{
- struct device_data *device_data = FIND_DEVICE_DATA(device);
+ struct device_data *device_data = FIND(struct device_data, device);
device_unmap_queues(device_data);
device_data->vtable.DestroyDevice(device, pAllocator);
destroy_device_data(device_data);
VkInstance instance,
const VkAllocationCallbacks* pAllocator)
{
- struct instance_data *instance_data = FIND_INSTANCE_DATA(instance);
+ struct instance_data *instance_data = FIND(struct instance_data, instance);
instance_data_map_physical_devices(instance_data, false);
instance_data->vtable.DestroyInstance(instance, pAllocator);
destroy_instance_data(instance_data);
if (dev == NULL) return NULL;
- struct device_data *device_data = FIND_DEVICE_DATA(dev);
+ struct device_data *device_data = FIND(struct device_data, dev);
if (device_data->vtable.GetDeviceProcAddr == NULL) return NULL;
return device_data->vtable.GetDeviceProcAddr(dev, funcName);
}
if (instance == NULL) return NULL;
- struct instance_data *instance_data = FIND_INSTANCE_DATA(instance);
+ struct instance_data *instance_data = FIND(struct instance_data, instance);
if (instance_data->vtable.GetInstanceProcAddr == NULL) return NULL;
return instance_data->vtable.GetInstanceProcAddr(instance, funcName);
}