callback: add debug callback object

This commit is contained in:
Danny Robson 2017-09-14 00:31:23 +10:00
parent cb8d895ec5
commit 300ac66d16
7 changed files with 85 additions and 11 deletions

View File

@ -41,11 +41,14 @@ DEPENDS
##----------------------------------------------------------------------------- ##-----------------------------------------------------------------------------
list (APPEND sources list (APPEND sources
vk.hpp vk.hpp
fwd.hpp fwd.hpp
object.cpp object.cpp
object.hpp object.hpp
buffer.cpp buffer.cpp
buffer.hpp buffer.hpp
callback.hpp
command_buffer.cpp command_buffer.cpp
command_buffer.hpp command_buffer.hpp
command_pool.cpp command_pool.cpp

30
callback.hpp Normal file
View File

@ -0,0 +1,30 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright:
* 2017, Danny Robson <danny@nerdcruft.net>
*/
#ifndef CRUFT_VK_CALLACK_HPP
#define CRUFT_VK_CALLACK_HPP
#include "./object.hpp"
#include "./fwd.hpp"
namespace cruft::vk {
struct debug_report : public owned<debug_report,instance> {
using owned::owned;
};
}
#endif

View File

@ -39,6 +39,7 @@ namespace cruft::vk {
struct command_pool; struct command_pool;
struct device; struct device;
struct device_memory; struct device_memory;
struct debug_report;
struct event; struct event;
struct fence; struct fence;
struct framebuffer; struct framebuffer;
@ -79,6 +80,7 @@ namespace cruft::vk {
MAP0(FUNC, \ MAP0(FUNC, \
buffer, \ buffer, \
command_pool, \ command_pool, \
debug_report, \
device_memory, \ device_memory, \
framebuffer, \ framebuffer, \
image_view, \ image_view, \

View File

@ -46,15 +46,15 @@ namespace cruft::vk {
util::view<const char**> extensions); util::view<const char**> extensions);
instance (const create_info_t &info); instance (const create_info_t &info);
template <typename T> template <typename FunctionT>
T FunctionT
proc (const char *name) proc (const char *name)
{ {
auto ret = vkGetInstanceProcAddr (native (), name); auto ret = vkGetInstanceProcAddr (native (), name);
if (!ret) if (!ret)
throw vk::invalid_argument ("invalid procedure name"); throw vk::invalid_argument ("invalid procedure name");
return reinterpret_cast<T> (ret); return reinterpret_cast<FunctionT> (ret);
} }
std::set<std::string> extensions (void) const; std::set<std::string> extensions (void) const;

View File

@ -14,6 +14,7 @@
#include <cruft/vk/device_memory.hpp> #include <cruft/vk/device_memory.hpp>
#include <cruft/vk/swapchain.hpp> #include <cruft/vk/swapchain.hpp>
#include <cruft/vk/pipeline.hpp> #include <cruft/vk/pipeline.hpp>
#include <cruft/vk/callback.hpp>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h> #include <GLFW/glfw3native.h>
@ -100,8 +101,9 @@ main (void)
util::make_view (extensions.data (), extensions.data () + extensions.size ()) util::make_view (extensions.data (), extensions.data () + extensions.size ())
); );
{ load_traits (instance);
VkDebugReportCallbackEXT callback;
auto callback = [&instance] () {
VkDebugReportCallbackCreateInfoEXT debug_info {}; VkDebugReportCallbackCreateInfoEXT debug_info {};
debug_info.sType = cruft::vk::structure_type_v<VkDebugReportCallbackCreateInfoEXT>; debug_info.sType = cruft::vk::structure_type_v<VkDebugReportCallbackCreateInfoEXT>;
debug_info.flags = //VK_DEBUG_REPORT_INFORMATION_BIT_EXT | debug_info.flags = //VK_DEBUG_REPORT_INFORMATION_BIT_EXT |
@ -112,12 +114,8 @@ main (void)
; ;
debug_info.pfnCallback = vk_debug_callback; debug_info.pfnCallback = vk_debug_callback;
auto func = (decltype(&vkCreateDebugReportCallbackEXT))vkGetInstanceProcAddr (instance.native (),"vkCreateDebugReportCallbackEXT"); return cruft::vk::make_owned<cruft::vk::debug_report> (instance, &debug_info, nullptr);
} ();
cruft::vk::error::try_func (
*func, instance.native (), &debug_info, nullptr, &callback
);
}
auto pdevices = cruft::vk::physical_device::find (instance); auto pdevices = cruft::vk::physical_device::find (instance);
auto &pdevice = pdevices[0]; auto &pdevice = pdevices[0];

View File

@ -17,5 +17,27 @@
#include "./traits.hpp" #include "./traits.hpp"
#include "./instance.hpp"
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#define INSTANTIATE(KLASS, NAME, FUNC) \
decltype(FUNC)* cruft::vk::life_traits<KLASS>::NAME = nullptr
INSTANTIATE(VkDebugReportCallbackEXT, create, vkCreateDebugReportCallbackEXT);
INSTANTIATE(VkDebugReportCallbackEXT, destroy, vkDestroyDebugReportCallbackEXT);
///////////////////////////////////////////////////////////////////////////////
void
cruft::vk::load_traits (instance &i)
{
#define LOAD(KLASS,NAME,FUNC) \
try { \
cruft::vk::life_traits<KLASS>::NAME = i.proc<decltype(&FUNC)> (#FUNC); \
} catch (const vk::invalid_argument&) \
{ ; }
LOAD(VkDebugReportCallbackEXT, create, vkCreateDebugReportCallbackEXT);
LOAD(VkDebugReportCallbackEXT, destroy, vkDestroyDebugReportCallbackEXT);
}

View File

@ -54,6 +54,7 @@ namespace cruft::vk {
template <> struct native_traits<shader_module> { using type = VkShaderModule; }; template <> struct native_traits<shader_module> { using type = VkShaderModule; };
template <> struct native_traits<surface> { using type = VkSurfaceKHR; }; template <> struct native_traits<surface> { using type = VkSurfaceKHR; };
template <> struct native_traits<swapchain> { using type = VkSwapchainKHR; }; template <> struct native_traits<swapchain> { using type = VkSwapchainKHR; };
template <> struct native_traits<debug_report> { using type = VkDebugReportCallbackEXT; };
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
template <> template <>
@ -172,6 +173,7 @@ namespace cruft::vk {
template <> struct owner_traits<swapchain> { using type = device; }; template <> struct owner_traits<swapchain> { using type = device; };
template <> struct owner_traits<pipeline<bindpoint::GRAPHICS>> { using type = device; }; template <> struct owner_traits<pipeline<bindpoint::GRAPHICS>> { using type = device; };
template <> struct owner_traits<pipeline<bindpoint::COMPUTE>> { using type = device; }; template <> struct owner_traits<pipeline<bindpoint::COMPUTE>> { using type = device; };
template <> struct owner_traits<debug_report> { using type = instance; };
template <typename T> template <typename T>
using owner_t = typename owner_traits<T>::type; using owner_t = typename owner_traits<T>::type;
@ -316,6 +318,22 @@ namespace cruft::vk {
}; };
template <> struct life_traits<VkDebugReportCallbackEXT> {
static decltype(vkCreateDebugReportCallbackEXT) *create;
static decltype(vkDestroyDebugReportCallbackEXT) *destroy;
};
// loads all extension function pointers from an instance into the
// appropriate life_traits pointers where available.
//
// this is unambigiously the wrong way of doing things: each instance may
// have their own function pointers to each of the extension methods.
//
// but... we only support one instance for the time being, and this easier.
void load_traits (instance&);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
template <typename T> template <typename T>
struct wrapper_traits : public life_traits<native_t<T>> { }; struct wrapper_traits : public life_traits<native_t<T>> { };
@ -341,6 +359,7 @@ namespace cruft::vk {
/// describes the functions required to enumerate native types /// describes the functions required to enumerate native types
template <typename> struct enum_traits { }; template <typename> struct enum_traits { };
template <> struct enum_traits<VkPhysicalDevice> { template <> struct enum_traits<VkPhysicalDevice> {
static constexpr auto &enumerate = vkEnumeratePhysicalDevices; static constexpr auto &enumerate = vkEnumeratePhysicalDevices;
}; };