本文整理汇总了C++中VkLayerDispatchTable类的典型用法代码示例。如果您正苦于以下问题:C++ VkLayerDispatchTable类的具体用法?C++ VkLayerDispatchTable怎么用?C++ VkLayerDispatchTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VkLayerDispatchTable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: vkAllocateCommandBuffers
VkResult VKAPI_CALL vkAllocateCommandBuffers(
VkDevice device,
const VkCommandBufferAllocateInfo* pAllocateInfo,
VkCommandBuffer* pCommandBuffers)
{
dispatch_key key = get_dispatch_key(device);
layer_data *my_data = get_my_data_ptr(key, layer_data_map);
VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
VkResult result;
startReadObject(my_data, device);
startWriteObject(my_data, pAllocateInfo->commandPool);
result = pTable->AllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers);
finishReadObject(my_data, device);
finishWriteObject(my_data, pAllocateInfo->commandPool);
// Record mapping from command buffer to command pool
if (VK_SUCCESS == result) {
for (int index=0;index<pAllocateInfo->commandBufferCount;index++) {
loader_platform_thread_lock_mutex(&threadingLock);
command_pool_map[pCommandBuffers[index]] = pAllocateInfo->commandPool;
loader_platform_thread_unlock_mutex(&threadingLock);
}
}
return result;
}
开发者ID:lhqsine,项目名称:Vulkan-LoaderAndValidationLayers,代码行数:27,代码来源:threading.cpp
示例2: assert
/* Various dispatchable objects will use the same underlying dispatch table if
* they
* are created from that "parent" object. Thus use pointer to dispatch table
* as the key to these table maps.
* Instance -> PhysicalDevice
* Device -> CommandBuffer or Queue
* If use the object themselves as key to map then implies Create entrypoints
* have to be intercepted
* and a new key inserted into map */
VkLayerDebugMarkerDispatchTable *initDebugMarkerTable(VkDevice device) {
VkLayerDebugMarkerDispatchTable *pDebugMarkerTable;
assert(device);
VkLayerDispatchTable *pDisp = *(VkLayerDispatchTable **)device;
std::unordered_map<void *,
VkLayerDebugMarkerDispatchTable *>::const_iterator it =
tableDebugMarkerMap.find((void *)pDisp);
if (it == tableDebugMarkerMap.end()) {
pDebugMarkerTable = new VkLayerDebugMarkerDispatchTable;
tableDebugMarkerMap[(void *)pDisp] = pDebugMarkerTable;
} else {
return it->second;
}
pDebugMarkerTable->CmdDbgMarkerBegin =
(PFN_vkCmdDbgMarkerBegin)pDisp->GetDeviceProcAddr(
device, "vkCmdDbgMarkerBegin");
pDebugMarkerTable->CmdDbgMarkerEnd =
(PFN_vkCmdDbgMarkerEnd)pDisp->GetDeviceProcAddr(device,
"vkCmdDbgMarkerEnd");
pDebugMarkerTable->DbgSetObjectTag =
(PFN_vkDbgSetObjectTag)pDisp->GetDeviceProcAddr(device,
"vkDbgSetObjectTag");
pDebugMarkerTable->DbgSetObjectName =
(PFN_vkDbgSetObjectName)pDisp->GetDeviceProcAddr(device,
"vkDbgSetObjectName");
return pDebugMarkerTable;
}
开发者ID:uraani,项目名称:StercusEngine,代码行数:40,代码来源:vk_layer_debug_marker_table.cpp
示例3: vkGetDeviceProcAddr
VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
#define ADD_HOOK(fn) \
if (!strncmp(#fn, funcName, sizeof(#fn))) \
return (PFN_vkVoidFunction)fn
ADD_HOOK(vkGetDeviceProcAddr);
ADD_HOOK(vkDestroyDevice);
ADD_HOOK(vkCreateSwapchainKHR);
ADD_HOOK(vkGetSwapchainImagesKHR);
ADD_HOOK(vkQueuePresentKHR);
ADD_HOOK(vkDestroySwapchainKHR);
ADD_HOOK(vkQueueSubmit);
#undef ADD_HOOK
if (dev == NULL)
return NULL;
layer_data *dev_data;
dev_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
VkLayerDispatchTable *pTable = dev_data->device_dispatch_table;
if (pTable->GetDeviceProcAddr == NULL)
return NULL;
return pTable->GetDeviceProcAddr(dev, funcName);
}
开发者ID:10imaging,项目名称:vulkan-basic-samples,代码行数:26,代码来源:overlay.cpp
示例4: vkFreeCommandBuffers
void VKAPI_CALL vkFreeCommandBuffers(
VkDevice device,
VkCommandPool commandPool,
uint32_t commandBufferCount,
const VkCommandBuffer* pCommandBuffers)
{
dispatch_key key = get_dispatch_key(device);
layer_data *my_data = get_my_data_ptr(key, layer_data_map);
VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
const bool lockCommandPool = false; // pool is already directly locked
startReadObject(my_data, device);
startWriteObject(my_data, commandPool);
for (int index=0;index<commandBufferCount;index++) {
startWriteObject(my_data, pCommandBuffers[index], lockCommandPool);
}
pTable->FreeCommandBuffers(device,commandPool,commandBufferCount,pCommandBuffers);
finishReadObject(my_data, device);
finishWriteObject(my_data, commandPool);
for (int index=0;index<commandBufferCount;index++) {
finishWriteObject(my_data, pCommandBuffers[index], lockCommandPool);
loader_platform_thread_lock_mutex(&threadingLock);
command_pool_map.erase(pCommandBuffers[index]);
loader_platform_thread_unlock_mutex(&threadingLock);
}
}
开发者ID:lhqsine,项目名称:Vulkan-LoaderAndValidationLayers,代码行数:26,代码来源:threading.cpp
示例5: vkQueueSubmit
VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
VkFence fence) {
layer_data *my_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
my_data->cmdBuffersThisFrame += submitCount; // XXX WRONG
return pTable->QueueSubmit(queue, submitCount, pSubmits, fence);
}
开发者ID:LunarG,项目名称:VulkanSamples,代码行数:9,代码来源:overlay.cpp
示例6: vkDestroyDevice
VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
dispatch_key key = get_dispatch_key(device);
layer_data *my_data = GetLayerDataPtr(key, layer_data_map);
my_data->Cleanup();
VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
pTable->DeviceWaitIdle(device);
pTable->DestroyDevice(device, pAllocator);
delete pTable;
layer_data_map.erase(key);
}
开发者ID:LunarG,项目名称:VulkanSamples,代码行数:10,代码来源:overlay.cpp
示例7: get_my_data_ptr
void WsiImageData::Cleanup(VkDevice dev) {
layer_data *my_data =
get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
// XXX: needs device data
// pTable->FreeCommandBuffers(dev, cmd, nullptr);
pTable->DestroyFramebuffer(dev, framebuffer, nullptr);
pTable->DestroyImageView(dev, view, nullptr);
pTable->DestroyBuffer(dev, vertexBuffer, nullptr);
pTable->FreeMemory(dev, vertexBufferMemory, nullptr);
}
开发者ID:10imaging,项目名称:vulkan-basic-samples,代码行数:12,代码来源:overlay.cpp
示例8: GetLayerDataPtr
void SwapChainData::Cleanup(VkDevice dev) {
layer_data *my_data = GetLayerDataPtr(get_dispatch_key(dev), layer_data_map);
VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
for (uint32_t i = 0; i < presentableImages.size(); i++) {
presentableImages[i]->Cleanup(dev);
delete presentableImages[i];
}
presentableImages.clear();
pTable->DestroyPipeline(dev, pipeline, nullptr);
pTable->DestroyRenderPass(dev, render_pass, nullptr);
}
开发者ID:LunarG,项目名称:VulkanSamples,代码行数:14,代码来源:overlay.cpp
示例9: DestroyDevice
VKAPI_ATTR void VKAPI_CALL
DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
DeviceMapStruct *devMap = get_dev_info(device);
assert(devMap);
VkLayerDispatchTable *pDisp = devMap->device_dispatch_table;
pDisp->DestroyDevice(device, pAllocator);
loader_platform_thread_lock_mutex(&globalLock);
delete pDisp;
delete devMap;
deviceMap.erase(device);
loader_platform_thread_unlock_mutex(&globalLock);
}
开发者ID:ZLixing,项目名称:VulkanTools,代码行数:14,代码来源:screenshot.cpp
示例10: GetSwapchainImagesKHR
VKAPI_ATTR VkResult VKAPI_CALL
GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
uint32_t *pCount, VkImage *pSwapchainImages) {
DeviceMapStruct *devMap = get_dev_info(device);
assert(devMap);
VkLayerDispatchTable *pDisp = devMap->device_dispatch_table;
VkResult result = pDisp->GetSwapchainImagesKHR(device, swapchain, pCount,
pSwapchainImages);
// Save the swapchain images in a map if we are taking screenshots
loader_platform_thread_lock_mutex(&globalLock);
if (screenshotEnvQueried && screenshotFrames.empty()) {
// No screenshots in the list to take
loader_platform_thread_unlock_mutex(&globalLock);
return result;
}
if (result == VK_SUCCESS && pSwapchainImages && !swapchainMap.empty() &&
swapchainMap.find(swapchain) != swapchainMap.end()) {
unsigned i;
for (i = 0; i < *pCount; i++) {
// Create a mapping for an image to a device, image extent, and
// format
if (imageMap[pSwapchainImages[i]] == NULL) {
ImageMapStruct *imageMapElem = new ImageMapStruct;
imageMap[pSwapchainImages[i]] = imageMapElem;
}
imageMap[pSwapchainImages[i]]->device =
swapchainMap[swapchain]->device;
imageMap[pSwapchainImages[i]]->imageExtent =
swapchainMap[swapchain]->imageExtent;
imageMap[pSwapchainImages[i]]->format =
swapchainMap[swapchain]->format;
}
// Add list of images to swapchain to image map
SwapchainMapStruct *swapchainMapElem = swapchainMap[swapchain];
if (i >= 1 && swapchainMapElem) {
VkImage *imageList = new VkImage[i];
swapchainMapElem->imageList = imageList;
for (unsigned j = 0; j < i; j++) {
swapchainMapElem->imageList[j] = pSwapchainImages[j];
}
}
}
loader_platform_thread_unlock_mutex(&globalLock);
return result;
}
开发者ID:ZLixing,项目名称:VulkanTools,代码行数:49,代码来源:screenshot.cpp
示例11: GetDeviceProcAddr
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char *funcName) {
PFN_vkVoidFunction addr;
layer_data *dev_data;
assert(device);
addr = layer_intercept_proc(funcName);
if (addr)
return addr;
dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
VkLayerDispatchTable *pTable = dev_data->device_dispatch_table;
if (pTable->GetDeviceProcAddr == NULL)
return NULL;
return pTable->GetDeviceProcAddr(device, funcName);
}
开发者ID:AdamRLukaitis,项目名称:VulkanSamples,代码行数:17,代码来源:threading.cpp
示例12: vkGetDeviceProcAddr
VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName) {
PFN_vkVoidFunction addr;
layer_data *dev_data;
if (device == VK_NULL_HANDLE) {
return NULL;
}
addr = layer_intercept_proc(funcName);
if (addr)
return addr;
dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
VkLayerDispatchTable *pTable = dev_data->device_dispatch_table;
if (pTable->GetDeviceProcAddr == NULL)
return NULL;
return pTable->GetDeviceProcAddr(device, funcName);
}
开发者ID:MichaelMcDonnell,项目名称:Vulkan-LoaderAndValidationLayers,代码行数:18,代码来源:threading.cpp
示例13: CreateSwapchainKHR
VKAPI_ATTR VkResult VKAPI_CALL CreateSwapchainKHR(
VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) {
DeviceMapStruct *devMap = get_dev_info(device);
assert(devMap);
VkLayerDispatchTable *pDisp = devMap->device_dispatch_table;
// This layer does an image copy later on, and the copy command expects the
// transfer src bit to be on.
VkSwapchainCreateInfoKHR myCreateInfo = *pCreateInfo;
myCreateInfo.imageUsage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
VkResult result = pDisp->CreateSwapchainKHR(device, &myCreateInfo,
pAllocator, pSwapchain);
// Save the swapchain in a map of we are taking screenshots.
loader_platform_thread_lock_mutex(&globalLock);
if (screenshotEnvQueried && screenshotFrames.empty()) {
// No screenshots in the list to take
loader_platform_thread_unlock_mutex(&globalLock);
return result;
}
if (result == VK_SUCCESS) {
// Create a mapping for a swapchain to a device, image extent, and
// format
SwapchainMapStruct *swapchainMapElem = new SwapchainMapStruct;
swapchainMapElem->device = device;
swapchainMapElem->imageExtent = pCreateInfo->imageExtent;
swapchainMapElem->format = pCreateInfo->imageFormat;
swapchainMap.insert(make_pair(*pSwapchain, swapchainMapElem));
// Create a mapping for the swapchain object into the dispatch table
// TODO is this needed? screenshot_device_table_map.emplace((void
// *)pSwapchain, pTable);
}
loader_platform_thread_unlock_mutex(&globalLock);
return result;
}
开发者ID:ZLixing,项目名称:VulkanTools,代码行数:40,代码来源:screenshot.cpp
示例14: CreateCommandPool
VKAPI_ATTR VkResult VKAPI_CALL CreateCommandPool(
VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool) {
DeviceMapStruct *devMap = get_dev_info(device);
assert(devMap);
VkLayerDispatchTable *pDisp = devMap->device_dispatch_table;
VkResult result =
pDisp->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
// Save the command pool on a map if we are taking screenshots.
loader_platform_thread_lock_mutex(&globalLock);
if (screenshotEnvQueried && screenshotFrames.empty()) {
// No screenshots in the list to take
loader_platform_thread_unlock_mutex(&globalLock);
return result;
}
// Create a mapping from a device to a commandPool
devMap->commandPool = *pCommandPool;
loader_platform_thread_unlock_mutex(&globalLock);
return result;
}
开发者ID:ZLixing,项目名称:VulkanTools,代码行数:22,代码来源:screenshot.cpp
示例15: GetDeviceProcAddr
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
GetDeviceProcAddr(VkDevice dev, const char *funcName) {
PFN_vkVoidFunction proc = intercept_core_device_command(funcName);
if (proc)
return proc;
if (dev == NULL) {
return NULL;
}
proc = intercept_khr_swapchain_command(funcName, dev);
if (proc)
return proc;
DeviceMapStruct *devMap = get_dev_info(dev);
assert(devMap);
VkLayerDispatchTable *pDisp = devMap->device_dispatch_table;
if (pDisp->GetDeviceProcAddr == NULL)
return NULL;
return pDisp->GetDeviceProcAddr(dev, funcName);
}
开发者ID:ZLixing,项目名称:VulkanTools,代码行数:22,代码来源:screenshot.cpp
示例16: vkGetDeviceProcAddr
VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
if (!strcmp(funcName, "vkGetDeviceProcAddr"))
return (PFN_vkVoidFunction)vkGetDeviceProcAddr;
if (!strcmp(funcName, "vkDestroyDevice"))
return (PFN_vkVoidFunction)vkDestroyDevice;
if (!strcmp(funcName, "vkGetDeviceQueue"))
return (PFN_vkVoidFunction)vkGetDeviceQueue;
if (!strcmp(funcName, "vkCreateRenderPass"))
return (PFN_vkVoidFunction)vkCreateRenderPass;
if (!strcmp(funcName, "vkCreateCommandPool"))
return (PFN_vkVoidFunction)vkCreateCommandPool;
if (!strcmp(funcName, "vkDestroyCommandPool"))
return (PFN_vkVoidFunction)vkDestroyCommandPool;
if (!strcmp(funcName, "vkResetCommandPool"))
return (PFN_vkVoidFunction)vkResetCommandPool;
if (!strcmp(funcName, "vkAllocateCommandBuffers"))
return (PFN_vkVoidFunction)vkAllocateCommandBuffers;
if (!strcmp(funcName, "vkFreeCommandBuffers"))
return (PFN_vkVoidFunction)vkFreeCommandBuffers;
if (!strcmp(funcName, "vkBeginCommandBuffer"))
return (PFN_vkVoidFunction)vkBeginCommandBuffer;
if (!strcmp(funcName, "vkCmdUpdateBuffer"))
return (PFN_vkVoidFunction)vkCmdUpdateBuffer;
if (!strcmp(funcName, "vkUpdateDescriptorSets"))
return (PFN_vkVoidFunction)vkUpdateDescriptorSets;
if (!strcmp(funcName, "vkCmdFillBuffer"))
return (PFN_vkVoidFunction)vkCmdFillBuffer;
if (dev == NULL)
return NULL;
layer_data *my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
{
if (pTable->GetDeviceProcAddr == NULL)
return NULL;
return pTable->GetDeviceProcAddr(dev, funcName);
}
}
开发者ID:ChristophHaag,项目名称:VulkanSamples,代码行数:39,代码来源:device_limits.cpp
示例17: AllocateCommandBuffers
VKAPI_ATTR VkResult VKAPI_CALL
AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo, VkCommandBuffer *pCommandBuffers) {
dispatch_key key = get_dispatch_key(device);
layer_data *my_data = get_my_data_ptr(key, layer_data_map);
VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
VkResult result;
startReadObject(my_data, device);
startWriteObject(my_data, pAllocateInfo->commandPool);
result = pTable->AllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers);
finishReadObject(my_data, device);
finishWriteObject(my_data, pAllocateInfo->commandPool);
// Record mapping from command buffer to command pool
if (VK_SUCCESS == result) {
for (uint32_t index = 0; index < pAllocateInfo->commandBufferCount; index++) {
std::lock_guard<std::mutex> lock(global_lock);
command_pool_map[pCommandBuffers[index]] = pAllocateInfo->commandPool;
}
}
return result;
}
开发者ID:AdamRLukaitis,项目名称:VulkanSamples,代码行数:23,代码来源:threading.cpp
示例18: GetDeviceQueue
VKAPI_ATTR void VKAPI_CALL GetDeviceQueue(VkDevice device,
uint32_t queueNodeIndex,
uint32_t queueIndex,
VkQueue *pQueue) {
DeviceMapStruct *devMap = get_dev_info(device);
assert(devMap);
VkLayerDispatchTable *pDisp = devMap->device_dispatch_table;
pDisp->GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
// Save the device queue in a map if we are taking screenshots.
loader_platform_thread_lock_mutex(&globalLock);
if (screenshotEnvQueried && screenshotFrames.empty()) {
// No screenshots in the list to take
loader_platform_thread_unlock_mutex(&globalLock);
return;
}
VkDevice que = static_cast<VkDevice>(static_cast<void *>(*pQueue));
deviceMap.emplace(que, devMap);
// Create a mapping from a device to a queue
devMap->queue = *pQueue;
loader_platform_thread_unlock_mutex(&globalLock);
}
开发者ID:ZLixing,项目名称:VulkanTools,代码行数:24,代码来源:screenshot.cpp
示例19: vkGetSwapchainImagesKHR
VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapChain, uint32_t *pCount,
VkImage *pImages) {
layer_data *my_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
VkResult result = my_data->pfnGetSwapchainImagesKHR(device, swapChain, pCount, pImages);
VkResult U_ASSERT_ONLY err;
/* GetSwapChainImagesWSI may be called without an images buffer, in which
* case it
* just returns the count to the caller. We're only interested in acting on
* the
* /actual/ fetch of the images.
*/
if (pImages) {
auto data = (*my_data->swapChains)[swapChain];
for (uint32_t i = 0; i < *pCount; i++) {
/* Create attachment view for each */
VkImageViewCreateInfo ivci;
ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
ivci.pNext = nullptr;
ivci.format = data->format;
ivci.components.r = VK_COMPONENT_SWIZZLE_R;
ivci.components.g = VK_COMPONENT_SWIZZLE_G;
ivci.components.b = VK_COMPONENT_SWIZZLE_B;
ivci.components.a = VK_COMPONENT_SWIZZLE_A;
ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
ivci.subresourceRange.baseMipLevel = 0;
ivci.subresourceRange.levelCount = 1;
ivci.subresourceRange.baseArrayLayer = 0;
ivci.subresourceRange.layerCount = 1;
ivci.image = pImages[i];
ivci.flags = 0;
VkImageView v;
pTable->CreateImageView(device, &ivci, nullptr, &v);
/* Create framebuffer for each */
VkFramebufferCreateInfo fci;
fci.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
fci.pNext = nullptr;
fci.flags = 0;
fci.renderPass = data->render_pass;
fci.attachmentCount = 1;
fci.pAttachments = &v;
fci.width = data->width;
fci.height = data->height;
fci.layers = 1;
VkFramebuffer fb;
pTable->CreateFramebuffer(device, &fci, nullptr, &fb);
/* Create command buffer for each */
VkCommandBufferAllocateInfo cbai;
cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
cbai.pNext = nullptr;
cbai.commandPool = my_data->pool;
cbai.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
cbai.commandBufferCount = 1;
VkCommandBuffer cmd;
pTable->AllocateCommandBuffers(device, &cbai, &cmd);
/* We have just created a dispatchable object, but the dispatch
* table has not been placed in the object yet.
* When a "normal" application creates a command buffer,
* the dispatch table is installed by the top-level binding
* (trampoline.c).
* But here, we have to do it ourselves. */
if (!my_data->pfn_dev_init) {
*((const void **)cmd) = *(void **)device;
} else {
err = my_data->pfn_dev_init(device, (void *)cmd);
assert(!err);
}
/* Create vertex buffer */
VkBufferCreateInfo bci;
memset(&bci, 0, sizeof(bci));
bci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
bci.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
bci.size = sizeof(vertex) * MAX_TEXT_VERTICES;
VkBuffer buf;
err = pTable->CreateBuffer(device, &bci, nullptr, &buf);
assert(!err);
VkMemoryRequirements mem_reqs;
pTable->GetBufferMemoryRequirements(device, buf, &mem_reqs);
assert(!err);
VkMemoryAllocateInfo mem_alloc;
memset(&mem_alloc, 0, sizeof(mem_alloc));
mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
mem_alloc.allocationSize = mem_reqs.size;
mem_alloc.memoryTypeIndex = choose_memory_type(
my_data->gpu, mem_reqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
//.........这里部分代码省略.........
开发者ID:LunarG,项目名称:VulkanSamples,代码行数:101,代码来源:overlay.cpp
示例20: writePPM
// Save an image to a PPM image file.
//
// This function issues commands to copy/convert the swapchain image
// from whatever compatible format the swapchain image uses
// to a single format (VK_FORMAT_R8G8B8A8_UNORM) so that the converted
// result can be easily written to a PPM file.
//
// Error handling: If there is a problem, this function should silently
// fail without affecting the Present operation going on in the caller.
// The numerous debug asserts are to catch programming errors and are not
// expected to assert. Recovery and clean up are implemented for image memory
// allocation failures.
// (TODO) It would be nice to pass any failure info to DebugReport or something.
static void writePPM(const char *filename, VkImage image1) {
VkResult err;
bool pass;
// Bail immediately if we can't find the image.
if (imageMap.empty() || imageMap.find(image1) == imageMap.end())
return;
// Collect object info from maps. This info is generally recorded
// by the other functions hooked in this layer.
VkDevice device = imageMap[image1]->device;
VkPhysicalDevice physicalDevice = deviceMap[device]->physicalDevice;
VkInstance instance = physDeviceMap[physicalDevice]->instance;
VkQueue queue = deviceMap[device]->queue;
DeviceMapStruct *devMap = get_dev_info(device);
if (NULL == devMap) {
assert(0);
return;
}
VkLayerDispatchTable *pTableDevice = devMap->device_dispatch_table;
VkLayerDispatchTable *pTableQueue =
get_dev_info(static_cast<VkDevice>(static_cast<void *>(queue)))
->device_dispatch_table;
VkLayerInstanceDispatchTable *pInstanceTable;
pInstanceTable = instance_dispatch_table(instance);
// Gather incoming image info and check image format for compatibility with
// the target format.
// This function supports both 24-bit and 32-bit swapchain images.
VkFormat const target32bitFormat = VK_FORMAT_R8G8B8A8_UNORM;
VkFormat const target24bitFormat = VK_FORMAT_R8G8B8_UNORM;
uint32_t const width = imageMap[image1]->imageExtent.width;
uint32_t const height = imageMap[image1]->imageExtent.height;
VkFormat const format = imageMap[image1]->format;
uint32_t const numChannels = vk_format_get_channel_count(format);
if ((vk_format_get_compatibility_class(target24bitFormat) !=
vk_format_get_compatibility_class(format)) &&
(vk_format_get_compatibility_class(target32bitFormat) !=
vk_format_get_compatibility_class(format))) {
assert(0);
return;
}
if ((3 != numChannels) && (4 != numChannels)) {
assert(0);
return;
}
// General Approach
//
// The idea here is to copy/convert the swapchain image into another image
// that can be mapped and read by the CPU to produce a PPM file.
// The image must be untiled and converted to a specific format for easy
// parsing. The memory for the final image must be host-visible.
// Note that in Vulkan, a BLIT operation must be used to perform a format
// conversion.
//
// Devices vary in their ability to blit to/from linear and optimal tiling.
// So we must query the device properties to get this information.
//
// If the device cannot BLIT to a LINEAR image, then the operation must be
// done in two steps:
// 1) BLIT the swapchain image (image1) to a temp image (image2) that is
// created with TILING_OPTIMAL.
// 2) COPY image2 to another temp image (image3) that is created with
// TILING_LINEAR.
// 3) Map image 3 and write the PPM file.
//
// If the device can BLIT to a LINEAR image, then:
// 1) BLIT the swapchain image (image1) to a temp image (image2) that is
// created with TILING_LINEAR.
// 2) Map image 2 and write the PPM file.
//
// There seems to be no way to tell if the swapchain image (image1) is tiled
// or not. We therefore assume that the BLIT operation can always read from
// both linear and optimal tiled (swapchain) images.
// There is therefore no point in looking at the BLIT_SRC properties.
//
// There is also the optimization where the incoming and target formats are
// the same. In this case, just do a COPY.
VkFormatProperties targetFormatProps;
pInstanceTable->GetPhysicalDeviceFormatProperties(
physicalDevice,
(3 == numChannels) ? target24bitFormat : target32bitFormat,
&targetFormatProps);
bool need2steps = false;
//.........这里部分代码省略.........
开发者ID:ZLixing,项目名称:VulkanTools,代码行数:101,代码来源:screenshot.cpp
注:本文中的VkLayerDispatchTable类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论