Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b00139

Browse files
committed
Improve debug callback signature with VKAPI_ATTR and VKAPI_CALL
1 parent 1bd7f90 commit 2b00139

27 files changed

Lines changed: 29 additions & 138 deletions

03_Drawing_a_triangle/00_Setup/02_Validation_layers.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,11 @@ the validation layers.
216216

217217
Now let's see what a callback function looks like. Add a new static member
218218
function called `debugCallback` with the `PFN_vkDebugReportCallbackEXT`
219-
prototype. It is required to have the `stdcall` calling convention on Windows.
220-
The calling convention does not have to be specified on Linux, because there is
221-
only one calling convention on that platform.
219+
prototype. The `VKAPI_ATTR` and `VKAPI_CALL` ensure that the function has the
220+
right signature for Vulkan to call it.
222221

223222
```c++
224-
#ifndef WIN32
225-
#define __stdcall
226-
#endif
227-
228-
static VkBool32 __stdcall debugCallback(
223+
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
229224
VkDebugReportFlagsEXT flags,
230225
VkDebugReportObjectTypeEXT objType,
231226
uint64_t obj,

code/command_buffers.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -780,11 +780,7 @@ class HelloTriangleApplication {
780780
return buffer;
781781
}
782782

783-
#ifndef WIN32
784-
#define __stdcall
785-
#endif
786-
787-
static VkBool32 __stdcall debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
783+
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
788784
std::cerr << "validation layer: " << msg << std::endl;
789785

790786
return VK_FALSE;

code/depth_buffering.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,11 +1467,7 @@ class HelloTriangleApplication {
14671467
return buffer;
14681468
}
14691469

1470-
#ifndef WIN32
1471-
#define __stdcall
1472-
#endif
1473-
1474-
static VkBool32 __stdcall debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
1470+
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
14751471
std::cerr << "validation layer: " << msg << std::endl;
14761472

14771473
return VK_FALSE;

code/descriptor_layout.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,11 +1123,7 @@ class HelloTriangleApplication {
11231123
return buffer;
11241124
}
11251125

1126-
#ifndef WIN32
1127-
#define __stdcall
1128-
#endif
1129-
1130-
static VkBool32 __stdcall debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
1126+
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
11311127
std::cerr << "validation layer: " << msg << std::endl;
11321128

11331129
return VK_FALSE;

code/descriptor_set.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,11 +1175,7 @@ class HelloTriangleApplication {
11751175
return buffer;
11761176
}
11771177

1178-
#ifndef WIN32
1179-
#define __stdcall
1180-
#endif
1181-
1182-
static VkBool32 __stdcall debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
1178+
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
11831179
std::cerr << "validation layer: " << msg << std::endl;
11841180

11851181
return VK_FALSE;

code/fixed_functions.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -641,11 +641,7 @@ class HelloTriangleApplication {
641641
return buffer;
642642
}
643643

644-
#ifndef WIN32
645-
#define __stdcall
646-
#endif
647-
648-
static VkBool32 __stdcall debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
644+
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
649645
std::cerr << "validation layer: " << msg << std::endl;
650646

651647
return VK_FALSE;

code/framebuffers.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -718,11 +718,7 @@ class HelloTriangleApplication {
718718
return buffer;
719719
}
720720

721-
#ifndef WIN32
722-
#define __stdcall
723-
#endif
724-
725-
static VkBool32 __stdcall debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
721+
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
726722
std::cerr << "validation layer: " << msg << std::endl;
727723

728724
return VK_FALSE;

code/graphics_pipeline.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,7 @@ class HelloTriangleApplication {
520520
return true;
521521
}
522522

523-
#ifndef WIN32
524-
#define __stdcall
525-
#endif
526-
527-
static VkBool32 __stdcall debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
523+
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
528524
std::cerr << "validation layer: " << msg << std::endl;
529525

530526
return VK_FALSE;

code/graphics_pipeline_complete.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -694,11 +694,7 @@ class HelloTriangleApplication {
694694
return buffer;
695695
}
696696

697-
#ifndef WIN32
698-
#define __stdcall
699-
#endif
700-
701-
static VkBool32 __stdcall debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
697+
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
702698
std::cerr << "validation layer: " << msg << std::endl;
703699

704700
return VK_FALSE;

code/hello_triangle.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -847,11 +847,7 @@ class HelloTriangleApplication {
847847
return buffer;
848848
}
849849

850-
#ifndef WIN32
851-
#define __stdcall
852-
#endif
853-
854-
static VkBool32 __stdcall debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
850+
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t obj, size_t location, int32_t code, const char* layerPrefix, const char* msg, void* userData) {
855851
std::cerr << "validation layer: " << msg << std::endl;
856852

857853
return VK_FALSE;

0 commit comments

Comments
 (0)