google/vulkan-performance-layers

Use dispatchable handles instead of tracking object relationships

Closed this issue · 6 comments

kuhar commented

This is a low priority refactoring task to simplify core layer code.
See the suggestion form @paulthomson: #18 (comment).

In other words, instead of using VkInstance as a key (and the same idea applies for VkDevice), use the "dispatch table pointer" of the VkInstance, which you get using this function (please ignore the snake_case naming). And when you have a VkPhysicalDevice, use pretty much the same function to get the VkInstance dispatch table pointer, which you can then use to look-up the data you have for the VkInstance (which should include the VkInstance value itself).

Another example of where this is somewhat nice is in a frame counter layer. We don't need to track VkQueue; we can go straight from the VkQueue to the DeviceData.

Hey @kuhar want to work on this.

kuhar commented

Hi @Hardik0307, great! Feel free to ask any questions under this issue.

Hi @Hardik0307, great! Feel free to ask any questions under this issue.
Creating dispatchable objects

is this helpful?

kuhar commented

Yes, this is a related section. You can find full context in Paul's comment with the suggestion on how to implement it: #18 (comment). The implementation in https://github.com/google/gf-layers/blob/master/src/VkLayer_GF_frame_counter/src/frame_counter_layer.cc uses vulkan objects exactly like we want.

@kuhar,
I've studied one layer frame_time_layer
and made changes in FrameTimeLayer_QueuePresentKHR like this

  auto device = layer_data->GetDevice.Get(DeviceKey(queue));
  
 auto next_proc = layer_data->GetNextDeviceProcAddr(
      device, &VkLayerDispatchTable::QueuePresentKHR);
  return (next_proc)(queue, present_info);

Review.

kuhar commented

@Hardik0307 cool, the next step would be to make sure that everything builds and you get some output with the layers enabled. You need a working Vulkan installation for that, either configured for your physical GPU, or a software-based one with something like swiftshader. See scripts/gen_sample_output.sh for instructions on generating sample output.
When your change is in a reasonable shape, just submit a pull request.