Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions generator/vk_codegen/device_defs.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include <memory>
#include <mutex>
#include <thread>

// Include from per-layer code
#include "utils.hpp"
Expand Down
2 changes: 0 additions & 2 deletions generator/vk_codegen/instance_defs.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include <memory>
#include <mutex>
#include <thread>

// Include from per-layer code
#include "device.hpp"
Expand Down
24 changes: 11 additions & 13 deletions generator/vk_layer/source/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#include "device.hpp"
#include "instance.hpp"

/**
* @brief The dispatch lookup for all of the created Vulkan instances.
*/
static std::unordered_map<void*, std::unique_ptr<Device>> g_devices;

/* See header for documentation. */
Expand All @@ -47,26 +50,26 @@ void Device::store(

/* See header for documentation. */
Device* Device::retrieve(
VkDevice handle)
{
VkDevice handle
) {
void* key = getDispatchKey(handle);
assert(isInMap(key, g_devices));
return g_devices.at(key).get();
}

/* See header for documentation. */
Device* Device::retrieve(
VkQueue handle)
{
VkQueue handle
) {
void* key = getDispatchKey(handle);
assert(isInMap(key, g_devices));
return g_devices.at(key).get();
}

/* See header for documentation. */
Device* Device::retrieve(
VkCommandBuffer handle)
{
VkCommandBuffer handle
) {
void* key = getDispatchKey(handle);
assert(isInMap(key, g_devices));
return g_devices.at(key).get();
Expand All @@ -85,15 +88,10 @@ Device::Device(
VkPhysicalDevice _physicalDevice,
VkDevice _device,
PFN_vkGetDeviceProcAddr nlayerGetProcAddress
): instance(_instance),
):
instance(_instance),
physicalDevice(_physicalDevice),
device(_device)
{
initDriverDeviceDispatchTable(device, nlayerGetProcAddress, driver);
}

/* See header for documentation. */
Device::~Device()
{

}
18 changes: 11 additions & 7 deletions generator/vk_layer/source/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
*/

/**
* @file
* Declares the root class for layer management of VkDevice objects.
* @file Declares the root class for layer management of VkDevice objects.
*
* Role summary
* ============
Expand All @@ -41,10 +40,9 @@
* Key properties
* ==============
*
* Unlike EGL contexts, Vulkan devices are designed to be used concurrently by
* multiple application threads. An application can have multiple concurrent
* devices (although this is less common than with OpenGL ES applications), and
* use each device from multiple threads.
* Vulkan devices are designed to be used concurrently by multiple application
* threads. An application can have multiple concurrent devices, and use each
* device from multiple threads.
*
* Access to the layer driver structures must therefore be kept thread-safe.
* For sake of simplicity, we generally implement this by:
Expand Down Expand Up @@ -80,6 +78,8 @@ class Device
* @brief Fetch a device from the global store of dispatchable devices.
*
* @param handle The dispatchable device handle to use as an indirect lookup.
*
* @return The layer device context.
*/
static Device* retrieve(
VkDevice handle);
Expand All @@ -88,6 +88,8 @@ class Device
* @brief Fetch a device from the global store of dispatchable devices.
*
* @param handle The dispatchable queue handle to use as an indirect lookup.
*
* @return The layer device context.
*/
static Device* retrieve(
VkQueue handle);
Expand All @@ -96,6 +98,8 @@ class Device
* @brief Fetch a device from the global store of dispatchable devices.
*
* @param handle The dispatchable command buffer handle to use as an indirect lookup.
*
* @return The layer device context.
*/
static Device* retrieve(
VkCommandBuffer handle);
Expand Down Expand Up @@ -125,7 +129,7 @@ class Device
/**
* @brief Destroy this layer device object.
*/
~Device();
~Device() = default;

public:
/**
Expand Down
14 changes: 9 additions & 5 deletions generator/vk_layer/source/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

#include "instance.hpp"

/**
* @brief The dispatch lookup for all of the created Vulkan instances.
*/
static std::unordered_map<void*, std::unique_ptr<Instance>> g_instances;

/* See header for documentation. */
Expand All @@ -42,17 +45,17 @@ void Instance::store(

/* See header for documentation. */
Instance* Instance::retrieve(
VkInstance handle)
{
VkInstance handle
) {
void* key = getDispatchKey(handle);
assert(isInMap(key, g_instances));
return g_instances.at(key).get();
}

/* See header for documentation. */
Instance* Instance::retrieve(
VkPhysicalDevice handle)
{
VkPhysicalDevice handle
) {
void* key = getDispatchKey(handle);
assert(isInMap(key, g_instances));
return g_instances.at(key).get();
Expand All @@ -68,7 +71,8 @@ void Instance::destroy(
/* See header for documentation. */
Instance::Instance(
VkInstance _instance,
PFN_vkGetInstanceProcAddr _nlayerGetProcAddress) :
PFN_vkGetInstanceProcAddr _nlayerGetProcAddress
) :
instance(_instance),
nlayerGetProcAddress(_nlayerGetProcAddress)
{
Expand Down
13 changes: 6 additions & 7 deletions generator/vk_layer/source/instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@
* Key properties
* ==============
*
* Unlike EGL contexts, Vulkan instances are designed to be used concurrently
* by multiple application threads. An application can have multiple concurrent
* instances (although this is less common than with OpenGL ES applications),
* Vulkan instances are designed to be used concurrently by multiple
* application threads. An application can have multiple concurrent instances,
* and use each instance from multiple threads.
*
* Access to the layer driver structures must therefore be kept thread-safe.
Expand All @@ -65,10 +64,6 @@

/**
* @brief This class implements the layer state tracker for a single instance.
*
* These objects are relatively light-weight, as they are rarely used once a VkDevice has been
* created, but we need to track the chain-of-ownership as the instance is the root object that
* the application creates when initializing a rendering context.
*/
class Instance
{
Expand All @@ -87,6 +82,8 @@ class Instance
* @brief Fetch an instance from the global store of dispatchable instances.
*
* @param handle The dispatchable instance handle to use as an indirect lookup.
*
* @return The layer instance context.
*/
static Instance* retrieve(
VkInstance handle);
Expand All @@ -95,6 +92,8 @@ class Instance
* @brief Fetch an instance from the global store of dispatchable instances.
*
* @param handle The dispatchable physical device handle to use as an indirect lookup.
*
* @return The layer instance context.
*/
static Instance* retrieve(
VkPhysicalDevice handle);
Expand Down
4 changes: 1 addition & 3 deletions generator/vk_layer/source/version.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
*/

/**
* @file
* This header implements placeholder templates that are populated by CMake
* during configure.
* @file Placeholder templates that are populated by CMake during configure.
*/

#pragma once
Expand Down
24 changes: 11 additions & 13 deletions layer_example/source/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#include "device.hpp"
#include "instance.hpp"

/**
* @brief The dispatch lookup for all of the created Vulkan instances.
*/
static std::unordered_map<void*, std::unique_ptr<Device>> g_devices;

/* See header for documentation. */
Expand All @@ -47,26 +50,26 @@ void Device::store(

/* See header for documentation. */
Device* Device::retrieve(
VkDevice handle)
{
VkDevice handle
) {
void* key = getDispatchKey(handle);
assert(isInMap(key, g_devices));
return g_devices.at(key).get();
}

/* See header for documentation. */
Device* Device::retrieve(
VkQueue handle)
{
VkQueue handle
) {
void* key = getDispatchKey(handle);
assert(isInMap(key, g_devices));
return g_devices.at(key).get();
}

/* See header for documentation. */
Device* Device::retrieve(
VkCommandBuffer handle)
{
VkCommandBuffer handle
) {
void* key = getDispatchKey(handle);
assert(isInMap(key, g_devices));
return g_devices.at(key).get();
Expand All @@ -85,15 +88,10 @@ Device::Device(
VkPhysicalDevice _physicalDevice,
VkDevice _device,
PFN_vkGetDeviceProcAddr nlayerGetProcAddress
): instance(_instance),
):
instance(_instance),
physicalDevice(_physicalDevice),
device(_device)
{
initDriverDeviceDispatchTable(device, nlayerGetProcAddress, driver);
}

/* See header for documentation. */
Device::~Device()
{

}
18 changes: 11 additions & 7 deletions layer_example/source/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
*/

/**
* @file
* Declares the root class for layer management of VkDevice objects.
* @file Declares the root class for layer management of VkDevice objects.
*
* Role summary
* ============
Expand All @@ -41,10 +40,9 @@
* Key properties
* ==============
*
* Unlike EGL contexts, Vulkan devices are designed to be used concurrently by
* multiple application threads. An application can have multiple concurrent
* devices (although this is less common than with OpenGL ES applications), and
* use each device from multiple threads.
* Vulkan devices are designed to be used concurrently by multiple application
* threads. An application can have multiple concurrent devices, and use each
* device from multiple threads.
*
* Access to the layer driver structures must therefore be kept thread-safe.
* For sake of simplicity, we generally implement this by:
Expand Down Expand Up @@ -80,6 +78,8 @@ class Device
* @brief Fetch a device from the global store of dispatchable devices.
*
* @param handle The dispatchable device handle to use as an indirect lookup.
*
* @return The layer device context.
*/
static Device* retrieve(
VkDevice handle);
Expand All @@ -88,6 +88,8 @@ class Device
* @brief Fetch a device from the global store of dispatchable devices.
*
* @param handle The dispatchable queue handle to use as an indirect lookup.
*
* @return The layer device context.
*/
static Device* retrieve(
VkQueue handle);
Expand All @@ -96,6 +98,8 @@ class Device
* @brief Fetch a device from the global store of dispatchable devices.
*
* @param handle The dispatchable command buffer handle to use as an indirect lookup.
*
* @return The layer device context.
*/
static Device* retrieve(
VkCommandBuffer handle);
Expand Down Expand Up @@ -125,7 +129,7 @@ class Device
/**
* @brief Destroy this layer device object.
*/
~Device();
~Device() = default;

public:
/**
Expand Down
14 changes: 9 additions & 5 deletions layer_example/source/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

#include "instance.hpp"

/**
* @brief The dispatch lookup for all of the created Vulkan instances.
*/
static std::unordered_map<void*, std::unique_ptr<Instance>> g_instances;

/* See header for documentation. */
Expand All @@ -42,17 +45,17 @@ void Instance::store(

/* See header for documentation. */
Instance* Instance::retrieve(
VkInstance handle)
{
VkInstance handle
) {
void* key = getDispatchKey(handle);
assert(isInMap(key, g_instances));
return g_instances.at(key).get();
}

/* See header for documentation. */
Instance* Instance::retrieve(
VkPhysicalDevice handle)
{
VkPhysicalDevice handle
) {
void* key = getDispatchKey(handle);
assert(isInMap(key, g_instances));
return g_instances.at(key).get();
Expand All @@ -68,7 +71,8 @@ void Instance::destroy(
/* See header for documentation. */
Instance::Instance(
VkInstance _instance,
PFN_vkGetInstanceProcAddr _nlayerGetProcAddress) :
PFN_vkGetInstanceProcAddr _nlayerGetProcAddress
) :
instance(_instance),
nlayerGetProcAddress(_nlayerGetProcAddress)
{
Expand Down
Loading