diff --git a/.idea/gradle.xml b/.idea/gradle.xml index f86c0e8..b8750de 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -6,13 +6,14 @@ diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..9f4529b --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_appBuffer_177283c.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_appBuffer_177283c.xml deleted file mode 100644 index 6238ff3..0000000 --- a/.idea/libraries/Gradle__com_github_kotlin_graphics_appBuffer_177283c.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_assimp_bfa5b44.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_assimp_bfa5b44.xml deleted file mode 100644 index cffdb57..0000000 --- a/.idea/libraries/Gradle__com_github_kotlin_graphics_assimp_bfa5b44.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_gli_055c801f8ff4ba2f2777d05fa16bbff9ad9eb5f6.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_gli_055c801f8ff4ba2f2777d05fa16bbff9ad9eb5f6.xml new file mode 100644 index 0000000..ca922ad --- /dev/null +++ b/.idea/libraries/Gradle__com_github_kotlin_graphics_gli_055c801f8ff4ba2f2777d05fa16bbff9ad9eb5f6.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_gli_4f1beb6.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_gli_4f1beb6.xml deleted file mode 100644 index 4f35c4b..0000000 --- a/.idea/libraries/Gradle__com_github_kotlin_graphics_gli_4f1beb6.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_glm_681d6b5505b570ec8b01692a22fa06e4cce437bd.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_glm_681d6b5505b570ec8b01692a22fa06e4cce437bd.xml new file mode 100644 index 0000000..7796c6a --- /dev/null +++ b/.idea/libraries/Gradle__com_github_kotlin_graphics_glm_681d6b5505b570ec8b01692a22fa06e4cce437bd.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_glm_6fc68ca.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_glm_6fc68ca.xml deleted file mode 100644 index c32942f..0000000 --- a/.idea/libraries/Gradle__com_github_kotlin_graphics_glm_6fc68ca.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_gln_b4eb299.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_gln_b4eb299.xml deleted file mode 100644 index 40a90f4..0000000 --- a/.idea/libraries/Gradle__com_github_kotlin_graphics_gln_b4eb299.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_gln_e3d4250f0c.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_gln_e3d4250f0c.xml new file mode 100644 index 0000000..ba9b3ee --- /dev/null +++ b/.idea/libraries/Gradle__com_github_kotlin_graphics_gln_e3d4250f0c.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_imgui_1_3_SNAPSHOT.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_imgui_1_3_SNAPSHOT.xml new file mode 100644 index 0000000..03216a7 --- /dev/null +++ b/.idea/libraries/Gradle__com_github_kotlin_graphics_imgui_1_3_SNAPSHOT.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_imgui_4c6d1b6.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_imgui_4c6d1b6.xml deleted file mode 100644 index cc6c8c0..0000000 --- a/.idea/libraries/Gradle__com_github_kotlin_graphics_imgui_4c6d1b6.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_kool_270db94affd9049d0002943136d6670a6f4d8365.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_kool_270db94affd9049d0002943136d6670a6f4d8365.xml new file mode 100644 index 0000000..6e94756 --- /dev/null +++ b/.idea/libraries/Gradle__com_github_kotlin_graphics_kool_270db94affd9049d0002943136d6670a6f4d8365.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_kotlin_unsigned_14e3eb683a8c5fc4bbbb0b3e336a7cdea738c4a0.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_kotlin_unsigned_14e3eb683a8c5fc4bbbb0b3e336a7cdea738c4a0.xml new file mode 100644 index 0000000..0ae930a --- /dev/null +++ b/.idea/libraries/Gradle__com_github_kotlin_graphics_kotlin_unsigned_14e3eb683a8c5fc4bbbb0b3e336a7cdea738c4a0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_kotlin_unsigned_a455438.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_kotlin_unsigned_a455438.xml deleted file mode 100644 index cbdef3f..0000000 --- a/.idea/libraries/Gradle__com_github_kotlin_graphics_kotlin_unsigned_a455438.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_uno_sdk_806fd6f.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_uno_sdk_806fd6f.xml deleted file mode 100644 index 64f35fa..0000000 --- a/.idea/libraries/Gradle__com_github_kotlin_graphics_uno_sdk_806fd6f.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_uno_sdk_e6130ed6fe79887e029cb1b6471e3b3848a5f1e1.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_uno_sdk_e6130ed6fe79887e029cb1b6471e3b3848a5f1e1.xml new file mode 100644 index 0000000..0f4936c --- /dev/null +++ b/.idea/libraries/Gradle__com_github_kotlin_graphics_uno_sdk_e6130ed6fe79887e029cb1b6471e3b3848a5f1e1.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_vkk_6110d303b90a0d84204b80f83ae3ed622bc87d15.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_vkk_6110d303b90a0d84204b80f83ae3ed622bc87d15.xml new file mode 100644 index 0000000..4a9f86d --- /dev/null +++ b/.idea/libraries/Gradle__com_github_kotlin_graphics_vkk_6110d303b90a0d84204b80f83ae3ed622bc87d15.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_github_kotlin_graphics_vkk_d8e8c1e.xml b/.idea/libraries/Gradle__com_github_kotlin_graphics_vkk_d8e8c1e.xml deleted file mode 100644 index 8c0614b..0000000 --- a/.idea/libraries/Gradle__com_github_kotlin_graphics_vkk_d8e8c1e.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_0.xml b/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_0.xml deleted file mode 100644 index 82cefc6..0000000 --- a/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_0.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_0_natives_linux.xml b/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_0_natives_linux.xml deleted file mode 100644 index d16206f..0000000 --- a/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_0_natives_linux.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_0_natives_windows.xml b/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_0_natives_windows.xml deleted file mode 100644 index 55a185d..0000000 --- a/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_0_natives_windows.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_1.xml b/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_1.xml new file mode 100644 index 0000000..55db1f5 --- /dev/null +++ b/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_1.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_1_natives_linux.xml b/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_1_natives_linux.xml new file mode 100644 index 0000000..3c49398 --- /dev/null +++ b/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_1_natives_linux.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_1_natives_windows.xml b/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_1_natives_windows.xml new file mode 100644 index 0000000..92ccce1 --- /dev/null +++ b/.idea/libraries/Gradle__graphics_scenery_spirvcrossj_0_4_1_natives_windows.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__io_github_microutils_kotlin_logging_1_4_6.xml b/.idea/libraries/Gradle__io_github_microutils_kotlin_logging_1_4_6.xml deleted file mode 100644 index bd7219b..0000000 --- a/.idea/libraries/Gradle__io_github_microutils_kotlin_logging_1_4_6.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__io_github_microutils_kotlin_logging_1_6_10.xml b/.idea/libraries/Gradle__io_github_microutils_kotlin_logging_1_6_10.xml new file mode 100644 index 0000000..dadea70 --- /dev/null +++ b/.idea/libraries/Gradle__io_github_microutils_kotlin_logging_1_6_10.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__io_github_microutils_kotlin_logging_common_1_6_10.xml b/.idea/libraries/Gradle__io_github_microutils_kotlin_logging_common_1_6_10.xml new file mode 100644 index 0000000..5a7b24d --- /dev/null +++ b/.idea/libraries/Gradle__io_github_microutils_kotlin_logging_common_1_6_10.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_reflect_1_2_51.xml b/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_reflect_1_2_51.xml deleted file mode 100644 index 9801d7f..0000000 --- a/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_reflect_1_2_51.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_reflect_1_3_0_rc_146.xml b/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_reflect_1_3_0_rc_146.xml new file mode 100644 index 0000000..e0c5ce8 --- /dev/null +++ b/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_reflect_1_3_0_rc_146.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_2_51.xml b/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_2_51.xml deleted file mode 100644 index 84ec8a9..0000000 --- a/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_2_51.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_3_0_rc_146.xml b/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_3_0_rc_146.xml new file mode 100644 index 0000000..dfe7b48 --- /dev/null +++ b/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_3_0_rc_146.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_common_1_2_51.xml b/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_common_1_2_51.xml deleted file mode 100644 index b085b2b..0000000 --- a/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_common_1_2_51.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_common_1_3_0_rc_146.xml b/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_common_1_3_0_rc_146.xml new file mode 100644 index 0000000..ad8f1be --- /dev/null +++ b/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_common_1_3_0_rc_146.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_jetbrains_kotlinx_atomicfu_common_0_11_0.xml b/.idea/libraries/Gradle__org_jetbrains_kotlinx_atomicfu_common_0_11_0.xml new file mode 100644 index 0000000..875c687 --- /dev/null +++ b/.idea/libraries/Gradle__org_jetbrains_kotlinx_atomicfu_common_0_11_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_jetbrains_kotlinx_kotlinx_coroutines_core_0_21.xml b/.idea/libraries/Gradle__org_jetbrains_kotlinx_kotlinx_coroutines_core_0_21.xml deleted file mode 100644 index cae07e4..0000000 --- a/.idea/libraries/Gradle__org_jetbrains_kotlinx_kotlinx_coroutines_core_0_21.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_jetbrains_kotlinx_kotlinx_coroutines_core_0_24_0_eap13.xml b/.idea/libraries/Gradle__org_jetbrains_kotlinx_kotlinx_coroutines_core_0_24_0_eap13.xml new file mode 100644 index 0000000..4c314cd --- /dev/null +++ b/.idea/libraries/Gradle__org_jetbrains_kotlinx_kotlinx_coroutines_core_0_24_0_eap13.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_jetbrains_kotlinx_kotlinx_coroutines_core_common_0_24_0_eap13.xml b/.idea/libraries/Gradle__org_jetbrains_kotlinx_kotlinx_coroutines_core_common_0_24_0_eap13.xml new file mode 100644 index 0000000..ee8c5c4 --- /dev/null +++ b/.idea/libraries/Gradle__org_jetbrains_kotlinx_kotlinx_coroutines_core_common_0_24_0_eap13.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_1_7_SNAPSHOT.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_1_7_SNAPSHOT.xml deleted file mode 100644 index ff891e2..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_1_7_SNAPSHOT.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_1_7_SNAPSHOT_natives_linux.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_1_7_SNAPSHOT_natives_linux.xml deleted file mode 100644 index 445b9a4..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_1_7_SNAPSHOT_natives_linux.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_1_7_SNAPSHOT_natives_windows.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_1_7_SNAPSHOT_natives_windows.xml deleted file mode 100644 index 42585a2..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_1_7_SNAPSHOT_natives_windows.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_2_0.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_2_0.xml new file mode 100644 index 0000000..3b94d23 --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_2_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_2_0_natives_linux.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_2_0_natives_linux.xml new file mode 100644 index 0000000..c1b3aa1 --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_2_0_natives_linux.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_2_0_natives_windows.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_2_0_natives_windows.xml new file mode 100644 index 0000000..59999e8 --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_3_2_0_natives_windows.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_1_7_SNAPSHOT.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_1_7_SNAPSHOT.xml deleted file mode 100644 index d0d14ef..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_1_7_SNAPSHOT.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_1_7_SNAPSHOT_natives_linux.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_1_7_SNAPSHOT_natives_linux.xml deleted file mode 100644 index 6068a34..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_1_7_SNAPSHOT_natives_linux.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_1_7_SNAPSHOT_natives_windows.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_1_7_SNAPSHOT_natives_windows.xml deleted file mode 100644 index cc52b9d..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_1_7_SNAPSHOT_natives_windows.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_2_0.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_2_0.xml new file mode 100644 index 0000000..3a46b4b --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_2_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_2_0_natives_linux.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_2_0_natives_linux.xml new file mode 100644 index 0000000..4211cbc --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_2_0_natives_linux.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_2_0_natives_windows.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_2_0_natives_windows.xml new file mode 100644 index 0000000..f29b666 --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_glfw_3_2_0_natives_windows.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_1_7_SNAPSHOT.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_1_7_SNAPSHOT.xml deleted file mode 100644 index 1562031..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_1_7_SNAPSHOT.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_1_7_SNAPSHOT_natives_linux.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_1_7_SNAPSHOT_natives_linux.xml deleted file mode 100644 index 2fdaec0..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_1_7_SNAPSHOT_natives_linux.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_1_7_SNAPSHOT_natives_windows.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_1_7_SNAPSHOT_natives_windows.xml deleted file mode 100644 index 1d442c8..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_1_7_SNAPSHOT_natives_windows.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_2_0.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_2_0.xml new file mode 100644 index 0000000..a448ed8 --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_2_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_2_0_natives_linux.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_2_0_natives_linux.xml new file mode 100644 index 0000000..48dc9ca --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_2_0_natives_linux.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_2_0_natives_windows.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_2_0_natives_windows.xml new file mode 100644 index 0000000..0162b71 --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_jemalloc_3_2_0_natives_windows.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_1_7_SNAPSHOT.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_1_7_SNAPSHOT.xml deleted file mode 100644 index e23d1e2..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_1_7_SNAPSHOT.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_1_7_SNAPSHOT_natives_linux.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_1_7_SNAPSHOT_natives_linux.xml deleted file mode 100644 index bb62990..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_1_7_SNAPSHOT_natives_linux.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_1_7_SNAPSHOT_natives_windows.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_1_7_SNAPSHOT_natives_windows.xml deleted file mode 100644 index 5573f93..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_1_7_SNAPSHOT_natives_windows.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_2_0.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_2_0.xml new file mode 100644 index 0000000..2984774 --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_2_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_2_0_natives_linux.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_2_0_natives_linux.xml new file mode 100644 index 0000000..0c79afa --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_2_0_natives_linux.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_2_0_natives_windows.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_2_0_natives_windows.xml new file mode 100644 index 0000000..fd22477 --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_openal_3_2_0_natives_windows.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_1_7_SNAPSHOT.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_1_7_SNAPSHOT.xml deleted file mode 100644 index 1383b21..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_1_7_SNAPSHOT.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_1_7_SNAPSHOT_natives_linux.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_1_7_SNAPSHOT_natives_linux.xml deleted file mode 100644 index e81588f..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_1_7_SNAPSHOT_natives_linux.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_1_7_SNAPSHOT_natives_windows.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_1_7_SNAPSHOT_natives_windows.xml deleted file mode 100644 index f6a9751..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_1_7_SNAPSHOT_natives_windows.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_2_0.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_2_0.xml new file mode 100644 index 0000000..57fa6be --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_2_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_2_0_natives_linux.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_2_0_natives_linux.xml new file mode 100644 index 0000000..2535ced --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_2_0_natives_linux.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_2_0_natives_windows.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_2_0_natives_windows.xml new file mode 100644 index 0000000..340e566 --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_opengl_3_2_0_natives_windows.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_1_7_SNAPSHOT.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_1_7_SNAPSHOT.xml deleted file mode 100644 index 7544368..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_1_7_SNAPSHOT.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_1_7_SNAPSHOT_natives_linux.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_1_7_SNAPSHOT_natives_linux.xml deleted file mode 100644 index 8dfded2..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_1_7_SNAPSHOT_natives_linux.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_1_7_SNAPSHOT_natives_windows.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_1_7_SNAPSHOT_natives_windows.xml deleted file mode 100644 index b56c481..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_1_7_SNAPSHOT_natives_windows.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_2_0.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_2_0.xml new file mode 100644 index 0000000..93adc71 --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_2_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_2_0_natives_linux.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_2_0_natives_linux.xml new file mode 100644 index 0000000..f449f82 --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_2_0_natives_linux.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_2_0_natives_windows.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_2_0_natives_windows.xml new file mode 100644 index 0000000..257a30e --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_stb_3_2_0_natives_windows.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_tootle_3_1_7_SNAPSHOT.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_tootle_3_1_7_SNAPSHOT.xml deleted file mode 100644 index a2431ab..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_tootle_3_1_7_SNAPSHOT.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_tootle_3_1_7_SNAPSHOT_natives_linux.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_tootle_3_1_7_SNAPSHOT_natives_linux.xml deleted file mode 100644 index ec97cde..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_tootle_3_1_7_SNAPSHOT_natives_linux.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_tootle_3_2_0.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_tootle_3_2_0.xml new file mode 100644 index 0000000..bbd2938 --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_tootle_3_2_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_tootle_3_2_0_natives_linux.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_tootle_3_2_0_natives_linux.xml new file mode 100644 index 0000000..27761a0 --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_tootle_3_2_0_natives_linux.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_vulkan_3_1_7_SNAPSHOT.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_vulkan_3_1_7_SNAPSHOT.xml deleted file mode 100644 index e074cc8..0000000 --- a/.idea/libraries/Gradle__org_lwjgl_lwjgl_vulkan_3_1_7_SNAPSHOT.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_lwjgl_lwjgl_vulkan_3_2_0.xml b/.idea/libraries/Gradle__org_lwjgl_lwjgl_vulkan_3_2_0.xml new file mode 100644 index 0000000..eee33d2 --- /dev/null +++ b/.idea/libraries/Gradle__org_lwjgl_lwjgl_vulkan_3_2_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index a528149..5fde407 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,9 +1,11 @@ + - + \ No newline at end of file diff --git a/Vulkan.iml b/Vulkan.iml index 6ab19e3..dd32cdf 100644 --- a/Vulkan.iml +++ b/Vulkan.iml @@ -7,14 +7,15 @@ @@ -39,37 +40,40 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -98,13 +102,13 @@ - - - - - - - + + + + + + + @@ -115,12 +119,12 @@ - - - - - - - + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 7c89ff0..3323fa6 100644 --- a/build.gradle +++ b/build.gradle @@ -34,7 +34,7 @@ allprojects { buildscript { - ext.kotlinVersion = '1.2.51' + ext.kotlinVersion = '1.3.0-rc-146' repositories { jcenter() // shadow @@ -54,17 +54,14 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" ext.kx = 'com.github.kotlin-graphics' - implementation "$kx:glm:6fc68ca" - implementation "$kx:vkk:d8e8c1e" - implementation "$kx:uno-sdk:806fd6f" - implementation "$kx:assimp:bfa5b44" - implementation "$kx:imgui:4c6d1b6" + implementation "$kx:assimp:1d4853cb425a0f7b3ee0dc142fb9e0970cbeb084" + implementation "$kx:imgui:1.3-SNAPSHOT" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.21" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.24.0-eap13" testCompile 'io.kotlintest:kotlintest:2.0.7' - ext.lwjglVersion = "3.1.7-SNAPSHOT" + ext.lwjglVersion = "3.2.0-SNAPSHOT" switch (OperatingSystem.current()) { case OperatingSystem.WINDOWS: ext.lwjglNatives = "natives-windows" @@ -81,7 +78,7 @@ dependencies { runtime "org.lwjgl:lwjgl$it:$lwjglVersion:$lwjglNatives" } - ext.spirvCross = "graphics.scenery:spirvcrossj:0.4.0" + ext.spirvCross = "graphics.scenery:spirvcrossj:0.4.1" implementation spirvCross runtime "$spirvCross:$lwjglNatives" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9eabf71..e9dec5e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip diff --git a/src/main/kotlin/vkk/MemoryStackPlus.kt b/src/main/kotlin/vkk/MemoryStackPlus.kt new file mode 100644 index 0000000..f738611 --- /dev/null +++ b/src/main/kotlin/vkk/MemoryStackPlus.kt @@ -0,0 +1,798 @@ +//package vkn +// +//import glm_.L +//import glm_.set +//import glm_.toUnsignedLong +//import org.lwjgl.BufferUtils +//import org.lwjgl.PointerBuffer +//import org.lwjgl.system.Configuration +//import org.lwjgl.system.MathUtil.mathIsPoT +//import org.lwjgl.system.MemoryUtil.* +//import org.lwjgl.system.Pointer +//import org.lwjgl.system.Pointer.POINTER_SHIFT +//import org.lwjgl.system.Pointer.POINTER_SIZE +//import java.nio.* +//import java.util.* +//import kotlin.collections.ArrayList +// +//open class MemoryStackPlus +///** +// * Creates a new [MemoryStackPlus] with the specified size. +// * +// * @param size the maximum number of bytes that may be allocated on the stack +// */ +//protected constructor( +// /** +// * Returns the size of the backing off-heap memory. +// * +// * This is the maximum number of bytes that may be allocated on the stack. +// */ +// private val size: Int) : AutoCloseable { +// +// private val buffer: ByteBuffer = BufferUtils.createByteBuffer(size) +// /** +// * Returns the address of the backing off-heap memory. +// * +// * The stack grows "downwards", so the bottom of the stack is at `address + size`, while the top is at `address`. +// */ +// val address = memAddress(buffer) +// +// var pointer = size +// +// private var frames = IntArray(DEFAULT_STACK_FRAMES) +// /** +// * Returns the current frame index. +// * +// * +// * This is the current number of nested [.push] calls. +// */ +// var frameIndex = 0 +// protected set +// +// /** +// * Stores the current stack pointer and pushes a new frame to the stack. +// * +// * This method should be called when entering a method, before doing any stack allocations. When exiting a method, call the [.pop] method to +// * restore the previous stack frame. +// * +// * +// * Pairs of push/pop calls may be nested. Care must be taken to: +// * +// * * match every push with a pop +// * * not call pop before push has been called at least once +// * * not nest push calls to more than the maximum supported depth +// * +// * +// * @return this stack +// */ +// open fun push(): MemoryStackPlus { +// if (frameIndex == frames.size) frameOverflow() +// frames[frameIndex++] = pointer +// return this +// } +// +// private fun frameOverflow() { +// frames = Arrays.copyOf(frames, frames.size * 3 / 2) +// } +// +// /** +// * Pops the current stack frame and moves the stack pointer to the end of the previous stack frame. +// * +// * @return this stack +// */ +// open fun pop(): MemoryStackPlus { +// pointer = frames[--frameIndex] +// return this +// } +// +// /** +// * Calls [.pop] on this [MemoryStackPlus]. +// * +// * This method should not be used directly. It is called automatically when the `MemoryStackPlus` is used as a resource in a try-with-resources +// * statement. +// */ +// override fun close() { +// pop() +// } +// +// private fun checkPointer(pointer: Int) { +// if (pointer < 0 || size < pointer) +// throw IndexOutOfBoundsException("Invalid stack ptr") +// } +// +// /** +// * Calls [.nmalloc] with `alignment` equal to 1. +// * +// * @param size the allocation size +// * +// * @return the memory address on the stack for the requested allocation +// */ +// fun nmalloc(size: Int) = nmalloc(1, size) +// +// /** +// * Allocates a block of `size` bytes of memory on the stack. The content of the newly allocated block of memory is not initialized, remaining with +// * indeterminate values. +// * +// * @param alignment the required alignment +// * @param size the allocation size +// * +// * @return the memory address on the stack for the requested allocation +// */ +// fun nmalloc(alignment: Int, size: Int): Long { +// var newPointer = pointer - size +// // Align pointer to the specified alignment +// newPointer = newPointer and (alignment - 1).inv() +// pointer = newPointer +// return address + newPointer.toUnsignedLong +// } +// +// /** +// * Allocates a block of memory on the stack for an array of `num` elements, each of them `size` bytes long, and initializes all its bits to +// * zero. +// * +// * @param alignment the required element alignment +// * @param num num the number of elements to allocate +// * @param size the size of each element +// * +// * @return the memory address on the stack for the requested allocation +// */ +// fun ncalloc(alignment: Int, num: Int, size: Int): Long { +// val bytes = num * size +// val address = nmalloc(alignment, bytes) +// memSet(address, 0, bytes.L) +// return address +// } +// +// // ------------------------------------------------- +// +// /** +// * Allocates an aligned [ByteBuffer] on the stack. +// * +// * @param alignment the required buffer alignment +// * @param size the number of elements in the buffer +// * +// * @return the allocated buffer +// */ +// fun malloc(alignment: Int, size: Int): ByteBuffer = memByteBuffer(nmalloc(alignment, size), size) +// +// /** Calloc version of [.malloc]. */ +// fun calloc(alignment: Int, size: Int): ByteBuffer = memByteBuffer(ncalloc(alignment, size, 1), size) +// +// /** +// * Allocates a [ByteBuffer] on the stack. +// * +// * @param size the number of elements in the buffer +// * +// * @return the allocated buffer +// */ +// fun malloc(size: Int = 1) = malloc(1, size) +// +// fun malloc(size: IntBuffer) = malloc(1, size[0]) +// +// /** Calloc version of [.malloc]. */ +// fun calloc(size: Int = 1) = calloc(1, size) +// +// fun calloc(size: IntBuffer) = calloc(1, size[0]) +// +// /** Single value version of [.malloc]. */ +// fun bytes(x: Byte): ByteBuffer = malloc(1).put(0, x) +// +// /** Two value version of [.malloc]. */ +// fun bytes(x: Byte, y: Byte): ByteBuffer = malloc(2).put(0, x).put(1, y) +// +// /** Three value version of [.malloc]. */ +// fun bytes(x: Byte, y: Byte, z: Byte): ByteBuffer = malloc(3).put(0, x).put(1, y).put(2, z) +// +// /** Four value version of [.malloc]. */ +// fun bytes(x: Byte, y: Byte, z: Byte, w: Byte): ByteBuffer = malloc(4).put(0, x).put(1, y).put(2, z).put(3, w) +// +// /** Vararg version of [.malloc]. */ +// fun bytes(vararg values: Byte): ByteBuffer = malloc(values.size).put(values).apply { flip() } +// +// // ------------------------------------------------- +// +// /** Short version of [.malloc]. */ +// fun mallocShort(size: Int = 1): ShortBuffer = memShortBuffer(nmalloc(2, size shl 1), size) +// +// fun mallocShort(size: IntBuffer): ShortBuffer = memShortBuffer(nmalloc(2, size[0] shl 1), size[0]) +// +// /** Short version of [.calloc]. */ +// fun callocShort(size: Int = 1): ShortBuffer = memShortBuffer(ncalloc(2, size, 2), size) +// +// fun callocShort(size: IntBuffer): ShortBuffer = memShortBuffer(ncalloc(2, size[0], 2), size[0]) +// +// /** Single value version of [.mallocShort]. */ +// fun shorts(x: Short): ShortBuffer = mallocShort(1).put(0, x) +// +// /** Two value version of [.mallocShort]. */ +// fun shorts(x: Short, y: Short): ShortBuffer = mallocShort(2).put(0, x).put(1, y) +// +// /** Three value version of [.mallocShort]. */ +// fun shorts(x: Short, y: Short, z: Short): ShortBuffer = mallocShort(3).put(0, x).put(1, y).put(2, z) +// +// /** Four value version of [.mallocShort]. */ +// fun shorts(x: Short, y: Short, z: Short, w: Short): ShortBuffer = mallocShort(4).put(0, x).put(1, y).put(2, z).put(3, w) +// +// /** Vararg version of [.mallocShort]. */ +// fun shorts(vararg values: Short): ShortBuffer = mallocShort(values.size).put(values).apply { flip() } +// +// // ------------------------------------------------- +// +// /** Int version of [.malloc]. */ +// fun mallocInt(size: Int = 1): IntBuffer = memIntBuffer(nmalloc(4, size shl 2), size) +// +// fun mallocInt(size: IntBuffer): IntBuffer = memIntBuffer(nmalloc(4, size[0] shl 2), size[0]) +// +// /** Int version of [.calloc]. */ +// fun callocInt(size: Int = 1): IntBuffer = memIntBuffer(ncalloc(4, size, 4), size) +// +// fun callocInt(size: IntBuffer): IntBuffer = memIntBuffer(ncalloc(4, size[0], 4), size[0]) +// +// /** Single value version of [.mallocInt]. */ +// fun ints(x: Int): IntBuffer = mallocInt(1).put(0, x) +// +// /** Two value version of [.mallocInt]. */ +// fun ints(x: Int, y: Int): IntBuffer = mallocInt(2).put(0, x).put(1, y) +// +// /** Three value version of [.mallocInt]. */ +// fun ints(x: Int, y: Int, z: Int): IntBuffer = mallocInt(3).put(0, x).put(1, y).put(2, z) +// +// /** Four value version of [.mallocInt]. */ +// fun ints(x: Int, y: Int, z: Int, w: Int): IntBuffer = mallocInt(4).put(0, x).put(1, y).put(2, z).put(3, w) +// +// /** Vararg version of [.mallocInt]. */ +// fun ints(vararg values: Int): IntBuffer = mallocInt(values.size).put(values).apply { flip() } +// +// // ------------------------------------------------- +// +// /** Long version of [.malloc]. */ +// fun mallocLong(size: Int = 1): LongBuffer = memLongBuffer(nmalloc(8, size shl 3), size) +// +// fun mallocLong(size: IntBuffer): LongBuffer = memLongBuffer(nmalloc(8, size[0] shl 3), size[0]) +// +// /** Long version of [.calloc]. */ +// fun callocLong(size: Int = 1): LongBuffer = memLongBuffer(ncalloc(8, size, 8), size) +// +// fun callocLong(size: IntBuffer): LongBuffer = memLongBuffer(ncalloc(8, size[0], 8), size[0]) +// +// /** Single value version of [.mallocLong]. */ +// fun longs(x: Long): LongBuffer = mallocLong(1).put(0, x) +// +// /** Two value version of [.mallocLong]. */ +// fun longs(x: Long, y: Long): LongBuffer = mallocLong(2).put(0, x).put(1, y) +// +// /** Three value version of [.mallocLong]. */ +// fun longs(x: Long, y: Long, z: Long): LongBuffer = mallocLong(3).put(0, x).put(1, y).put(2, z) +// +// /** Four value version of [.mallocLong]. */ +// fun longs(x: Long, y: Long, z: Long, w: Long): LongBuffer = mallocLong(4).put(0, x).put(1, y).put(2, z).put(3, w) +// +// /** Vararg version of [.mallocLong]. */ +// fun longs(vararg more: Long): LongBuffer = mallocLong(more.size).put(more).apply { flip() } +// +// // ------------------------------------------------- +// +// /** Float version of [.malloc]. */ +// fun mallocFloat(size: Int = 1): FloatBuffer = memFloatBuffer(nmalloc(4, size shl 2), size) +// +// fun mallocFloat(size: IntBuffer): FloatBuffer = memFloatBuffer(nmalloc(4, size[0] shl 2), size[0]) +// +// /** Float version of [.calloc]. */ +// fun callocFloat(size: Int = 1): FloatBuffer = memFloatBuffer(ncalloc(4, size, 4), size) +// +// fun callocFloat(size: IntBuffer): FloatBuffer = memFloatBuffer(ncalloc(4, size[0], 4), size[0]) +// +// /** Single value version of [.mallocFloat]. */ +// fun floats(x: Float): FloatBuffer = mallocFloat(1).put(0, x) +// +// /** Two value version of [.mallocFloat]. */ +// fun floats(x: Float, y: Float): FloatBuffer = mallocFloat(2).put(0, x).put(1, y) +// +// /** Three value version of [.mallocFloat]. */ +// fun floats(x: Float, y: Float, z: Float): FloatBuffer = mallocFloat(3).put(0, x).put(1, y).put(2, z) +// +// /** Four value version of [.mallocFloat]. */ +// fun floats(x: Float, y: Float, z: Float, w: Float): FloatBuffer = mallocFloat(4).put(0, x).put(1, y).put(2, z).put(3, w) +// +// /** Vararg version of [.mallocFloat]. */ +// fun floats(vararg values: Float): FloatBuffer = mallocFloat(values.size).put(values).apply { flip() } +// +// // ------------------------------------------------- +// +// /** Double version of [.malloc]. */ +// fun mallocDouble(size: Int = 1): DoubleBuffer = memDoubleBuffer(nmalloc(8, size shl 3), size) +// +// fun mallocDouble(size: IntBuffer): DoubleBuffer = memDoubleBuffer(nmalloc(8, size[0] shl 3), size[0]) +// +// /** Double version of [.calloc]. */ +// fun callocDouble(size: Int = 1): DoubleBuffer = memDoubleBuffer(ncalloc(8, size, 8), size) +// +// fun callocDouble(size: IntBuffer): DoubleBuffer = memDoubleBuffer(ncalloc(8, size[0], 8), size[0]) +// +// /** Single value version of [.mallocDouble]. */ +// fun doubles(x: Double): DoubleBuffer = mallocDouble(1).put(0, x) +// +// /** Two value version of [.mallocDouble]. */ +// fun doubles(x: Double, y: Double): DoubleBuffer = mallocDouble(2).put(0, x).put(1, y) +// +// /** Three value version of [.mallocDouble]. */ +// fun doubles(x: Double, y: Double, z: Double): DoubleBuffer = mallocDouble(3).put(0, x).put(1, y).put(2, z) +// +// /** Four value version of [.mallocDouble]. */ +// fun doubles(x: Double, y: Double, z: Double, w: Double): DoubleBuffer = mallocDouble(4).put(0, x).put(1, y).put(2, z).put(3, w) +// +// /** Vararg version of [.mallocDouble]. */ +// fun doubles(vararg values: Double): DoubleBuffer = mallocDouble(values.size).put(values).apply { flip() } +// +// // ------------------------------------------------- +// +// /** Pointer version of [.malloc]. */ +// fun mallocPointer(size: Int = 1): PointerBuffer = memPointerBuffer(nmalloc(POINTER_SIZE, size shl POINTER_SHIFT), size) +// +// fun mallocPointer(size: IntBuffer): PointerBuffer = memPointerBuffer(nmalloc(POINTER_SIZE, size[0] shl POINTER_SHIFT), size[0]) +// +// /** Pointer version of [.calloc]. */ +// fun callocPointer(size: Int = 1): PointerBuffer = memPointerBuffer(ncalloc(POINTER_SIZE, size, POINTER_SIZE), size) +// +// fun callocPointer(size: IntBuffer): PointerBuffer = memPointerBuffer(ncalloc(POINTER_SIZE, size[0], POINTER_SIZE), size[0]) +// +// /** Single value version of [.mallocPointer]. */ +// fun pointers(x: Long): PointerBuffer = mallocPointer(1).put(0, x) +// +// /** Two value version of [.mallocPointer]. */ +// fun pointers(x: Long, y: Long): PointerBuffer = mallocPointer(2).put(0, x).put(1, y) +// +// /** Three value version of [.mallocPointer]. */ +// fun pointers(x: Long, y: Long, z: Long): PointerBuffer = mallocPointer(3).put(0, x).put(1, y).put(2, z) +// +// /** Four value version of [.mallocPointer]. */ +// fun pointers(x: Long, y: Long, z: Long, w: Long): PointerBuffer = mallocPointer(4).put(0, x).put(1, y).put(2, z).put(3, w) +// +// /** Vararg version of [.mallocPointer]. */ +// fun pointers(vararg values: Long): PointerBuffer = mallocPointer(values.size).put(values).apply { flip() } +// +// /** Single value version of [.mallocPointer]. */ +// fun pointers(x: Pointer): PointerBuffer = mallocPointer(1).put(0, x) +// +// /** Two value version of [.mallocPointer]. */ +// fun pointers(x: Pointer, y: Pointer): PointerBuffer = mallocPointer(2).put(0, x).put(1, y) +// +// /** Three value version of [.mallocPointer]. */ +// fun pointers(x: Pointer, y: Pointer, z: Pointer): PointerBuffer = mallocPointer(3).put(0, x).put(1, y).put(2, z) +// +// /** Four value version of [.mallocPointer]. */ +// fun pointers(x: Pointer, y: Pointer, z: Pointer, w: Pointer): PointerBuffer = mallocPointer(4).put(0, x).put(1, y).put(2, z).put(3, w) +// +// /** Vararg version of [.mallocPointer]. */ +// fun pointers(vararg values: Pointer): PointerBuffer { +// val buffer = mallocPointer(values.size) +// for (i in values.indices) +// buffer[i] = values[i] +// return buffer +// } +// +// /** +// * Encodes the specified text on the stack using ascii encoding and returns a ByteBuffer that points to the encoded text. +// * +// * @param text the text to encode +// * @param nullTerminated if true, a null-terminator is included at the end of the encoded text +// */ +// @JvmOverloads +// fun ascii(text: CharSequence, nullTerminated: Boolean = true): ByteBuffer { +// val encoded = malloc(memLengthASCII(text, nullTerminated)) +// memASCII(text, nullTerminated, encoded) +// return encoded +// } +// +// /** Like [ascii][.ascii], but returns `null` if `text` is `null`. */ +// @JvmOverloads +// fun asciiSafe(text: CharSequence?, nullTerminated: Boolean = true) = text?.let { ascii(it, nullTerminated) } +// +// /** +// * Encodes the specified text on the stack using utf8 encoding and returns a ByteBuffer that points to the encoded text. +// * +// * @param text the text to encode +// * @param nullTerminated if true, a null-terminator is included at the end of the encoded text +// */ +// @JvmOverloads +// fun utf8(text: CharSequence, nullTerminated: Boolean = true): ByteBuffer { +// val encoded = malloc(memLengthUTF8(text, nullTerminated)) +// memUTF8(text, nullTerminated, encoded) +// return encoded +// } +// +// /** Like [utf8][.utf8], but returns `null` if `text` is `null`. */ +// @JvmOverloads +// fun utf8Safe(text: CharSequence?, nullTerminated: Boolean = true) = text?.let { utf8(it, nullTerminated) } +// +// /** +// * Encodes the specified text on the stack using utf16 encoding and returns a ByteBuffer that points to the encoded text. +// * +// * @param text the text to encode +// * @param nullTerminated if true, a null-terminator is included at the end of the encoded text +// */ +// @JvmOverloads +// fun utf16(text: CharSequence, nullTerminated: Boolean = true): ByteBuffer { +// val encoded = malloc(2, memLengthUTF16(text, nullTerminated)) +// memUTF16(text, nullTerminated, encoded) +// return encoded +// } +// +// /** Like [utf16][.utf16], but returns `null` if `text` is `null`. */ +// @JvmOverloads +// fun utf16Safe(text: CharSequence?, nullTerminated: Boolean = true) = text?.let { utf16(it, nullTerminated) } +// +// companion object { +// +// private val DEFAULT_STACK_SIZE = Configuration.STACK_SIZE.get(64) * 1024 +// private val DEFAULT_STACK_FRAMES = 8 +// +// private val DEBUG_STACK = Configuration.DEBUG_STACK.get(false) +// +// private val TLS = ThreadLocal.withInitial({ create() }) +// +// init { +// if (DEFAULT_STACK_SIZE < 0) +// throw IllegalStateException("Invalid stack size.") +// } +// +// /** +// * Creates a new [MemoryStackPlus] with the specified size. +// * +// * @param size the maximum number of bytes that may be allocated on the stack +// */ +// @JvmOverloads +// fun create(size: Int = DEFAULT_STACK_SIZE) = MemoryStackPlus(size) +// +// private fun checkAlignment(alignment: Int) { +// if (!mathIsPoT(alignment)) +// throw IllegalArgumentException("Alignment must be a power-of-two value.") +// } +// +// private fun checkPush(pointer: Int) { +// if (pointer < 0) +// throw OutOfMemoryError("Out of stack space.") +// } +// +// // ----------------------------------------------------- +// // ----------------------------------------------------- +// // ----------------------------------------------------- +// +// /** Returns the stack of the current thread. */ +// fun stackGet(): MemoryStackPlus = TLS.get() +// +// /** +// * Calls [.push] on the stack of the current thread. +// * +// * @return the stack of the current thread. +// */ +//// @Deprecated("", ReplaceWith("withStack{..}", "same import")) +// fun stackPush() = stackGet().push() +// +//// inline fun withStack(block: MemoryStackPlus.() -> R): R { +//// var exception: Throwable? = null +//// val stack = stackGet().push() +//// try { +//// return stack.block() +//// } catch (e: Throwable) { +//// exception = e +//// throw e +//// } finally { +//// stack.closeFinally(exception) +//// } +//// } +//// +////// @SinceKotlin("1.1") +////// @Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") +////// @kotlin.internal.InlineOnly +////// inline fun T.use(block: (T) -> R): R { +////// var exception: Throwable? = null +////// try { +////// return block(this) +////// } catch (e: Throwable) { +////// exception = e +////// throw e +////// } finally { +////// this.closeFinally(exception) +////// } +////// } +//// +//// @SinceKotlin("1.1") +//// @PublishedApi +//// internal fun AutoCloseable?.closeFinally(cause: Throwable?) = when { +//// this == null -> Unit +//// cause == null -> close() +//// else -> +//// try { +//// close() +//// } catch (closeException: Throwable) { +//// cause.addSuppressed(closeException) +//// } +//// } +// +// /** +// * Calls [.pop] on the stack of the current thread. +// * +// * @return the stack of the current thread. +// */ +// fun stackPop() = stackGet().pop() +// +// /** Thread-local version of [.nmalloc]. */ +// fun nstackMalloc(size: Int = 1) = stackGet().nmalloc(size) +// +// /** Thread-local version of [.nmalloc]. */ +// fun nstackMalloc(alignment: Int, size: Int) = stackGet().nmalloc(alignment, size) +// +// /** Thread-local version of [.ncalloc]. */ +// fun nstackCalloc(alignment: Int, num: Int, size: Int) = stackGet().ncalloc(alignment, num, size) +// +// // ------------------------------------------------- +// +// /** Thread-local version of [.malloc]. */ +// fun stackMalloc(size: Int = 1) = stackGet().malloc(size) +// +// fun stackMalloc(size: IntBuffer) = stackGet().malloc(size[0]) +// +// /** Thread-local version of [.calloc]. */ +// fun stackCalloc(size: Int = 1) = stackGet().calloc(size) +// +// fun stackCalloc(size: IntBuffer) = stackGet().calloc(size[0]) +// +// /** Thread-local version of [.bytes]. */ +// fun stackBytes(x: Byte) = stackGet().bytes(x) +// +// /** Thread-local version of [.bytes]. */ +// fun stackBytes(x: Byte, y: Byte) = stackGet().bytes(x, y) +// +// /** Thread-local version of [.bytes]. */ +// fun stackBytes(x: Byte, y: Byte, z: Byte) = stackGet().bytes(x, y, z) +// +// /** Thread-local version of [.bytes]. */ +// fun stackBytes(x: Byte, y: Byte, z: Byte, w: Byte) = stackGet().bytes(x, y, z, w) +// +// /** Thread-local version of [.bytes]. */ +// fun stackBytes(vararg values: Byte) = stackGet().bytes(*values) +// +// // ------------------------------------------------- +// +// /** Thread-local version of [.mallocShort]. */ +// fun stackMallocShort(size: Int = 1) = stackGet().mallocShort(size) +// +// fun stackMallocShort(size: IntBuffer) = stackGet().mallocShort(size[0]) +// +// /** Thread-local version of [.callocShort]. */ +// fun stackCallocShort(size: Int = 1) = stackGet().callocShort(size) +// +// fun stackCallocShort(size: IntBuffer) = stackGet().callocShort(size[0]) +// +// /** Thread-local version of [.shorts]. */ +// fun stackShorts(x: Short) = stackGet().shorts(x) +// +// /** Thread-local version of [.shorts]. */ +// fun stackShorts(x: Short, y: Short) = stackGet().shorts(x, y) +// +// /** Thread-local version of [.shorts]. */ +// fun stackShorts(x: Short, y: Short, z: Short) = stackGet().shorts(x, y, z) +// +// /** Thread-local version of [.shorts]. */ +// fun stackShorts(x: Short, y: Short, z: Short, w: Short) = stackGet().shorts(x, y, z, w) +// +// /** Thread-local version of [.shorts]. */ +// fun stackShorts(vararg values: Short) = stackGet().shorts(*values) +// +// // ------------------------------------------------- +// +// /** Thread-local version of [.mallocInt]. */ +// fun stackMallocInt(size: Int = 1) = stackGet().mallocInt(size) +// +// fun stackMallocInt(size: IntBuffer) = stackGet().mallocInt(size[0]) +// +// /** Thread-local version of [.callocInt]. */ +// fun stackCallocInt(size: Int = 1) = stackGet().callocInt(size) +// +// fun stackCallocInt(size: IntBuffer) = stackGet().callocInt(size[0]) +// +// /** Thread-local version of [.ints]. */ +// fun stackInts(x: Int) = stackGet().ints(x) +// +// /** Thread-local version of [.ints]. */ +// fun stackInts(x: Int, y: Int) = stackGet().ints(x, y) +// +// /** Thread-local version of [.ints]. */ +// fun stackInts(x: Int, y: Int, z: Int) = stackGet().ints(x, y, z) +// +// /** Thread-local version of [.ints]. */ +// fun stackInts(x: Int, y: Int, z: Int, w: Int) = stackGet().ints(x, y, z, w) +// +// /** Thread-local version of [.ints]. */ +// fun stackInts(vararg values: Int) = stackGet().ints(*values) +// +// // ------------------------------------------------- +// +// /** Thread-local version of [.mallocLong]. */ +// fun stackMallocLong(size: Int = 1) = stackGet().mallocLong(size) +// +// fun stackMallocLong(size: IntBuffer) = stackGet().mallocLong(size[0]) +// +// /** Thread-local version of [.callocLong]. */ +// fun stackCallocLong(size: Int = 1) = stackGet().callocLong(size) +// +// fun stackCallocLong(size: IntBuffer) = stackGet().callocLong(size[0]) +// +// /** Thread-local version of [.longs]. */ +// fun stackLongs(x: Long) = stackGet().longs(x) +// +// /** Thread-local version of [.longs]. */ +// fun stackLongs(x: Long, y: Long) = stackGet().longs(x, y) +// +// /** Thread-local version of [.longs]. */ +// fun stackLongs(x: Long, y: Long, z: Long) = stackGet().longs(x, y, z) +// +// /** Thread-local version of [.longs]. */ +// fun stackLongs(x: Long, y: Long, z: Long, w: Long) = stackGet().longs(x, y, z, w) +// +// /** Thread-local version of [.longs]. */ +// fun stackLongs(vararg values: Long) = stackGet().longs(*values) +// +// // ------------------------------------------------- +// +// /** Thread-local version of [.mallocFloat]. */ +// fun stackMallocFloat(size: Int = 1) = stackGet().mallocFloat(size) +// +// fun stackMallocFloat(size: IntBuffer) = stackGet().mallocFloat(size[0]) +// +// /** Thread-local version of [.callocFloat]. */ +// fun stackCallocFloat(size: Int = 1) = stackGet().callocFloat(size) +// +// fun stackCallocFloat(size: IntBuffer) = stackGet().callocFloat(size[0]) +// +// /** Thread-local version of [.floats]. */ +// fun stackFloats(x: Float) = stackGet().floats(x) +// +// /** Thread-local version of [.floats]. */ +// fun stackFloats(x: Float, y: Float) = stackGet().floats(x, y) +// +// /** Thread-local version of [.floats]. */ +// fun stackFloats(x: Float, y: Float, z: Float) = stackGet().floats(x, y, z) +// +// /** Thread-local version of [.floats]. */ +// fun stackFloats(x: Float, y: Float, z: Float, w: Float) = stackGet().floats(x, y, z, w) +// +// /** Thread-local version of [.floats]. */ +// fun stackFloats(vararg values: Float) = stackGet().floats(*values) +// +// // ------------------------------------------------- +// +// /** Thread-local version of [.mallocDouble]. */ +// fun stackMallocDouble(size: Int = 1) = stackGet().mallocDouble(size) +// +// fun stackMallocDouble(size: IntBuffer) = stackGet().mallocDouble(size[0]) +// +// /** Thread-local version of [.callocDouble]. */ +// fun stackCallocDouble(size: Int = 1) = stackGet().callocDouble(size) +// +// fun stackCallocDouble(size: IntBuffer) = stackGet().callocDouble(size[0]) +// +// /** Thread-local version of [.doubles]. */ +// fun stackDoubles(x: Double) = stackGet().doubles(x) +// +// /** Thread-local version of [.doubles]. */ +// fun stackDoubles(x: Double, y: Double) = stackGet().doubles(x, y) +// +// /** Thread-local version of [.doubles]. */ +// fun stackDoubles(x: Double, y: Double, z: Double) = stackGet().doubles(x, y, z) +// +// /** Thread-local version of [.doubles]. */ +// fun stackDoubles(x: Double, y: Double, z: Double, w: Double) = stackGet().doubles(x, y, z, w) +// +// /** Thread-local version of [.doubles]. */ +// fun stackDoubles(vararg values: Double) = stackGet().doubles(*values) +// +// // ------------------------------------------------- +// +// /** Thread-local version of [.mallocPointer]. */ +// fun stackMallocPointer(size: Int = 1) = stackGet().mallocPointer(size) +// +// fun stackMallocPointer(size: IntBuffer) = stackGet().mallocPointer(size[0]) +// +// /** Thread-local version of [.callocPointer]. */ +// fun stackCallocPointer(size: Int = 1) = stackGet().callocPointer(size) +// +// fun stackCallocPointer(size: IntBuffer) = stackGet().callocPointer(size[0]) +// +// /** Thread-local version of [.pointers]. */ +// fun stackPointers(x: Long) = stackGet().pointers(x) +// +// /** Thread-local version of [.pointers]. */ +// fun stackPointers(x: Long, y: Long) = stackGet().pointers(x, y) +// +// /** Thread-local version of [.pointers]. */ +// fun stackPointers(x: Long, y: Long, z: Long) = stackGet().pointers(x, y, z) +// +// /** Thread-local version of [.pointers]. */ +// fun stackPointers(x: Long, y: Long, z: Long, w: Long) = stackGet().pointers(x, y, z, w) +// +// /** Thread-local version of [.pointers]. */ +// fun stackPointers(vararg values: Long) = stackGet().pointers(*values) +// +// /** Thread-local version of [.pointers]. */ +// fun stackPointers(x: Pointer) = stackGet().pointers(x) +// +// /** Thread-local version of [.pointers]. */ +// fun stackPointers(x: Pointer, y: Pointer) = stackGet().pointers(x, y) +// +// /** Thread-local version of [.pointers]. */ +// fun stackPointers(x: Pointer, y: Pointer, z: Pointer) = stackGet().pointers(x, y, z) +// +// /** Thread-local version of [.pointers]. */ +// fun stackPointers(x: Pointer, y: Pointer, z: Pointer, w: Pointer) = stackGet().pointers(x, y, z, w) +// +// /** Thread-local version of [.pointers]. */ +// fun stackPointers(vararg values: Pointer) = stackGet().pointers(*values) +// +// // ------------------------------------------------- +// +// /** Thread-local version of [.ascii]. */ +// fun stackASCII(text: CharSequence) = stackGet().ascii(text) +// +// /** Thread-local version of [.ascii]. */ +// fun stackASCII(text: CharSequence, nullTerminated: Boolean) = stackGet().ascii(text, nullTerminated) +// +// /** Thread-local version of [.utf8]. */ +// fun stackUTF8(text: CharSequence) = stackGet().utf8(text) +// +// /** Thread-local version of [.utf8]. */ +// fun stackUTF8(text: CharSequence, nullTerminated: Boolean) = stackGet().utf8(text, nullTerminated) +// +// /** Thread-local version of [.utf16]. */ +// fun stackUTF16(text: CharSequence) = stackGet().utf16(text) +// +// /** Thread-local version of [.utf16]. */ +// fun stackUTF16(text: CharSequence, nullTerminated: Boolean) = stackGet().utf16(text, nullTerminated) +// +// /** Thread-local version of [.ascii]. */ +// fun stackASCIISafe(text: CharSequence?) = stackGet().asciiSafe(text) +// +// /** Thread-local version of [.ascii]. */ +// fun stackASCIISafe(text: CharSequence?, nullTerminated: Boolean) = stackGet().asciiSafe(text, nullTerminated) +// +// /** Thread-local version of [.utf8]. */ +// fun stackUTF8Safe(text: CharSequence?) = stackGet().utf8Safe(text) +// +// /** Thread-local version of [.utf8]. */ +// fun stackUTF8Safe(text: CharSequence?, nullTerminated: Boolean) = stackGet().utf8Safe(text, nullTerminated) +// +// /** Thread-local version of [.utf16]. */ +// fun stackUTF16Safe(text: CharSequence?) = stackGet().utf16Safe(text) +// +// /** Thread-local version of [.utf16]. */ +// fun stackUTF16Safe(text: CharSequence, nullTerminated: Boolean) = stackGet().utf16Safe(text, nullTerminated) +// } +// +// fun Collection.toPointerBuffer(): PointerBuffer { +// val buf = mallocPointer(size) +// for (i in indices) buf[i] = elementAt(i) +// return buf +// } +// +// fun Collection.toIntBuffer(): IntBuffer { +// val buf = mallocInt(size) +// for (i in indices) buf[i] = elementAt(i) +// return buf +// } +// +// inline fun PointerBuffer.toArrayListString(count: Int = remaining()): ArrayList { +// val res = ArrayList(count) +// for (i in 0 until count) +// res += getStringUTF8(i) +// return res +// } +// +// inline operator fun PointerBuffer.set(index: Int, string: String) { +// put(index, string.utf8) +// } +// +// // inline val String.memUTF16: ByteBuffer get() = memUTF16(this) +// inline val String.utf8: ByteBuffer get() = utf8(this) +// inline val Long.toUTF8: String get() = memUTF8(this) +//} \ No newline at end of file diff --git a/src/main/kotlin/vkk/VkMemoryStack.kt b/src/main/kotlin/vkk/VkMemoryStack.kt new file mode 100644 index 0000000..b280a77 --- /dev/null +++ b/src/main/kotlin/vkk/VkMemoryStack.kt @@ -0,0 +1,730 @@ +import vkk.VkDebugReportFlagsEXT +import vkk.VkDebugReportObjectType + +//package vkn +// +//import glm_.i +//import org.lwjgl.PointerBuffer +//import org.lwjgl.system.Configuration +//import org.lwjgl.system.MemoryUtil +//import org.lwjgl.system.MemoryUtil.* +//import org.lwjgl.vulkan.* +//import uno.kotlin.buffers.toCollection +//import vkk.* +//import java.nio.ByteBuffer +//import java.nio.FloatBuffer +//import java.nio.IntBuffer +//import java.nio.LongBuffer +//import kotlin.reflect.KMutableProperty0 +// +//class VkMemoryStack private constructor(size: Int) : MemoryStackPlus(size) { +// +// fun vkAllocateCommandBuffers(device: VkDevice, allocateInfo: VkCommandBufferAllocateInfo, count: Int, +// commandBuffers: ArrayList): VkResult { +// val pCommandBuffer = mallocPointer(count) +// return VkResult of VK10.vkAllocateCommandBuffers(device, allocateInfo, pCommandBuffer).also { +// for (i in 0 until count) +// commandBuffers += VkCommandBuffer(pCommandBuffer[i], device) +// } +// } +// +// fun vkAllocateCommandBuffers(device: VkDevice, allocateInfo: VkCommandBufferAllocateInfo, +// commandBuffer: KMutableProperty0): VkResult { +// val pCommandBuffer = mallocPointer() +// return VkResult of VK10.vkAllocateCommandBuffers(device, allocateInfo, pCommandBuffer).also { +// commandBuffer.set(VkCommandBuffer(pCommandBuffer[0], device)) +// } +// } +// +// +// +// +// fun vkGetSwapchainImagesKHR(device: VkDevice, swapchain: VkSwapchainKHR, images: ArrayList): VkResult { +// val count = mallocInt() +// val ret = VkResult of KHRSwapchain.vkGetSwapchainImagesKHR(device, swapchain, count, null) +// if(ret()) return ret +// val pImages = mallocLong(count) +// return VkResult of KHRSwapchain.vkGetSwapchainImagesKHR(device, swapchain, count, pImages).also { +// pImages.toCollection(images) +// } +// } +//// +//// fun vkCreateDebugReportCallback(instance: VkInstance, createInfo: VkDebugReportCallbackCreateInfoEXT, +//// allocator: VkAllocationCallbacks?, callback: VkDebugReportCallbackFunc?): VkResult { +//// vkDebugReportCallback = VkDebugReportCallback().apply { cb = callback } +//// val pCallback = longs(vkDebugReportCallback!!.adr) +//// return VkResult of EXTDebugReport.vkCreateDebugReportCallbackEXT(instance, createInfo, allocator, pCallback).also { +////// vkDebugReportCallback = VkDebugReportCallback(pCallback[0]).apply { cb = callback } +//// } +//// } +// +// fun vkCreateImageView(device: VkDevice, createInfo: VkImageViewCreateInfo, allocator: VkAllocationCallbacks?, +// view: KMutableProperty0): VkResult { +// val pView = mallocLong() +// return VkResult of VK10.vkCreateImageView(device, createInfo, allocator, pView).also { +// view.set(pView) +// } +// } +// +// fun vkCreateImage(device: VkDevice, createInfo: VkImageCreateInfo, allocator: VkAllocationCallbacks?, +// image: KMutableProperty0): VkResult { +// val pImage = mallocLong() +// return VkResult of VK10.vkCreateImage(device, createInfo, allocator, pImage).also { +// image.set(pImage) +// } +// } +// +// +// +// fun vkGetImageMemoryRequirements(device: VkDevice, image: VkImageBlit, memoryRequirements: VkMemoryRequirements) = +// VK10.vkGetImageMemoryRequirements(device, image.address(), memoryRequirements) +// +// fun vkAllocateMemory(device: VkDevice, allocateInfo: VkMemoryAllocateInfo, allocator: VkAllocationCallbacks?, +// memory: KMutableProperty0): VkResult { +// val pMemory = mallocLong() +// return VkResult of VK10.vkAllocateMemory(device, allocateInfo, allocator, pMemory).also { +// memory.set(pMemory) +// } +// } +// +// fun vkBindImageMemory(device: VkDevice, image: VkImage, memory: VkDeviceMemory, memoryOffset: VkDeviceSize) = +// VK10.vkBindImageMemory(device, image, memory, memoryOffset) +// +// fun vkCreateRenderPass(device: VkDevice, createInfo: VkRenderPassCreateInfo, allocator: VkAllocationCallbacks?, +// renderPass: KMutableProperty0): VkResult { +// val pRenderPass = mallocLong() +// return VkResult of VK10.vkCreateRenderPass(device, createInfo, allocator, pRenderPass).also { +// renderPass.set(pRenderPass) +// } +// } +// +// fun vkCreatePipelineCache(device: VkDevice, createInfo: VkPipelineCacheCreateInfo, allocator: VkAllocationCallbacks?, +// pipelineCache: KMutableProperty0): VkResult { +// val pPipelineCache = mallocLong() +// return VkResult of VK10.vkCreatePipelineCache(device, createInfo, allocator, pPipelineCache).also { +// pipelineCache.set(pPipelineCache) +// } +// } +// +// fun vkCreateFramebuffer(device: VkDevice, createInfo: VkFramebufferCreateInfo, allocator: VkAllocationCallbacks?, +// framebuffer: ArrayList, index: Int): VkResult { +// val pFramebuffer = mallocLong() +// return VkResult of VK10.vkCreateFramebuffer(device, createInfo, allocator, pFramebuffer).also { +// framebuffer[index] = pFramebuffer +// } +// } +// +// fun vkAcquireNextImageKHR(device: VkDevice, swapchain: VkSwapchainKHR, timeout: Long, semaphore: VkSemaphore, fence: VkFence, +// imageIndex: KMutableProperty0): VkResult { +// val pImageIndex = mallocInt() +// return VkResult of KHRSwapchain.vkAcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex).also { +// imageIndex.set(pImageIndex) +// } +// } +// +// fun vkFreeCommandBuffers(device: VkDevice, commandPool: VkCommandPool, commandBuffers: ArrayList) { +// val pointers = mallocPointer(commandBuffers.size) +// for (i in commandBuffers.indices) +// pointers[i] = commandBuffers[i].address() +// return VK10.vkFreeCommandBuffers(device, commandPool, pointers) +// } +// +// fun vkCreateFences(device: VkDevice, createInfo: VkFenceCreateInfo, allocator: VkAllocationCallbacks?, fences: ArrayList) { +// val pFence = mallocLong() +// for (i in fences.indices) { +// VK10.vkCreateFence(device, createInfo, allocator, pFence) +// fences[i] = pFence +// } +// } +// +// fun vkCreateBuffer(device: VkDevice, createInfo: VkBufferCreateInfo, allocator: VkAllocationCallbacks?, +// buffer: KMutableProperty0): VkResult { +// val pBuffer = mallocLong() +// return VkResult of VK10.nvkCreateBuffer(device, createInfo.address(), memAddressSafe(allocator), memAddress(pBuffer)).also { +// buffer.set(pBuffer) +// } +// } +// +// fun vkCreateDescriptorSetLayout(device: VkDevice, createInfo: VkDescriptorSetLayoutCreateInfo, allocator: VkAllocationCallbacks?, +// setLayout: KMutableProperty0): VkResult { +// val pSetLayout = mallocLong() +// return VkResult of VK10.vkCreateDescriptorSetLayout(device, createInfo, allocator, pSetLayout).also { +// setLayout.set(pSetLayout) +// } +// } +// +// fun vkCreatePipelineLayout(device: VkDevice, createInfo: VkPipelineLayoutCreateInfo, allocator: VkAllocationCallbacks?, +// pipelineLayout: KMutableProperty0): VkResult { +// val pPipelineLayout = mallocLong() +// return VkResult of VK10.vkCreatePipelineLayout(device, createInfo, allocator, pPipelineLayout).also { +// pipelineLayout.set(pPipelineLayout) +// } +// } +// +// fun vkCreateGraphicsPipelines(device: VkDevice, pipelineCache: VkPipelineCache, createInfos: VkGraphicsPipelineCreateInfo.Buffer, +// allocator: VkAllocationCallbacks?, pipelines: KMutableProperty0): VkResult { +// val pPipelines = mallocLong() +// return VkResult of VK10.vkCreateGraphicsPipelines(device, pipelineCache, createInfos, allocator, pPipelines).also { +// pipelines.set(pPipelines) +// } +// } +// +// fun vkCreateDescriptorPool(device: VkDevice, createInfo: VkDescriptorPoolCreateInfo, allocator: VkAllocationCallbacks?, +// descriptorPool: KMutableProperty0): VkResult { +// val pDescriptorPool = mallocLong() +// return VkResult of VK10.vkCreateDescriptorPool(device, createInfo, allocator, pDescriptorPool).also { +// descriptorPool.set(pDescriptorPool) +// } +// } +// +// fun vkAllocateDescriptorSets(device: VkDevice, allocateInfo: VkDescriptorSetAllocateInfo, +// descriptorSets: KMutableProperty0): VkResult { +// val pDescriptorSets = mallocLong() +// return VkResult of VK10.vkAllocateDescriptorSets(device, allocateInfo, pDescriptorSets).also { +// descriptorSets.set(pDescriptorSets) +// } +// } +// +// fun vkCmdBindDescriptorSets(commandBuffer: VkCommandBuffer, pipelineBindPoint: VkPipelineBindPoint, layout: VkPipelineLayout, +// firstSet: Int, descriptorSets: KMutableProperty0, dynamicOffsets: IntBuffer?) { +// val pDescriptorSets = callocLong().apply { set(0, descriptorSets()) } +// VK10.vkCmdBindDescriptorSets(commandBuffer, pipelineBindPoint.i, layout, firstSet, pDescriptorSets, dynamicOffsets).also { +// descriptorSets.set(pDescriptorSets) +// } +// } +// +// fun vkCmdBindVertexBuffers(commandBuffer: VkCommandBuffer, firstBinding: Int, buffers: KMutableProperty0, +// offsets: LongBuffer) { +// val pBuffer = mallocLong().apply { set(0, buffers()) } +// VK10.vkCmdBindVertexBuffers(commandBuffer, firstBinding, pBuffer, offsets).also { +// buffers.set(pBuffer) +// } +// } +// +// +// fun ArrayList.toBuffer(): VkDeviceQueueCreateInfo.Buffer { +// val buffer = VkDeviceQueueCreateInfo.calloc(size) +// for (i in indices) +// buffer += get(i) +// return buffer.flip() +// } +// +// inline fun VkMemoryStack.withLong(block: VkMemoryStack.(LongBuffer) -> R): Long { +// val pLong = mallocLong() +// block(pLong) +// return pLong[0] +// } +// +////fun Struct.use(block: (Struct) -> R) = block(this).also { free() } +// +// +// fun KMutableProperty0.set(longBuffer: LongBuffer) = set(longBuffer[0]) +// fun KMutableProperty0.set(intBuffer: IntBuffer) = set(intBuffer[0]) +// +// val VkExtensionProperties.extensionName get() = extensionName() +// var VkApplicationInfo.type: VkStructureType +// get() = VkStructureType of sType() +// set(value) { +// sType(value.i) +// } +// var VkApplicationInfo.applicationName +// get() = pApplicationNameString()// TODO +// set(value) { +// pApplicationName(value?.utf8) +// } +// var VkApplicationInfo.engineName +// get() = pEngineNameString() +// set(value) { +// pEngineName(value?.utf8) +// } +// var VkApplicationInfo.apiVersion +// get() = apiVersion() +// set(value) { +// apiVersion(value) +// } +// +// +// var VkInstanceCreateInfo.type: VkStructureType +// get() = VkStructureType of sType() +// set(value) { +// sType(value.i) +// } +// var VkInstanceCreateInfo.next +// get() = pNext() +// set(value) { +// pNext(value) +// } +// var VkInstanceCreateInfo.applicationInfo +// get() = pApplicationInfo() +// set(value) { +// pApplicationInfo(value) +// } +// // var VkInstanceCreateInfo.enabledExtensionNames +//// get() = ppEnabledExtensionNames()?.toArrayListString(enabledExtensionCount()) +//// set(value) { +//// ppEnabledExtensionNames(value?.toPointerBuffer()) +//// } +// var VkInstanceCreateInfo.enabledExtensionNames +// get() = ppEnabledExtensionNames() +// set(value) { +// ppEnabledExtensionNames(value) +// } +// var VkInstanceCreateInfo.enabledLayerNames +// get() = ppEnabledLayerNames() +// set(value) { +// ppEnabledLayerNames(value) +// } +// +// +// var VkDebugReportCallbackCreateInfoEXT.type: VkStructureType +// get() = VkStructureType of sType() +// set(value) { +// sType(value.i) +// } +// var VkDebugReportCallbackCreateInfoEXT.callback: VkDebugReportCallbackFunc? +//// get() = pfnCallback() +// get() = null +// set(value) { +// value?.let { +// pfnCallback { flags, objectType, `object`, location, messageCode, layerPrefix, message, userData -> +// val type = VkDebugReportObjectType of objectType +// it(flags, type, `object`, location, messageCode, layerPrefix.toUTF8, message.toUTF8, userData as Any).i +// } +// } +// } +// var VkDebugReportCallbackCreateInfoEXT.flags +// get() = flags() +// set(value) { +// flags(value) +// } +// +// +// var VkDeviceQueueCreateInfo.type: VkStructureType +// get() = VkStructureType of sType() +// set(value) { +// sType(value.i) +// } +// var VkDeviceQueueCreateInfo.queueFamilyIndex +// get() = queueFamilyIndex() +// set(value) { +// queueFamilyIndex(value) +// } +// var VkDeviceQueueCreateInfo.queuePriorities: FloatBuffer +// get() = pQueuePriorities() +// set(value) { +// pQueuePriorities(value) +// } +// +// var VkDeviceCreateInfo.type: VkStructureType +// get() = VkStructureType of sType() +// set(value) { +// sType(value.i) +// } +// var VkDeviceCreateInfo.queueCreateInfos: VkDeviceQueueCreateInfo.Buffer +// get() = pQueueCreateInfos() +// set(value) { +// pQueueCreateInfos(value) +//// pQueueCreateInfos(VkDeviceQueueCreateInfo.create(value[0].address(), value.size)) +// } +// var VkDeviceCreateInfo.enabledFeatures +// get() = pEnabledFeatures() +// set(value) { +// pEnabledFeatures(value) +// } +// var VkDeviceCreateInfo.enabledExtensionNames +// get() = ppEnabledExtensionNames() +// set(value) { +// ppEnabledExtensionNames(value) +// } +// +// var VkCommandPoolCreateInfo.type: VkStructureType +// get() = VkStructureType of sType() +// set(value) { +// sType(value.i) +// } +// var VkCommandPoolCreateInfo.queueFamilyIndex +// get() = queueFamilyIndex() +// set(value) { +// queueFamilyIndex(value) +// } +// var VkCommandPoolCreateInfo.flags: VkCommandPoolCreateFlags +// get() = flags() +// set(value) { +// flags(value) +// } +// +// inline fun VkSubmitInfo.commandBuffers(array: ArrayList, index: Int, count: Int = 1) { +// val pointers = mallocPointer(count) +// for (i in 0 until count) pointers[0] = array[index + i] +// commandBuffers = pointers +// } +// +// val VkFormatProperties.optimalTilingFeatures get() = optimalTilingFeatures() +// +// inline var VkPipelineShaderStageCreateInfo.name: String +// get() = pNameString() +// set(value) { +// pName(value.utf8) +// } +// +//// fun VkClearValue.color(x: Float, y: Float, z: Float, w: Float) { +//// val floats = memByteBuffer(adr, Vec4.size).asFloatBuffer() +//// floats[0] = x +//// floats[1] = y +//// floats[2] = z +//// floats[3] = w +//// } +// +//// fun VkClearValue.depthStencil(float: Float, int: Int) { +//// val bytes = memByteBuffer(adr, Float.BYTES + Int.BYTES) +//// bytes.putFloat(0, float) +//// bytes.putInt(Float.BYTES, int) +//// } +// +// +//// typedef union VkClearValue { +//// VkClearColorValue color; +//// VkClearDepthStencilValue depthStencil; +//// } VkClearValue; +////typedef union VkClearColorValue { +//// float float32[4]; +//// int32_t int32[4]; +//// uint32_t uint32[4]; +////} VkClearColorValue; +//// +////typedef struct VkClearDepthStencilValue { +//// float depth; +//// uint32_t stencil; +////} VkClearDepthStencilValue; +// +// +//// fun VkDeviceQueueCreateInfo.Buffer.toArrayList(count: Int): ArrayList { +//// val res = ArrayList(count) +//// for (i in 0 until count) +//// res += get(i) +//// return res +//// } +// +//// fun ArrayList.toVkDeviceQueueCreateInfo_Buffer(): VkDeviceQueueCreateInfo.Buffer { +//// val res = sVkDeviceQueueCreateInfo_Buffer(size) +//// for (i in indices) +//// res.put(i, get(i)) +//// return res +//// } +// +// // inline fun mVkQueueFamilyProperties(capacity: IntBuffer): VkQueueFamilyProperties.Buffer = VkQueueFamilyProperties.create(nmalloc(VkQueueFamilyProperties.ALIGNOF, capacity[0] * VkQueueFamilyProperties.SIZEOF), capacity[0]) +// inline fun cVkQueueFamilyProperties(capacity: Int): VkQueueFamilyProperties.Buffer = VkQueueFamilyProperties.create(ncalloc(VkQueueFamilyProperties.ALIGNOF, capacity, VkQueueFamilyProperties.SIZEOF), capacity) +// +// inline fun cVkSurfaceFormatKHR(capacity: Int): VkSurfaceFormatKHR.Buffer = VkSurfaceFormatKHR.create(ncalloc(VkSurfaceFormatKHR.ALIGNOF, capacity, VkSurfaceFormatKHR.SIZEOF), capacity) +// // inline fun mVkSurfaceFormatKHR(capacity: Int): VkSurfaceFormatKHR.Buffer = VkSurfaceFormatKHR.create(nmalloc(VkSurfaceFormatKHR.ALIGNOF, capacity * VkSurfaceFormatKHR.SIZEOF), capacity) +//// inline fun mVkExtensionProperties(capacity: Int): VkExtensionProperties.Buffer = VkExtensionProperties.create(nmalloc(VkExtensionProperties.ALIGNOF, capacity * VkExtensionProperties.SIZEOF), capacity) +// inline fun cVkExtensionProperties(capacity: Int): VkExtensionProperties.Buffer = VkExtensionProperties.create(ncalloc(VkExtensionProperties.ALIGNOF, capacity, VkExtensionProperties.SIZEOF), capacity) +// +// inline fun cVkAttachmentDescription(capacity: Int): VkAttachmentDescription.Buffer = VkAttachmentDescription.create(ncalloc(VkAttachmentDescription.ALIGNOF, capacity, VkAttachmentDescription.SIZEOF), capacity) +// inline fun cVkApplicationInfo() = VkApplicationInfo.create(ncalloc(VkApplicationInfo.ALIGNOF, 1, VkApplicationInfo.SIZEOF)) +// +// inline fun cVkApplicationInfo(block: VkApplicationInfo.() -> Unit) = cVkApplicationInfo().also(block) +// +// inline fun cVkInstanceCreateInfo(): VkInstanceCreateInfo = VkInstanceCreateInfo.create(ncalloc(VkInstanceCreateInfo.ALIGNOF, 1, VkInstanceCreateInfo.SIZEOF)) +// inline fun cVkInstanceCreateInfo(block: VkInstanceCreateInfo.() -> Unit) = cVkInstanceCreateInfo().also(block) +// +// inline fun cVkDebugReportCallbackCreateInfoEXT(): VkDebugReportCallbackCreateInfoEXT = VkDebugReportCallbackCreateInfoEXT.create(ncalloc(VkDebugReportCallbackCreateInfoEXT.ALIGNOF, 1, VkDebugReportCallbackCreateInfoEXT.SIZEOF)) +// inline fun cVkDebugReportCallbackCreateInfoEXT(block: VkDebugReportCallbackCreateInfoEXT.() -> Unit) = cVkDebugReportCallbackCreateInfoEXT().also(block) +// +//// inline fun mVkDeviceQueueCreateInfo(capacity: Int): VkDeviceQueueCreateInfo.Buffer = VkDeviceQueueCreateInfo.create(nmalloc(VkDeviceQueueCreateInfo.ALIGNOF, capacity * VkDeviceQueueCreateInfo.SIZEOF), capacity) +// inline fun cVkDeviceQueueCreateInfo(capacity: Int): VkDeviceQueueCreateInfo.Buffer = VkDeviceQueueCreateInfo.create(ncalloc(VkDeviceQueueCreateInfo.ALIGNOF, capacity, VkDeviceQueueCreateInfo.SIZEOF), capacity) +// inline fun cVkDeviceQueueCreateInfo(): VkDeviceQueueCreateInfo = VkDeviceQueueCreateInfo.create(ncalloc(VkInstanceCreateInfo.ALIGNOF, 1, VkInstanceCreateInfo.SIZEOF)) +// inline fun cVkDeviceQueueCreateInfo(block: VkDeviceQueueCreateInfo.() -> Unit) = cVkDeviceQueueCreateInfo().also(block) +// +// inline fun cVkCommandPoolCreateInfo(): VkCommandPoolCreateInfo = VkCommandPoolCreateInfo.create(ncalloc(VkCommandPoolCreateInfo.ALIGNOF, 1, VkCommandPoolCreateInfo.SIZEOF)) +// inline fun cVkCommandPoolCreateInfo(block: VkCommandPoolCreateInfo.() -> Unit) = cVkCommandPoolCreateInfo().also(block) +// +//// inline fun mVkFormatProperties(): VkFormatProperties = VkFormatProperties.create(nmalloc(VkFormatProperties.ALIGNOF, VkFormatProperties.SIZEOF)) +// inline fun cVkFormatProperties(): VkFormatProperties = VkFormatProperties.create(ncalloc(VkFormatProperties.ALIGNOF, 1, VkFormatProperties.SIZEOF)) +// +// inline fun cVkSemaphoreCreateInfo(): VkSemaphoreCreateInfo = VkSemaphoreCreateInfo.create(ncalloc(VkSemaphoreCreateInfo.ALIGNOF, 1, VkSemaphoreCreateInfo.SIZEOF)) +// inline fun cVkSemaphoreCreateInfo(block: VkSemaphoreCreateInfo.() -> Unit) = cVkSemaphoreCreateInfo().also(block) +// +// inline fun cVkFenceCreateInfo(): VkFenceCreateInfo = VkFenceCreateInfo.create(ncalloc(VkFenceCreateInfo.ALIGNOF, 1, VkFenceCreateInfo.SIZEOF)) +// inline fun cVkFenceCreateInfo(block: VkFenceCreateInfo.() -> Unit) = cVkFenceCreateInfo().also(block) +// +// inline fun cVkSubmitInfo(): VkSubmitInfo = VkSubmitInfo.create(ncalloc(VkSubmitInfo.ALIGNOF, 1, VkSubmitInfo.SIZEOF)) +// inline fun cVkSubmitInfo(block: VkSubmitInfo.() -> Unit) = cVkSubmitInfo().also(block) +// +// inline fun cVkSurfaceCapabilitiesKHR(): VkSurfaceCapabilitiesKHR = VkSurfaceCapabilitiesKHR.create(ncalloc(VkSurfaceCapabilitiesKHR.ALIGNOF, 1, VkSurfaceCapabilitiesKHR.SIZEOF)) +// inline fun cVkSurfaceCapabilitiesKHR(block: VkSurfaceCapabilitiesKHR.() -> Unit) = cVkSurfaceCapabilitiesKHR().also(block) +// +//// inline fun mVkSurfaceCapabilitiesKHR(): VkSurfaceCapabilitiesKHR = VkSurfaceCapabilitiesKHR.create(nmalloc(VkSurfaceCapabilitiesKHR.ALIGNOF, VkSurfaceCapabilitiesKHR.SIZEOF)) +// +// inline fun cVkExtent2D(): VkExtent2D = VkExtent2D.create(ncalloc(VkExtent2D.ALIGNOF, 1, VkExtent2D.SIZEOF)) +// +// inline fun cVkSwapchainCreateInfoKHR(): VkSwapchainCreateInfoKHR = VkSwapchainCreateInfoKHR.create(ncalloc(VkSwapchainCreateInfoKHR.ALIGNOF, 1, VkSwapchainCreateInfoKHR.SIZEOF)) +// inline fun cVkSwapchainCreateInfoKHR(block: VkSwapchainCreateInfoKHR.() -> Unit) = cVkSwapchainCreateInfoKHR().also(block) +// +// inline fun cVkDeviceCreateInfo(): VkDeviceCreateInfo = VkDeviceCreateInfo.create(ncalloc(VkDeviceCreateInfo.ALIGNOF, 1, VkDeviceCreateInfo.SIZEOF)) +// inline fun cVkDeviceCreateInfo(block: VkDeviceCreateInfo.() -> Unit) = cVkDeviceCreateInfo().also(block) +// +//// inline fun mVkImageViewCreateInfo(): VkImageViewCreateInfo = VkImageViewCreateInfo.create(nmalloc(VkImageViewCreateInfo.ALIGNOF, VkImageViewCreateInfo.SIZEOF)) +//// inline fun mVkImageViewCreateInfo(block: VkImageViewCreateInfo.() -> Unit) = mVkImageViewCreateInfo().also(block) +// inline fun cVkImageViewCreateInfo(): VkImageViewCreateInfo = VkImageViewCreateInfo.create(ncalloc(VkImageViewCreateInfo.ALIGNOF, 1, VkImageViewCreateInfo.SIZEOF)) +// inline fun cVkImageViewCreateInfo(block: VkImageViewCreateInfo .() -> Unit) = cVkImageViewCreateInfo().also(block) +// +// inline fun cVkCommandBufferAllocateInfo(): VkCommandBufferAllocateInfo = VkCommandBufferAllocateInfo.create(ncalloc(VkCommandBufferAllocateInfo.ALIGNOF, 1, VkCommandBufferAllocateInfo.SIZEOF)) +// inline fun cVkCommandBufferAllocateInfo(block: VkCommandBufferAllocateInfo.() -> Unit) = cVkCommandBufferAllocateInfo().also(block) +//// inline fun mVkCommandBufferAllocateInfo(): VkCommandBufferAllocateInfo = VkCommandBufferAllocateInfo.create(nmalloc(VkCommandBufferAllocateInfo.ALIGNOF, VkCommandBufferAllocateInfo.SIZEOF)) +//// inline fun mVkCommandBufferAllocateInfo(block: VkCommandBufferAllocateInfo.() -> Unit) = mVkCommandBufferAllocateInfo().also(block) +// +// inline fun cVkImageCreateInfo(): VkImageCreateInfo = VkImageCreateInfo.create(ncalloc(VkImageCreateInfo.ALIGNOF, 1, VkImageCreateInfo.SIZEOF)) +// inline fun cVkImageCreateInfo(block: VkImageCreateInfo.() -> Unit) = cVkImageCreateInfo().also(block) +// +// +// inline fun cVkMemoryAllocateInfo(): VkMemoryAllocateInfo = VkMemoryAllocateInfo.create(ncalloc(VkMemoryAllocateInfo.ALIGNOF, 1, VkMemoryAllocateInfo.SIZEOF)) +// inline fun cVkMemoryAllocateInfo(block: VkMemoryAllocateInfo.() -> Unit) = cVkMemoryAllocateInfo().also(block) +// inline fun cVkMemoryRequirements(): VkMemoryRequirements = VkMemoryRequirements.create(ncalloc(VkMemoryRequirements.ALIGNOF, 1, VkMemoryRequirements.SIZEOF)) +// +// inline fun cVkAttachmentReference(): VkAttachmentReference = VkAttachmentReference.create(ncalloc(VkAttachmentReference.ALIGNOF, 1, VkAttachmentReference.SIZEOF)) +// inline fun cVkAttachmentReference(block: VkAttachmentReference.() -> Unit) = cVkAttachmentReference().also(block) +// // TODO c m +// inline fun cVkAttachmentReference(capacity: Int): VkAttachmentReference.Buffer = VkAttachmentReference.create(ncalloc(VkAttachmentReference.ALIGNOF, capacity, VkAttachmentReference.SIZEOF), capacity) +// +// inline fun cVkAttachmentReference(capacity: Int, block: VkAttachmentReference.() -> Unit) = cVkAttachmentReference(capacity).apply { get(0).block() } +// +// inline fun cVkSubpassDescription(): VkSubpassDescription = VkSubpassDescription.create(ncalloc(VkSubpassDescription.ALIGNOF, 1, VkSubpassDescription.SIZEOF)) +// inline fun cVkSubpassDescription(block: VkSubpassDescription.() -> Unit) = cVkSubpassDescription().also(block) +// inline fun cVkSubpassDescription(capacity: Int): VkSubpassDescription.Buffer = VkSubpassDescription.create(ncalloc(VkSubpassDescription.ALIGNOF, capacity, VkSubpassDescription.SIZEOF), capacity) +// inline fun cVkSubpassDescription(capacity: Int, block: VkSubpassDescription.() -> Unit) = cVkSubpassDescription(capacity).apply { get(0).block() } +// +// inline fun cVkSubpassDependency(capacity: Int): VkSubpassDependency.Buffer = VkSubpassDependency.create(ncalloc(VkSubpassDependency.ALIGNOF, capacity, VkSubpassDependency.SIZEOF), capacity) +// inline fun cVkSubpassDependency(capacity: Int, block: VkSubpassDependency.() -> Unit) = cVkSubpassDependency(capacity).apply { get(0).block() } +// +// inline fun cVkRenderPassCreateInfo(): VkRenderPassCreateInfo = VkRenderPassCreateInfo.create(ncalloc(VkRenderPassCreateInfo.ALIGNOF, 1, VkRenderPassCreateInfo.SIZEOF)) +// inline fun cVkRenderPassCreateInfo(block: VkRenderPassCreateInfo.() -> Unit) = cVkRenderPassCreateInfo().also(block) +// +// inline fun cVkPipelineCacheCreateInfo(): VkPipelineCacheCreateInfo = VkPipelineCacheCreateInfo.create(ncalloc(VkPipelineCacheCreateInfo.ALIGNOF, 1, VkPipelineCacheCreateInfo.SIZEOF)) +// inline fun cVkPipelineCacheCreateInfo(block: VkPipelineCacheCreateInfo.() -> Unit) = cVkPipelineCacheCreateInfo().also(block) +// +// inline fun cVkFramebufferCreateInfo(): VkFramebufferCreateInfo = VkFramebufferCreateInfo.create(ncalloc(VkFramebufferCreateInfo.ALIGNOF, 1, VkFramebufferCreateInfo.SIZEOF)) +// inline fun cVkFramebufferCreateInfo(block: VkFramebufferCreateInfo.() -> Unit) = cVkFramebufferCreateInfo().also(block) +// +// inline fun cVkPresentInfoKHR(): VkPresentInfoKHR = VkPresentInfoKHR.create(ncalloc(VkPresentInfoKHR.ALIGNOF, 1, VkPresentInfoKHR.SIZEOF)) +// inline fun cVkPresentInfoKHR(block: VkPresentInfoKHR.() -> Unit) = cVkPresentInfoKHR().also(block) +// +// inline fun cVkBufferCreateInfo(): VkBufferCreateInfo = VkBufferCreateInfo.create(ncalloc(VkBufferCreateInfo.ALIGNOF, 1, VkBufferCreateInfo.SIZEOF)) +// inline fun cVkBufferCreateInfo(block: VkBufferCreateInfo.() -> Unit) = cVkBufferCreateInfo().also(block) +// +// inline fun cVkCommandBufferBeginInfo(): VkCommandBufferBeginInfo = VkCommandBufferBeginInfo.create(ncalloc(VkCommandBufferBeginInfo.ALIGNOF, 1, VkCommandBufferBeginInfo.SIZEOF)) +// inline fun cVkCommandBufferBeginInfo(block: VkCommandBufferBeginInfo.() -> Unit) = cVkCommandBufferBeginInfo().also(block) +// +// inline fun cVkDescriptorSetLayoutBinding(): VkDescriptorSetLayoutBinding = VkDescriptorSetLayoutBinding.create(ncalloc(VkDescriptorSetLayoutBinding.ALIGNOF, 1, VkDescriptorSetLayoutBinding.SIZEOF)) +// inline fun cVkDescriptorSetLayoutBinding(block: VkDescriptorSetLayoutBinding.() -> Unit) = cVkDescriptorSetLayoutBinding().also(block) +// inline fun cVkDescriptorSetLayoutBinding(capacity: Int): VkDescriptorSetLayoutBinding.Buffer = VkDescriptorSetLayoutBinding.create(ncalloc(VkDescriptorSetLayoutBinding.ALIGNOF, capacity, VkDescriptorSetLayoutBinding.SIZEOF), capacity) +// inline fun cVkDescriptorSetLayoutBinding(capacity: Int, block: VkDescriptorSetLayoutBinding.() -> Unit) = cVkDescriptorSetLayoutBinding(capacity).apply { get(0).block() } +// +// inline fun cVkDescriptorSetLayoutCreateInfo(): VkDescriptorSetLayoutCreateInfo = VkDescriptorSetLayoutCreateInfo.create(ncalloc(VkDescriptorSetLayoutCreateInfo.ALIGNOF, 1, VkDescriptorSetLayoutCreateInfo.SIZEOF)) +// inline fun cVkDescriptorSetLayoutCreateInfo(block: VkDescriptorSetLayoutCreateInfo .() -> Unit) = cVkDescriptorSetLayoutCreateInfo().also(block) +// +// inline fun cVkPipelineLayoutCreateInfo(): VkPipelineLayoutCreateInfo = VkPipelineLayoutCreateInfo.create(ncalloc(VkPipelineLayoutCreateInfo.ALIGNOF, 1, VkPipelineLayoutCreateInfo.SIZEOF)) +// inline fun cVkPipelineLayoutCreateInfo(block: VkPipelineLayoutCreateInfo.() -> Unit) = cVkPipelineLayoutCreateInfo().also(block) +// +// inline fun cVkGraphicsPipelineCreateInfo(): VkGraphicsPipelineCreateInfo = VkGraphicsPipelineCreateInfo.create(ncalloc(VkGraphicsPipelineCreateInfo.ALIGNOF, 1, VkGraphicsPipelineCreateInfo.SIZEOF)) +// inline fun cVkGraphicsPipelineCreateInfo(block: VkGraphicsPipelineCreateInfo.() -> Unit) = cVkGraphicsPipelineCreateInfo().also(block) +// inline fun cVkGraphicsPipelineCreateInfo(capacity: Int): VkGraphicsPipelineCreateInfo.Buffer = VkGraphicsPipelineCreateInfo.create(ncalloc(VkGraphicsPipelineCreateInfo.ALIGNOF, capacity, VkGraphicsPipelineCreateInfo.SIZEOF), capacity) +// inline fun cVkGraphicsPipelineCreateInfo(capacity: Int, block: VkGraphicsPipelineCreateInfo.() -> Unit) = cVkGraphicsPipelineCreateInfo(capacity).apply { get(0).block() } +// +// +// inline fun cVkPipelineViewportStateCreateInfo(): VkPipelineViewportStateCreateInfo = VkPipelineViewportStateCreateInfo.create(ncalloc(VkPipelineViewportStateCreateInfo.ALIGNOF, 1, VkPipelineViewportStateCreateInfo.SIZEOF)) +// inline fun cVkPipelineViewportStateCreateInfo(block: VkPipelineViewportStateCreateInfo.() -> Unit) = cVkPipelineViewportStateCreateInfo().also(block) +// +// inline fun cVkPipelineDynamicStateCreateInfo(): VkPipelineDynamicStateCreateInfo = VkPipelineDynamicStateCreateInfo.create(ncalloc(VkPipelineDynamicStateCreateInfo.ALIGNOF, 1, VkPipelineDynamicStateCreateInfo.SIZEOF)) +// inline fun cVkPipelineDynamicStateCreateInfo(block: VkPipelineDynamicStateCreateInfo.() -> Unit) = cVkPipelineDynamicStateCreateInfo().also(block) +// +// inline fun cVkPipelineInputAssemblyStateCreateInfo(): VkPipelineInputAssemblyStateCreateInfo = VkPipelineInputAssemblyStateCreateInfo.create(ncalloc(VkPipelineInputAssemblyStateCreateInfo.ALIGNOF, 1, VkPipelineInputAssemblyStateCreateInfo.SIZEOF)) +// inline fun cVkPipelineInputAssemblyStateCreateInfo(block: VkPipelineInputAssemblyStateCreateInfo.() -> Unit) = cVkPipelineInputAssemblyStateCreateInfo().also(block) +// +// inline fun cVkPipelineRasterizationStateCreateInfo(): VkPipelineRasterizationStateCreateInfo = VkPipelineRasterizationStateCreateInfo.create(ncalloc(VkPipelineRasterizationStateCreateInfo.ALIGNOF, 1, VkPipelineRasterizationStateCreateInfo.SIZEOF)) +// inline fun cVkPipelineRasterizationStateCreateInfo(block: VkPipelineRasterizationStateCreateInfo.() -> Unit) = cVkPipelineRasterizationStateCreateInfo().also(block) +// +// inline fun cVkPipelineColorBlendStateCreateInfo(): VkPipelineColorBlendStateCreateInfo = VkPipelineColorBlendStateCreateInfo.create(ncalloc(VkPipelineColorBlendStateCreateInfo.ALIGNOF, 1, VkPipelineColorBlendStateCreateInfo.SIZEOF)) +// inline fun cVkPipelineColorBlendStateCreateInfo(block: VkPipelineColorBlendStateCreateInfo.() -> Unit) = cVkPipelineColorBlendStateCreateInfo().also(block) +// +// inline fun cVkPipelineDepthStencilStateCreateInfo(): VkPipelineDepthStencilStateCreateInfo = VkPipelineDepthStencilStateCreateInfo.create(ncalloc(VkPipelineDepthStencilStateCreateInfo.ALIGNOF, 1, VkPipelineDepthStencilStateCreateInfo.SIZEOF)) +// inline fun cVkPipelineDepthStencilStateCreateInfo(block: VkPipelineDepthStencilStateCreateInfo.() -> Unit) = cVkPipelineDepthStencilStateCreateInfo().also(block) +// +// inline fun cVkPipelineMultisampleStateCreateInfo(): VkPipelineMultisampleStateCreateInfo = VkPipelineMultisampleStateCreateInfo.create(ncalloc(VkPipelineMultisampleStateCreateInfo.ALIGNOF, 1, VkPipelineMultisampleStateCreateInfo.SIZEOF)) +// inline fun cVkPipelineMultisampleStateCreateInfo(block: VkPipelineMultisampleStateCreateInfo.() -> Unit) = cVkPipelineMultisampleStateCreateInfo().also(block) +// +// inline fun cVkVertexInputBindingDescription(): VkVertexInputBindingDescription = VkVertexInputBindingDescription.create(ncalloc(VkVertexInputBindingDescription.ALIGNOF, 1, VkVertexInputBindingDescription.SIZEOF)) +// inline fun cVkVertexInputBindingDescription(block: VkVertexInputBindingDescription.() -> Unit) = cVkVertexInputBindingDescription().also(block) +// inline fun cVkVertexInputBindingDescription(capacity: Int): VkVertexInputBindingDescription.Buffer = VkVertexInputBindingDescription.create(ncalloc(VkVertexInputBindingDescription.ALIGNOF, capacity, VkVertexInputBindingDescription.SIZEOF), capacity) +// inline fun cVkVertexInputBindingDescription(capacity: Int, block: VkVertexInputBindingDescription.() -> Unit) = cVkVertexInputBindingDescription(capacity).apply { get(0).block() } +// +// inline fun cVkPipelineShaderStageCreateInfo(capacity: Int): VkPipelineShaderStageCreateInfo.Buffer = VkPipelineShaderStageCreateInfo.create(ncalloc(VkPipelineShaderStageCreateInfo.ALIGNOF, capacity, VkPipelineShaderStageCreateInfo.SIZEOF), capacity) +// inline fun cVkPipelineShaderStageCreateInfo(capacity: Int, block: VkPipelineShaderStageCreateInfo.() -> Unit) = cVkPipelineShaderStageCreateInfo(capacity).apply { get(0).block() } +// +// inline fun cVkDescriptorPoolSize(capacity: Int): VkDescriptorPoolSize.Buffer = VkDescriptorPoolSize.create(ncalloc(VkDescriptorPoolSize.ALIGNOF, capacity, VkDescriptorPoolSize.SIZEOF), capacity) +// inline fun cVkDescriptorPoolSize(capacity: Int, block: VkDescriptorPoolSize.() -> Unit) = cVkDescriptorPoolSize(capacity).apply { get(0).block() } +// +// inline fun cVkPipelineVertexInputStateCreateInfo(): VkPipelineVertexInputStateCreateInfo = VkPipelineVertexInputStateCreateInfo.create(ncalloc(VkPipelineVertexInputStateCreateInfo.ALIGNOF, 1, VkPipelineVertexInputStateCreateInfo.SIZEOF)) +// inline fun cVkPipelineVertexInputStateCreateInfo(block: VkPipelineVertexInputStateCreateInfo.() -> Unit) = cVkPipelineVertexInputStateCreateInfo().also(block) +// +// inline fun cVkDescriptorPoolCreateInfo(): VkDescriptorPoolCreateInfo = VkDescriptorPoolCreateInfo.create(ncalloc(VkDescriptorPoolCreateInfo.ALIGNOF, 1, VkDescriptorPoolCreateInfo.SIZEOF)) +// inline fun cVkDescriptorPoolCreateInfo(block: VkDescriptorPoolCreateInfo.() -> Unit) = cVkDescriptorPoolCreateInfo().also(block) +// +// inline fun cVkShaderModuleCreateInfo(): VkShaderModuleCreateInfo = VkShaderModuleCreateInfo.create(ncalloc(VkShaderModuleCreateInfo.ALIGNOF, 1, VkShaderModuleCreateInfo.SIZEOF)) +// inline fun cVkShaderModuleCreateInfo(block: VkShaderModuleCreateInfo.() -> Unit) = cVkShaderModuleCreateInfo().also(block) +// +// inline fun cVkDescriptorSetAllocateInfo(): VkDescriptorSetAllocateInfo = VkDescriptorSetAllocateInfo.create(ncalloc(VkDescriptorSetAllocateInfo.ALIGNOF, 1, VkDescriptorSetAllocateInfo.SIZEOF)) +// inline fun cVkDescriptorSetAllocateInfo(block: VkDescriptorSetAllocateInfo.() -> Unit) = cVkDescriptorSetAllocateInfo().also(block) +// +// inline fun cVkRenderPassBeginInfo(): VkRenderPassBeginInfo = VkRenderPassBeginInfo.create(ncalloc(VkRenderPassBeginInfo.ALIGNOF, 1, VkRenderPassBeginInfo.SIZEOF)) +// inline fun cVkRenderPassBeginInfo(block: VkRenderPassBeginInfo.() -> Unit) = cVkRenderPassBeginInfo().also(block) +// +// inline fun cVkViewport(): VkViewport = VkViewport.create(ncalloc(VkViewport.ALIGNOF, 1, VkViewport.SIZEOF)) +// inline fun cVkViewport(block: VkViewport .() -> Unit) = cVkViewport().also(block) +// inline fun cVkViewport(capacity: Int): VkViewport.Buffer = VkViewport.create(ncalloc(VkViewport.ALIGNOF, capacity, VkViewport.SIZEOF), capacity) +// inline fun cVkViewport(capacity: Int, block: VkViewport.() -> Unit) = cVkViewport(capacity).apply { get(0).block() } +// +// inline fun cVkRect2D(): VkRect2D = VkRect2D.create(ncalloc(VkRect2D.ALIGNOF, 1, VkRect2D.SIZEOF)) +// inline fun cVkRect2D(block: VkRect2D .() -> Unit) = cVkRect2D().also(block) +// inline fun cVkRect2D(capacity: Int): VkRect2D.Buffer = VkRect2D.create(ncalloc(VkRect2D.ALIGNOF, capacity, VkRect2D.SIZEOF), capacity) +// inline fun cVkRect2D(capacity: Int, block: VkRect2D.() -> Unit) = cVkRect2D(capacity).apply { get(0).block() } +// +// inline fun cVkWriteDescriptorSet(): VkWriteDescriptorSet = VkWriteDescriptorSet.create(ncalloc(VkWriteDescriptorSet.ALIGNOF, 1, VkWriteDescriptorSet.SIZEOF)) +// inline fun cVkWriteDescriptorSet(block: VkWriteDescriptorSet.() -> Unit) = cVkWriteDescriptorSet().also(block) +// inline fun cVkWriteDescriptorSet(capacity: Int): VkWriteDescriptorSet.Buffer = VkWriteDescriptorSet.create(ncalloc(VkWriteDescriptorSet.ALIGNOF, capacity, VkWriteDescriptorSet.SIZEOF), capacity) +// inline fun cVkWriteDescriptorSet(capacity: Int, block: VkWriteDescriptorSet.() -> Unit) = cVkWriteDescriptorSet(capacity).apply { get(0).block() } +// +// inline fun cVkClearValue(): VkClearValue = VkClearValue.create(ncalloc(VkClearValue.ALIGNOF, 1, VkClearValue.SIZEOF)) +// inline fun cVkClearValue(block: VkClearValue.() -> Unit) = cVkClearValue().also(block) +// inline fun cVkClearValue(capacity: Int): VkClearValue.Buffer = VkClearValue.create(ncalloc(VkClearValue.ALIGNOF, capacity, VkClearValue.SIZEOF), capacity) +// inline fun cVkClearValue(capacity: Int, block: VkClearValue.() -> Unit) = cVkClearValue(capacity).apply { get(0).block() } +// +//// inline fun cVkStencilOpState(): VkStencilOpState = VkStencilOpState.create(ncalloc(VkStencilOpState.ALIGNOF, 1, VkStencilOpState.SIZEOF)) +//// inline fun cVkStencilOpState(block: VkStencilOpState.() -> Unit) = cVkStencilOpState().also(block) +// +// inline fun cVkBufferCopy(): VkBufferCopy = VkBufferCopy.create(ncalloc(VkBufferCopy.ALIGNOF, 1, VkBufferCopy.SIZEOF)) +// inline fun cVkBufferCopy(block: VkBufferCopy.() -> Unit) = cVkBufferCopy().also(block) +// inline fun cVkBufferCopy(capacity: Int): VkBufferCopy.Buffer = VkBufferCopy.create(ncalloc(VkBufferCopy.ALIGNOF, capacity, VkBufferCopy.SIZEOF), capacity) +// inline fun cVkBufferCopy(capacity: Int, block: VkBufferCopy.() -> Unit) = cVkBufferCopy(capacity).apply { get(0).block() } +// +// inline fun cVkVertexInputAttributeDescription(capacity: Int): VkVertexInputAttributeDescription.Buffer = VkVertexInputAttributeDescription.create(ncalloc(VkVertexInputAttributeDescription.ALIGNOF, capacity, VkVertexInputAttributeDescription.SIZEOF), capacity) +// inline fun cVkVertexInputAttributeDescription(capacity: Int, block: VkVertexInputAttributeDescription.() -> Unit) = cVkVertexInputAttributeDescription(capacity).apply { get(0).block() } +// +// inline fun cVkPipelineColorBlendAttachmentState(): VkPipelineColorBlendAttachmentState = VkPipelineColorBlendAttachmentState.create(ncalloc(VkPipelineColorBlendAttachmentState.ALIGNOF, 1, VkPipelineColorBlendAttachmentState.SIZEOF)) +// inline fun cVkPipelineColorBlendAttachmentState(block: VkPipelineColorBlendAttachmentState.() -> Unit) = cVkPipelineColorBlendAttachmentState().also(block) +// inline fun cVkPipelineColorBlendAttachmentState(capacity: Int): VkPipelineColorBlendAttachmentState.Buffer = VkPipelineColorBlendAttachmentState.create(ncalloc(VkPipelineColorBlendAttachmentState.ALIGNOF, capacity, VkPipelineColorBlendAttachmentState.SIZEOF), capacity) +// inline fun cVkPipelineColorBlendAttachmentState(capacity: Int, block: VkPipelineColorBlendAttachmentState.() -> Unit) = cVkPipelineColorBlendAttachmentState(capacity).apply { get(0).block() } +// +// inline fun cVkImageView(capacity: Int) = callocLong(capacity) +// inline fun vkImageViewOf(view0: VkImageView, view1: VkImageView): VkImageViewBuffer = longs(view0, view1) +// +// operator fun PointerBuffer.plusAssign(string: String) { +// put(string.utf8) +// } +// +// operator fun PointerBuffer.plusAssign(pointerBuffer: PointerBuffer) { +// put(pointerBuffer) +// } +// +// operator fun PointerBuffer.plusAssign(collection: Collection) { +// for (i in collection) +// put(i.utf8) +// } +// +// operator fun VkDeviceQueueCreateInfo.Buffer.plusAssign(info: VkDeviceQueueCreateInfo) { +// put(info) +// } +// +// fun VkCommandBuffer.toPointerBuffer() = pointers(adr) +// fun Long.toLongBuffer() = longs(this) +// +// override fun push(): VkMemoryStack { +// super.push() +// return this +// } +// +// companion object { +// +// private val DEFAULT_STACK_SIZE = Configuration.STACK_SIZE.get(64) * 1024 +// private val DEFAULT_STACK_FRAMES = 8 +// +// private val TLS = ThreadLocal.withInitial({ create() }) +// +// init { +// if (DEFAULT_STACK_SIZE < 0) +// throw IllegalStateException("Invalid stack size.") +// } +// +// /** +// * Creates a new [MemoryStackPlus] with the specified size. +// * +// * @param size the maximum number of bytes that may be allocated on the stack +// */ +// @JvmOverloads +// fun create(size: Int = DEFAULT_STACK_SIZE) = VkMemoryStack(size) +// +// /** Returns the stack of the current thread. */ +// fun stackGet() = TLS.get() +// +// inline fun withStack(block: VkMemoryStack.() -> R): R { +// var exception: Throwable? = null +// val stack = stackGet().push() +// try { +// return stack.block() +// } catch (e: Throwable) { +// exception = e +// throw e +// } finally { +// stack.closeFinally(exception) +// } +// } +// +//// @SinceKotlin("1.1") +//// @Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") +//// @kotlin.internal.InlineOnly +//// inline fun T.use(block: (T) -> R): R { +//// var exception: Throwable? = null +//// try { +//// return block(this) +//// } catch (e: Throwable) { +//// exception = e +//// throw e +//// } finally { +//// this.closeFinally(exception) +//// } +//// } +// +// @SinceKotlin("1.1") +// @PublishedApi +// internal fun AutoCloseable?.closeFinally(cause: Throwable?) = when { +// this == null -> Unit +// cause == null -> close() +// else -> +// try { +// close() +// } catch (closeException: Throwable) { +// cause.addSuppressed(closeException) +// } +// } +// } +// +// val Long.utf8: String get() = MemoryUtil.memUTF8(this) +// val ByteBuffer.utf8: String get() = MemoryUtil.memUTF8(this) +//} +// +typealias VkDebugReportCallbackFunc = (VkDebugReportFlagsEXT, VkDebugReportObjectType, Long, Long, Int, String, String, Any?) -> Boolean +// +////var vkDebugReportCallback: VkDebugReportCallback? = null +//// +////class VkDebugReportCallback : VkDebugReportCallbackEXT() { +////// val instance: VkDebugReportCallbackEXT = create(address) +//// var cb: VkDebugReportCallbackFunc? = null +//// override fun invoke(flags: VkDebugReportFlagsEXT, objectType: VkDebugReportObjectTypeEXT, `object`: Long, location: Long, +//// messageCode: Int, pLayerPrefix: Long, pMessage: Long, userData: Long): VkBool32 = withStack { +//// val layerPrefix = getString(pLayerPrefix) +//// val message = getString(pMessage) +//// println("ou") +//// return cb?.invoke(flags, objectType, `object`, location, messageCode, layerPrefix, message, userData)?.i +//// ?: VK_FALSE +//// } +////} \ No newline at end of file diff --git a/src/main/kotlin/vkk/debug.kt b/src/main/kotlin/vkk/debug.kt new file mode 100644 index 0000000..3c61345 --- /dev/null +++ b/src/main/kotlin/vkk/debug.kt @@ -0,0 +1,25 @@ +package vkk + +import kool.stak +import org.lwjgl.PointerBuffer +import org.lwjgl.system.MemoryUtil +import org.lwjgl.system.MemoryUtil.memLengthUTF8 +import org.lwjgl.system.MemoryUtil.memUTF8 +import org.lwjgl.vulkan.VkDeviceQueueCreateInfo +import java.nio.ByteBuffer + +val String.utf8: ByteBuffer + get() = stak { + val size = memLengthUTF8(this, true) + val target = it.malloc(size) + memUTF8(this, true, target) + return target + } +val Long.utf8: String get() = MemoryUtil.memUTF8(this) + + +operator fun PointerBuffer.set(index: Int, string: String): PointerBuffer = put(index, string.utf8) + +operator fun VkDeviceQueueCreateInfo.Buffer.plusAssign(info: VkDeviceQueueCreateInfo) { + put(info) +} diff --git a/src/main/kotlin/vkk/direct fields A.kt b/src/main/kotlin/vkk/direct fields A.kt new file mode 100644 index 0000000..e79b337 --- /dev/null +++ b/src/main/kotlin/vkk/direct fields A.kt @@ -0,0 +1,1992 @@ +package vkk + +import glm_.BYTES +import glm_.bool +import glm_.f +import glm_.i +import glm_.vec2.Vec2 +import glm_.vec2.Vec2i +import glm_.vec3.Vec3i +import kool.Ptr +import kool.stak +import org.lwjgl.PointerBuffer +import org.lwjgl.system.MemoryStack +import org.lwjgl.system.MemoryUtil.* +import org.lwjgl.system.Pointer +import org.lwjgl.vulkan.* +import java.nio.ByteBuffer +import java.nio.FloatBuffer +import java.nio.IntBuffer +import java.nio.LongBuffer + + +inline var VkApplicationInfo.type: VkStructureType + get() = VkStructureType of VkApplicationInfo.nsType(adr) + set(value) = VkApplicationInfo.nsType(adr, value.i) +inline var VkApplicationInfo.next: Ptr + get() = VkApplicationInfo.npNext(adr) + set(value) = VkApplicationInfo.npNext(adr, value) +inline var VkApplicationInfo.applicationName: String? + get() = VkApplicationInfo.npApplicationNameString(adr) + set(value) = VkApplicationInfo.npApplicationName(adr, value?.utf8) +inline var VkApplicationInfo.applicationVersion: Int + get() = VkApplicationInfo.napplicationVersion(adr) + set(value) = VkApplicationInfo.napiVersion(adr, value) +inline var VkApplicationInfo.engineName: String? + get() = VkApplicationInfo.npEngineNameString(adr) + set(value) = VkApplicationInfo.npEngineName(adr, value?.utf8) +inline var VkApplicationInfo.apiVersion: Int + get() = VkApplicationInfo.napiVersion(adr) + set(value) = VkApplicationInfo.napiVersion(adr, value) + + +inline var VkInstanceCreateInfo.type: VkStructureType + get() = VkStructureType of VkInstanceCreateInfo.nsType(adr) + set(value) = VkInstanceCreateInfo.nsType(adr, value.i) +inline var VkInstanceCreateInfo.next: Ptr + get() = VkInstanceCreateInfo.npNext(adr) + set(value) = VkInstanceCreateInfo.npNext(adr, value) +// flags is reserved for future usage, till now must be 0 +//inline var VkInstanceCreateInfo.flag: VkInstanceCreateFlags +// get() = VkInstanceCreateInfo.nflags(adr) +// set(value) = VkInstanceCreateInfo.nflags(adr, value) +inline var VkInstanceCreateInfo.flags: VkInstanceCreateFlags + get() = VkInstanceCreateInfo.nflags(adr) + set(value) = VkInstanceCreateInfo.nflags(adr, value) +inline var VkInstanceCreateInfo.applicationInfo + get() = VkInstanceCreateInfo.npApplicationInfo(adr) + set(value) = VkInstanceCreateInfo.npApplicationInfo(adr, value) +inline var VkInstanceCreateInfo.enabledLayerNames: Collection + get() = VkInstanceCreateInfo.nppEnabledLayerNames(adr).toArrayList() + set(value) = VkInstanceCreateInfo.nppEnabledLayerNames(adr, value.toPointerBuffer()) +inline var VkInstanceCreateInfo.enabledExtensionNames + get() = VkInstanceCreateInfo.nppEnabledExtensionNames(adr).toArrayList() + set(value) = VkInstanceCreateInfo.nppEnabledExtensionNames(adr, value.toPointerBuffer()) + +//typedef struct VkAllocationCallbacks { +// void* pUserData; +// PFN_vkAllocationFunction pfnAllocation; +// PFN_vkReallocationFunction pfnReallocation; +// PFN_vkFreeFunction pfnFree; +// PFN_vkInternalAllocationNotification pfnInternalAllocation; +// PFN_vkInternalFreeNotification pfnInternalFree; +//} VkAllocationCallbacks; + +inline var VkPhysicalDeviceFeatures.robustBufferAccess: Boolean + get() = VkPhysicalDeviceFeatures.nrobustBufferAccess(adr).bool + set(value) = VkPhysicalDeviceFeatures.nrobustBufferAccess(adr, value.i) +inline var VkPhysicalDeviceFeatures.fullDrawIndexUint32: Boolean + get() = VkPhysicalDeviceFeatures.nfullDrawIndexUint32(adr).bool + set(value) = VkPhysicalDeviceFeatures.nfullDrawIndexUint32(adr, value.i) +inline var VkPhysicalDeviceFeatures.imageCubeArray: Boolean + get() = VkPhysicalDeviceFeatures.nimageCubeArray(adr).bool + set(value) = VkPhysicalDeviceFeatures.nimageCubeArray(adr, value.i) +inline var VkPhysicalDeviceFeatures.independentBlend: Boolean + get() = VkPhysicalDeviceFeatures.nindependentBlend(adr).bool + set(value) = VkPhysicalDeviceFeatures.nindependentBlend(adr, value.i) +inline var VkPhysicalDeviceFeatures.geometryShader: Boolean + get() = VkPhysicalDeviceFeatures.ngeometryShader(adr).bool + set(value) = VkPhysicalDeviceFeatures.ngeometryShader(adr, value.i) +inline var VkPhysicalDeviceFeatures.tessellationShader: Boolean + get() = VkPhysicalDeviceFeatures.ntessellationShader(adr).bool + set(value) = VkPhysicalDeviceFeatures.ntessellationShader(adr, value.i) +inline var VkPhysicalDeviceFeatures.sampleRateShading: Boolean + get() = VkPhysicalDeviceFeatures.nsampleRateShading(adr).bool + set(value) = VkPhysicalDeviceFeatures.nsampleRateShading(adr, value.i) +inline var VkPhysicalDeviceFeatures.dualSrcBlend: Boolean + get() = VkPhysicalDeviceFeatures.ndualSrcBlend(adr).bool + set(value) = VkPhysicalDeviceFeatures.ndualSrcBlend(adr, value.i) +inline var VkPhysicalDeviceFeatures.logicOp: Boolean + get() = VkPhysicalDeviceFeatures.nlogicOp(adr).bool + set(value) = VkPhysicalDeviceFeatures.nlogicOp(adr, value.i) +inline var VkPhysicalDeviceFeatures.multiDrawIndirect: Boolean + get() = VkPhysicalDeviceFeatures.nmultiDrawIndirect(adr).bool + set(value) = VkPhysicalDeviceFeatures.nmultiDrawIndirect(adr, value.i) +inline var VkPhysicalDeviceFeatures.drawIndirectFirstInstance: Boolean + get() = VkPhysicalDeviceFeatures.ndrawIndirectFirstInstance(adr).bool + set(value) = VkPhysicalDeviceFeatures.ndrawIndirectFirstInstance(adr, value.i) +inline var VkPhysicalDeviceFeatures.depthClamp: Boolean + get() = VkPhysicalDeviceFeatures.ndepthClamp(adr).bool + set(value) = VkPhysicalDeviceFeatures.ndepthClamp(adr, value.i) +inline var VkPhysicalDeviceFeatures.depthBiasClamp: Boolean + get() = VkPhysicalDeviceFeatures.ndepthBiasClamp(adr).bool + set(value) = VkPhysicalDeviceFeatures.ndepthBiasClamp(adr, value.i) +inline var VkPhysicalDeviceFeatures.fillModeNonSolid: Boolean + get() = VkPhysicalDeviceFeatures.nfillModeNonSolid(adr).bool + set(value) = VkPhysicalDeviceFeatures.nfillModeNonSolid(adr, value.i) +inline var VkPhysicalDeviceFeatures.depthBounds: Boolean + get() = VkPhysicalDeviceFeatures.ndepthBounds(adr).bool + set(value) = VkPhysicalDeviceFeatures.ndepthBounds(adr, value.i) +inline var VkPhysicalDeviceFeatures.wideLines: Boolean + get() = VkPhysicalDeviceFeatures.nwideLines(adr).bool + set(value) = VkPhysicalDeviceFeatures.nwideLines(adr, value.i) +inline var VkPhysicalDeviceFeatures.largePoints: Boolean + get() = VkPhysicalDeviceFeatures.nlargePoints(adr).bool + set(value) = VkPhysicalDeviceFeatures.nlargePoints(adr, value.i) +inline var VkPhysicalDeviceFeatures.alphaToOne: Boolean + get() = VkPhysicalDeviceFeatures.nalphaToOne(adr).bool + set(value) = VkPhysicalDeviceFeatures.nalphaToOne(adr, value.i) +inline var VkPhysicalDeviceFeatures.multiViewport: Boolean + get() = VkPhysicalDeviceFeatures.nmultiViewport(adr).bool + set(value) = VkPhysicalDeviceFeatures.nmultiViewport(adr, value.i) +inline var VkPhysicalDeviceFeatures.samplerAnisotropy: Boolean + get() = VkPhysicalDeviceFeatures.nsamplerAnisotropy(adr).bool + set(value) = VkPhysicalDeviceFeatures.nsamplerAnisotropy(adr, value.i) +inline var VkPhysicalDeviceFeatures.textureCompressionETC2: Boolean + get() = VkPhysicalDeviceFeatures.ntextureCompressionETC2(adr).bool + set(value) = VkPhysicalDeviceFeatures.ntextureCompressionETC2(adr, value.i) +inline var VkPhysicalDeviceFeatures.textureCompressionASTC_LDR: Boolean + get() = VkPhysicalDeviceFeatures.ntextureCompressionASTC_LDR(adr).bool + set(value) = VkPhysicalDeviceFeatures.ntextureCompressionASTC_LDR(adr, value.i) +inline var VkPhysicalDeviceFeatures.textureCompressionBC: Boolean + get() = VkPhysicalDeviceFeatures.ntextureCompressionBC(adr).bool + set(value) = VkPhysicalDeviceFeatures.ntextureCompressionBC(adr, value.i) +inline var VkPhysicalDeviceFeatures.occlusionQueryPrecise: Boolean + get() = VkPhysicalDeviceFeatures.nocclusionQueryPrecise(adr).bool + set(value) = VkPhysicalDeviceFeatures.nocclusionQueryPrecise(adr, value.i) +inline var VkPhysicalDeviceFeatures.pipelineStatisticsQuery: Boolean + get() = VkPhysicalDeviceFeatures.npipelineStatisticsQuery(adr).bool + set(value) = VkPhysicalDeviceFeatures.npipelineStatisticsQuery(adr, value.i) +inline var VkPhysicalDeviceFeatures.vertexPipelineStoresAndAtomics: Boolean + get() = VkPhysicalDeviceFeatures.nvertexPipelineStoresAndAtomics(adr).bool + set(value) = VkPhysicalDeviceFeatures.nvertexPipelineStoresAndAtomics(adr, value.i) +inline var VkPhysicalDeviceFeatures.fragmentStoresAndAtomics: Boolean + get() = VkPhysicalDeviceFeatures.nfragmentStoresAndAtomics(adr).bool + set(value) = VkPhysicalDeviceFeatures.nfragmentStoresAndAtomics(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderTessellationAndGeometryPointSize: Boolean + get() = VkPhysicalDeviceFeatures.nshaderTessellationAndGeometryPointSize(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderTessellationAndGeometryPointSize(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderImageGatherExtended: Boolean + get() = VkPhysicalDeviceFeatures.nshaderImageGatherExtended(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderImageGatherExtended(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderStorageImageExtendedFormats: Boolean + get() = VkPhysicalDeviceFeatures.nshaderStorageImageExtendedFormats(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderStorageImageExtendedFormats(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderStorageImageMultisample: Boolean + get() = VkPhysicalDeviceFeatures.nshaderStorageImageMultisample(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderStorageImageMultisample(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderStorageImageReadWithoutFormat: Boolean + get() = VkPhysicalDeviceFeatures.nshaderStorageImageReadWithoutFormat(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderStorageImageReadWithoutFormat(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderStorageImageWriteWithoutFormat: Boolean + get() = VkPhysicalDeviceFeatures.nshaderStorageImageWriteWithoutFormat(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderStorageImageWriteWithoutFormat(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderUniformBufferArrayDynamicIndexing: Boolean + get() = VkPhysicalDeviceFeatures.nshaderUniformBufferArrayDynamicIndexing(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderUniformBufferArrayDynamicIndexing(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderSampledImageArrayDynamicIndexing: Boolean + get() = VkPhysicalDeviceFeatures.nshaderSampledImageArrayDynamicIndexing(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderSampledImageArrayDynamicIndexing(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderStorageBufferArrayDynamicIndexing: Boolean + get() = VkPhysicalDeviceFeatures.nshaderStorageBufferArrayDynamicIndexing(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderStorageBufferArrayDynamicIndexing(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderStorageImageArrayDynamicIndexing: Boolean + get() = VkPhysicalDeviceFeatures.nshaderStorageImageArrayDynamicIndexing(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderStorageImageArrayDynamicIndexing(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderClipDistance: Boolean + get() = VkPhysicalDeviceFeatures.nshaderClipDistance(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderClipDistance(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderCullDistance: Boolean + get() = VkPhysicalDeviceFeatures.nshaderCullDistance(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderCullDistance(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderFloat64: Boolean + get() = VkPhysicalDeviceFeatures.nshaderFloat64(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderFloat64(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderInt64: Boolean + get() = VkPhysicalDeviceFeatures.nshaderInt64(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderInt64(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderInt16: Boolean + get() = VkPhysicalDeviceFeatures.nshaderInt16(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderInt16(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderResourceResidency: Boolean + get() = VkPhysicalDeviceFeatures.nshaderResourceResidency(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderResourceResidency(adr, value.i) +inline var VkPhysicalDeviceFeatures.shaderResourceMinLod: Boolean + get() = VkPhysicalDeviceFeatures.nshaderResourceMinLod(adr).bool + set(value) = VkPhysicalDeviceFeatures.nshaderResourceMinLod(adr, value.i) +inline var VkPhysicalDeviceFeatures.sparseBinding: Boolean + get() = VkPhysicalDeviceFeatures.nsparseBinding(adr).bool + set(value) = VkPhysicalDeviceFeatures.nsparseBinding(adr, value.i) +inline var VkPhysicalDeviceFeatures.sparseResidencyBuffer: Boolean + get() = VkPhysicalDeviceFeatures.nsparseResidencyBuffer(adr).bool + set(value) = VkPhysicalDeviceFeatures.nsparseResidencyBuffer(adr, value.i) +inline var VkPhysicalDeviceFeatures.sparseResidencyImage2D: Boolean + get() = VkPhysicalDeviceFeatures.nsparseResidencyImage2D(adr).bool + set(value) = VkPhysicalDeviceFeatures.nsparseResidencyImage2D(adr, value.i) +inline var VkPhysicalDeviceFeatures.sparseResidencyImage3D: Boolean + get() = VkPhysicalDeviceFeatures.nsparseResidencyImage3D(adr).bool + set(value) = VkPhysicalDeviceFeatures.nsparseResidencyImage3D(adr, value.i) +inline var VkPhysicalDeviceFeatures.sparseResidency2Samples: Boolean + get() = VkPhysicalDeviceFeatures.nsparseResidency2Samples(adr).bool + set(value) = VkPhysicalDeviceFeatures.nsparseResidency2Samples(adr, value.i) +inline var VkPhysicalDeviceFeatures.sparseResidency4Samples: Boolean + get() = VkPhysicalDeviceFeatures.nsparseResidency4Samples(adr).bool + set(value) = VkPhysicalDeviceFeatures.nsparseResidency4Samples(adr, value.i) +inline var VkPhysicalDeviceFeatures.sparseResidency8Samples: Boolean + get() = VkPhysicalDeviceFeatures.nsparseResidency8Samples(adr).bool + set(value) = VkPhysicalDeviceFeatures.nsparseResidency8Samples(adr, value.i) +inline var VkPhysicalDeviceFeatures.sparseResidency16Samples: Boolean + get() = VkPhysicalDeviceFeatures.nsparseResidency16Samples(adr).bool + set(value) = VkPhysicalDeviceFeatures.nrobustBufferAccess(adr, value.i) +inline var VkPhysicalDeviceFeatures.sparseResidencyAliased: Boolean + get() = VkPhysicalDeviceFeatures.nsparseResidencyAliased(adr).bool + set(value) = VkPhysicalDeviceFeatures.nsparseResidencyAliased(adr, value.i) +inline var VkPhysicalDeviceFeatures.variableMultisampleRate: Boolean + get() = VkPhysicalDeviceFeatures.nvariableMultisampleRate(adr).bool + set(value) = VkPhysicalDeviceFeatures.nvariableMultisampleRate(adr, value.i) +inline var VkPhysicalDeviceFeatures.inheritedQueries: Boolean + get() = VkPhysicalDeviceFeatures.ninheritedQueries(adr).bool + set(value) = VkPhysicalDeviceFeatures.ninheritedQueries(adr, value.i) + +inline val VkFormatProperties.linearTilingFeatures: VkFormatFeatureFlags get() = VkFormatProperties.nlinearTilingFeatures(adr) +inline val VkFormatProperties.optimalTilingFeatures: VkFormatFeatureFlags get() = VkFormatProperties.noptimalTilingFeatures(adr) +inline val VkFormatProperties.bufferFeatures: VkFormatFeatureFlags get() = VkFormatProperties.nbufferFeatures(adr) + +//typedef struct VkExtent3D { +// uint32_t width; +// uint32_t height; +// uint32_t depth; +//} VkExtent3D; +// +//typedef struct VkImageFormatProperties { +// VkExtent3D maxExtent; +// uint32_t maxMipLevels; +// uint32_t maxArrayLayers; +// VkSampleCountFlags sampleCounts; +// VkDeviceSize maxResourceSize; +//} VkImageFormatProperties; + +inline val VkPhysicalDeviceLimits.maxImageDimension1D + get() = VkPhysicalDeviceLimits.nmaxImageDimension1D(adr) +inline val VkPhysicalDeviceLimits.maxImageDimension2D + get() = VkPhysicalDeviceLimits.nmaxImageDimension2D(adr) +inline val VkPhysicalDeviceLimits.maxImageDimension3D + get() = VkPhysicalDeviceLimits.nmaxImageDimension3D(adr) +inline val VkPhysicalDeviceLimits.maxImageDimensionCube + get() = VkPhysicalDeviceLimits.nmaxImageDimensionCube(adr) +inline val VkPhysicalDeviceLimits.maxImageArrayLayers + get() = VkPhysicalDeviceLimits.nmaxImageArrayLayers(adr) +inline val VkPhysicalDeviceLimits.maxTexelBufferElements + get() = VkPhysicalDeviceLimits.nmaxTexelBufferElements(adr) +inline val VkPhysicalDeviceLimits.maxUniformBufferRange + get() = VkPhysicalDeviceLimits.nmaxUniformBufferRange(adr) +inline val VkPhysicalDeviceLimits.maxStorageBufferRange + get() = VkPhysicalDeviceLimits.nmaxStorageBufferRange(adr) +inline val VkPhysicalDeviceLimits.maxPushConstantsSize + get() = VkPhysicalDeviceLimits.nmaxPushConstantsSize(adr) +inline val VkPhysicalDeviceLimits.maxMemoryAllocationCount + get() = VkPhysicalDeviceLimits.nmaxMemoryAllocationCount(adr) +inline val VkPhysicalDeviceLimits.maxSamplerAllocationCount + get() = VkPhysicalDeviceLimits.nmaxSamplerAllocationCount(adr) +inline val VkPhysicalDeviceLimits.bufferImageGranularity: VkDeviceSize + get() = VkDeviceSize(VkPhysicalDeviceLimits.nbufferImageGranularity(adr)) +inline val VkPhysicalDeviceLimits.sparseAddressSpaceSize: VkDeviceSize + get() = VkDeviceSize(VkPhysicalDeviceLimits.nsparseAddressSpaceSize(adr)) +inline val VkPhysicalDeviceLimits.maxBoundDescriptorSets + get() = VkPhysicalDeviceLimits.nmaxBoundDescriptorSets(adr) +inline val VkPhysicalDeviceLimits.maxPerStageDescriptorSamplers + get() = VkPhysicalDeviceLimits.nmaxPerStageDescriptorSamplers(adr) +inline val VkPhysicalDeviceLimits.maxPerStageDescriptorUniformBuffers + get() = VkPhysicalDeviceLimits.nmaxPerStageDescriptorUniformBuffers(adr) +inline val VkPhysicalDeviceLimits.maxPerStageDescriptorStorageBuffers + get() = VkPhysicalDeviceLimits.nmaxPerStageDescriptorStorageBuffers(adr) +inline val VkPhysicalDeviceLimits.maxPerStageDescriptorSampledImages + get() = VkPhysicalDeviceLimits.nmaxPerStageDescriptorSampledImages(adr) +inline val VkPhysicalDeviceLimits.maxPerStageDescriptorStorageImages + get() = VkPhysicalDeviceLimits.nmaxPerStageDescriptorStorageImages(adr) +inline val VkPhysicalDeviceLimits.maxPerStageDescriptorInputAttachments + get() = VkPhysicalDeviceLimits.nmaxPerStageDescriptorInputAttachments(adr) +inline val VkPhysicalDeviceLimits.maxPerStageResources + get() = VkPhysicalDeviceLimits.nmaxPerStageResources(adr) +inline val VkPhysicalDeviceLimits.maxDescriptorSetSamplers + get() = VkPhysicalDeviceLimits.nmaxDescriptorSetSamplers(adr) +inline val VkPhysicalDeviceLimits.maxDescriptorSetUniformBuffers + get() = VkPhysicalDeviceLimits.nmaxDescriptorSetUniformBuffers(adr) +inline val VkPhysicalDeviceLimits.maxDescriptorSetUniformBuffersDynamic + get() = VkPhysicalDeviceLimits.nmaxDescriptorSetUniformBuffersDynamic(adr) +inline val VkPhysicalDeviceLimits.maxDescriptorSetStorageBuffers + get() = VkPhysicalDeviceLimits.nmaxDescriptorSetStorageBuffers(adr) +inline val VkPhysicalDeviceLimits.maxDescriptorSetStorageBuffersDynamic + get() = VkPhysicalDeviceLimits.nmaxDescriptorSetStorageBuffersDynamic(adr) +inline val VkPhysicalDeviceLimits.maxDescriptorSetSampledImages + get() = VkPhysicalDeviceLimits.nmaxDescriptorSetSampledImages(adr) +inline val VkPhysicalDeviceLimits.maxDescriptorSetStorageImages + get() = VkPhysicalDeviceLimits.nmaxDescriptorSetStorageImages(adr) +inline val VkPhysicalDeviceLimits.maxDescriptorSetInputAttachments + get() = VkPhysicalDeviceLimits.nmaxDescriptorSetInputAttachments(adr) +inline val VkPhysicalDeviceLimits.maxVertexInputAttributes + get() = VkPhysicalDeviceLimits.nmaxVertexInputAttributes(adr) +inline val VkPhysicalDeviceLimits.maxVertexInputBindings + get() = VkPhysicalDeviceLimits.nmaxVertexInputBindings(adr) +inline val VkPhysicalDeviceLimits.maxVertexInputAttributeOffset + get() = VkPhysicalDeviceLimits.nmaxVertexInputAttributeOffset(adr) +inline val VkPhysicalDeviceLimits.maxVertexInputBindingStride + get() = VkPhysicalDeviceLimits.nmaxVertexInputBindingStride(adr) +inline val VkPhysicalDeviceLimits.maxVertexOutputComponents + get() = VkPhysicalDeviceLimits.nmaxVertexOutputComponents(adr) +inline val VkPhysicalDeviceLimits.maxTessellationGenerationLevel + get() = VkPhysicalDeviceLimits.nmaxTessellationGenerationLevel(adr) +inline val VkPhysicalDeviceLimits.maxTessellationPatchSize + get() = VkPhysicalDeviceLimits.nmaxTessellationPatchSize(adr) +inline val VkPhysicalDeviceLimits.maxTessellationControlPerVertexInputComponents + get() = VkPhysicalDeviceLimits.nmaxTessellationControlPerVertexInputComponents(adr) +inline val VkPhysicalDeviceLimits.maxTessellationControlPerVertexOutputComponents + get() = VkPhysicalDeviceLimits.nmaxTessellationControlPerVertexOutputComponents(adr) +inline val VkPhysicalDeviceLimits.maxTessellationControlPerPatchOutputComponents + get() = VkPhysicalDeviceLimits.nmaxTessellationControlPerPatchOutputComponents(adr) +inline val VkPhysicalDeviceLimits.maxTessellationControlTotalOutputComponents + get() = VkPhysicalDeviceLimits.nmaxTessellationControlTotalOutputComponents(adr) +inline val VkPhysicalDeviceLimits.maxTessellationEvaluationInputComponents + get() = VkPhysicalDeviceLimits.nmaxTessellationEvaluationInputComponents(adr) +inline val VkPhysicalDeviceLimits.maxTessellationEvaluationOutputComponents + get() = VkPhysicalDeviceLimits.nmaxTessellationEvaluationOutputComponents(adr) +inline val VkPhysicalDeviceLimits.maxGeometryShaderInvocations + get() = VkPhysicalDeviceLimits.nmaxGeometryShaderInvocations(adr) +inline val VkPhysicalDeviceLimits.maxGeometryInputComponents + get() = VkPhysicalDeviceLimits.nmaxGeometryInputComponents(adr) +inline val VkPhysicalDeviceLimits.maxGeometryOutputComponents + get() = VkPhysicalDeviceLimits.nmaxGeometryOutputComponents(adr) +inline val VkPhysicalDeviceLimits.maxGeometryOutputVertices + get() = VkPhysicalDeviceLimits.nmaxGeometryOutputVertices(adr) +inline val VkPhysicalDeviceLimits.maxGeometryTotalOutputComponents + get() = VkPhysicalDeviceLimits.nmaxGeometryTotalOutputComponents(adr) +inline val VkPhysicalDeviceLimits.maxFragmentInputComponents + get() = VkPhysicalDeviceLimits.nmaxFragmentInputComponents(adr) +inline val VkPhysicalDeviceLimits.maxFragmentOutputAttachments + get() = VkPhysicalDeviceLimits.nmaxFragmentOutputAttachments(adr) +inline val VkPhysicalDeviceLimits.maxFragmentDualSrcAttachments + get() = VkPhysicalDeviceLimits.nmaxFragmentDualSrcAttachments(adr) +inline val VkPhysicalDeviceLimits.maxFragmentCombinedOutputResources + get() = VkPhysicalDeviceLimits.nmaxFragmentCombinedOutputResources(adr) +inline val VkPhysicalDeviceLimits.maxComputeSharedMemorySize + get() = VkPhysicalDeviceLimits.nmaxComputeSharedMemorySize(adr) +inline val VkPhysicalDeviceLimits.maxComputeWorkGroupCount: Vec3i + get() = Vec3i { VkPhysicalDeviceLimits.nmaxComputeWorkGroupCount(adr, it) } +inline val VkPhysicalDeviceLimits.maxComputeWorkGroupInvocations + get() = VkPhysicalDeviceLimits.nmaxComputeWorkGroupInvocations(adr) +inline val VkPhysicalDeviceLimits.maxComputeWorkGroupSize: Vec3i + get() = Vec3i { VkPhysicalDeviceLimits.nmaxComputeWorkGroupSize(adr, it) } +inline val VkPhysicalDeviceLimits.subPixelPrecisionBits + get() = VkPhysicalDeviceLimits.nsubPixelPrecisionBits(adr) +inline val VkPhysicalDeviceLimits.subTexelPrecisionBits + get() = VkPhysicalDeviceLimits.nsubTexelPrecisionBits(adr) +inline val VkPhysicalDeviceLimits.mipmapPrecisionBits + get() = VkPhysicalDeviceLimits.nmipmapPrecisionBits(adr) +inline val VkPhysicalDeviceLimits.maxDrawIndexedIndexValue + get() = VkPhysicalDeviceLimits.nmaxDrawIndexedIndexValue(adr) +inline val VkPhysicalDeviceLimits.maxDrawIndirectCount + get() = VkPhysicalDeviceLimits.nmaxDrawIndirectCount(adr) +inline val VkPhysicalDeviceLimits.maxSamplerLodBias + get() = VkPhysicalDeviceLimits.nmaxSamplerLodBias(adr) +inline val VkPhysicalDeviceLimits.maxSamplerAnisotropy + get() = VkPhysicalDeviceLimits.nmaxSamplerAnisotropy(adr) +inline val VkPhysicalDeviceLimits.maxViewports + get() = VkPhysicalDeviceLimits.nmaxViewports(adr) +inline val VkPhysicalDeviceLimits.maxViewportDimensions: Vec2i + get() = Vec2i { VkPhysicalDeviceLimits.nmaxViewportDimensions(adr, it) } +inline val VkPhysicalDeviceLimits.viewportBoundsRange: Vec2 + get() = Vec2 { VkPhysicalDeviceLimits.nviewportBoundsRange(adr, it) } +inline val VkPhysicalDeviceLimits.viewportSubPixelBits + get() = VkPhysicalDeviceLimits.nviewportSubPixelBits(adr) +inline val VkPhysicalDeviceLimits.minMemoryMapAlignment + get() = VkPhysicalDeviceLimits.nminMemoryMapAlignment(adr) +inline val VkPhysicalDeviceLimits.minTexelBufferOffsetAlignment: VkDeviceSize + get() = VkDeviceSize(VkPhysicalDeviceLimits.nminTexelBufferOffsetAlignment(adr)) +inline val VkPhysicalDeviceLimits.minUniformBufferOffsetAlignment: VkDeviceSize + get() = VkDeviceSize(VkPhysicalDeviceLimits.nminUniformBufferOffsetAlignment(adr)) +inline val VkPhysicalDeviceLimits.minStorageBufferOffsetAlignment: VkDeviceSize + get() = VkDeviceSize(VkPhysicalDeviceLimits.nminStorageBufferOffsetAlignment(adr)) +inline val VkPhysicalDeviceLimits.minTexelOffset + get() = VkPhysicalDeviceLimits.nminTexelOffset(adr) +inline val VkPhysicalDeviceLimits.maxTexelOffset + get() = VkPhysicalDeviceLimits.nmaxTexelOffset(adr) +inline val VkPhysicalDeviceLimits.minTexelGatherOffset + get() = VkPhysicalDeviceLimits.nminTexelGatherOffset(adr) +inline val VkPhysicalDeviceLimits.maxTexelGatherOffset + get() = VkPhysicalDeviceLimits.nmaxTexelGatherOffset(adr) +inline val VkPhysicalDeviceLimits.minInterpolationOffset + get() = VkPhysicalDeviceLimits.nminInterpolationOffset(adr) +inline val VkPhysicalDeviceLimits.maxInterpolationOffset + get() = VkPhysicalDeviceLimits.nmaxInterpolationOffset(adr) +inline val VkPhysicalDeviceLimits.subPixelInterpolationOffsetBits + get() = VkPhysicalDeviceLimits.nsubPixelInterpolationOffsetBits(adr) +inline val VkPhysicalDeviceLimits.maxFramebufferWidth + get() = VkPhysicalDeviceLimits.nmaxFramebufferWidth(adr) +inline val VkPhysicalDeviceLimits.maxFramebufferHeight + get() = VkPhysicalDeviceLimits.nmaxFramebufferHeight(adr) +inline val VkPhysicalDeviceLimits.maxFramebufferLayers + get() = VkPhysicalDeviceLimits.nmaxFramebufferLayers(adr) +inline val VkPhysicalDeviceLimits.framebufferColorSampleCounts: VkSampleCountFlags + get() = VkPhysicalDeviceLimits.nframebufferColorSampleCounts(adr) +inline val VkPhysicalDeviceLimits.framebufferDepthSampleCounts: VkSampleCountFlags + get() = VkPhysicalDeviceLimits.nframebufferDepthSampleCounts(adr) +inline val VkPhysicalDeviceLimits.framebufferStencilSampleCounts: VkSampleCountFlags + get() = VkPhysicalDeviceLimits.nframebufferStencilSampleCounts(adr) +inline val VkPhysicalDeviceLimits.framebufferNoAttachmentsSampleCounts: VkSampleCountFlags + get() = VkPhysicalDeviceLimits.nframebufferNoAttachmentsSampleCounts(adr) +inline val VkPhysicalDeviceLimits.maxColorAttachments: Int + get() = VkPhysicalDeviceLimits.nmaxColorAttachments(adr) +inline val VkPhysicalDeviceLimits.sampledImageColorSampleCounts: VkSampleCountFlags + get() = VkPhysicalDeviceLimits.nsampledImageColorSampleCounts(adr) +inline val VkPhysicalDeviceLimits.sampledImageIntegerSampleCounts: VkSampleCountFlags + get() = VkPhysicalDeviceLimits.nsampledImageIntegerSampleCounts(adr) +inline val VkPhysicalDeviceLimits.sampledImageDepthSampleCounts: VkSampleCountFlags + get() = VkPhysicalDeviceLimits.nsampledImageDepthSampleCounts(adr) +inline val VkPhysicalDeviceLimits.sampledImageStencilSampleCounts: VkSampleCountFlags + get() = VkPhysicalDeviceLimits.nsampledImageStencilSampleCounts(adr) +inline val VkPhysicalDeviceLimits.storageImageSampleCounts: VkSampleCountFlags + get() = VkPhysicalDeviceLimits.nstorageImageSampleCounts(adr) +inline val VkPhysicalDeviceLimits.maxSampleMaskWords: Int + get() = VkPhysicalDeviceLimits.nmaxSampleMaskWords(adr) +inline val VkPhysicalDeviceLimits.timestampComputeAndGraphics: Boolean + get() = VkPhysicalDeviceLimits.ntimestampComputeAndGraphics(adr).bool +inline val VkPhysicalDeviceLimits.timestampPeriod: Float + get() = VkPhysicalDeviceLimits.ntimestampPeriod(adr) +inline val VkPhysicalDeviceLimits.maxClipDistances: Int + get() = VkPhysicalDeviceLimits.nmaxClipDistances(adr) +inline val VkPhysicalDeviceLimits.maxCullDistances: Int + get() = VkPhysicalDeviceLimits.nmaxCullDistances(adr) +inline val VkPhysicalDeviceLimits.maxCombinedClipAndCullDistances: Int + get() = VkPhysicalDeviceLimits.nmaxCombinedClipAndCullDistances(adr) +inline val VkPhysicalDeviceLimits.discreteQueuePriorities: Int + get() = VkPhysicalDeviceLimits.ndiscreteQueuePriorities(adr) +inline val VkPhysicalDeviceLimits.pointSizeRange: Vec2 + get() = Vec2 { VkPhysicalDeviceLimits.npointSizeRange(adr, it) } +inline val VkPhysicalDeviceLimits.lineWidthRange: Vec2 + get() = Vec2 { VkPhysicalDeviceLimits.nlineWidthRange(adr, it) } +inline val VkPhysicalDeviceLimits.pointSizeGranularity: Float + get() = VkPhysicalDeviceLimits.npointSizeGranularity(adr) +inline val VkPhysicalDeviceLimits.lineWidthGranularity: Float + get() = VkPhysicalDeviceLimits.nlineWidthGranularity(adr) +inline val VkPhysicalDeviceLimits.strictLines: Boolean + get() = VkPhysicalDeviceLimits.nstrictLines(adr).bool +inline val VkPhysicalDeviceLimits.standardSampleLocations: Boolean + get() = VkPhysicalDeviceLimits.nstandardSampleLocations(adr).bool +inline val VkPhysicalDeviceLimits.optimalBufferCopyOffsetAlignment: VkDeviceSize + get() = VkDeviceSize(VkPhysicalDeviceLimits.noptimalBufferCopyOffsetAlignment(adr)) +inline val VkPhysicalDeviceLimits.optimalBufferCopyRowPitchAlignment: VkDeviceSize + get() = VkDeviceSize(VkPhysicalDeviceLimits.noptimalBufferCopyRowPitchAlignment(adr)) +inline val VkPhysicalDeviceLimits.nonCoherentAtomSize: VkDeviceSize + get() = VkDeviceSize(VkPhysicalDeviceLimits.nnonCoherentAtomSize(adr)) + +//typedef struct VkPhysicalDeviceSparseProperties { +// VkBool32 residencyStandard2DBlockShape; +// VkBool32 residencyStandard2DMultisampleBlockShape; +// VkBool32 residencyStandard3DBlockShape; +// VkBool32 residencyAlignedMipSize; +// VkBool32 residencyNonResidentStrict; +//} VkPhysicalDeviceSparseProperties; + + +inline val VkPhysicalDeviceProperties.apiVersion: Int + get() = VkPhysicalDeviceProperties.napiVersion(adr) +inline val VkPhysicalDeviceProperties.driverVersion: Int + get() = VkPhysicalDeviceProperties.ndriverVersion(adr) +inline val VkPhysicalDeviceProperties.vendorID: Int + get() = VkPhysicalDeviceProperties.nvendorID(adr) +inline val VkPhysicalDeviceProperties.deviceID: Int + get() = VkPhysicalDeviceProperties.ndeviceID(adr) +inline val VkPhysicalDeviceProperties.deviceType: VkPhysicalDeviceType + get() = VkPhysicalDeviceType of VkPhysicalDeviceProperties.ndeviceType(adr) +inline val VkPhysicalDeviceProperties.deviceName: String + get() = VkPhysicalDeviceProperties.ndeviceNameString(adr) +inline val VkPhysicalDeviceProperties.pipelineCacheUUID: ByteBuffer + get() = VkPhysicalDeviceProperties.npipelineCacheUUID(adr) +inline val VkPhysicalDeviceProperties.limits: VkPhysicalDeviceLimits + get() = VkPhysicalDeviceProperties.nlimits(adr) +inline val VkPhysicalDeviceProperties.sparseProperties: VkPhysicalDeviceSparseProperties + get() = VkPhysicalDeviceProperties.nsparseProperties(adr) + +/* --------------------------------------------------------------------------------------------------------------------- + * JVM custom */ +inline val VkPhysicalDeviceProperties.apiVersionString: String + get() = _decode(apiVersion) +inline val VkPhysicalDeviceProperties.driverVersionString: String + get() = _decode(driverVersion) + +enum class VkVendor { AMD, Nvidia, Intel, Unknown } + +inline val VkPhysicalDeviceProperties.vendor: VkVendor + get() = when (vendorID) { + 0x1002 -> VkVendor.AMD + 0x10DE -> VkVendor.Nvidia + 0x8086 -> VkVendor.Intel + else -> VkVendor.Unknown + } + +fun _decode(int: Int) = "${int and 0xFFC00000.i shr 22}.${int and 0x003FF000 shr 12}.${int and 0x00000FFF}" +/* JVM custom +* -------------------------------------------------------------------------------------------------------------------*/ + + +//typedef struct VkPhysicalDeviceProperties { +// uint32_t apiVersion; +// uint32_t driverVersion; +// uint32_t vendorID; +// uint32_t deviceID; +// VkPhysicalDeviceType deviceType; +// char deviceName[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE]; +// uint8_t pipelineCacheUUID[VK_UUID_SIZE]; +// VkPhysicalDeviceLimits limits; +// VkPhysicalDeviceSparseProperties sparseProperties; +//} VkPhysicalDeviceProperties; + +inline val VkQueueFamilyProperties.queueFlags: VkQueueFlags + get() = VkQueueFamilyProperties.nqueueFlags(adr) +inline val VkQueueFamilyProperties.queueCount: Int + get() = VkQueueFamilyProperties.nqueueCount(adr) +inline val VkQueueFamilyProperties.timestampValidBits: Int + get() = VkQueueFamilyProperties.ntimestampValidBits(adr) +inline val VkQueueFamilyProperties.minImageTransferGranularity: VkExtent3D + get() = VkQueueFamilyProperties.nminImageTransferGranularity(adr) + + +inline val VkMemoryType.propertyFlags: VkMemoryPropertyFlags get() = VkMemoryType.npropertyFlags(adr) +inline val VkMemoryType.heapIndex: Int get() = VkMemoryType.nheapIndex(adr) + + +//typedef struct VkMemoryHeap { +// VkDeviceSize size; +// VkMemoryHeapFlags flags; +//} VkMemoryHeap; + +inline val VkPhysicalDeviceMemoryProperties.memoryTypeCount get() = VkPhysicalDeviceMemoryProperties.nmemoryTypeCount(adr) +inline val VkPhysicalDeviceMemoryProperties.memoryTypes: VkMemoryType.Buffer get() = VkPhysicalDeviceMemoryProperties.nmemoryTypes(adr) +inline val VkPhysicalDeviceMemoryProperties.memoryHeapCount get() = VkPhysicalDeviceMemoryProperties.nmemoryHeapCount(adr) +inline val VkPhysicalDeviceMemoryProperties.memoryHeaps: VkMemoryHeap.Buffer get() = VkPhysicalDeviceMemoryProperties.nmemoryHeaps(adr) + + +//typedef void (VKAPI_PTR *PFN_vkVoidFunction)(void); + +inline var VkDeviceQueueCreateInfo.type: VkStructureType + get() = VkStructureType of VkDeviceQueueCreateInfo.nsType(adr) + set(value) = VkDeviceQueueCreateInfo.nsType(adr, value.i) +inline var VkDeviceQueueCreateInfo.next + get() = VkDeviceQueueCreateInfo.npNext(adr) + set(value) = VkDeviceQueueCreateInfo.npNext(adr, value) +inline var VkDeviceQueueCreateInfo.flag: VkDeviceQueueCreate + get() = TODO() + set(value) = VkDeviceQueueCreateInfo.nflags(adr, value.i) +inline var VkDeviceQueueCreateInfo.flags: VkDeviceQueueCreateFlags + get() = VkDeviceQueueCreateInfo.nflags(adr) + set(value) = VkDeviceQueueCreateInfo.nflags(adr, value) +inline var VkDeviceQueueCreateInfo.queueFamilyIndex + get() = VkDeviceQueueCreateInfo.nqueueFamilyIndex(adr) + set(value) = VkDeviceQueueCreateInfo.nqueueFamilyIndex(adr, value) +//inline val VkDeviceQueueCreateInfo.queueCount get() = VkDeviceQueueCreateInfo.nqueueCount(address) +inline var VkDeviceQueueCreateInfo.queuePriorities: FloatBuffer + get() = VkDeviceQueueCreateInfo.npQueuePriorities(adr) + set(value) = VkDeviceQueueCreateInfo.npQueuePriorities(adr, value) +/** JVM custom */ +inline var VkDeviceQueueCreateInfo.queuePriority: Float + get() = VkDeviceQueueCreateInfo.npQueuePriorities(adr)[0] + set(value) = stak { + val buf = it.nmalloc(1, Float.BYTES) + memPutFloat(buf, value) + memPutAddress(adr + VkDeviceQueueCreateInfo.PQUEUEPRIORITIES, buf) + VkDeviceQueueCreateInfo.nqueueCount(adr, 1) + } + +//typedef struct VkDeviceQueueCreateInfo { +// VkStructureType sType; +// const void* pNext; +// VkDeviceQueueCreateFlags flags; +// uint32_t queueFamilyIndex; +// uint32_t queueCount; +// const float* pQueuePriorities; +//} VkDeviceQueueCreateInfo; + +inline var VkDeviceCreateInfo.type: VkStructureType + get() = VkStructureType of VkDeviceCreateInfo.nsType(adr) + set(value) = VkDeviceCreateInfo.nsType(adr, value.i) +inline var VkDeviceCreateInfo.next + get() = VkDeviceCreateInfo.npNext(adr) + set(value) = VkDeviceCreateInfo.npNext(adr, value) +inline var VkDeviceCreateInfo.flags: VkDeviceCreateFlags + get() = VkDeviceCreateInfo.nflags(adr) + set(value) = VkDeviceCreateInfo.nflags(adr, value) +//inline val VkDeviceCreateInfo.queueCreateInfoCount get() = queueCreateInfoCount() +inline var VkDeviceCreateInfo.queueCreateInfos: VkDeviceQueueCreateInfo.Buffer + get() = VkDeviceCreateInfo.npQueueCreateInfos(adr) + set(value) = VkDeviceCreateInfo.npQueueCreateInfos(adr, value) +/** JVM custom */ +inline var VkDeviceCreateInfo.queueCreateInfo: VkDeviceQueueCreateInfo + get() = VkDeviceCreateInfo.npQueueCreateInfos(adr)[0] + set(value) { + memPutAddress(adr + VkDeviceCreateInfo.PQUEUECREATEINFOS, value.adr) + VkDeviceCreateInfo.nqueueCreateInfoCount(adr, 1) + } +inline var VkDeviceCreateInfo.enabledLayerNames: Collection + get() = VkDeviceCreateInfo.nppEnabledLayerNames(adr).toArrayList() + set(value) = VkDeviceCreateInfo.nppEnabledLayerNames(adr, value.toPointerBuffer()) +inline var VkDeviceCreateInfo.enabledExtensionNames: Collection + get() = VkDeviceCreateInfo.nppEnabledExtensionNames(adr).toArrayList() + set(value) = VkDeviceCreateInfo.nppEnabledExtensionNames(adr, value.toPointerBuffer()) +inline var VkDeviceCreateInfo.enabledFeatures: VkPhysicalDeviceFeatures? + get() = VkDeviceCreateInfo.npEnabledFeatures(adr) + set(value) = VkDeviceCreateInfo.npEnabledFeatures(adr, value) + +// +//typedef struct VkExtensionProperties { +// char extensionName[VK_MAX_EXTENSION_NAME_SIZE]; +// uint32_t specVersion; +//} VkExtensionProperties; +// +//typedef struct VkLayerProperties { +// char layerName[VK_MAX_EXTENSION_NAME_SIZE]; +// uint32_t specVersion; +// uint32_t implementationVersion; +// char description[VK_MAX_DESCRIPTION_SIZE]; +//} VkLayerProperties; + +inline var VkSubmitInfo.type: VkStructureType + get() = VkStructureType of VkSubmitInfo.nsType(adr) + set(value) = VkSubmitInfo.nsType(adr, value.i) +inline var VkSubmitInfo.next + get() = VkSubmitInfo.npNext(adr) + set(value) = VkSubmitInfo.npNext(adr, value) +inline var VkSubmitInfo.waitSemaphoreCount + get() = VkSubmitInfo.nwaitSemaphoreCount(adr) + set(value) = VkSubmitInfo.nwaitSemaphoreCount(adr, value) +inline var VkSubmitInfo.waitSemaphores + get() = VkSubmitInfo.npWaitSemaphores(adr) + set(value) = VkSubmitInfo.npWaitSemaphores(adr, value) +/** JVM custom */ +inline var VkSubmitInfo.waitSemaphore: VkSemaphore + get() = VkSemaphore(VkSubmitInfo.npWaitSemaphores(adr)?.get(0) ?: NULL) + set(value) = stak { + val pSemaphore = it.nmalloc(1, Long.BYTES) + memPutLong(pSemaphore, value.L) + memPutAddress(adr + VkSubmitInfo.PWAITSEMAPHORES, pSemaphore) + } +inline var VkSubmitInfo.waitDstStageMask: IntBuffer? + get() = VkSubmitInfo.npWaitDstStageMask(adr) + set(value) = VkSubmitInfo.npWaitDstStageMask(adr, value) +//inline val VkSubmitInfo.commandBufferCount get() = VkSubmitInfo.ncommandBufferCount(address) +inline var VkSubmitInfo.commandBuffers: PointerBuffer? + get() = VkSubmitInfo.npCommandBuffers(adr) + set(value) = VkSubmitInfo.npCommandBuffers(adr, value) +/** JVM custom */ +inline var VkSubmitInfo.commandBuffer: VkCommandBuffer? + get() = null + set(value) = stak { + val pCmdBuff = it.nmalloc(Pointer.POINTER_SIZE, Pointer.POINTER_SIZE) + memPutAddress(pCmdBuff, value?.adr ?: NULL) + memPutAddress(adr + VkSubmitInfo.PCOMMANDBUFFERS, pCmdBuff) + VkSubmitInfo.ncommandBufferCount(adr, if (value == null) 0 else 1) + } +//inline val VkSubmitInfo.signalSemaphoreCount get() = VkSubmitInfo.nsignalSemaphoreCount(address) +inline var VkSubmitInfo.signalSemaphores: LongBuffer? + get() = VkSubmitInfo.npSignalSemaphores(adr) + set(value) = VkSubmitInfo.npSignalSemaphores(adr, value) +/** JVM custom */ +var VkSubmitInfo.signalSemaphore: VkSemaphore // TODO BUG, inline + get() = VkSemaphore(VkSubmitInfo.npSignalSemaphores(adr)?.get(0) ?: NULL) + set(value) = stak { + val pSemaphore = it.nmalloc(1, Long.BYTES) + memPutLong(pSemaphore, value.L) + memPutAddress(adr + VkSubmitInfo.PSIGNALSEMAPHORES, pSemaphore) + VkSubmitInfo.nsignalSemaphoreCount(adr, if (value.L == NULL) 0 else 1) + } + +//typedef struct VkSubmitInfo { +// VkStructureType sType; +// const void* pNext; +// uint32_t waitSemaphoreCount; +// const VkSemaphore* pWaitSemaphores; +// const VkPipelineStageFlags* pWaitDstStageMask; +// uint32_t commandBufferCount; +// const VkCommandBuffer* pCommandBuffers; +// uint32_t signalSemaphoreCount; +// const VkSemaphore* pSignalSemaphores; +//} VkSubmitInfo; + + +inline var VkMemoryAllocateInfo.type: VkStructureType + get() = VkStructureType of VkMemoryAllocateInfo.nsType(adr) + set(value) = VkMemoryAllocateInfo.nsType(adr, value.i) +inline var VkMemoryAllocateInfo.next + get() = VkMemoryAllocateInfo.npNext(adr) + set(value) = VkMemoryAllocateInfo.npNext(adr, value) +inline var VkMemoryAllocateInfo.allocationSize: VkDeviceSize + get() = VkDeviceSize(VkMemoryAllocateInfo.nallocationSize(adr)) + set(value) = VkMemoryAllocateInfo.nallocationSize(adr, value.L) +inline var VkMemoryAllocateInfo.memoryTypeIndex + get() = VkMemoryAllocateInfo.nmemoryTypeIndex(adr) + set(value) = VkMemoryAllocateInfo.nmemoryTypeIndex(adr, value) + + +inline var VkMappedMemoryRange.type: VkStructureType + get() = VkStructureType of VkMappedMemoryRange.nsType(adr) + set(value) = VkMappedMemoryRange.nsType(adr, value.i) +inline var VkMappedMemoryRange.next + get() = VkMappedMemoryRange.npNext(adr) + set(value) = VkMappedMemoryRange.npNext(adr, value) +inline var VkMappedMemoryRange.memory: VkDeviceMemory + get() = VkDeviceMemory(VkMappedMemoryRange.nmemory(adr)) + set(value) = VkMappedMemoryRange.nmemory(adr, value.L) +inline var VkMappedMemoryRange.offset: VkDeviceSize + get() = VkDeviceSize(VkMappedMemoryRange.noffset(adr)) + set(value) = VkMappedMemoryRange.noffset(adr, value.L) +inline var VkMappedMemoryRange.size: VkDeviceSize + get() = VkDeviceSize(VkMappedMemoryRange.nsize(adr)) + set(value) = VkMappedMemoryRange.nsize(adr, value.L) + + +inline val VkMemoryRequirements.size: VkDeviceSize + get() = VkDeviceSize(VkMemoryRequirements.nsize(adr)) +inline val VkMemoryRequirements.alignment: VkDeviceSize + get() = VkDeviceSize(VkMemoryRequirements.nalignment(adr)) +inline val VkMemoryRequirements.memoryTypeBits: Int + get() = VkMemoryRequirements.nmemoryTypeBits(adr) + + +//typedef struct VkSparseImageFormatProperties { +// VkImageAspectFlags aspectMask; +// VkExtent3D imageGranularity; +// VkSparseImageFormatFlags flags; +//} VkSparseImageFormatProperties; +// +//typedef struct VkSparseImageMemoryRequirements { +// VkSparseImageFormatProperties formatProperties; +// uint32_t imageMipTailFirstLod; +// VkDeviceSize imageMipTailSize; +// VkDeviceSize imageMipTailOffset; +// VkDeviceSize imageMipTailStride; +//} VkSparseImageMemoryRequirements; +// +//typedef struct VkSparseMemoryBind { +// VkDeviceSize resourceOffset; +// VkDeviceSize size; +// VkDeviceMemory memory; +// VkDeviceSize memoryOffset; +// VkSparseMemoryBindFlags flags; +//} VkSparseMemoryBind; +// +//typedef struct VkSparseBufferMemoryBindInfo { +// VkBuffer buffer; +// uint32_t bindCount; +// const VkSparseMemoryBind* pBinds; +//} VkSparseBufferMemoryBindInfo; +// +//typedef struct VkSparseImageOpaqueMemoryBindInfo { +// VkImage image; +// uint32_t bindCount; +// const VkSparseMemoryBind* pBinds; +//} VkSparseImageOpaqueMemoryBindInfo; + +inline var VkImageSubresource.aspectMask: VkImageAspectFlags + get() = VkImageSubresource.naspectMask(adr) + set(value) = VkImageSubresource.naspectMask(adr, value.i) +inline var VkImageSubresource.mipLevel: Int + get() = VkImageSubresource.nmipLevel(adr) + set(value) = VkImageSubresource.nmipLevel(adr, value) +inline var VkImageSubresource.arrayLayer: Int + get() = VkImageSubresource.narrayLayer(adr) + set(value) = VkImageSubresource.narrayLayer(adr, value) + +//typedef struct VkOffset3D { +// int32_t x; +// int32_t y; +// int32_t z; +//} VkOffset3D; +// +//typedef struct VkSparseImageMemoryBind { +// VkImageSubresource subresource; +// VkOffset3D offset; +// VkExtent3D extent; +// VkDeviceMemory memory; +// VkDeviceSize memoryOffset; +// VkSparseMemoryBindFlags flags; +//} VkSparseImageMemoryBind; +// +//typedef struct VkSparseImageMemoryBindInfo { +// VkImage image; +// uint32_t bindCount; +// const VkSparseImageMemoryBind* pBinds; +//} VkSparseImageMemoryBindInfo; +// +//typedef struct VkBindSparseInfo { +// VkStructureType sType; +// const void* pNext; +// uint32_t waitSemaphoreCount; +// const VkSemaphore* pWaitSemaphores; +// uint32_t bufferBindCount; +// const VkSparseBufferMemoryBindInfo* pBufferBinds; +// uint32_t imageOpaqueBindCount; +// const VkSparseImageOpaqueMemoryBindInfo* pImageOpaqueBinds; +// uint32_t imageBindCount; +// const VkSparseImageMemoryBindInfo* pImageBinds; +// uint32_t signalSemaphoreCount; +// const VkSemaphore* pSignalSemaphores; +//} VkBindSparseInfo; + +inline var VkFenceCreateInfo.type: VkStructureType + get() = VkStructureType of VkFenceCreateInfo.nsType(adr) + set(value) = VkFenceCreateInfo.nsType(adr, value.i) +inline var VkFenceCreateInfo.next + get() = VkFenceCreateInfo.npNext(adr) + set(value) = VkFenceCreateInfo.npNext(adr, value) +inline var VkFenceCreateInfo.flags: VkFenceCreateFlags + get() = VkFenceCreateInfo.nflags(adr) + set(value) = VkFenceCreateInfo.nflags(adr, value) + + +inline var VkSemaphoreCreateInfo.type: VkStructureType + get() = VkStructureType of VkSemaphoreCreateInfo.nsType(adr) + set(value) = VkSemaphoreCreateInfo.nsType(adr, value.i) +inline var VkSemaphoreCreateInfo.next + get() = VkSemaphoreCreateInfo.npNext(adr) + set(value) = VkSemaphoreCreateInfo.npNext(adr, value) +inline var VkSemaphoreCreateInfo.flags: VkSemaphoreCreateFlags + get() = VkSemaphoreCreateInfo.nflags(adr) + set(value) = VkSemaphoreCreateInfo.nflags(adr, value) + + +//typedef struct VkSemaphoreCreateInfo { +// VkStructureType sType; +// const void* pNext; +// VkSemaphoreCreateFlags flags; +//} VkSemaphoreCreateInfo; +// +//typedef struct VkEventCreateInfo { +// VkStructureType sType; +// const void* pNext; +// VkEventCreateFlags flags; +//} VkEventCreateInfo; + + +inline var VkQueryPoolCreateInfo.type: VkStructureType + get() = VkStructureType of VkQueryPoolCreateInfo.nsType(adr) + set(value) = VkQueryPoolCreateInfo.nsType(adr, value.i) +inline var VkQueryPoolCreateInfo.next + get() = VkQueryPoolCreateInfo.npNext(adr) + set(value) = VkQueryPoolCreateInfo.npNext(adr, value) +inline var VkQueryPoolCreateInfo.flags: VkQueryPoolCreateFlags + get() = VkQueryPoolCreateInfo.nflags(adr) + set(value) = VkQueryPoolCreateInfo.nflags(adr, value) +inline var VkQueryPoolCreateInfo.queryType: VkQueryType + get() = VkQueryType of VkQueryPoolCreateInfo.nqueryType(adr) + set(value) = VkQueryPoolCreateInfo.nqueryType(adr, value.i) +inline var VkQueryPoolCreateInfo.queryCount: Int + get() = VkQueryPoolCreateInfo.nqueryCount(adr) + set(value) = VkQueryPoolCreateInfo.nqueryCount(adr, value) +inline var VkQueryPoolCreateInfo.pipelineStatistics: VkQueryPipelineStatisticFlags + get() = VkQueryPoolCreateInfo.npipelineStatistics(adr) + set(value) = VkQueryPoolCreateInfo.npipelineStatistics(adr, value) + + +inline var VkBufferCreateInfo.type: VkStructureType + get() = VkStructureType of VkBufferCreateInfo.nsType(adr) + set(value) = VkBufferCreateInfo.nsType(adr, value.i) +inline var VkBufferCreateInfo.next + get() = VkBufferCreateInfo.npNext(adr) + set(value) = VkBufferCreateInfo.npNext(adr, value) +/** JVM custom */ +inline var VkBufferCreateInfo.flag: VkBufferCreate + get() = TODO() + set(value) = VkBufferCreateInfo.nflags(adr, value.i) +inline var VkBufferCreateInfo.flags: VkBufferCreateFlags + get() = VkBufferCreateInfo.nflags(adr) + set(value) = VkBufferCreateInfo.nflags(adr, value) +inline var VkBufferCreateInfo.size: VkDeviceSize + get() = VkDeviceSize(VkBufferCreateInfo.nsize(adr)) + set(value) = VkBufferCreateInfo.nsize(adr, value.L) +inline var VkBufferCreateInfo.usage: VkBufferUsageFlags + get() = VkBufferCreateInfo.nusage(adr) + set(value) = VkBufferCreateInfo.nusage(adr, value) +inline var VkBufferCreateInfo.sharingMode: VkSharingMode + get() = VkSharingMode of VkBufferCreateInfo.nsharingMode(adr) + set(value) = VkBufferCreateInfo.nsharingMode(adr, value.i) +inline var VkBufferCreateInfo.queueFamilyIndexCount + get() = VkBufferCreateInfo.nqueueFamilyIndexCount(adr) + set(value) = VkBufferCreateInfo.nqueueFamilyIndexCount(adr, value) +inline var VkBufferCreateInfo.queueFamilyIndices + get() = VkBufferCreateInfo.npQueueFamilyIndices(adr) + set(value) = VkBufferCreateInfo.npQueueFamilyIndices(adr, value) + + +//typedef struct VkBufferViewCreateInfo { +// VkStructureType sType; +// const void* pNext; +// VkBufferViewCreateFlags flags; +// VkBuffer buffer; +// VkFormat format; +// VkDeviceSize offset; +// VkDeviceSize range; +//} VkBufferViewCreateInfo; + + +inline var VkImageViewCreateInfo.type: VkStructureType + get() = VkStructureType of VkImageViewCreateInfo.nsType(adr) + set(value) = VkImageViewCreateInfo.nsType(adr, value.i) +inline var VkImageViewCreateInfo.next + get() = VkImageViewCreateInfo.npNext(adr) + set(value) = VkImageViewCreateInfo.npNext(adr, value) +inline var VkImageViewCreateInfo.flags: VkImageViewCreateFlags + get() = VkImageViewCreateInfo.nflags(adr) + set(value) = VkImageViewCreateInfo.nflags(adr, value) +inline var VkImageViewCreateInfo.image: VkImage + get() = VkImage(VkImageViewCreateInfo.nimage(adr)) + set(value) = VkImageViewCreateInfo.nimage(adr, value.L) +inline var VkImageViewCreateInfo.viewType: VkImageViewType + get() = VkImageViewType of VkImageViewCreateInfo.nviewType(adr) + set(value) = VkImageViewCreateInfo.nviewType(adr, value.i) +inline var VkImageViewCreateInfo.format: VkFormat + get() = VkFormat of VkImageViewCreateInfo.nformat(adr) + set(value) = VkImageViewCreateInfo.nformat(adr, value.i) +inline var VkImageViewCreateInfo.components: VkComponentMapping + get() = VkImageViewCreateInfo.ncomponents(adr) + set(value) = VkImageViewCreateInfo.ncomponents(adr, value) + +/** JVM custom */ +fun VkImageViewCreateInfo.components(r: VkComponentSwizzle, g: VkComponentSwizzle, b: VkComponentSwizzle, a: VkComponentSwizzle) { + components.r = r + components.g = g + components.b = b + components.a = a +} + +inline var VkImageViewCreateInfo.subresourceRange: VkImageSubresourceRange + get() = VkImageViewCreateInfo.nsubresourceRange(adr) + set(value) = VkImageViewCreateInfo.nsubresourceRange(adr, value) + + +inline var VkImageCreateInfo.type: VkStructureType + get() = VkStructureType of VkImageCreateInfo.nsType(adr) + set(value) = VkImageCreateInfo.nsType(adr, value.i) +inline var VkImageCreateInfo.next + get() = VkImageCreateInfo.npNext(adr) + set(value) = VkImageCreateInfo.npNext(adr, value) +/** JVM custom */ +inline var VkImageCreateInfo.flag: VkImageCreate + get() = TODO() + set(value) = VkImageCreateInfo.nflags(adr, value.i) +inline var VkImageCreateInfo.flags: VkImageCreateFlags + get() = VkImageCreateInfo.nflags(adr) + set(value) = VkImageCreateInfo.nflags(adr, value) +inline var VkImageCreateInfo.imageType: VkImageType + get() = VkImageType of VkImageCreateInfo.nimageType(adr) + set(value) = VkImageCreateInfo.nimageType(adr, value.i) +inline var VkImageCreateInfo.format: VkFormat + get() = VkFormat of VkImageCreateInfo.nformat(adr) + set(value) = VkImageCreateInfo.nformat(adr, value.i) +inline var VkImageCreateInfo.extent: VkExtent3D + get() = VkImageCreateInfo.nextent(adr) + set(value) = VkImageCreateInfo.nextent(adr, value) + +/** JVM custom */ +fun VkImageCreateInfo.extent(extent: Vec3i) { + this.extent.set(extent.x, extent.y, extent.z) +} + +/** JVM custom */ +fun VkImageCreateInfo.extent(extent: Vec2i, depth: Int) { + this.extent.set(extent.x, extent.y, depth) +} + +inline var VkImageCreateInfo.mipLevels + get() = VkImageCreateInfo.nmipLevels(adr) + set(value) = VkImageCreateInfo.nmipLevels(adr, value) +inline var VkImageCreateInfo.arrayLayers + get() = VkImageCreateInfo.narrayLayers(adr) + set(value) = VkImageCreateInfo.narrayLayers(adr, value) +inline var VkImageCreateInfo.samples: VkSampleCount + get() = VkSampleCount of VkImageCreateInfo.nsamples(adr) + set(value) = VkImageCreateInfo.nsamples(adr, value.i) +inline var VkImageCreateInfo.tiling: VkImageTiling + get() = VkImageTiling of VkImageCreateInfo.ntiling(adr) + set(value) = VkImageCreateInfo.ntiling(adr, value.i) +inline var VkImageCreateInfo.usage: VkImageUsageFlags + get() = VkImageCreateInfo.nusage(adr) + set(value) = VkImageCreateInfo.nusage(adr, value) +inline var VkImageCreateInfo.sharingMode: VkSharingMode + get() = VkSharingMode of VkImageCreateInfo.nsharingMode(adr) + set(value) = VkImageCreateInfo.nsharingMode(adr, value.i) +//inline val VkImageCreateInfo.queueFamilyIndexCount get() = queueFamilyIndexCount() +inline var VkImageCreateInfo.queueFamilyIndices + get() = VkImageCreateInfo.npQueueFamilyIndices(adr) + set(value) = VkImageCreateInfo.npQueueFamilyIndices(adr, value) +inline var VkImageCreateInfo.initialLayout: VkImageLayout + get() = VkImageLayout of VkImageCreateInfo.ninitialLayout(adr) + set(value) = VkImageCreateInfo.ninitialLayout(adr, value.i) + +//typedef struct VkSubresourceLayout { +// VkDeviceSize offset; +// VkDeviceSize size; +// VkDeviceSize rowPitch; +// VkDeviceSize arrayPitch; +// VkDeviceSize depthPitch; +//} VkSubresourceLayout; + +operator fun VkComponentMapping.invoke(r: VkComponentSwizzle, g: VkComponentSwizzle, b: VkComponentSwizzle, a: VkComponentSwizzle) { + this.r = r + this.g = g + this.b = b + this.a = a +} + +inline var VkComponentMapping.r: VkComponentSwizzle + get() = VkComponentSwizzle of VkComponentMapping.nr(adr) + set(value) = VkComponentMapping.nr(adr, value.i) +inline var VkComponentMapping.g: VkComponentSwizzle + get() = VkComponentSwizzle of VkComponentMapping.ng(adr) + set(value) = VkComponentMapping.ng(adr, value.i) +inline var VkComponentMapping.b: VkComponentSwizzle + get() = VkComponentSwizzle of VkComponentMapping.nb(adr) + set(value) = VkComponentMapping.nb(adr, value.i) +inline var VkComponentMapping.a: VkComponentSwizzle + get() = VkComponentSwizzle of VkComponentMapping.na(adr) + set(value) = VkComponentMapping.na(adr, value.i) + + +inline var VkImageSubresourceRange.aspectMask: VkImageAspectFlags + get() = VkImageSubresourceRange.naspectMask(adr) + set(value) = VkImageSubresourceRange.naspectMask(adr, value) +inline var VkImageSubresourceRange.baseMipLevel: Int + get() = VkImageSubresourceRange.nbaseMipLevel(adr) + set(value) = VkImageSubresourceRange.nbaseMipLevel(adr, value) +inline var VkImageSubresourceRange.levelCount: Int + get() = VkImageSubresourceRange.nlevelCount(adr) + set(value) = VkImageSubresourceRange.nlevelCount(adr, value) +inline var VkImageSubresourceRange.baseArrayLayer: Int + get() = VkImageSubresourceRange.nbaseArrayLayer(adr) + set(value) = VkImageSubresourceRange.nbaseArrayLayer(adr, value) +inline var VkImageSubresourceRange.layerCount: Int + get() = VkImageSubresourceRange.nlayerCount(adr) + set(value) = VkImageSubresourceRange.nlayerCount(adr, value) + +//typedef struct VkImageViewCreateInfo { +// VkStructureType sType; +// const void* pNext; +// VkImageViewCreateFlags flags; +// VkImage image; +// VkImageViewType viewType; +// VkFormat format; +// VkComponentMapping components; +// VkImageSubresourceRange subresourceRange; +//} VkImageViewCreateInfo; + +inline var VkShaderModuleCreateInfo.type: VkStructureType + get() = VkStructureType of VkShaderModuleCreateInfo.nsType(adr) + set(value) = VkShaderModuleCreateInfo.nsType(adr, value.i) +inline var VkShaderModuleCreateInfo.next + get() = VkShaderModuleCreateInfo.npNext(adr) + set(value) = VkShaderModuleCreateInfo.npNext(adr, value) +inline var VkShaderModuleCreateInfo.flags: VkShaderModuleCreateFlags + get() = VkShaderModuleCreateInfo.nflags(adr) + set(value) = VkShaderModuleCreateInfo.nflags(adr, value) +//inline val VkShaderModuleCreateInfo.codeSize get() = VkShaderModuleCreateInfo.ncodeSize(adr) +inline var VkShaderModuleCreateInfo.code: ByteBuffer + get() = VkShaderModuleCreateInfo.npCode(adr) + set(value) = VkShaderModuleCreateInfo.npCode(adr, value) + + +inline var VkPipelineCacheCreateInfo.type: VkStructureType + get() = VkStructureType of VkPipelineCacheCreateInfo.nsType(adr) + set(value) = VkPipelineCacheCreateInfo.nsType(adr, value.i) +inline var VkPipelineCacheCreateInfo.next + get() = VkPipelineCacheCreateInfo.npNext(adr) + set(value) = VkPipelineCacheCreateInfo.npNext(adr, value) +inline var VkPipelineCacheCreateInfo.flags: VkPipelineCacheCreateFlags + get() = VkPipelineCacheCreateInfo.nflags(adr) + set(value) = VkPipelineCacheCreateInfo.nflags(adr, value) +inline val VkPipelineCacheCreateInfo.initialDataSize get() = initialDataSize() +inline var VkPipelineCacheCreateInfo.initialData + get() = VkPipelineCacheCreateInfo.npInitialData(adr) + set(value) = VkPipelineCacheCreateInfo.npInitialData(adr, value) + + +inline var VkSpecializationMapEntry.constantId: Int + get() = VkSpecializationMapEntry.nconstantID(adr) + set(value) = VkSpecializationMapEntry.nconstantID(adr, value) +inline var VkSpecializationMapEntry.offset: Int + get() = VkSpecializationMapEntry.noffset(adr) + set(value) = VkSpecializationMapEntry.noffset(adr, value) +inline var VkSpecializationMapEntry.size: Long + get() = VkSpecializationMapEntry.nsize(adr) + set(value) = VkSpecializationMapEntry.nsize(adr, value) + + +//inline val VkSpecializationInfo.mapEntryCount: Int get() = VkSpecializationInfo.nmapEntryCount(adr) +inline var VkSpecializationInfo.mapEntries: VkSpecializationMapEntry.Buffer? + get() = VkSpecializationInfo.npMapEntries(adr) + set(value) = VkSpecializationInfo.npMapEntries(adr, value) +/** JVM custom */ +inline var VkSpecializationInfo.mapEntry: VkSpecializationMapEntry? + get() = VkSpecializationInfo.npMapEntries(adr)?.get(0) + set(value) { + memPutAddress(adr + VkSpecializationInfo.PMAPENTRIES, memAddressSafe(value)) + VkSpecializationInfo.nmapEntryCount(adr, if (value == null) 0 else 1) + } +//inline val VkSpecializationInfo.dataSize: Long get() = VkSpecializationInfo.ndataSize(adr) +inline var VkSpecializationInfo.data: ByteBuffer? + get() = VkSpecializationInfo.npData(adr) + set(value) = VkSpecializationInfo.npData(adr, value) + + +//typedef struct VkSpecializationInfo { +// uint32_t mapEntryCount; +// const VkSpecializationMapEntry* pMapEntries; +// size_t dataSize; +// const void* pData; +//} VkSpecializationInfo; + + +inline var VkPipelineShaderStageCreateInfo.type: VkStructureType + get() = VkStructureType of VkPipelineShaderStageCreateInfo.nsType(adr) + set(value) = VkPipelineShaderStageCreateInfo.nsType(adr, value.i) +inline var VkPipelineShaderStageCreateInfo.next + get() = VkPipelineShaderStageCreateInfo.npNext(adr) + set(value) = VkPipelineShaderStageCreateInfo.npNext(adr, value) +inline var VkPipelineShaderStageCreateInfo.flags: VkPipelineShaderStageCreateFlags + get() = VkPipelineShaderStageCreateInfo.nflags(adr) + set(value) = VkPipelineShaderStageCreateInfo.nflags(adr, value) +inline var VkPipelineShaderStageCreateInfo.stage: VkShaderStage + get() = VkShaderStage of VkPipelineShaderStageCreateInfo.nstage(adr) + set(value) = VkPipelineShaderStageCreateInfo.nstage(adr, value.i) +inline var VkPipelineShaderStageCreateInfo.module: VkShaderModule + get() = VkShaderModule(VkPipelineShaderStageCreateInfo.nmodule(adr)) + set(value) = VkPipelineShaderStageCreateInfo.nmodule(adr, value.L) +inline var VkPipelineShaderStageCreateInfo.name: String + get() = VkPipelineShaderStageCreateInfo.npNameString(adr) + set(value) = VkPipelineShaderStageCreateInfo.npName(adr, value.utf8) +inline var VkPipelineShaderStageCreateInfo.specializationInfo + get() = VkPipelineShaderStageCreateInfo.npSpecializationInfo(adr) + set(value) = VkPipelineShaderStageCreateInfo.npSpecializationInfo(adr, value) + + +inline var VkVertexInputBindingDescription.binding + get() = VkVertexInputBindingDescription.nbinding(adr) + set(value) = VkVertexInputBindingDescription.nbinding(adr, value) +inline var VkVertexInputBindingDescription.stride + get() = VkVertexInputBindingDescription.nstride(adr) + set(value) = VkVertexInputBindingDescription.nstride(adr, value) +inline var VkVertexInputBindingDescription.inputRate: VkVertexInputRate + get() = VkVertexInputRate of VkVertexInputBindingDescription.ninputRate(adr) + set(value) = VkVertexInputBindingDescription.ninputRate(adr, value.i) + + +inline var VkVertexInputAttributeDescription.location + get() = VkVertexInputAttributeDescription.nlocation(adr) + set(value) = VkVertexInputAttributeDescription.nlocation(adr, value) +inline var VkVertexInputAttributeDescription.binding + get() = VkVertexInputAttributeDescription.nbinding(adr) + set(value) = VkVertexInputAttributeDescription.nbinding(adr, value) +inline var VkVertexInputAttributeDescription.format: VkFormat + get() = VkFormat of VkVertexInputAttributeDescription.nformat(adr) + set(value) = VkVertexInputAttributeDescription.nformat(adr, value.i) +inline var VkVertexInputAttributeDescription.offset + get() = VkVertexInputAttributeDescription.noffset(adr) + set(value) = VkVertexInputAttributeDescription.noffset(adr, value) + + +inline var VkPipelineVertexInputStateCreateInfo.type: VkStructureType + get() = VkStructureType of VkPipelineVertexInputStateCreateInfo.nsType(adr) + set(value) { + sType(value.i) + } +inline var VkPipelineVertexInputStateCreateInfo.next + get() = VkPipelineVertexInputStateCreateInfo.npNext(adr) + set(value) = VkPipelineVertexInputStateCreateInfo.npNext(adr, value) +inline var VkPipelineVertexInputStateCreateInfo.flags: VkPipelineVertexInputStateCreateFlags + get() = VkPipelineVertexInputStateCreateInfo.nflags(adr) + set(value) = VkPipelineVertexInputStateCreateInfo.nflags(adr, value) +//inline val VkPipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount get() = VkPipelineVertexInputStateCreateInfo.nvertexBindingDescriptionCount(adr) +inline var VkPipelineVertexInputStateCreateInfo.vertexBindingDescriptions: VkVertexInputBindingDescription.Buffer? + get() = VkPipelineVertexInputStateCreateInfo.npVertexBindingDescriptions(adr) + set(value) = VkPipelineVertexInputStateCreateInfo.npVertexBindingDescriptions(adr, value) +/** JVM custom */ +inline var VkPipelineVertexInputStateCreateInfo.vertexBindingDescription: VkVertexInputBindingDescription? + get() = VkVertexInputBindingDescription.createSafe(memGetAddress(adr + VkPipelineVertexInputStateCreateInfo.PVERTEXBINDINGDESCRIPTIONS)) + set(value) { + memPutAddress(adr + VkPipelineVertexInputStateCreateInfo.PVERTEXBINDINGDESCRIPTIONS, memAddressSafe(value)) + VkPipelineVertexInputStateCreateInfo.nvertexBindingDescriptionCount(adr, if (value == null) 0 else 1) + } +//inline val VkPipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount get() = VkPipelineVertexInputStateCreateInfo.nvertexAttributeDescriptionCount(adr) +inline var VkPipelineVertexInputStateCreateInfo.vertexAttributeDescriptions: VkVertexInputAttributeDescription.Buffer? + get() = VkPipelineVertexInputStateCreateInfo.npVertexAttributeDescriptions(adr) + set(value) = VkPipelineVertexInputStateCreateInfo.npVertexAttributeDescriptions(adr, value) + + +inline var VkPipelineInputAssemblyStateCreateInfo.type: VkStructureType + get() = VkStructureType of VkPipelineInputAssemblyStateCreateInfo.nsType(adr) + set(value) = VkPipelineInputAssemblyStateCreateInfo.nsType(adr, value.i) +inline var VkPipelineInputAssemblyStateCreateInfo.next + get() = VkPipelineInputAssemblyStateCreateInfo.npNext(adr) + set(value) = VkPipelineInputAssemblyStateCreateInfo.npNext(adr, value) +inline var VkPipelineInputAssemblyStateCreateInfo.flags: VkPipelineInputAssemblyStateCreateFlags + get() = VkPipelineInputAssemblyStateCreateInfo.nflags(adr) + set(value) = VkPipelineInputAssemblyStateCreateInfo.nflags(adr, value) +inline var VkPipelineInputAssemblyStateCreateInfo.topology: VkPrimitiveTopology + get() = VkPrimitiveTopology of VkPipelineInputAssemblyStateCreateInfo.ntopology(adr) + set(value) = VkPipelineInputAssemblyStateCreateInfo.ntopology(adr, value.i) +inline var VkPipelineInputAssemblyStateCreateInfo.primitiveRestartEnable + get() = VkPipelineInputAssemblyStateCreateInfo.nprimitiveRestartEnable(adr).bool + set(value) = VkPipelineInputAssemblyStateCreateInfo.nprimitiveRestartEnable(adr, value.i) + +//typedef struct VkPipelineInputAssemblyStateCreateInfo { +// VkStructureType sType; +// const void* pNext; +// VkPipelineInputAssemblyStateCreateFlags flags; +// VkPrimitiveTopology topology; +// VkBool32 primitiveRestartEnable; +//} VkPipelineInputAssemblyStateCreateInfo; +// +//typedef struct VkPipelineTessellationStateCreateInfo { +// VkStructureType sType; +// const void* pNext; +// VkPipelineTessellationStateCreateFlags flags; +// uint32_t patchControlPoints; +//} VkPipelineTessellationStateCreateInfo; + + +inline var VkViewport.x: Float + get() = VkViewport.nx(adr) + set(value) = VkViewport.nx(adr, value) +inline var VkViewport.y: Float + get() = VkViewport.ny(adr) + set(value) = VkViewport.ny(adr, value) +inline var VkViewport.width: Float + get() = VkViewport.nwidth(adr) + set(value) = VkViewport.nwidth(adr, value) +inline var VkViewport.height: Float + get() = VkViewport.nheight(adr) + set(value) = VkViewport.nheight(adr, value) +inline var VkViewport.minDepth: Float + get() = VkViewport.nminDepth(adr) + set(value) = VkViewport.nminDepth(adr, value) +inline var VkViewport.maxDepth: Float + get() = VkViewport.nmaxDepth(adr) + set(value) = VkViewport.nmaxDepth(adr, value) + +/** JVM custom */ +fun VkViewport.offset(f: Float) = offset(f, f) + +/** JVM custom */ +fun VkViewport.offset(x: Float, y: Float) { + this.x = x + this.y = y +} + +/** JVM custom */ +fun VkViewport.size(size: Vec2i) { + width = size.x.f + height = size.y.f +} + +/** JVM custom */ +fun VkViewport.depth(minDepth: Float, maxDepth: Float) { + this.minDepth = minDepth + this.maxDepth = maxDepth +} +//inline var VkViewport.pos +// get() = Vec2(x, y) +// set(value) { +// x = value.x +// y = value.y +// } +//inline fun VkViewport.size(size: Vec2t) { TODO BUG +// width = size.x.f +// height = size.y.f +//} + +//inline var VkViewport.size +// get() = Vec2(width, height) +// set(value) { +// width = value.x +// height = value.y +// } +//inline fun VkViewport.depth(min: Float, max: Float) { TODO BUG +// minDepth = min +// maxDepth = max +//} +//inline var VkViewport.depth +// get() = Vec2(minDepth, maxDepth) +// set(value) { +// minDepth = value.x +// maxDepth = value.y +// } + + +inline var VkOffset2D.x + get() = VkOffset2D.nx(adr) + set(value) = VkOffset2D.nx(adr, value) +inline var VkOffset2D.y + get() = VkOffset2D.ny(adr) + set(value) = VkOffset2D.ny(adr, value) +//inline operator fun VkOffset2D.invoke(size: Vec2i) { +// x = size.x +// y = size.y +//} +//inline operator fun VkOffset2D.invoke(x: Int, y: Int) { +// this.x = x +// this.y = y +//} + + +inline var VkExtent2D.width + get() = VkExtent2D.nwidth(adr) + set(value) = VkExtent2D.nwidth(adr, value) +inline var VkExtent2D.height + get() = VkExtent2D.nheight(adr) + set(value) = VkExtent2D.nheight(adr, value) + +//var VkExtent2D.size BUG +// get() = Vec2i(width, height) +// set(value) { +// width = value.x +// height = value.y +// } +fun VkOffset2D.pos(x: Int, y: Int) { + this.x = x + this.y = y +} + +//inline var VkOffset2D.pos BUG +// get() = Vec2i(x, y) +// set(value) { +// x = value.x +// y = value.y +// } +inline var VkExtent3D.width + get() = width() + set(value) { + width(value) + } +inline var VkExtent3D.height + get() = height() + set(value) { + height(value) + } +inline var VkExtent3D.depth + get() = depth() + set(value) { + depth(value) + } + +fun VkExtent3D.size(x: Int, y: Int, z: Int) { + width = x + height = y + depth = z +} +//inline var VkExtent3D.size +// get() = Vec3i(width, height, depth) +// set(value) { +// width = value.x +// height = value.y +// depth = value.z +// } TODO BUG + + +inline var VkRect2D.offset: VkOffset2D + get() = VkRect2D.noffset(adr) + set(value) = VkRect2D.noffset(adr, value) +inline var VkRect2D.extent: VkExtent2D + get() = VkRect2D.nextent(adr) + set(value) = VkRect2D.nextent(adr, value) + +/** JVM custom */ +fun VkRect2D.offset(offset: Int) = offset(offset, offset) + +/** JVM custom */ +fun VkRect2D.offset(x: Int, y: Int) { + offset.x = x + offset.y = y +} + +/** JVM custom */ +fun VkRect2D.extent(size: Vec2i) = extent(size.x, size.y) + +/** JVM custom */ +fun VkRect2D.extent(width: Int, height: Int) { + extent.width = width + extent.height = height +} + +/** JVM custom */ +fun VkRect2D.extent(width: Number, height: Number) = extent(width.i, height.i) + +/** JVM custom */ +fun VkRect2D.offset(width: Number, height: Number) = offset(width.i, height.i) + + +inline var VkPipelineViewportStateCreateInfo.type: VkStructureType + get() = VkStructureType of VkPipelineViewportStateCreateInfo.nsType(adr) + set(value) = VkPipelineViewportStateCreateInfo.nsType(adr, value.i) +inline var VkPipelineViewportStateCreateInfo.next + get() = VkPipelineViewportStateCreateInfo.npNext(adr) + set(value) = VkPipelineViewportStateCreateInfo.npNext(adr, value) +inline var VkPipelineViewportStateCreateInfo.flags: VkPipelineViewportStateCreateFlags + get() = VkPipelineViewportStateCreateInfo.nflags(adr) + set(value) = VkPipelineViewportStateCreateInfo.nflags(adr, value) +inline var VkPipelineViewportStateCreateInfo.viewportCount + get() = VkPipelineViewportStateCreateInfo.nviewportCount(adr) + set(value) = VkPipelineViewportStateCreateInfo.nviewportCount(adr, value) +inline var VkPipelineViewportStateCreateInfo.viewports + get() = VkPipelineViewportStateCreateInfo.npViewports(adr) + set(value) = VkPipelineViewportStateCreateInfo.npViewports(adr, value) +inline var VkPipelineViewportStateCreateInfo.scissorCount + get() = VkPipelineViewportStateCreateInfo.nscissorCount(adr) + set(value) = VkPipelineViewportStateCreateInfo.nscissorCount(adr, value) +inline var VkPipelineViewportStateCreateInfo.scissors + get() = VkPipelineViewportStateCreateInfo.npScissors(adr) + set(value) = VkPipelineViewportStateCreateInfo.npScissors(adr, value) + + +inline var VkPipelineRasterizationStateCreateInfo.type: VkStructureType + get() = VkStructureType of VkPipelineRasterizationStateCreateInfo.nsType(adr) + set(value) = VkPipelineRasterizationStateCreateInfo.nsType(adr, value.i) +inline var VkPipelineRasterizationStateCreateInfo.next + get() = VkPipelineRasterizationStateCreateInfo.npNext(adr) + set(value) = VkPipelineRasterizationStateCreateInfo.npNext(adr, value) +inline var VkPipelineRasterizationStateCreateInfo.flags: VkPipelineRasterizationStateCreateFlags + get() = VkPipelineRasterizationStateCreateInfo.nflags(adr) + set(value) = VkPipelineRasterizationStateCreateInfo.nflags(adr, value) +inline var VkPipelineRasterizationStateCreateInfo.depthClampEnable + get() = VkPipelineRasterizationStateCreateInfo.ndepthClampEnable(adr).bool + set(value) = VkPipelineRasterizationStateCreateInfo.ndepthClampEnable(adr, value.i) +inline var VkPipelineRasterizationStateCreateInfo.rasterizerDiscardEnable + get() = VkPipelineRasterizationStateCreateInfo.nrasterizerDiscardEnable(adr).bool + set(value) = VkPipelineRasterizationStateCreateInfo.nrasterizerDiscardEnable(adr, value.i) +inline var VkPipelineRasterizationStateCreateInfo.polygonMode: VkPolygonMode + get() = VkPolygonMode of VkPipelineRasterizationStateCreateInfo.npolygonMode(adr) + set(value) = VkPipelineRasterizationStateCreateInfo.npolygonMode(adr, value.i) +inline var VkPipelineRasterizationStateCreateInfo.cullMode: VkCullModeFlags + get() = VkPipelineRasterizationStateCreateInfo.ncullMode(adr) + set(value) = VkPipelineRasterizationStateCreateInfo.ncullMode(adr, value) +inline var VkPipelineRasterizationStateCreateInfo.frontFace: VkFrontFace + get() = VkFrontFace of VkPipelineRasterizationStateCreateInfo.nfrontFace(adr) + set(value) = VkPipelineRasterizationStateCreateInfo.nfrontFace(adr, value.i) +inline var VkPipelineRasterizationStateCreateInfo.depthBiasEnable + get() = VkPipelineRasterizationStateCreateInfo.ndepthBiasEnable(adr).bool + set(value) = VkPipelineRasterizationStateCreateInfo.ndepthBiasEnable(adr, value.i) +inline var VkPipelineRasterizationStateCreateInfo.depthBiasConstantFactor + get() = VkPipelineRasterizationStateCreateInfo.ndepthBiasConstantFactor(adr) + set(value) = VkPipelineRasterizationStateCreateInfo.ndepthBiasConstantFactor(adr, value) +inline var VkPipelineRasterizationStateCreateInfo.depthBiasClamp + get() = VkPipelineRasterizationStateCreateInfo.ndepthBiasClamp(adr) + set(value) = VkPipelineRasterizationStateCreateInfo.ndepthBiasClamp(adr, value) +inline var VkPipelineRasterizationStateCreateInfo.depthBiasSlopeFactor + get() = VkPipelineRasterizationStateCreateInfo.ndepthBiasSlopeFactor(adr) + set(value) = VkPipelineRasterizationStateCreateInfo.ndepthBiasSlopeFactor(adr, value) +inline var VkPipelineRasterizationStateCreateInfo.lineWidth + get() = VkPipelineRasterizationStateCreateInfo.nlineWidth(adr) + set(value) = VkPipelineRasterizationStateCreateInfo.nlineWidth(adr, value) + + +inline var VkPipelineMultisampleStateCreateInfo.type: VkStructureType + get() = VkStructureType of VkPipelineMultisampleStateCreateInfo.nsType(adr) + set(value) = VkPipelineMultisampleStateCreateInfo.nsType(adr, value.i) +inline var VkPipelineMultisampleStateCreateInfo.next + get() = VkPipelineMultisampleStateCreateInfo.npNext(adr) + set(value) = VkPipelineMultisampleStateCreateInfo.npNext(adr, value) +inline var VkPipelineMultisampleStateCreateInfo.flags: VkPipelineMultisampleStateCreateFlags + get() = VkPipelineMultisampleStateCreateInfo.nflags(adr) + set(value) = VkPipelineMultisampleStateCreateInfo.nflags(adr, value) +inline var VkPipelineMultisampleStateCreateInfo.rasterizationSamples: VkSampleCount + get() = VkSampleCount of VkPipelineMultisampleStateCreateInfo.nrasterizationSamples(adr) + set(value) = VkPipelineMultisampleStateCreateInfo.nrasterizationSamples(adr, value.i) +inline var VkPipelineMultisampleStateCreateInfo.sampleShadingEnable + get() = VkPipelineMultisampleStateCreateInfo.nsampleShadingEnable(adr).bool + set(value) = VkPipelineMultisampleStateCreateInfo.nsampleShadingEnable(adr, value.i) +inline var VkPipelineMultisampleStateCreateInfo.minSampleShading + get() = VkPipelineMultisampleStateCreateInfo.nminSampleShading(adr) + set(value) = VkPipelineMultisampleStateCreateInfo.nminSampleShading(adr, value) +/** https://stackoverflow.com/a/38863042/1047713 */ +inline var VkPipelineMultisampleStateCreateInfo.sampleMask: Int? + get() = memGetInt(memGetAddress(adr + VkPipelineMultisampleStateCreateInfo.PSAMPLEMASK)) + set(value) = stak { + val pInt = when { + value != null -> it.nmalloc(1, Int.BYTES).also { memPutInt(it, value) } + else -> NULL + } + memPutAddress(adr + VkPipelineMultisampleStateCreateInfo.PSAMPLEMASK, pInt) + } +inline var VkPipelineMultisampleStateCreateInfo.alphaToCoverageEnable + get() = VkPipelineMultisampleStateCreateInfo.nalphaToCoverageEnable(adr).bool + set(value) = VkPipelineMultisampleStateCreateInfo.nalphaToCoverageEnable(adr, value.i) +inline var VkPipelineMultisampleStateCreateInfo.alphaToOneEnable + get() = VkPipelineMultisampleStateCreateInfo.nalphaToOneEnable(adr).bool + set(value) = VkPipelineMultisampleStateCreateInfo.nalphaToOneEnable(adr, value.i) + + +inline var VkStencilOpState.failOp: VkStencilOp + get() = VkStencilOp of VkStencilOpState.nfailOp(adr) + set(value) = VkStencilOpState.nfailOp(adr, value.i) +inline var VkStencilOpState.passOp: VkStencilOp + get() = VkStencilOp of VkStencilOpState.npassOp(adr) + set(value) = VkStencilOpState.npassOp(adr, value.i) +inline var VkStencilOpState.depthFailOp: VkStencilOp + get() = VkStencilOp of VkStencilOpState.ndepthFailOp(adr) + set(value) = VkStencilOpState.ndepthFailOp(adr, value.i) +inline var VkStencilOpState.compareOp: VkCompareOp + get() = VkCompareOp of VkStencilOpState.ncompareOp(adr) + set(value) = VkStencilOpState.ncompareOp(adr, value.i) +inline var VkStencilOpState.compareMask + get() = VkStencilOpState.ncompareMask(adr) + set(value) = VkStencilOpState.ncompareMask(adr, value) +inline var VkStencilOpState.writeMask + get() = VkStencilOpState.nwriteMask(adr) + set(value) = VkStencilOpState.nwriteMask(adr, value) +inline var VkStencilOpState.reference + get() = VkStencilOpState.nreference(adr) + set(value) = VkStencilOpState.nreference(adr, value) + + +inline var VkPipelineDepthStencilStateCreateInfo.type: VkStructureType + get() = VkStructureType of VkPipelineDepthStencilStateCreateInfo.nsType(adr) + set(value) = VkPipelineDepthStencilStateCreateInfo.nsType(adr, value.i) +inline var VkPipelineDepthStencilStateCreateInfo.next + get() = VkPipelineDepthStencilStateCreateInfo.npNext(adr) + set(value) = VkPipelineDepthStencilStateCreateInfo.npNext(adr, value) +inline var VkPipelineDepthStencilStateCreateInfo.flags: VkPipelineDepthStencilStateCreateFlags + get() = VkPipelineDepthStencilStateCreateInfo.nflags(adr) + set(value) = VkPipelineDepthStencilStateCreateInfo.nflags(adr, value) +inline var VkPipelineDepthStencilStateCreateInfo.depthTestEnable + get() = VkPipelineDepthStencilStateCreateInfo.ndepthTestEnable(adr).bool + set(value) = VkPipelineDepthStencilStateCreateInfo.ndepthTestEnable(adr, value.i) +inline var VkPipelineDepthStencilStateCreateInfo.depthWriteEnable + get() = VkPipelineDepthStencilStateCreateInfo.ndepthWriteEnable(adr).bool + set(value) = VkPipelineDepthStencilStateCreateInfo.ndepthWriteEnable(adr, value.i) +inline var VkPipelineDepthStencilStateCreateInfo.depthCompareOp: VkCompareOp + get() = VkCompareOp of VkPipelineDepthStencilStateCreateInfo.ndepthCompareOp(adr) + set(value) = VkPipelineDepthStencilStateCreateInfo.ndepthCompareOp(adr, value.i) +inline var VkPipelineDepthStencilStateCreateInfo.depthBoundsTestEnable + get() = VkPipelineDepthStencilStateCreateInfo.ndepthBoundsTestEnable(adr).bool + set(value) = VkPipelineDepthStencilStateCreateInfo.ndepthBoundsTestEnable(adr, value.i) +inline var VkPipelineDepthStencilStateCreateInfo.stencilTestEnable + get() = VkPipelineDepthStencilStateCreateInfo.nstencilTestEnable(adr).bool + set(value) = VkPipelineDepthStencilStateCreateInfo.nstencilTestEnable(adr, value.i) +inline var VkPipelineDepthStencilStateCreateInfo.front: VkStencilOpState + get() = VkPipelineDepthStencilStateCreateInfo.nfront(adr) + set(value) = VkPipelineDepthStencilStateCreateInfo.nfront(adr, value) +inline var VkPipelineDepthStencilStateCreateInfo.back: VkStencilOpState + get() = VkPipelineDepthStencilStateCreateInfo.nback(adr) + set(value) = VkPipelineDepthStencilStateCreateInfo.nback(adr, value) +inline var VkPipelineDepthStencilStateCreateInfo.minDepthBounds + get() = VkPipelineDepthStencilStateCreateInfo.nminDepthBounds(adr) + set(value) = VkPipelineDepthStencilStateCreateInfo.nminDepthBounds(adr, value) +inline var VkPipelineDepthStencilStateCreateInfo.maxDepthBounds + get() = VkPipelineDepthStencilStateCreateInfo.nmaxDepthBounds(adr) + set(value) = VkPipelineDepthStencilStateCreateInfo.nmaxDepthBounds(adr, value) + + +inline var VkPipelineColorBlendAttachmentState.blendEnable + get() = VkPipelineColorBlendAttachmentState.nblendEnable(adr).bool + set(value) = VkPipelineColorBlendAttachmentState.nblendEnable(adr, value.i) +inline var VkPipelineColorBlendAttachmentState.srcColorBlendFactor: VkBlendFactor + get() = VkBlendFactor of VkPipelineColorBlendAttachmentState.nsrcColorBlendFactor(adr) + set(value) = VkPipelineColorBlendAttachmentState.nsrcColorBlendFactor(adr, value.i) +inline var VkPipelineColorBlendAttachmentState.dstColorBlendFactor: VkBlendFactor + get() = VkBlendFactor of VkPipelineColorBlendAttachmentState.ndstColorBlendFactor(adr) + set(value) = VkPipelineColorBlendAttachmentState.ndstColorBlendFactor(adr, value.i) +inline var VkPipelineColorBlendAttachmentState.colorBlendOp: VkBlendOp + get() = VkBlendOp of VkPipelineColorBlendAttachmentState.ncolorBlendOp(adr) + set(value) = VkPipelineColorBlendAttachmentState.ncolorBlendOp(adr, value.i) +inline var VkPipelineColorBlendAttachmentState.srcAlphaBlendFactor: VkBlendFactor + get() = VkBlendFactor of VkPipelineColorBlendAttachmentState.nsrcAlphaBlendFactor(adr) + set(value) = VkPipelineColorBlendAttachmentState.nsrcAlphaBlendFactor(adr, value.i) +inline var VkPipelineColorBlendAttachmentState.dstAlphaBlendFactor: VkBlendFactor + get() = VkBlendFactor of VkPipelineColorBlendAttachmentState.ndstAlphaBlendFactor(adr) + set(value) = VkPipelineColorBlendAttachmentState.ndstAlphaBlendFactor(adr, value.i) +inline var VkPipelineColorBlendAttachmentState.alphaBlendOp: VkBlendOp + get() = VkBlendOp of VkPipelineColorBlendAttachmentState.nalphaBlendOp(adr) + set(value) = VkPipelineColorBlendAttachmentState.nalphaBlendOp(adr, value.i) +inline var VkPipelineColorBlendAttachmentState.colorWriteMask: VkColorComponentFlags + get() = VkPipelineColorBlendAttachmentState.ncolorWriteMask(adr) + set(value) = VkPipelineColorBlendAttachmentState.ncolorWriteMask(adr, value) + + +inline var VkPipelineColorBlendStateCreateInfo.type: VkStructureType + get() = VkStructureType of VkPipelineColorBlendStateCreateInfo.nsType(adr) + set(value) = VkPipelineColorBlendStateCreateInfo.nsType(adr, value.i) +inline var VkPipelineColorBlendStateCreateInfo.next + get() = VkPipelineColorBlendStateCreateInfo.npNext(adr) + set(value) = VkPipelineColorBlendStateCreateInfo.npNext(adr, value) +inline var VkPipelineColorBlendStateCreateInfo.flags: VkPipelineColorBlendStateCreateFlags + get() = VkPipelineColorBlendStateCreateInfo.nflags(adr) + set(value) = VkPipelineColorBlendStateCreateInfo.nflags(adr, value) +inline var VkPipelineColorBlendStateCreateInfo.logicOpEnable + get() = VkPipelineColorBlendStateCreateInfo.nlogicOpEnable(adr).bool + set(value) = VkPipelineColorBlendStateCreateInfo.nlogicOpEnable(adr, value.i) +inline var VkPipelineColorBlendStateCreateInfo.logicOp: VkLogicOp + get() = VkLogicOp of VkPipelineColorBlendStateCreateInfo.nlogicOp(adr) + set(value) = VkPipelineColorBlendStateCreateInfo.nlogicOp(adr, value.i) +//inline val VkPipelineColorBlendStateCreateInfo.attachmentCount: Int get() = VkPipelineColorBlendStateCreateInfo.nattachmentCount(adr) +inline var VkPipelineColorBlendStateCreateInfo.attachments: VkPipelineColorBlendAttachmentState.Buffer? + get() = VkPipelineColorBlendStateCreateInfo.npAttachments(adr) + set(value) = VkPipelineColorBlendStateCreateInfo.npAttachments(adr, value) +/** JVM custom */ +inline var VkPipelineColorBlendStateCreateInfo.attachment: VkPipelineColorBlendAttachmentState? + get() = VkPipelineColorBlendAttachmentState.createSafe(memGetAddress(adr + VkPipelineColorBlendStateCreateInfo.PATTACHMENTS)) + set(value) { + memPutAddress(adr + VkPipelineColorBlendStateCreateInfo.PATTACHMENTS, memAddressSafe(value)) + VkPipelineColorBlendStateCreateInfo.nattachmentCount(adr, if (value == null) 0 else 1) + } +inline var VkPipelineColorBlendStateCreateInfo.blendConstants: FloatBuffer + get() = VkPipelineColorBlendStateCreateInfo.nblendConstants(adr) + set(value) = VkPipelineColorBlendStateCreateInfo.nblendConstants(adr, value) + + +inline var VkPipelineDynamicStateCreateInfo.type: VkStructureType + get() = VkStructureType of VkPipelineDynamicStateCreateInfo.nsType(adr) + set(value) = VkPipelineDynamicStateCreateInfo.nsType(adr, value.i) +inline var VkPipelineDynamicStateCreateInfo.next + get() = VkPipelineDynamicStateCreateInfo.npNext(adr) + set(value) = VkPipelineDynamicStateCreateInfo.npNext(adr, value) +inline var VkPipelineDynamicStateCreateInfo.flags: VkPipelineDynamicStateCreateFlags + get() = VkPipelineDynamicStateCreateInfo.nflags(adr) + set(value) = VkPipelineDynamicStateCreateInfo.nflags(adr, value) +//inline val VkPipelineDynamicStateCreateInfo.dynamicStateCount get() = VkPipelineDynamicStateCreateInfo.ndynamicStateCount(adr) +inline var VkPipelineDynamicStateCreateInfo.dynamicStates: VkDynamicStateBuffer + get() = VkDynamicStateBuffer(VkPipelineDynamicStateCreateInfo.npDynamicStates(adr)) + set(value) = VkPipelineDynamicStateCreateInfo.npDynamicStates(adr, value.buffer) + +//typedef struct VkPipelineDynamicStateCreateInfo { +// VkStructureType sType; +// const void* pNext; +// VkPipelineDynamicStateCreateFlags flags; +// uint32_t dynamicStateCount; +// const VkDynamicState* pDynamicStates; +//} VkPipelineDynamicStateCreateInfo; +// + +inline var VkGraphicsPipelineCreateInfo.type: VkStructureType + get() = VkStructureType of VkGraphicsPipelineCreateInfo.nsType(adr) + set(value) = VkGraphicsPipelineCreateInfo.nsType(adr, value.i) +inline var VkGraphicsPipelineCreateInfo.next + get() = VkGraphicsPipelineCreateInfo.npNext(adr) + set(value) = VkGraphicsPipelineCreateInfo.npNext(adr, value) +/** JVM custom */ +inline var VkGraphicsPipelineCreateInfo.flag: VkPipelineCreate + get() = TODO() + set(value) = VkGraphicsPipelineCreateInfo.nflags(adr, value.i) +inline var VkGraphicsPipelineCreateInfo.flags: VkPipelineCreateFlags + get() = VkGraphicsPipelineCreateInfo.nflags(adr) + set(value) = VkGraphicsPipelineCreateInfo.nflags(adr, value) +//inline val VkGraphicsPipelineCreateInfo.stageCount get() = VkGraphicsPipelineCreateInfo.nstageCount(adr) +inline var VkGraphicsPipelineCreateInfo.stages: VkPipelineShaderStageCreateInfo.Buffer + get() = VkGraphicsPipelineCreateInfo.npStages(adr) + set(value) = VkGraphicsPipelineCreateInfo.npStages(adr, value) +inline var VkGraphicsPipelineCreateInfo.vertexInputState: VkPipelineVertexInputStateCreateInfo + get() = VkGraphicsPipelineCreateInfo.npVertexInputState(adr) + set(value) = VkGraphicsPipelineCreateInfo.npVertexInputState(adr, value) +inline var VkGraphicsPipelineCreateInfo.inputAssemblyState: VkPipelineInputAssemblyStateCreateInfo + get() = VkGraphicsPipelineCreateInfo.npInputAssemblyState(adr) + set(value) = VkGraphicsPipelineCreateInfo.npInputAssemblyState(adr, value) +inline var VkGraphicsPipelineCreateInfo.tessellationState + get() = VkGraphicsPipelineCreateInfo.npTessellationState(adr) + set(value) = VkGraphicsPipelineCreateInfo.npTessellationState(adr, value) +inline var VkGraphicsPipelineCreateInfo.viewportState + get() = VkGraphicsPipelineCreateInfo.npViewportState(adr) + set(value) = VkGraphicsPipelineCreateInfo.npViewportState(adr, value) +inline var VkGraphicsPipelineCreateInfo.rasterizationState: VkPipelineRasterizationStateCreateInfo + get() = VkGraphicsPipelineCreateInfo.npRasterizationState(adr) + set(value) = VkGraphicsPipelineCreateInfo.npRasterizationState(adr, value) +inline var VkGraphicsPipelineCreateInfo.multisampleState + get() = VkGraphicsPipelineCreateInfo.npMultisampleState(adr) + set(value) = VkGraphicsPipelineCreateInfo.npMultisampleState(adr, value) +inline var VkGraphicsPipelineCreateInfo.depthStencilState + get() = VkGraphicsPipelineCreateInfo.npDepthStencilState(adr) + set(value) = VkGraphicsPipelineCreateInfo.npDepthStencilState(adr, value) +inline var VkGraphicsPipelineCreateInfo.colorBlendState + get() = VkGraphicsPipelineCreateInfo.npColorBlendState(adr) + set(value) = VkGraphicsPipelineCreateInfo.npColorBlendState(adr, value) +inline var VkGraphicsPipelineCreateInfo.dynamicState + get() = VkGraphicsPipelineCreateInfo.npDynamicState(adr) + set(value) = VkGraphicsPipelineCreateInfo.npDynamicState(adr, value) +inline var VkGraphicsPipelineCreateInfo.layout: VkPipelineLayout + get() = VkPipelineLayout(VkGraphicsPipelineCreateInfo.nlayout(adr)) + set(value) = VkGraphicsPipelineCreateInfo.nlayout(adr, value.L) +inline var VkGraphicsPipelineCreateInfo.renderPass: VkRenderPass + get() = VkRenderPass(VkGraphicsPipelineCreateInfo.nrenderPass(adr)) + set(value) = VkGraphicsPipelineCreateInfo.nrenderPass(adr, value.L) +inline var VkGraphicsPipelineCreateInfo.subpass + get() = VkGraphicsPipelineCreateInfo.nsubpass(adr) + set(value) = VkGraphicsPipelineCreateInfo.nsubpass(adr, value) +inline var VkGraphicsPipelineCreateInfo.basePipelineHandle: VkPipeline + get() = VkPipeline(VkGraphicsPipelineCreateInfo.nbasePipelineHandle(adr)) + set(value) = VkGraphicsPipelineCreateInfo.nbasePipelineHandle(adr, value.L) +inline var VkGraphicsPipelineCreateInfo.basePipelineIndex + get() = VkGraphicsPipelineCreateInfo.nbasePipelineIndex(adr) + set(value) = VkGraphicsPipelineCreateInfo.nbasePipelineIndex(adr, value) + + +inline var VkComputePipelineCreateInfo.type: VkStructureType + get() = VkStructureType of VkComputePipelineCreateInfo.nsType(adr) + set(value) = VkComputePipelineCreateInfo.nsType(adr, value.i) +inline var VkComputePipelineCreateInfo.next: Long + get() = VkComputePipelineCreateInfo.npNext(adr) + set(value) = VkComputePipelineCreateInfo.npNext(adr, value) +inline var VkComputePipelineCreateInfo.flags: VkPipelineCreateFlags + get() = VkComputePipelineCreateInfo.nflags(adr) + set(value) = VkComputePipelineCreateInfo.nflags(adr, value) +inline var VkComputePipelineCreateInfo.stage: VkPipelineShaderStageCreateInfo + get() = VkComputePipelineCreateInfo.nstage(adr) + set(value) = VkComputePipelineCreateInfo.nstage(adr, value) +inline var VkComputePipelineCreateInfo.layout: VkPipelineLayout + get() = VkPipelineLayout(VkComputePipelineCreateInfo.nlayout(adr)) + set(value) = VkComputePipelineCreateInfo.nlayout(adr, value.L) +inline var VkComputePipelineCreateInfo.basePipelineHandle: VkPipeline + get() = VkPipeline(VkComputePipelineCreateInfo.nbasePipelineHandle(adr)) + set(value) = VkComputePipelineCreateInfo.nbasePipelineHandle(adr, value.L) +inline var VkComputePipelineCreateInfo.basePipelineIndex: Int + get() = VkComputePipelineCreateInfo.nbasePipelineIndex(adr) + set(value) = VkComputePipelineCreateInfo.nbasePipelineIndex(adr, value) + + +inline var VkPushConstantRange.stageFlags: VkShaderStageFlags + get() = VkPushConstantRange.nstageFlags(adr) + set(value) = VkPushConstantRange.nstageFlags(adr, value) +inline var VkPushConstantRange.offset: Int + get() = VkPushConstantRange.noffset(adr) + set(value) = VkPushConstantRange.noffset(adr, value) +inline var VkPushConstantRange.size: Int + get() = VkPushConstantRange.nsize(adr) + set(value) = VkPushConstantRange.nsize(adr, value) + + +inline var VkPipelineLayoutCreateInfo.type: VkStructureType + get() = VkStructureType of VkPipelineLayoutCreateInfo.nsType(adr) + set(value) = VkPipelineLayoutCreateInfo.nsType(adr, value.i) +inline var VkPipelineLayoutCreateInfo.next + get() = VkPipelineLayoutCreateInfo.npNext(adr) + set(value) = VkPipelineLayoutCreateInfo.npNext(adr, value) +inline var VkPipelineLayoutCreateInfo.flags: VkPipelineLayoutCreateFlags + get() = VkPipelineLayoutCreateInfo.nflags(adr) + set(value) = VkPipelineLayoutCreateInfo.nflags(adr, value) +//inline val VkPipelineLayoutCreateInfo.setLayoutCount get() = VkPipelineLayoutCreateInfo.nsetLayoutCount(adr) +inline var VkPipelineLayoutCreateInfo.setLayouts: LongBuffer? + get() = VkPipelineLayoutCreateInfo.npSetLayouts(adr) + set(value) = VkPipelineLayoutCreateInfo.npSetLayouts(adr, value) +//inline var VkPipelineLayoutCreateInfo.setLayout: VkDescriptorSetLayout? TODO BUG, inline it back +/** JVM custom */ +var VkPipelineLayoutCreateInfo.setLayout: VkDescriptorSetLayout? + get() = VkPipelineLayoutCreateInfo.npSetLayouts(adr)?.let { VkDescriptorSetLayout(it[0]) } + set(value) = when (value) { + null -> VkPipelineLayoutCreateInfo.npSetLayouts(adr, null) + else -> stak.longBuffer(value.L) { VkPipelineLayoutCreateInfo.npSetLayouts(adr, it) } + } +//inline val VkPipelineLayoutCreateInfo.pushConstantRangeCount get() = VkPipelineLayoutCreateInfo.npushConstantRangeCount(adr) +inline var VkPipelineLayoutCreateInfo.pushConstantRanges + get() = VkPipelineLayoutCreateInfo.npPushConstantRanges(adr) + set(value) = VkPipelineLayoutCreateInfo.npPushConstantRanges(adr, value) +/** JVM Custom */ +inline var VkPipelineLayoutCreateInfo.pushConstantRange: VkPushConstantRange? + get() = VkPushConstantRange.createSafe(memGetAddress(adr + VkPipelineLayoutCreateInfo.PPUSHCONSTANTRANGES)) + set(value) { + memPutAddress(adr + VkPipelineLayoutCreateInfo.PPUSHCONSTANTRANGES, memAddressSafe(value)) + VkPipelineLayoutCreateInfo.npushConstantRangeCount(adr, if (value != null) 1 else 0) + } + +//typedef struct VkPipelineLayoutCreateInfo { +// VkStructureType sType; +// const void* pNext; +// VkPipelineLayoutCreateFlags flags; +// uint32_t setLayoutCount; +// const VkDescriptorSetLayout* pSetLayouts; +// uint32_t pushConstantRangeCount; +// const VkPushConstantRange* pPushConstantRanges; +//} VkPipelineLayoutCreateInfo; + + +inline var VkSamplerCreateInfo.type: VkStructureType + get() = VkStructureType of VkSamplerCreateInfo.nsType(adr) + set(value) = VkSamplerCreateInfo.nsType(adr, value.i) +inline var VkSamplerCreateInfo.next + get() = VkSamplerCreateInfo.npNext(adr) + set(value) = VkSamplerCreateInfo.npNext(adr, value) +inline var VkSamplerCreateInfo.flags: VkSamplerCreateFlags + get() = VkSamplerCreateInfo.nflags(adr) + set(value) = VkSamplerCreateInfo.nflags(adr, value) +inline var VkSamplerCreateInfo.magFilter: VkFilter + get() = VkFilter of VkSamplerCreateInfo.nmagFilter(adr) + set(value) = VkSamplerCreateInfo.nmagFilter(adr, value.i) +inline var VkSamplerCreateInfo.minFilter: VkFilter + get() = VkFilter of VkSamplerCreateInfo.nminFilter(adr) + set(value) = VkSamplerCreateInfo.nminFilter(adr, value.i) +inline var VkSamplerCreateInfo.mipmapMode: VkSamplerMipmapMode + get() = VkSamplerMipmapMode of VkSamplerCreateInfo.nmipmapMode(adr) + set(value) = VkSamplerCreateInfo.nmipmapMode(adr, value.i) +inline var VkSamplerCreateInfo.addressModeU: VkSamplerAddressMode + get() = VkSamplerAddressMode of VkSamplerCreateInfo.naddressModeU(adr) + set(value) = VkSamplerCreateInfo.naddressModeU(adr, value.i) +inline var VkSamplerCreateInfo.addressModeV: VkSamplerAddressMode + get() = VkSamplerAddressMode of VkSamplerCreateInfo.naddressModeV(adr) + set(value) = VkSamplerCreateInfo.naddressModeV(adr, value.i) +inline var VkSamplerCreateInfo.addressModeW: VkSamplerAddressMode + get() = VkSamplerAddressMode of VkSamplerCreateInfo.naddressModeW(adr) + set(value) = VkSamplerCreateInfo.naddressModeW(adr, value.i) +/** JVM custom */ +inline var VkSamplerCreateInfo.addressMode: VkSamplerAddressMode + get() = throw Error() + set(value) { + addressModeU = value + addressModeV = value + addressModeW = value + } +inline var VkSamplerCreateInfo.mipLodBias: Float + get() = VkSamplerCreateInfo.nmipLodBias(adr) + set(value) = VkSamplerCreateInfo.nmipLodBias(adr, value) +inline var VkSamplerCreateInfo.anisotropyEnable: Boolean + get() = VkSamplerCreateInfo.nanisotropyEnable(adr).bool + set(value) = VkSamplerCreateInfo.nanisotropyEnable(adr, value.i) +inline var VkSamplerCreateInfo.maxAnisotropy: Float + get() = VkSamplerCreateInfo.nmaxAnisotropy(adr) + set(value) = VkSamplerCreateInfo.nmaxAnisotropy(adr, value) +inline var VkSamplerCreateInfo.compareEnable: Boolean + get() = VkSamplerCreateInfo.ncompareEnable(adr).bool + set(value) = VkSamplerCreateInfo.ncompareEnable(adr, value.i) +inline var VkSamplerCreateInfo.compareOp: VkCompareOp + get() = VkCompareOp of VkSamplerCreateInfo.ncompareOp(adr) + set(value) = VkSamplerCreateInfo.ncompareOp(adr, value.i) +inline var VkSamplerCreateInfo.minLod: Float + get() = VkSamplerCreateInfo.nminLod(adr) + set(value) = VkSamplerCreateInfo.nminLod(adr, value) +inline var VkSamplerCreateInfo.maxLod: Float + get() = VkSamplerCreateInfo.nmaxLod(adr) + set(value) = VkSamplerCreateInfo.nmaxLod(adr, value) +inline var VkSamplerCreateInfo.borderColor: VkBorderColor + get() = VkBorderColor of VkSamplerCreateInfo.nborderColor(adr) + set(value) = VkSamplerCreateInfo.nborderColor(adr, value.i) +inline var VkSamplerCreateInfo.unnormalizedCoordinates: Boolean + get() = VkSamplerCreateInfo.nunnormalizedCoordinates(adr).bool + set(value) = VkSamplerCreateInfo.nunnormalizedCoordinates(adr, value.i) + + +inline var VkDescriptorSetLayoutBinding.binding + get() = VkDescriptorSetLayoutBinding.nbinding(adr) + set(value) = VkDescriptorSetLayoutBinding.nbinding(adr, value) +inline var VkDescriptorSetLayoutBinding.descriptorType: VkDescriptorType + get() = VkDescriptorType of VkDescriptorSetLayoutBinding.ndescriptorType(adr) + set(value) = VkDescriptorSetLayoutBinding.ndescriptorType(adr, value.i) +inline var VkDescriptorSetLayoutBinding.descriptorCount + get() = VkDescriptorSetLayoutBinding.ndescriptorCount(adr) + set(value) = VkDescriptorSetLayoutBinding.ndescriptorCount(adr, value) +/** JVM custom */ +inline var VkDescriptorSetLayoutBinding.stageFlag: VkShaderStage + get() = TODO() + set(value) = VkDescriptorSetLayoutBinding.nstageFlags(adr, value.i) +inline var VkDescriptorSetLayoutBinding.stageFlags: VkShaderStageFlags + get() = VkDescriptorSetLayoutBinding.nstageFlags(adr) + set(value) = VkDescriptorSetLayoutBinding.nstageFlags(adr, value) +inline var VkDescriptorSetLayoutBinding.immutableSamplers: VkSamplerBuffer? + get() = VkDescriptorSetLayoutBinding.npImmutableSamplers(adr) + set(value) = VkDescriptorSetLayoutBinding.npImmutableSamplers(adr, value) +/** JVM custom */ +inline var VkDescriptorSetLayoutBinding.immutableSampler: VkSampler? + get() = VkDescriptorSetLayoutBinding.npImmutableSamplers(adr)?.let { VkSampler(it[0]) } + set(value) = when (value) { + null -> memPutAddress(adr + VkDescriptorSetLayoutBinding.PIMMUTABLESAMPLERS, NULL) + else -> stak.longAddress(value.L) { pSampler -> + memPutAddress(adr + VkDescriptorSetLayoutBinding.PIMMUTABLESAMPLERS, pSampler) + VkDescriptorSetLayoutBinding.ndescriptorCount(adr, 1) + } + } + + +inline var VkDescriptorSetLayoutCreateInfo.type: VkStructureType + get() = VkStructureType of VkDescriptorSetLayoutCreateInfo.nsType(adr) + set(value) = VkDescriptorSetLayoutCreateInfo.nsType(adr, value.i) +inline var VkDescriptorSetLayoutCreateInfo.next + get() = VkDescriptorSetLayoutCreateInfo.npNext(adr) + set(value) = VkDescriptorSetLayoutCreateInfo.npNext(adr, value) +/** JVM custom */ +inline var VkDescriptorSetLayoutCreateInfo.flag: VkDescriptorSetLayoutCreate + get() = TODO() + set(value) = VkDescriptorSetLayoutCreateInfo.nflags(adr, value.i) +inline var VkDescriptorSetLayoutCreateInfo.flags: VkDescriptorSetLayoutCreateFlags + get() = VkDescriptorSetLayoutCreateInfo.nflags(adr) + set(value) = VkDescriptorSetLayoutCreateInfo.nflags(adr, value) +//inline val VkDescriptorSetLayoutCreateInfo.bindingCount get() = VkDescriptorSetLayoutCreateInfo.nbindingCount(adr) +inline var VkDescriptorSetLayoutCreateInfo.bindings: VkDescriptorSetLayoutBinding.Buffer? + get() = VkDescriptorSetLayoutCreateInfo.npBindings(adr) + set(value) = VkDescriptorSetLayoutCreateInfo.npBindings(adr, value) +/** JVM custom */ +inline var VkDescriptorSetLayoutCreateInfo.binding: VkDescriptorSetLayoutBinding? + get() = VkDescriptorSetLayoutBinding.createSafe(memGetAddress(adr + VkDescriptorSetLayoutCreateInfo.PBINDINGS)) + set(value) { + memPutAddress(adr + VkDescriptorSetLayoutCreateInfo.PBINDINGS, value?.adr ?: NULL) + VkDescriptorSetLayoutCreateInfo.nbindingCount(adr, if (value == null) 0 else 1) + } + + +inline var VkDescriptorPoolSize.type: VkDescriptorType + get() = VkDescriptorType of VkDescriptorPoolSize.ntype(adr) + set(value) = VkDescriptorPoolSize.ntype(adr, value.i) +inline var VkDescriptorPoolSize.descriptorCount + get() = VkDescriptorPoolSize.ndescriptorCount(adr) + set(value) = VkDescriptorPoolSize.ndescriptorCount(adr, value) + + +inline var VkDescriptorPoolCreateInfo.type: VkStructureType + get() = VkStructureType of VkDescriptorPoolCreateInfo.nsType(adr) + set(value) = VkDescriptorPoolCreateInfo.nsType(adr, value.i) +inline var VkDescriptorPoolCreateInfo.next + get() = VkDescriptorPoolCreateInfo.npNext(adr) + set(value) = VkDescriptorPoolCreateInfo.npNext(adr, value) +/** JVM custom */ +inline var VkDescriptorPoolCreateInfo.flag: VkDescriptorPoolCreate + get() = TODO() + set(value) = VkDescriptorPoolCreateInfo.nflags(adr, value.i) +inline var VkDescriptorPoolCreateInfo.flags: VkDescriptorPoolCreateFlags + get() = VkDescriptorPoolCreateInfo.nflags(adr) + set(value) = VkDescriptorPoolCreateInfo.nflags(adr, value) +inline var VkDescriptorPoolCreateInfo.maxSets + get() = VkDescriptorPoolCreateInfo.nmaxSets(adr) + set(value) = VkDescriptorPoolCreateInfo.nmaxSets(adr, value) +//inline val VkDescriptorPoolCreateInfo.poolSizeCount get() = VkDescriptorPoolCreateInfo.npoolSizeCount(adr) +inline var VkDescriptorPoolCreateInfo.poolSizes: VkDescriptorPoolSize.Buffer + get() = VkDescriptorPoolCreateInfo.npPoolSizes(adr) + set(value) = VkDescriptorPoolCreateInfo.npPoolSizes(adr, value) +/** JVM custom */ +inline var VkDescriptorPoolCreateInfo.poolSize: VkDescriptorPoolSize + get() = VkDescriptorPoolSize.create(memGetAddress(adr + VkDescriptorPoolCreateInfo.PPOOLSIZES)) + set(value) { + memPutAddress(adr + VkDescriptorPoolCreateInfo.PPOOLSIZES, value.adr) + VkDescriptorPoolCreateInfo.npoolSizeCount(adr, 1) + } + + +inline var VkDescriptorSetAllocateInfo.type: VkStructureType + get() = VkStructureType of VkDescriptorSetAllocateInfo.nsType(adr) + set(value) = VkDescriptorSetAllocateInfo.nsType(adr, value.i) +inline var VkDescriptorSetAllocateInfo.next + get() = VkDescriptorSetAllocateInfo.npNext(adr) + set(value) = VkDescriptorSetAllocateInfo.npNext(adr, value) +inline var VkDescriptorSetAllocateInfo.descriptorPool: VkDescriptorPool + get() = VkDescriptorPool(VkDescriptorSetAllocateInfo.ndescriptorPool(adr)) + set(value) = VkDescriptorSetAllocateInfo.ndescriptorPool(adr, value.L) +inline var VkDescriptorSetAllocateInfo.descriptorSetCount + get() = VkDescriptorSetAllocateInfo.ndescriptorSetCount(adr) + set(value) = VkDescriptorSetAllocateInfo.ndescriptorSetCount(adr, value) +inline var VkDescriptorSetAllocateInfo.setLayouts: LongBuffer + get() = VkDescriptorSetAllocateInfo.npSetLayouts(adr) + set(value) = VkDescriptorSetAllocateInfo.npSetLayouts(adr, value) +/** JVM custom */ +inline var VkDescriptorSetAllocateInfo.setLayout: VkDescriptorSetLayout + get() = VkDescriptorSetLayout(VkDescriptorSetAllocateInfo.npSetLayouts(adr)[0]) + set(value) = stak.longBuffer(value.L) { VkDescriptorSetAllocateInfo.npSetLayouts(adr, it) } + + +inline var VkDescriptorImageInfo.sampler: VkSampler + get() = VkSampler(VkDescriptorImageInfo.nsampler(adr)) + set(value) = VkDescriptorImageInfo.nsampler(adr, value.L) +inline var VkDescriptorImageInfo.imageView: VkImageView + get() = VkImageView(VkDescriptorImageInfo.nimageView(adr)) + set(value) = VkDescriptorImageInfo.nimageView(adr, value.L) +inline var VkDescriptorImageInfo.imageLayout: VkImageLayout + get() = VkImageLayout of VkDescriptorImageInfo.nimageLayout(adr) + set(value) = VkDescriptorImageInfo.nimageLayout(adr, value.i) + + +inline var VkDescriptorBufferInfo.buffer: VkBuffer + get() = VkBuffer(VkDescriptorBufferInfo.nbuffer(adr)) + set(value) = VkDescriptorBufferInfo.nbuffer(adr, value.L) +inline var VkDescriptorBufferInfo.offset: VkDeviceSize + get() = VkDeviceSize(VkDescriptorBufferInfo.noffset(adr)) + set(value) = VkDescriptorBufferInfo.noffset(adr, value.L) +inline var VkDescriptorBufferInfo.range: VkDeviceSize + get() = VkDeviceSize(VkDescriptorBufferInfo.nrange(adr)) + set(value) = VkDescriptorBufferInfo.nrange(adr, value.L) \ No newline at end of file diff --git a/src/main/kotlin/vkk/direct fields B.kt b/src/main/kotlin/vkk/direct fields B.kt new file mode 100644 index 0000000..80a2b7d --- /dev/null +++ b/src/main/kotlin/vkk/direct fields B.kt @@ -0,0 +1,1978 @@ +package vkk + +import glm_.BYTES +import glm_.bool +import glm_.i +import glm_.vec2.Vec2i +import glm_.vec3.Vec3i +import glm_.vec4.Vec4 +import kool.Ptr +import kool.stak +import org.lwjgl.system.MemoryUtil.* +import org.lwjgl.vulkan.* +import java.nio.IntBuffer + + +inline var VkWriteDescriptorSet.type: VkStructureType + get() = VkStructureType of VkWriteDescriptorSet.nsType(adr) + set(value) = VkWriteDescriptorSet.nsType(adr, value.i) +inline var VkWriteDescriptorSet.next: Ptr + get() = VkWriteDescriptorSet.npNext(adr) + set(value) = VkWriteDescriptorSet.npNext(adr, value) +inline var VkWriteDescriptorSet.dstSet: VkDescriptorSet + get() = VkDescriptorSet(VkWriteDescriptorSet.ndstSet(adr)) + set(value) = VkWriteDescriptorSet.ndstSet(adr, value.L) +inline var VkWriteDescriptorSet.dstBinding + get() = VkWriteDescriptorSet.ndstBinding(adr) + set(value) = VkWriteDescriptorSet.ndstBinding(adr, value) +inline var VkWriteDescriptorSet.dstArrayElement + get() = VkWriteDescriptorSet.ndstArrayElement(adr) + set(value) = VkWriteDescriptorSet.ndstArrayElement(adr, value) +//inline val VkWriteDescriptorSet.descriptorCount get() = VkWriteDescriptorSet.ndescriptorCount(adr) +inline var VkWriteDescriptorSet.descriptorType: VkDescriptorType + get() = VkDescriptorType of VkWriteDescriptorSet.ndescriptorType(adr) + set(value) = VkWriteDescriptorSet.ndescriptorType(adr, value.i) +inline var VkWriteDescriptorSet.imageInfo: VkDescriptorImageInfo.Buffer? + get() = VkWriteDescriptorSet.npImageInfo(adr) + set(value) = VkWriteDescriptorSet.npImageInfo(adr, value) +/** JVM custom */ +inline var VkWriteDescriptorSet.imageInfo_: VkDescriptorImageInfo? + get() = VkDescriptorImageInfo.createSafe(memGetAddress(adr + VkWriteDescriptorSet.PIMAGEINFO)) + set(value) { + memPutAddress(adr + VkWriteDescriptorSet.PIMAGEINFO, memAddressSafe(value)) + value?.let { VkWriteDescriptorSet.ndescriptorCount(adr, 1) } + } +inline var VkWriteDescriptorSet.bufferInfo: VkDescriptorBufferInfo.Buffer? + get() = VkWriteDescriptorSet.npBufferInfo(adr) + set(value) = VkWriteDescriptorSet.npBufferInfo(adr, value) +/** JVM custom */ +inline var VkWriteDescriptorSet.bufferInfo_: VkDescriptorBufferInfo? + get() = VkDescriptorBufferInfo.createSafe(memGetAddress(adr + VkWriteDescriptorSet.PBUFFERINFO)) + set(value) { + memPutAddress(adr + VkWriteDescriptorSet.PBUFFERINFO, memAddressSafe(value)) + value?.let { VkWriteDescriptorSet.ndescriptorCount(adr, 1) } + } +inline var VkWriteDescriptorSet.texelBufferView + get() = VkWriteDescriptorSet.npTexelBufferView(adr) + set(value) = VkWriteDescriptorSet.npTexelBufferView(adr, value) + + +//typedef struct VkCopyDescriptorSet { +// VkStructureType sType; +// const void* pNext; +// VkDescriptorSet srcSet; +// uint32_t srcBinding; +// uint32_t srcArrayElement; +// VkDescriptorSet dstSet; +// uint32_t dstBinding; +// uint32_t dstArrayElement; +// uint32_t descriptorCount; +//} VkCopyDescriptorSet; + + +inline var VkFramebufferCreateInfo.type: VkStructureType + get() = VkStructureType of VkFramebufferCreateInfo.nsType(adr) + set(value) = VkFramebufferCreateInfo.nsType(adr, value.i) +inline var VkFramebufferCreateInfo.next + get() = VkFramebufferCreateInfo.npNext(adr) + set(value) = VkFramebufferCreateInfo.npNext(adr, value) +inline var VkFramebufferCreateInfo.flags: VkFramebufferCreateFlags + get() = VkFramebufferCreateInfo.nflags(adr) + set(value) = VkFramebufferCreateInfo.nflags(adr, value) +inline var VkFramebufferCreateInfo.renderPass: VkRenderPass + get() = VkRenderPass(VkFramebufferCreateInfo.nrenderPass(adr)) + set(value) = VkFramebufferCreateInfo.nrenderPass(adr, value.L) +//inline val VkFramebufferCreateInfo.attachmentCount get() = attachmentCount() +inline var VkFramebufferCreateInfo.attachments: VkImageViewBuffer? + get() = VkFramebufferCreateInfo.npAttachments(adr)?.let(::VkImageViewBuffer) + set(value) = VkFramebufferCreateInfo.npAttachments(adr, value?.buffer) +/** JVM custom */ +inline var VkFramebufferCreateInfo.attachment: VkImageView? + get() = VkFramebufferCreateInfo.npAttachments(adr)?.let { VkImageView(it[0]) } + set(value) = when (value) { + null -> { + memPutAddress(adr + VkFramebufferCreateInfo.PATTACHMENTS, NULL) + VkFramebufferCreateInfo.nattachmentCount(adr, 0) + } + else -> stak.longAddress(value.L) { + memPutAddress(adr + VkFramebufferCreateInfo.PATTACHMENTS, it) + VkFramebufferCreateInfo.nattachmentCount(adr, 1) + } + } +inline var VkFramebufferCreateInfo.width + get() = VkFramebufferCreateInfo.nwidth(adr) + set(value) = VkFramebufferCreateInfo.nwidth(adr, value) +inline var VkFramebufferCreateInfo.height + get() = VkFramebufferCreateInfo.nheight(adr) + set(value) = VkFramebufferCreateInfo.nheight(adr, value) +inline var VkFramebufferCreateInfo.layers + get() = VkFramebufferCreateInfo.nlayers(adr) + set(value) = VkFramebufferCreateInfo.nlayers(adr, value) + +fun VkFramebufferCreateInfo.extent(extent: Vec2i, layers: Int) { + width = extent.x + height = extent.y + this.layers = layers +} + +/** JVM custom */ +inline var VkAttachmentDescription.flag: VkAttachmentDescriptionFlag + get() = TODO() + set(value) = VkAttachmentDescription.nflags(adr, value.i) +inline var VkAttachmentDescription.flags: VkAttachmentDescriptionFlags + get() = VkAttachmentDescription.nflags(adr) + set(value) = VkAttachmentDescription.nflags(adr, value) +inline var VkAttachmentDescription.format: VkFormat + get() = VkFormat of VkAttachmentDescription.nformat(adr) + set(value) = VkAttachmentDescription.nformat(adr, value.i) +inline var VkAttachmentDescription.samples: VkSampleCount + get() = VkSampleCount of VkAttachmentDescription.nsamples(adr) + set(value) = VkAttachmentDescription.nsamples(adr, value.i) +inline var VkAttachmentDescription.loadOp: VkAttachmentLoadOp + get() = VkAttachmentLoadOp of VkAttachmentDescription.nloadOp(adr) + set(value) = VkAttachmentDescription.nloadOp(adr, value.i) +inline var VkAttachmentDescription.storeOp: VkAttachmentStoreOp + get() = VkAttachmentStoreOp of VkAttachmentDescription.nstoreOp(adr) + set(value) = VkAttachmentDescription.nstoreOp(adr, value.i) +inline var VkAttachmentDescription.stencilLoadOp: VkAttachmentLoadOp + get() = VkAttachmentLoadOp of VkAttachmentDescription.nstencilLoadOp(adr) + set(value) = VkAttachmentDescription.nstencilLoadOp(adr, value.i) +inline var VkAttachmentDescription.stencilStoreOp: VkAttachmentStoreOp + get() = VkAttachmentStoreOp of VkAttachmentDescription.nstencilStoreOp(adr) + set(value) = VkAttachmentDescription.nstencilStoreOp(adr, value.i) +inline var VkAttachmentDescription.initialLayout: VkImageLayout + get() = VkImageLayout of VkAttachmentDescription.ninitialLayout(adr) + set(value) = VkAttachmentDescription.ninitialLayout(adr, value.i) +inline var VkAttachmentDescription.finalLayout: VkImageLayout + get() = VkImageLayout of VkAttachmentDescription.nfinalLayout(adr) + set(value) = VkAttachmentDescription.nfinalLayout(adr, value.i) + + +inline var VkAttachmentReference.attachment + get() = VkAttachmentReference.nattachment(adr) + set(value) = VkAttachmentReference.nattachment(adr, value) +inline var VkAttachmentReference.layout: VkImageLayout + get() = VkImageLayout of VkAttachmentReference.nlayout(adr) + set(value) = VkAttachmentReference.nlayout(adr, value.i) + + +/** JVM custom */ +inline var VkSubpassDescription.flag: VkSubpassDescriptionFlag + get() = TODO() + set(value) = VkSubpassDescription.nflags(adr, value.i) +inline var VkSubpassDescription.flags: VkSubpassDescriptionFlags + get() = VkSubpassDescription.nflags(adr) + set(value) = VkSubpassDescription.nflags(adr, value) +inline var VkSubpassDescription.pipelineBindPoint: VkPipelineBindPoint + get() = VkPipelineBindPoint of VkSubpassDescription.npipelineBindPoint(adr) + set(value) = VkSubpassDescription.npipelineBindPoint(adr, value.i) +//inline val VkSubpassDescription.inputAttachmentCount get() = VkSubpassDescription.ninputAttachmentCount(adr) +inline var VkSubpassDescription.inputAttachments + get() = VkSubpassDescription.npInputAttachments(adr) + set(value) = VkSubpassDescription.npInputAttachments(adr, value) +inline var VkSubpassDescription.colorAttachmentCount + get() = VkSubpassDescription.ncolorAttachmentCount(adr) + set(value) = VkSubpassDescription.ncolorAttachmentCount(adr, value) +inline var VkSubpassDescription.colorAttachments: VkAttachmentReference.Buffer? + get() = VkSubpassDescription.npColorAttachments(adr) + set(value) = VkSubpassDescription.npColorAttachments(adr, value) +/** JVM custom */ +inline var VkSubpassDescription.colorAttachment: VkAttachmentReference? + get() = VkSubpassDescription.npColorAttachments(adr)?.get(0) + set(value) = memPutAddress(adr + VkSubpassDescription.PCOLORATTACHMENTS, memAddressSafe(value)) +inline var VkSubpassDescription.resolveAttachments + get() = VkSubpassDescription.npResolveAttachments(adr) + set(value) = VkSubpassDescription.npResolveAttachments(adr, value) +inline var VkSubpassDescription.depthStencilAttachment + get() = VkSubpassDescription.npDepthStencilAttachment(adr) + set(value) = VkSubpassDescription.npDepthStencilAttachment(adr, value) +//inline val VkSubpassDescription.preserveAttachmentCount get() = VkSubpassDescription.npreserveAttachmentCount(adr) +inline var VkSubpassDescription.preserveAttachments + get() = VkSubpassDescription.npPreserveAttachments(adr) + set(value) = VkSubpassDescription.npPreserveAttachments(adr, value) + + +inline var VkSubpassDependency.srcSubpass + get() = VkSubpassDependency.nsrcSubpass(adr) + set(value) = VkSubpassDependency.nsrcSubpass(adr, value) +inline var VkSubpassDependency.dstSubpass + get() = VkSubpassDependency.ndstSubpass(adr) + set(value) = VkSubpassDependency.ndstSubpass(adr, value) +inline var VkSubpassDependency.srcStageMask: VkPipelineStageFlags + get() = VkSubpassDependency.nsrcStageMask(adr) + set(value) = VkSubpassDependency.nsrcStageMask(adr, value) +inline var VkSubpassDependency.dstStageMask: VkPipelineStageFlags + get() = VkSubpassDependency.ndstStageMask(adr) + set(value) = VkSubpassDependency.ndstStageMask(adr, value) +inline var VkSubpassDependency.srcAccessMask: VkAccessFlags + get() = VkSubpassDependency.nsrcAccessMask(adr) + set(value) = VkSubpassDependency.nsrcAccessMask(adr, value) +inline var VkSubpassDependency.dstAccessMask: VkAccessFlags + get() = VkSubpassDependency.ndstAccessMask(adr) + set(value) = VkSubpassDependency.ndstAccessMask(adr, value) +inline var VkSubpassDependency.dependencyFlags: VkDependencyFlags + get() = VkSubpassDependency.ndependencyFlags(adr) + set(value) = VkSubpassDependency.ndependencyFlags(adr, value) + + +inline var VkRenderPassCreateInfo.type: VkStructureType + get() = VkStructureType of VkRenderPassCreateInfo.nsType(adr) + set(value) = VkRenderPassCreateInfo.nsType(adr, value.i) +inline var VkRenderPassCreateInfo.next + get() = VkRenderPassCreateInfo.npNext(adr) + set(value) = VkRenderPassCreateInfo.npNext(adr, value) +inline var VkRenderPassCreateInfo.flags: VkRenderPassCreateFlags + get() = VkRenderPassCreateInfo.nflags(adr) + set(value) = VkRenderPassCreateInfo.nflags(adr, value) +inline var VkRenderPassCreateInfo.attachmentCount: Int + get() = VkRenderPassCreateInfo.nattachmentCount(adr) + set(value) = VkRenderPassCreateInfo.nattachmentCount(adr, value) +inline var VkRenderPassCreateInfo.attachments: VkAttachmentDescription.Buffer? + get() = VkRenderPassCreateInfo.npAttachments(adr) + set(value) = VkRenderPassCreateInfo.npAttachments(adr, value) +/** JVM custom */ +inline var VkRenderPassCreateInfo.attachment: VkAttachmentDescription? + get() = VkRenderPassCreateInfo.npAttachments(adr)?.get(0) + set(value) { + memPutAddress(adr + VkRenderPassCreateInfo.PATTACHMENTS, memAddressSafe(value)) + VkRenderPassCreateInfo.nattachmentCount(adr, if (value == null) 0 else 1) + } +inline var VkRenderPassCreateInfo.subpassCount: Int + get() = VkRenderPassCreateInfo.nsubpassCount(adr) + set(value) = VkRenderPassCreateInfo.nsubpassCount(adr, value) +inline var VkRenderPassCreateInfo.subpasses: VkSubpassDescription.Buffer + get() = VkRenderPassCreateInfo.npSubpasses(adr) + set(value) = VkRenderPassCreateInfo.npSubpasses(adr, value) +/** JVM custom */ +inline var VkRenderPassCreateInfo.subpass: VkSubpassDescription + get() = VkRenderPassCreateInfo.npSubpasses(adr)[0] + set(value) { + memPutAddress(adr + VkRenderPassCreateInfo.PSUBPASSES, value.address()) + VkRenderPassCreateInfo.nsubpassCount(adr, 1) + } +inline var VkRenderPassCreateInfo.dependencyCount: Int + get() = VkRenderPassCreateInfo.ndependencyCount(adr) + set(value) = VkRenderPassCreateInfo.ndependencyCount(adr, value) +inline var VkRenderPassCreateInfo.dependencies: VkSubpassDependency.Buffer? + get() = VkRenderPassCreateInfo.npDependencies(adr) + set(value) = VkRenderPassCreateInfo.npDependencies(adr, value) +/** JVM custom */ +inline var VkRenderPassCreateInfo.dependency: VkSubpassDependency? + get() = VkRenderPassCreateInfo.npDependencies(adr)?.get(0) + set(value) { + memPutAddress(adr + VkRenderPassCreateInfo.PDEPENDENCIES, memAddressSafe(value)) + VkRenderPassCreateInfo.ndependencyCount(adr, if (value == null) 0 else 1) + } + + +inline var VkCommandPoolCreateInfo.type: VkStructureType + get() = VkStructureType of VkCommandPoolCreateInfo.nsType(adr) + set(value) = VkCommandPoolCreateInfo.nsType(adr, value.i) +inline var VkCommandPoolCreateInfo.next + get() = VkCommandPoolCreateInfo.npNext(adr) + set(value) = VkCommandPoolCreateInfo.npNext(adr, value) +/** JVM custom */ +inline var VkCommandPoolCreateInfo.flag: VkCommandPoolCreate + get() = TODO() + set(value) = VkCommandPoolCreateInfo.nflags(adr, value.i) +inline var VkCommandPoolCreateInfo.flags: VkCommandPoolCreateFlags + get() = VkCommandPoolCreateInfo.nflags(adr) + set(value) = VkCommandPoolCreateInfo.nflags(adr, value) +inline var VkCommandPoolCreateInfo.queueFamilyIndex + get() = VkCommandPoolCreateInfo.nqueueFamilyIndex(adr) + set(value) = VkCommandPoolCreateInfo.nqueueFamilyIndex(adr, value) + +//typedef struct VkCommandPoolCreateInfo { +// VkStructureType sType; +// const void* pNext; +// VkCommandPoolCreateFlags flags; +// uint32_t queueFamilyIndex; +//} VkCommandPoolCreateInfo; + +inline var VkCommandBufferAllocateInfo.type: VkStructureType + get() = VkStructureType of VkCommandBufferAllocateInfo.nsType(adr) + set(value) = VkCommandBufferAllocateInfo.nsType(adr, value.i) +var VkCommandBufferAllocateInfo.next + get() = VkCommandBufferAllocateInfo.npNext(adr) + set(value) = VkCommandBufferAllocateInfo.npNext(adr, value) +var VkCommandBufferAllocateInfo.commandPool: VkCommandPool + get() = VkCommandPool(VkCommandBufferAllocateInfo.ncommandPool(adr)) + set(value) = VkCommandBufferAllocateInfo.ncommandPool(adr, value.L) +var VkCommandBufferAllocateInfo.level: VkCommandBufferLevel + get() = VkCommandBufferLevel of VkCommandBufferAllocateInfo.nlevel(adr) + set(value) = VkCommandBufferAllocateInfo.nlevel(adr, value.i) +var VkCommandBufferAllocateInfo.commandBufferCount + get() = VkCommandBufferAllocateInfo.ncommandBufferCount(adr) + set(value) = VkCommandBufferAllocateInfo.ncommandBufferCount(adr, value) + + +//typedef struct VkCommandBufferAllocateInfo { +// VkStructureType sType; +// const void* pNext; +// VkCommandPool commandPool; +// VkCommandBufferLevel level; +// uint32_t commandBufferCount; +//} VkCommandBufferAllocateInfo; +// +//typedef struct VkCommandBufferInheritanceInfo { +// VkStructureType sType; +// const void* pNext; +// VkRenderPass renderPass; +// uint32_t subpass; +// VkFramebuffer framebuffer; +// VkBool32 occlusionQueryEnable; +// VkQueryControlFlags queryFlags; +// VkQueryPipelineStatisticFlags pipelineStatistics; +//} VkCommandBufferInheritanceInfo; +// + +inline var VkCommandBufferBeginInfo.type: VkStructureType + get() = VkStructureType of VkCommandBufferBeginInfo.nsType(adr) + set(value) = VkCommandBufferBeginInfo.nsType(adr, value.i) +inline var VkCommandBufferBeginInfo.next + get() = VkCommandBufferBeginInfo.npNext(adr) + set(value) = VkCommandBufferBeginInfo.npNext(adr, value) +/** JVM custom */ +inline var VkCommandBufferBeginInfo.flag: VkCommandBufferUsage + get() = TODO() + set(value) = VkCommandBufferBeginInfo.nflags(adr, value.i) +inline var VkCommandBufferBeginInfo.flags: VkCommandBufferUsageFlags + get() = VkCommandBufferBeginInfo.nflags(adr) + set(value) = VkCommandBufferBeginInfo.nflags(adr, value) +inline var VkCommandBufferBeginInfo.inheritanceInfo + get() = VkCommandBufferBeginInfo.npInheritanceInfo(adr) + set(value) = VkCommandBufferBeginInfo.npInheritanceInfo(adr, value) + + +inline var VkBufferCopy.srcOffset: VkDeviceSize + get() = VkDeviceSize(VkBufferCopy.nsrcOffset(adr)) + set(value) = VkBufferCopy.nsrcOffset(adr, value.L) +inline var VkBufferCopy.dstOffset: VkDeviceSize + get() = VkDeviceSize(VkBufferCopy.ndstOffset(adr)) + set(value) = VkBufferCopy.ndstOffset(adr, value.L) +inline var VkBufferCopy.size: VkDeviceSize + get() = VkDeviceSize(VkBufferCopy.nsize(adr)) + set(value) = VkBufferCopy.nsize(adr, value.L) + +inline var VkBufferCopy.Buffer.size: VkDeviceSize // TODO remove all .Buffer fields? + get() = VkDeviceSize(size()) + set(value) { + size(value.L) + } + + +inline var VkImageSubresourceLayers.aspectMask: VkImageAspectFlags + get() = VkImageSubresourceLayers.naspectMask(adr) + set(value) = VkImageSubresourceLayers.naspectMask(adr, value) +inline var VkImageSubresourceLayers.mipLevel: Int + get() = VkImageSubresourceLayers.nmipLevel(adr) + set(value) = VkImageSubresourceLayers.nmipLevel(adr, value) +inline var VkImageSubresourceLayers.baseArrayLayer: Int + get() = VkImageSubresourceLayers.nbaseArrayLayer(adr) + set(value) = VkImageSubresourceLayers.nbaseArrayLayer(adr, value) +inline var VkImageSubresourceLayers.layerCount: Int + get() = VkImageSubresourceLayers.nlayerCount(adr) + set(value) = VkImageSubresourceLayers.nlayerCount(adr, value) + + +inline var VkImageCopy.srcSubresource: VkImageSubresourceLayers + get() = VkImageCopy.nsrcSubresource(adr) + set(value) = VkImageCopy.nsrcSubresource(adr, value) +inline var VkImageCopy.srcOffset: VkOffset3D + get() = VkImageCopy.nsrcOffset(adr) + set(value) = VkImageCopy.nsrcOffset(adr, value) +inline var VkImageCopy.dstSubresource: VkImageSubresourceLayers + get() = VkImageCopy.ndstSubresource(adr) + set(value) = VkImageCopy.ndstSubresource(adr, value) +inline var VkImageCopy.dstOffset: VkOffset3D + get() = VkImageCopy.ndstOffset(adr) + set(value) = VkImageCopy.ndstOffset(adr, value) +inline var VkImageCopy.extent: VkExtent3D + get() = VkImageCopy.nextent(adr) + set(value) = VkImageCopy.nextent(adr, value) + + +inline var VkImageBlit.srcSubresource: VkImageSubresourceLayers + get() = VkImageBlit.nsrcSubresource(adr) + set(value) = VkImageBlit.nsrcSubresource(adr, value) +inline var VkImageBlit.srcOffsets: VkOffset3D.Buffer + get() = VkImageBlit.nsrcOffsets(adr) + set(value) = VkImageBlit.nsrcOffsets(adr, value) +inline var VkImageBlit.dstSubresource: VkImageSubresourceLayers + get() = VkImageBlit.ndstSubresource(adr) + set(value) = VkImageBlit.ndstSubresource(adr, value) +inline var VkImageBlit.dstOffsets: VkOffset3D.Buffer + get() = VkImageBlit.ndstOffsets(adr) + set(value) = VkImageBlit.ndstOffsets(adr, value) + + +inline var VkBufferImageCopy.bufferOffset: VkDeviceSize + get() = VkDeviceSize(VkBufferImageCopy.nbufferOffset(adr)) + set(value) = VkBufferImageCopy.nbufferOffset(adr, value.L) +inline var VkBufferImageCopy.bufferRowLength: Int + get() = VkBufferImageCopy.nbufferRowLength(adr) + set(value) = VkBufferImageCopy.nbufferRowLength(adr, value) +inline var VkBufferImageCopy.bufferImageHeight: Int + get() = VkBufferImageCopy.nbufferImageHeight(adr) + set(value) = VkBufferImageCopy.nbufferImageHeight(adr, value) +inline var VkBufferImageCopy.imageSubresource: VkImageSubresourceLayers + get() = VkBufferImageCopy.nimageSubresource(adr) + set(value) = VkBufferImageCopy.nimageSubresource(adr, value) +inline var VkBufferImageCopy.imageOffset: VkOffset3D + get() = VkBufferImageCopy.nimageOffset(adr) + set(value) = VkBufferImageCopy.nimageOffset(adr, value) +inline var VkBufferImageCopy.imageExtent: VkExtent3D + get() = VkBufferImageCopy.nimageExtent(adr) + set(value) = VkBufferImageCopy.nimageExtent(adr, value) + +/** JVM custom */ +fun VkBufferImageCopy.imageExtent(extent: Vec2i, depth: Int) { + imageExtent.apply { + width = extent.x + height = extent.y + this.depth = depth + } +} + +/** JVM custom */ +fun VkBufferImageCopy.imageExtent(extent: Vec3i) { + this.imageExtent.set(extent.x, extent.y, extent.z) +} + +//typedef union VkClearColorValue { +// float float32[4]; +// int32_t int32[4]; +// uint32_t uint32[4]; +//} VkClearColorValue; +// +//typedef struct VkClearDepthStencilValue { +// float depth; +// uint32_t stencil; +//} VkClearDepthStencilValue; + +inline var VkClearValue.color: VkClearColorValue + get() = VkClearValue.ncolor(adr) + set(value) = VkClearValue.ncolor(adr, value) +inline var VkClearValue.depthStencil: VkClearDepthStencilValue + get() = VkClearValue.ndepthStencil(adr) + set(value) = VkClearValue.ndepthStencil(adr, value) + +fun VkClearValue.color(float: Float) = color(float, float, float, float) +fun VkClearValue.color(color: Vec4) = color(color.r, color.g, color.b, color.a) +fun VkClearValue.color(r: Float, g: Float, b: Float, a: Float) { + memPutFloat(adr, r) + memPutFloat(adr + Float.BYTES, g) + memPutFloat(adr + Float.BYTES * 2, b) + memPutFloat(adr + Float.BYTES * 3, a) +} + + +fun VkClearValue.depthStencil(depth: Float, stencil: Int) { + memPutFloat(adr, depth) + memPutInt(adr + Float.BYTES, stencil) +} + +//typedef union VkClearValue { +// VkClearColorValue color; +// VkClearDepthStencilValue depthStencil; +//} VkClearValue; + +//typedef struct VkClearAttachment { +// VkImageAspectFlags aspectMask; +// uint32_t colorAttachment; +// VkClearValue clearValue; +//} VkClearAttachment; +// +//typedef struct VkClearRect { +// VkRect2D rect; +// uint32_t baseArrayLayer; +// uint32_t layerCount; +//} VkClearRect; +// +//typedef struct VkImageResolve { +// VkImageSubresourceLayers srcSubresource; +// VkOffset3D srcOffset; +// VkImageSubresourceLayers dstSubresource; +// VkOffset3D dstOffset; +// VkExtent3D extent; +//} VkImageResolve; +// +//typedef struct VkMemoryBarrier { +// VkStructureType sType; +// const void* pNext; +// VkAccessFlags srcAccessMask; +// VkAccessFlags dstAccessMask; +//} VkMemoryBarrier; + +inline var VkBufferMemoryBarrier.type: VkStructureType + get() = VkStructureType of VkBufferMemoryBarrier.nsType(adr) + set(value) = VkBufferMemoryBarrier.nsType(adr, value.i) +inline var VkBufferMemoryBarrier.next: Long + get() = VkBufferMemoryBarrier.npNext(adr) + set(value) = VkBufferMemoryBarrier.npNext(adr, value) +inline var VkBufferMemoryBarrier.srcAccessMask: VkAccessFlags + get() = VkBufferMemoryBarrier.nsrcAccessMask(adr) + set(value) = VkBufferMemoryBarrier.nsrcAccessMask(adr, value) +inline var VkBufferMemoryBarrier.dstAccessMask: VkAccessFlags + get() = VkBufferMemoryBarrier.ndstAccessMask(adr) + set(value) = VkBufferMemoryBarrier.ndstAccessMask(adr, value) +inline var VkBufferMemoryBarrier.srcQueueFamilyIndex: Int + get() = VkBufferMemoryBarrier.nsrcQueueFamilyIndex(adr) + set(value) = VkBufferMemoryBarrier.nsrcQueueFamilyIndex(adr, value) +inline var VkBufferMemoryBarrier.dstQueueFamilyIndex: Int + get() = VkBufferMemoryBarrier.ndstQueueFamilyIndex(adr) + set(value) = VkBufferMemoryBarrier.ndstQueueFamilyIndex(adr, value) +inline var VkBufferMemoryBarrier.buffer: VkBuffer + get() = VkBuffer(VkBufferMemoryBarrier.nbuffer(adr)) + set(value) = VkBufferMemoryBarrier.nbuffer(adr, value.L) +inline var VkBufferMemoryBarrier.offset: VkDeviceSize + get() = VkDeviceSize(VkBufferMemoryBarrier.noffset(adr)) + set(value) = VkBufferMemoryBarrier.noffset(adr, value.L) +inline var VkBufferMemoryBarrier.size: VkDeviceSize + get() = VkDeviceSize(VkBufferMemoryBarrier.nsize(adr)) + set(value) = VkBufferMemoryBarrier.nsize(adr, value.L) + + +inline var VkImageMemoryBarrier.type: VkStructureType + get() = VkStructureType of VkImageMemoryBarrier.nsType(adr) + set(value) = VkImageMemoryBarrier.nsType(adr, value.i) +inline var VkImageMemoryBarrier.next + get() = VkImageMemoryBarrier.npNext(adr) + set(value) = VkImageMemoryBarrier.npNext(adr, value) +inline var VkImageMemoryBarrier.srcAccessMask: VkAccessFlags + get() = VkImageMemoryBarrier.nsrcAccessMask(adr) + set(value) = VkImageMemoryBarrier.nsrcAccessMask(adr, value) +inline var VkImageMemoryBarrier.dstAccessMask: VkAccessFlags + get() = VkImageMemoryBarrier.ndstAccessMask(adr) + set(value) = VkImageMemoryBarrier.ndstAccessMask(adr, value) +inline var VkImageMemoryBarrier.oldLayout: VkImageLayout + get() = VkImageLayout of VkImageMemoryBarrier.noldLayout(adr) + set(value) = VkImageMemoryBarrier.noldLayout(adr, value.i) +inline var VkImageMemoryBarrier.newLayout: VkImageLayout + get() = VkImageLayout of VkImageMemoryBarrier.nnewLayout(adr) + set(value) = VkImageMemoryBarrier.nnewLayout(adr, value.i) +inline var VkImageMemoryBarrier.srcQueueFamilyIndex + get() = VkImageMemoryBarrier.nsrcQueueFamilyIndex(adr) + set(value) = VkImageMemoryBarrier.nsrcQueueFamilyIndex(adr, value) +inline var VkImageMemoryBarrier.dstQueueFamilyIndex + get() = VkImageMemoryBarrier.ndstQueueFamilyIndex(adr) + set(value) = VkImageMemoryBarrier.ndstQueueFamilyIndex(adr, value) +inline var VkImageMemoryBarrier.image: VkImage + get() = VkImage(VkImageMemoryBarrier.nimage(adr)) + set(value) = VkImageMemoryBarrier.nimage(adr, value.L) +inline var VkImageMemoryBarrier.subresourceRange: VkImageSubresourceRange + get() = VkImageMemoryBarrier.nsubresourceRange(adr) + set(value) = VkImageMemoryBarrier.nsubresourceRange(adr, value) + + +inline var VkRenderPassBeginInfo.type: VkStructureType + get() = VkStructureType of VkRenderPassBeginInfo.nsType(adr) + set(value) = VkRenderPassBeginInfo.nsType(adr, value.i) +inline var VkRenderPassBeginInfo.next + get() = VkRenderPassBeginInfo.npNext(adr) + set(value) = VkRenderPassBeginInfo.npNext(adr, value) +inline var VkRenderPassBeginInfo.renderPass: VkRenderPass + get() = VkRenderPass(VkRenderPassBeginInfo.nrenderPass(adr)) + set(value) = VkRenderPassBeginInfo.nrenderPass(adr, value.L) +inline var VkRenderPassBeginInfo.framebuffer: VkFramebuffer + get() = VkFramebuffer(VkRenderPassBeginInfo.nframebuffer(adr)) + set(value) = VkRenderPassBeginInfo.nframebuffer(adr, value.L) +inline var VkRenderPassBeginInfo.renderArea: VkRect2D + get() = VkRenderPassBeginInfo.nrenderArea(adr) + set(value) = VkRenderPassBeginInfo.nrenderArea(adr, value) +inline val VkRenderPassBeginInfo.clearValueCount get() = clearValueCount() +inline var VkRenderPassBeginInfo.clearValues: VkClearValue.Buffer? + get() = VkRenderPassBeginInfo.npClearValues(adr) + set(value) = VkRenderPassBeginInfo.npClearValues(adr, value) +/** JVM custom */ +inline var VkRenderPassBeginInfo.clearValue: VkClearValue? + get() = VkRenderPassBeginInfo.npClearValues(adr)?.get(0) + set(value) { + memPutAddress(adr + VkRenderPassBeginInfo.PCLEARVALUES, value?.adr ?: NULL) + VkRenderPassBeginInfo.nclearValueCount(adr, if (value == null) 0 else 1) + } + +/** JVM custom */ +fun VkRenderPassBeginInfo.clearValue(vec4: Vec4) { + memPutFloat(adr + VkRenderPassBeginInfo.PCLEARVALUES, vec4.x) + memPutFloat(adr + VkRenderPassBeginInfo.PCLEARVALUES + Float.BYTES, vec4.y) + memPutFloat(adr + VkRenderPassBeginInfo.PCLEARVALUES + Float.BYTES * 2, vec4.z) + memPutFloat(adr + VkRenderPassBeginInfo.PCLEARVALUES + Float.BYTES * 3, vec4.w) + VkRenderPassBeginInfo.nclearValueCount(adr, 1) +} + +//typedef struct VkRenderPassBeginInfo { +// VkStructureType sType; +// const void* pNext; +// VkRenderPass renderPass; +// VkFramebuffer framebuffer; +// VkRect2D renderArea; +// uint32_t clearValueCount; +// const VkClearValue* pClearValues; +//} VkRenderPassBeginInfo; +// +//typedef struct VkDispatchIndirectCommand { +// uint32_t x; +// uint32_t y; +// uint32_t z; +//} VkDispatchIndirectCommand; +// +//typedef struct VkDrawIndexedIndirectCommand { +// uint32_t indexCount; +// uint32_t instanceCount; +// uint32_t firstIndex; +// int32_t vertexOffset; +// uint32_t firstInstance; +//} VkDrawIndexedIndirectCommand; +// +//typedef struct VkDrawIndirectCommand { +// uint32_t vertexCount; +// uint32_t instanceCount; +// uint32_t firstVertex; +// uint32_t firstInstance; +//} VkDrawIndirectCommand; +// +// +//typedef struct VkBaseOutStructure { +// VkStructureType sType; +// struct VkBaseOutStructure* pNext; +//} VkBaseOutStructure; +// +//typedef struct VkBaseInStructure { +// VkStructureType sType; +// const struct VkBaseInStructure* pNext; +//} VkBaseInStructure; +// +//typedef VkResult (VKAPI_PTR *PFN_vkCreateInstance)(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance); +//typedef void (VKAPI_PTR *PFN_vkDestroyInstance)(VkInstance instance, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkEnumeratePhysicalDevices)(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices); +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceFeatures)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures); +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceFormatProperties)(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties); +//typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceImageFormatProperties)(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties); +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceProperties)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties); +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceQueueFamilyProperties)(VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties* pQueueFamilyProperties); +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceMemoryProperties)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties); +//typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vkGetInstanceProcAddr)(VkInstance instance, const char* pName); +//typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vkGetDeviceProcAddr)(VkDevice device, const char* pName); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateDevice)(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice); +//typedef void (VKAPI_PTR *PFN_vkDestroyDevice)(VkDevice device, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkEnumerateInstanceExtensionProperties)(const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties); +//typedef VkResult (VKAPI_PTR *PFN_vkEnumerateDeviceExtensionProperties)(VkPhysicalDevice physicalDevice, const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties); +//typedef VkResult (VKAPI_PTR *PFN_vkEnumerateInstanceLayerProperties)(uint32_t* pPropertyCount, VkLayerProperties* pProperties); +//typedef VkResult (VKAPI_PTR *PFN_vkEnumerateDeviceLayerProperties)(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkLayerProperties* pProperties); +//typedef void (VKAPI_PTR *PFN_vkGetDeviceQueue)(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue); +//typedef VkResult (VKAPI_PTR *PFN_vkQueueSubmit)(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence); +//typedef VkResult (VKAPI_PTR *PFN_vkQueueWaitIdle)(VkQueue queue); +//typedef VkResult (VKAPI_PTR *PFN_vkDeviceWaitIdle)(VkDevice device); +//typedef VkResult (VKAPI_PTR *PFN_vkAllocateMemory)(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory); +//typedef void (VKAPI_PTR *PFN_vkFreeMemory)(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkMapMemory)(VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags, void** ppData); +//typedef void (VKAPI_PTR *PFN_vkUnmapMemory)(VkDevice device, VkDeviceMemory memory); +//typedef VkResult (VKAPI_PTR *PFN_vkFlushMappedMemoryRanges)(VkDevice device, uint32_t memoryRangeCount, const VkMappedMemoryRange* pMemoryRanges); +//typedef VkResult (VKAPI_PTR *PFN_vkInvalidateMappedMemoryRanges)(VkDevice device, uint32_t memoryRangeCount, const VkMappedMemoryRange* pMemoryRanges); +//typedef void (VKAPI_PTR *PFN_vkGetDeviceMemoryCommitment)(VkDevice device, VkDeviceMemory memory, VkDeviceSize* pCommittedMemoryInBytes); +//typedef VkResult (VKAPI_PTR *PFN_vkBindBufferMemory)(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize memoryOffset); +//typedef VkResult (VKAPI_PTR *PFN_vkBindImageMemory)(VkDevice device, VkImage image, VkDeviceMemory memory, VkDeviceSize memoryOffset); +//typedef void (VKAPI_PTR *PFN_vkGetBufferMemoryRequirements)(VkDevice device, VkBuffer buffer, VkMemoryRequirements* pMemoryRequirements); +//typedef void (VKAPI_PTR *PFN_vkGetImageMemoryRequirements)(VkDevice device, VkImage image, VkMemoryRequirements* pMemoryRequirements); +//typedef void (VKAPI_PTR *PFN_vkGetImageSparseMemoryRequirements)(VkDevice device, VkImage image, uint32_t* pSparseMemoryRequirementCount, VkSparseImageMemoryRequirements* pSparseMemoryRequirements); +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceSparseImageFormatProperties)(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pPropertyCount, VkSparseImageFormatProperties* pProperties); +//typedef VkResult (VKAPI_PTR *PFN_vkQueueBindSparse)(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, VkFence fence); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateFence)(VkDevice device, const VkFenceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence); +//typedef void (VKAPI_PTR *PFN_vkDestroyFence)(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkResetFences)(VkDevice device, uint32_t fenceCount, const VkFence* pFences); +//typedef VkResult (VKAPI_PTR *PFN_vkGetFenceStatus)(VkDevice device, VkFence fence); +//typedef VkResult (VKAPI_PTR *PFN_vkWaitForFences)(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateSemaphore)(VkDevice device, const VkSemaphoreCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSemaphore* pSemaphore); +//typedef void (VKAPI_PTR *PFN_vkDestroySemaphore)(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateEvent)(VkDevice device, const VkEventCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkEvent* pEvent); +//typedef void (VKAPI_PTR *PFN_vkDestroyEvent)(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkGetEventStatus)(VkDevice device, VkEvent event); +//typedef VkResult (VKAPI_PTR *PFN_vkSetEvent)(VkDevice device, VkEvent event); +//typedef VkResult (VKAPI_PTR *PFN_vkResetEvent)(VkDevice device, VkEvent event); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateQueryPool)(VkDevice device, const VkQueryPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkQueryPool* pQueryPool); +//typedef void (VKAPI_PTR *PFN_vkDestroyQueryPool)(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkGetQueryPoolResults)(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateBuffer)(VkDevice device, const VkBufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer); +//typedef void (VKAPI_PTR *PFN_vkDestroyBuffer)(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateBufferView)(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBufferView* pView); +//typedef void (VKAPI_PTR *PFN_vkDestroyBufferView)(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateImage)(VkDevice device, const VkImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImage* pImage); +//typedef void (VKAPI_PTR *PFN_vkDestroyImage)(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator); +//typedef void (VKAPI_PTR *PFN_vkGetImageSubresourceLayout)(VkDevice device, VkImage image, const VkImageSubresource* pSubresource, VkSubresourceLayout* pLayout); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateImageView)(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImageView* pView); +//typedef void (VKAPI_PTR *PFN_vkDestroyImageView)(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateShaderModule)(VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule); +//typedef void (VKAPI_PTR *PFN_vkDestroyShaderModule)(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkCreatePipelineCache)(VkDevice device, const VkPipelineCacheCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineCache* pPipelineCache); +//typedef void (VKAPI_PTR *PFN_vkDestroyPipelineCache)(VkDevice device, VkPipelineCache pipelineCache, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkGetPipelineCacheData)(VkDevice device, VkPipelineCache pipelineCache, size_t* pDataSize, void* pData); +//typedef VkResult (VKAPI_PTR *PFN_vkMergePipelineCaches)(VkDevice device, VkPipelineCache dstCache, uint32_t srcCacheCount, const VkPipelineCache* pSrcCaches); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateGraphicsPipelines)(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, const VkGraphicsPipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateComputePipelines)(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, const VkComputePipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines); +//typedef void (VKAPI_PTR *PFN_vkDestroyPipeline)(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkCreatePipelineLayout)(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout); +//typedef void (VKAPI_PTR *PFN_vkDestroyPipelineLayout)(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateSampler)(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSampler* pSampler); +//typedef void (VKAPI_PTR *PFN_vkDestroySampler)(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateDescriptorSetLayout)(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorSetLayout* pSetLayout); +//typedef void (VKAPI_PTR *PFN_vkDestroyDescriptorSetLayout)(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateDescriptorPool)(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorPool* pDescriptorPool); +//typedef void (VKAPI_PTR *PFN_vkDestroyDescriptorPool)(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkResetDescriptorPool)(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags); +//typedef VkResult (VKAPI_PTR *PFN_vkAllocateDescriptorSets)(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets); +//typedef VkResult (VKAPI_PTR *PFN_vkFreeDescriptorSets)(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount, const VkDescriptorSet* pDescriptorSets); +//typedef void (VKAPI_PTR *PFN_vkUpdateDescriptorSets)(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pDescriptorCopies); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateFramebuffer)(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer); +//typedef void (VKAPI_PTR *PFN_vkDestroyFramebuffer)(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateRenderPass)(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass); +//typedef void (VKAPI_PTR *PFN_vkDestroyRenderPass)(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator); +//typedef void (VKAPI_PTR *PFN_vkGetRenderAreaGranularity)(VkDevice device, VkRenderPass renderPass, VkExtent2D* pGranularity); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateCommandPool)(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool); +//typedef void (VKAPI_PTR *PFN_vkDestroyCommandPool)(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkResetCommandPool)(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags); +//typedef VkResult (VKAPI_PTR *PFN_vkAllocateCommandBuffers)(VkDevice device, const VkCommandBufferAllocateInfo* pAllocateInfo, VkCommandBuffer* pCommandBuffers); +//typedef void (VKAPI_PTR *PFN_vkFreeCommandBuffers)(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers); +//typedef VkResult (VKAPI_PTR *PFN_vkBeginCommandBuffer)(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo); +//typedef VkResult (VKAPI_PTR *PFN_vkEndCommandBuffer)(VkCommandBuffer commandBuffer); +//typedef VkResult (VKAPI_PTR *PFN_vkResetCommandBuffer)(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags); +//typedef void (VKAPI_PTR *PFN_vkCmdBindPipeline)(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline); +//typedef void (VKAPI_PTR *PFN_vkCmdSetViewport)(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount, const VkViewport* pViewports); +//typedef void (VKAPI_PTR *PFN_vkCmdSetScissor)(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D* pScissors); +//typedef void (VKAPI_PTR *PFN_vkCmdSetLineWidth)(VkCommandBuffer commandBuffer, float lineWidth); +//typedef void (VKAPI_PTR *PFN_vkCmdSetDepthBias)(VkCommandBuffer commandBuffer, float depthBiasConstantFactor, float depthBiasClamp, float depthBiasSlopeFactor); +//typedef void (VKAPI_PTR *PFN_vkCmdSetBlendConstants)(VkCommandBuffer commandBuffer, const float blendConstants[4]); +//typedef void (VKAPI_PTR *PFN_vkCmdSetDepthBounds)(VkCommandBuffer commandBuffer, float minDepthBounds, float maxDepthBounds); +//typedef void (VKAPI_PTR *PFN_vkCmdSetStencilCompareMask)(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t compareMask); +//typedef void (VKAPI_PTR *PFN_vkCmdSetStencilWriteMask)(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t writeMask); +//typedef void (VKAPI_PTR *PFN_vkCmdSetStencilReference)(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t reference); +//typedef void (VKAPI_PTR *PFN_vkCmdBindDescriptorSets)(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t firstSet, uint32_t descriptorSetCount, const VkDescriptorSet* pDescriptorSets, uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets); +//typedef void (VKAPI_PTR *PFN_vkCmdBindIndexBuffer)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType); +//typedef void (VKAPI_PTR *PFN_vkCmdBindVertexBuffers)(VkCommandBuffer commandBuffer, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers, const VkDeviceSize* pOffsets); +//typedef void (VKAPI_PTR *PFN_vkCmdDraw)(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance); +//typedef void (VKAPI_PTR *PFN_vkCmdDrawIndexed)(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance); +//typedef void (VKAPI_PTR *PFN_vkCmdDrawIndirect)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride); +//typedef void (VKAPI_PTR *PFN_vkCmdDrawIndexedIndirect)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride); +//typedef void (VKAPI_PTR *PFN_vkCmdDispatch)(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ); +//typedef void (VKAPI_PTR *PFN_vkCmdDispatchIndirect)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset); +//typedef void (VKAPI_PTR *PFN_vkCmdCopyBuffer)(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferCopy* pRegions); +//typedef void (VKAPI_PTR *PFN_vkCmdCopyImage)(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy* pRegions); +//typedef void (VKAPI_PTR *PFN_vkCmdBlitImage)(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit* pRegions, VkFilter filter); +//typedef void (VKAPI_PTR *PFN_vkCmdCopyBufferToImage)(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkBufferImageCopy* pRegions); +//typedef void (VKAPI_PTR *PFN_vkCmdCopyImageToBuffer)(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy* pRegions); +//typedef void (VKAPI_PTR *PFN_vkCmdUpdateBuffer)(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const void* pData); +//typedef void (VKAPI_PTR *PFN_vkCmdFillBuffer)(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data); +//typedef void (VKAPI_PTR *PFN_vkCmdClearColorImage)(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearColorValue* pColor, uint32_t rangeCount, const VkImageSubresourceRange* pRanges); +//typedef void (VKAPI_PTR *PFN_vkCmdClearDepthStencilImage)(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue* pDepthStencil, uint32_t rangeCount, const VkImageSubresourceRange* pRanges); +//typedef void (VKAPI_PTR *PFN_vkCmdClearAttachments)(VkCommandBuffer commandBuffer, uint32_t attachmentCount, const VkClearAttachment* pAttachments, uint32_t rectCount, const VkClearRect* pRects); +//typedef void (VKAPI_PTR *PFN_vkCmdResolveImage)(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageResolve* pRegions); +//typedef void (VKAPI_PTR *PFN_vkCmdSetEvent)(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask); +//typedef void (VKAPI_PTR *PFN_vkCmdResetEvent)(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask); +//typedef void (VKAPI_PTR *PFN_vkCmdWaitEvents)(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers); +//typedef void (VKAPI_PTR *PFN_vkCmdPipelineBarrier)(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers); +//typedef void (VKAPI_PTR *PFN_vkCmdBeginQuery)(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t query, VkQueryControlFlags flags); +//typedef void (VKAPI_PTR *PFN_vkCmdEndQuery)(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t query); +//typedef void (VKAPI_PTR *PFN_vkCmdResetQueryPool)(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount); +//typedef void (VKAPI_PTR *PFN_vkCmdWriteTimestamp)(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t query); +//typedef void (VKAPI_PTR *PFN_vkCmdCopyQueryPoolResults)(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize stride, VkQueryResultFlags flags); +//typedef void (VKAPI_PTR *PFN_vkCmdPushConstants)(VkCommandBuffer commandBuffer, VkPipelineLayout layout, VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size, const void* pValues); +//typedef void (VKAPI_PTR *PFN_vkCmdBeginRenderPass)(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, VkSubpassContents contents); +//typedef void (VKAPI_PTR *PFN_vkCmdNextSubpass)(VkCommandBuffer commandBuffer, VkSubpassContents contents); +//typedef void (VKAPI_PTR *PFN_vkCmdEndRenderPass)(VkCommandBuffer commandBuffer); +//typedef void (VKAPI_PTR *PFN_vkCmdExecuteCommands)(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance( +//const VkInstanceCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkInstance* pInstance); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyInstance( +//VkInstance instance, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices( +//VkInstance instance, +//uint32_t* pPhysicalDeviceCount, +//VkPhysicalDevice* pPhysicalDevices); +// +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures( +//VkPhysicalDevice physicalDevice, +//VkPhysicalDeviceFeatures* pFeatures); +// +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFormatProperties( +//VkPhysicalDevice physicalDevice, +//VkFormat format, +//VkFormatProperties* pFormatProperties); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceImageFormatProperties( +//VkPhysicalDevice physicalDevice, +//VkFormat format, +//VkImageType type, +//VkImageTiling tiling, +//VkImageUsageFlags usage, +//VkImageCreateFlags flags, +//VkImageFormatProperties* pImageFormatProperties); +// +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties( +//VkPhysicalDevice physicalDevice, +//VkPhysicalDeviceProperties* pProperties); +// +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceQueueFamilyProperties( +//VkPhysicalDevice physicalDevice, +//uint32_t* pQueueFamilyPropertyCount, +//VkQueueFamilyProperties* pQueueFamilyProperties); +// +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties( +//VkPhysicalDevice physicalDevice, +//VkPhysicalDeviceMemoryProperties* pMemoryProperties); +// +//VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr( +//VkInstance instance, +//const char* pName); +// +//VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr( +//VkDevice device, +//const char* pName); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice( +//VkPhysicalDevice physicalDevice, +//const VkDeviceCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkDevice* pDevice); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyDevice( +//VkDevice device, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties( +//const char* pLayerName, +//uint32_t* pPropertyCount, +//VkExtensionProperties* pProperties); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties( +//VkPhysicalDevice physicalDevice, +//const char* pLayerName, +//uint32_t* pPropertyCount, +//VkExtensionProperties* pProperties); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties( +//uint32_t* pPropertyCount, +//VkLayerProperties* pProperties); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties( +//VkPhysicalDevice physicalDevice, +//uint32_t* pPropertyCount, +//VkLayerProperties* pProperties); +// +//VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue( +//VkDevice device, +//uint32_t queueFamilyIndex, +//uint32_t queueIndex, +//VkQueue* pQueue); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit( +//VkQueue queue, +//uint32_t submitCount, +//const VkSubmitInfo* pSubmits, +//VkFence fence); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle( +//VkQueue queue); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle( +//VkDevice device); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkAllocateMemory( +//VkDevice device, +//const VkMemoryAllocateInfo* pAllocateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkDeviceMemory* pMemory); +// +//VKAPI_ATTR void VKAPI_CALL vkFreeMemory( +//VkDevice device, +//VkDeviceMemory memory, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory( +//VkDevice device, +//VkDeviceMemory memory, +//VkDeviceSize offset, +//VkDeviceSize size, +//VkMemoryMapFlags flags, +//void** ppData); +// +//VKAPI_ATTR void VKAPI_CALL vkUnmapMemory( +//VkDevice device, +//VkDeviceMemory memory); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkFlushMappedMemoryRanges( +//VkDevice device, +//uint32_t memoryRangeCount, +//const VkMappedMemoryRange* pMemoryRanges); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkInvalidateMappedMemoryRanges( +//VkDevice device, +//uint32_t memoryRangeCount, +//const VkMappedMemoryRange* pMemoryRanges); +// +//VKAPI_ATTR void VKAPI_CALL vkGetDeviceMemoryCommitment( +//VkDevice device, +//VkDeviceMemory memory, +//VkDeviceSize* pCommittedMemoryInBytes); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkBindBufferMemory( +//VkDevice device, +//VkBuffer buffer, +//VkDeviceMemory memory, +//VkDeviceSize memoryOffset); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory( +//VkDevice device, +//VkImage image, +//VkDeviceMemory memory, +//VkDeviceSize memoryOffset); +// +//VKAPI_ATTR void VKAPI_CALL vkGetBufferMemoryRequirements( +//VkDevice device, +//VkBuffer buffer, +//VkMemoryRequirements* pMemoryRequirements); +// +//VKAPI_ATTR void VKAPI_CALL vkGetImageMemoryRequirements( +//VkDevice device, +//VkImage image, +//VkMemoryRequirements* pMemoryRequirements); +// +//VKAPI_ATTR void VKAPI_CALL vkGetImageSparseMemoryRequirements( +//VkDevice device, +//VkImage image, +//uint32_t* pSparseMemoryRequirementCount, +//VkSparseImageMemoryRequirements* pSparseMemoryRequirements); +// +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceSparseImageFormatProperties( +//VkPhysicalDevice physicalDevice, +//VkFormat format, +//VkImageType type, +//VkSampleCountFlagBits samples, +//VkImageUsageFlags usage, +//VkImageTiling tiling, +//uint32_t* pPropertyCount, +//VkSparseImageFormatProperties* pProperties); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse( +//VkQueue queue, +//uint32_t bindInfoCount, +//const VkBindSparseInfo* pBindInfo, +//VkFence fence); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateFence( +//VkDevice device, +//const VkFenceCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkFence* pFence); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyFence( +//VkDevice device, +//VkFence fence, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkResetFences( +//VkDevice device, +//uint32_t fenceCount, +//const VkFence* pFences); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus( +//VkDevice device, +//VkFence fence); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences( +//VkDevice device, +//uint32_t fenceCount, +//const VkFence* pFences, +//VkBool32 waitAll, +//uint64_t timeout); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore( +//VkDevice device, +//const VkSemaphoreCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkSemaphore* pSemaphore); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore( +//VkDevice device, +//VkSemaphore semaphore, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateEvent( +//VkDevice device, +//const VkEventCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkEvent* pEvent); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyEvent( +//VkDevice device, +//VkEvent event, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetEventStatus( +//VkDevice device, +//VkEvent event); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent( +//VkDevice device, +//VkEvent event); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkResetEvent( +//VkDevice device, +//VkEvent event); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateQueryPool( +//VkDevice device, +//const VkQueryPoolCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkQueryPool* pQueryPool); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool( +//VkDevice device, +//VkQueryPool queryPool, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults( +//VkDevice device, +//VkQueryPool queryPool, +//uint32_t firstQuery, +//uint32_t queryCount, +//size_t dataSize, +//void* pData, +//VkDeviceSize stride, +//VkQueryResultFlags flags); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateBuffer( +//VkDevice device, +//const VkBufferCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkBuffer* pBuffer); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer( +//VkDevice device, +//VkBuffer buffer, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateBufferView( +//VkDevice device, +//const VkBufferViewCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkBufferView* pView); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView( +//VkDevice device, +//VkBufferView bufferView, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage( +//VkDevice device, +//const VkImageCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkImage* pImage); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyImage( +//VkDevice device, +//VkImage image, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR void VKAPI_CALL vkGetImageSubresourceLayout( +//VkDevice device, +//VkImage image, +//const VkImageSubresource* pSubresource, +//VkSubresourceLayout* pLayout); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView( +//VkDevice device, +//const VkImageViewCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkImageView* pView); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyImageView( +//VkDevice device, +//VkImageView imageView, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule( +//VkDevice device, +//const VkShaderModuleCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkShaderModule* pShaderModule); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule( +//VkDevice device, +//VkShaderModule shaderModule, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache( +//VkDevice device, +//const VkPipelineCacheCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkPipelineCache* pPipelineCache); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache( +//VkDevice device, +//VkPipelineCache pipelineCache, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData( +//VkDevice device, +//VkPipelineCache pipelineCache, +//size_t* pDataSize, +//void* pData); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches( +//VkDevice device, +//VkPipelineCache dstCache, +//uint32_t srcCacheCount, +//const VkPipelineCache* pSrcCaches); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines( +//VkDevice device, +//VkPipelineCache pipelineCache, +//uint32_t createInfoCount, +//const VkGraphicsPipelineCreateInfo* pCreateInfos, +//const VkAllocationCallbacks* pAllocator, +//VkPipeline* pPipelines); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines( +//VkDevice device, +//VkPipelineCache pipelineCache, +//uint32_t createInfoCount, +//const VkComputePipelineCreateInfo* pCreateInfos, +//const VkAllocationCallbacks* pAllocator, +//VkPipeline* pPipelines); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline( +//VkDevice device, +//VkPipeline pipeline, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout( +//VkDevice device, +//const VkPipelineLayoutCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkPipelineLayout* pPipelineLayout); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout( +//VkDevice device, +//VkPipelineLayout pipelineLayout, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateSampler( +//VkDevice device, +//const VkSamplerCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkSampler* pSampler); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroySampler( +//VkDevice device, +//VkSampler sampler, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorSetLayout( +//VkDevice device, +//const VkDescriptorSetLayoutCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkDescriptorSetLayout* pSetLayout); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout( +//VkDevice device, +//VkDescriptorSetLayout descriptorSetLayout, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorPool( +//VkDevice device, +//const VkDescriptorPoolCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkDescriptorPool* pDescriptorPool); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool( +//VkDevice device, +//VkDescriptorPool descriptorPool, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool( +//VkDevice device, +//VkDescriptorPool descriptorPool, +//VkDescriptorPoolResetFlags flags); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets( +//VkDevice device, +//const VkDescriptorSetAllocateInfo* pAllocateInfo, +//VkDescriptorSet* pDescriptorSets); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkFreeDescriptorSets( +//VkDevice device, +//VkDescriptorPool descriptorPool, +//uint32_t descriptorSetCount, +//const VkDescriptorSet* pDescriptorSets); +// +//VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSets( +//VkDevice device, +//uint32_t descriptorWriteCount, +//const VkWriteDescriptorSet* pDescriptorWrites, +//uint32_t descriptorCopyCount, +//const VkCopyDescriptorSet* pDescriptorCopies); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateFramebuffer( +//VkDevice device, +//const VkFramebufferCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkFramebuffer* pFramebuffer); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer( +//VkDevice device, +//VkFramebuffer framebuffer, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass( +//VkDevice device, +//const VkRenderPassCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkRenderPass* pRenderPass); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass( +//VkDevice device, +//VkRenderPass renderPass, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR void VKAPI_CALL vkGetRenderAreaGranularity( +//VkDevice device, +//VkRenderPass renderPass, +//VkExtent2D* pGranularity); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool( +//VkDevice device, +//const VkCommandPoolCreateInfo* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkCommandPool* pCommandPool); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool( +//VkDevice device, +//VkCommandPool commandPool, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool( +//VkDevice device, +//VkCommandPool commandPool, +//VkCommandPoolResetFlags flags); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers( +//VkDevice device, +//const VkCommandBufferAllocateInfo* pAllocateInfo, +//VkCommandBuffer* pCommandBuffers); +// +//VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers( +//VkDevice device, +//VkCommandPool commandPool, +//uint32_t commandBufferCount, +//const VkCommandBuffer* pCommandBuffers); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer( +//VkCommandBuffer commandBuffer, +//const VkCommandBufferBeginInfo* pBeginInfo); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer( +//VkCommandBuffer commandBuffer); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer( +//VkCommandBuffer commandBuffer, +//VkCommandBufferResetFlags flags); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline( +//VkCommandBuffer commandBuffer, +//VkPipelineBindPoint pipelineBindPoint, +//VkPipeline pipeline); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport( +//VkCommandBuffer commandBuffer, +//uint32_t firstViewport, +//uint32_t viewportCount, +//const VkViewport* pViewports); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor( +//VkCommandBuffer commandBuffer, +//uint32_t firstScissor, +//uint32_t scissorCount, +//const VkRect2D* pScissors); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth( +//VkCommandBuffer commandBuffer, +//float lineWidth); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias( +//VkCommandBuffer commandBuffer, +//float depthBiasConstantFactor, +//float depthBiasClamp, +//float depthBiasSlopeFactor); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants( +//VkCommandBuffer commandBuffer, +//const float blendConstants[4]); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds( +//VkCommandBuffer commandBuffer, +//float minDepthBounds, +//float maxDepthBounds); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask( +//VkCommandBuffer commandBuffer, +//VkStencilFaceFlags faceMask, +//uint32_t compareMask); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask( +//VkCommandBuffer commandBuffer, +//VkStencilFaceFlags faceMask, +//uint32_t writeMask); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference( +//VkCommandBuffer commandBuffer, +//VkStencilFaceFlags faceMask, +//uint32_t reference); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdBindDescriptorSets( +//VkCommandBuffer commandBuffer, +//VkPipelineBindPoint pipelineBindPoint, +//VkPipelineLayout layout, +//uint32_t firstSet, +//uint32_t descriptorSetCount, +//const VkDescriptorSet* pDescriptorSets, +//uint32_t dynamicOffsetCount, +//const uint32_t* pDynamicOffsets); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer( +//VkCommandBuffer commandBuffer, +//VkBuffer buffer, +//VkDeviceSize offset, +//VkIndexType indexType); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers( +//VkCommandBuffer commandBuffer, +//uint32_t firstBinding, +//uint32_t bindingCount, +//const VkBuffer* pBuffers, +//const VkDeviceSize* pOffsets); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdDraw( +//VkCommandBuffer commandBuffer, +//uint32_t vertexCount, +//uint32_t instanceCount, +//uint32_t firstVertex, +//uint32_t firstInstance); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexed( +//VkCommandBuffer commandBuffer, +//uint32_t indexCount, +//uint32_t instanceCount, +//uint32_t firstIndex, +//int32_t vertexOffset, +//uint32_t firstInstance); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirect( +//VkCommandBuffer commandBuffer, +//VkBuffer buffer, +//VkDeviceSize offset, +//uint32_t drawCount, +//uint32_t stride); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirect( +//VkCommandBuffer commandBuffer, +//VkBuffer buffer, +//VkDeviceSize offset, +//uint32_t drawCount, +//uint32_t stride); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdDispatch( +//VkCommandBuffer commandBuffer, +//uint32_t groupCountX, +//uint32_t groupCountY, +//uint32_t groupCountZ); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect( +//VkCommandBuffer commandBuffer, +//VkBuffer buffer, +//VkDeviceSize offset); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdCopyBuffer( +//VkCommandBuffer commandBuffer, +//VkBuffer srcBuffer, +//VkBuffer dstBuffer, +//uint32_t regionCount, +//const VkBufferCopy* pRegions); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage( +//VkCommandBuffer commandBuffer, +//VkImage srcImage, +//VkImageLayout srcImageLayout, +//VkImage dstImage, +//VkImageLayout dstImageLayout, +//uint32_t regionCount, +//const VkImageCopy* pRegions); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage( +//VkCommandBuffer commandBuffer, +//VkImage srcImage, +//VkImageLayout srcImageLayout, +//VkImage dstImage, +//VkImageLayout dstImageLayout, +//uint32_t regionCount, +//const VkImageBlit* pRegions, +//VkFilter filter); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage( +//VkCommandBuffer commandBuffer, +//VkBuffer srcBuffer, +//VkImage dstImage, +//VkImageLayout dstImageLayout, +//uint32_t regionCount, +//const VkBufferImageCopy* pRegions); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer( +//VkCommandBuffer commandBuffer, +//VkImage srcImage, +//VkImageLayout srcImageLayout, +//VkBuffer dstBuffer, +//uint32_t regionCount, +//const VkBufferImageCopy* pRegions); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer( +//VkCommandBuffer commandBuffer, +//VkBuffer dstBuffer, +//VkDeviceSize dstOffset, +//VkDeviceSize dataSize, +//const void* pData); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdFillBuffer( +//VkCommandBuffer commandBuffer, +//VkBuffer dstBuffer, +//VkDeviceSize dstOffset, +//VkDeviceSize size, +//uint32_t data); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage( +//VkCommandBuffer commandBuffer, +//VkImage image, +//VkImageLayout imageLayout, +//const VkClearColorValue* pColor, +//uint32_t rangeCount, +//const VkImageSubresourceRange* pRanges); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage( +//VkCommandBuffer commandBuffer, +//VkImage image, +//VkImageLayout imageLayout, +//const VkClearDepthStencilValue* pDepthStencil, +//uint32_t rangeCount, +//const VkImageSubresourceRange* pRanges); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments( +//VkCommandBuffer commandBuffer, +//uint32_t attachmentCount, +//const VkClearAttachment* pAttachments, +//uint32_t rectCount, +//const VkClearRect* pRects); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage( +//VkCommandBuffer commandBuffer, +//VkImage srcImage, +//VkImageLayout srcImageLayout, +//VkImage dstImage, +//VkImageLayout dstImageLayout, +//uint32_t regionCount, +//const VkImageResolve* pRegions); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent( +//VkCommandBuffer commandBuffer, +//VkEvent event, +//VkPipelineStageFlags stageMask); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent( +//VkCommandBuffer commandBuffer, +//VkEvent event, +//VkPipelineStageFlags stageMask); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents( +//VkCommandBuffer commandBuffer, +//uint32_t eventCount, +//const VkEvent* pEvents, +//VkPipelineStageFlags srcStageMask, +//VkPipelineStageFlags dstStageMask, +//uint32_t memoryBarrierCount, +//const VkMemoryBarrier* pMemoryBarriers, +//uint32_t bufferMemoryBarrierCount, +//const VkBufferMemoryBarrier* pBufferMemoryBarriers, +//uint32_t imageMemoryBarrierCount, +//const VkImageMemoryBarrier* pImageMemoryBarriers); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier( +//VkCommandBuffer commandBuffer, +//VkPipelineStageFlags srcStageMask, +//VkPipelineStageFlags dstStageMask, +//VkDependencyFlags dependencyFlags, +//uint32_t memoryBarrierCount, +//const VkMemoryBarrier* pMemoryBarriers, +//uint32_t bufferMemoryBarrierCount, +//const VkBufferMemoryBarrier* pBufferMemoryBarriers, +//uint32_t imageMemoryBarrierCount, +//const VkImageMemoryBarrier* pImageMemoryBarriers); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery( +//VkCommandBuffer commandBuffer, +//VkQueryPool queryPool, +//uint32_t query, +//VkQueryControlFlags flags); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery( +//VkCommandBuffer commandBuffer, +//VkQueryPool queryPool, +//uint32_t query); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdResetQueryPool( +//VkCommandBuffer commandBuffer, +//VkQueryPool queryPool, +//uint32_t firstQuery, +//uint32_t queryCount); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp( +//VkCommandBuffer commandBuffer, +//VkPipelineStageFlagBits pipelineStage, +//VkQueryPool queryPool, +//uint32_t query); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults( +//VkCommandBuffer commandBuffer, +//VkQueryPool queryPool, +//uint32_t firstQuery, +//uint32_t queryCount, +//VkBuffer dstBuffer, +//VkDeviceSize dstOffset, +//VkDeviceSize stride, +//VkQueryResultFlags flags); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdPushConstants( +//VkCommandBuffer commandBuffer, +//VkPipelineLayout layout, +//VkShaderStageFlags stageFlags, +//uint32_t offset, +//uint32_t size, +//const void* pValues); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass( +//VkCommandBuffer commandBuffer, +//const VkRenderPassBeginInfo* pRenderPassBegin, +//VkSubpassContents contents); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass( +//VkCommandBuffer commandBuffer, +//VkSubpassContents contents); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass( +//VkCommandBuffer commandBuffer); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands( +//VkCommandBuffer commandBuffer, +//uint32_t commandBufferCount, +//const VkCommandBuffer* pCommandBuffers); +//#endif +// +//#define VK_KHR_surface 1 +//VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSurfaceKHR) +// +//#define VK_KHR_SURFACE_SPEC_VERSION 25 +//#define VK_KHR_SURFACE_EXTENSION_NAME "VK_KHR_surface" +//#define VK_COLORSPACE_SRGB_NONLINEAR_KHR VK_COLOR_SPACE_SRGB_NONLINEAR_KHR +// +// + + +inline val VkSurfaceCapabilitiesKHR.minImageCount get() = VkSurfaceCapabilitiesKHR.nminImageCount(adr) +inline val VkSurfaceCapabilitiesKHR.maxImageCount get() = VkSurfaceCapabilitiesKHR.nmaxImageCount(adr) +inline val VkSurfaceCapabilitiesKHR.currentExtent: VkExtent2D get() = VkSurfaceCapabilitiesKHR.ncurrentExtent(adr) +inline val VkSurfaceCapabilitiesKHR.minImageExtent: VkExtent2D get() = VkSurfaceCapabilitiesKHR.nminImageExtent(adr) +inline val VkSurfaceCapabilitiesKHR.maxImageExtent: VkExtent2D get() = VkSurfaceCapabilitiesKHR.nmaxImageExtent(adr) +inline val VkSurfaceCapabilitiesKHR.maxImageArrayLayers get() = VkSurfaceCapabilitiesKHR.nmaxImageArrayLayers(adr) +inline val VkSurfaceCapabilitiesKHR.supportedTransforms: VkSurfaceTransformFlagsKHR get() = VkSurfaceCapabilitiesKHR.nsupportedTransforms(adr) +inline val VkSurfaceCapabilitiesKHR.currentTransform: VkSurfaceTransform get() = VkSurfaceTransform of VkSurfaceCapabilitiesKHR.ncurrentTransform(adr) +inline val VkSurfaceCapabilitiesKHR.supportedCompositeAlpha: VkCompositeAlphaFlagsKHR get() = VkSurfaceCapabilitiesKHR.nsupportedCompositeAlpha(adr) +inline val VkSurfaceCapabilitiesKHR.supportedUsageFlags: VkImageUsageFlags get() = VkSurfaceCapabilitiesKHR.nsupportedUsageFlags(adr) + +//typedef struct VkSurfaceCapabilitiesKHR { +// uint32_t minImageCount; +// uint32_t maxImageCount; +// VkExtent2D currentExtent; +// VkExtent2D minImageExtent; +// VkExtent2D maxImageExtent; +// uint32_t maxImageArrayLayers; +// VkSurfaceTransformFlagsKHR supportedTransforms; +// VkSurfaceTransformFlagBitsKHR currentTransform; +// VkCompositeAlphaFlagsKHR supportedCompositeAlpha; +// VkImageUsageFlags supportedUsageFlags; +//} VkSurfaceCapabilitiesKHR; + +inline var VkSurfaceFormatKHR.format: VkFormat + get() = VkFormat of VkSurfaceFormatKHR.nformat(adr) + set(value) = memPutInt(adr + VkSurfaceFormatKHR.FORMAT, value.i) +inline var VkSurfaceFormatKHR.colorSpace: VkColorSpace + get() = VkColorSpace of VkSurfaceFormatKHR.ncolorSpace(adr) + set(value) = memPutInt(adr + VkSurfaceFormatKHR.COLORSPACE, value.i) + +operator fun VkSurfaceFormatKHR.invoke(surfaceFormatKHR: VkSurfaceFormatKHR) { + format = surfaceFormatKHR.format + colorSpace = surfaceFormatKHR.colorSpace +} +// +//typedef void (VKAPI_PTR *PFN_vkDestroySurfaceKHR)(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, VkSurfaceKHR surface, VkBool32* pSupported); +//typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR* pSurfaceCapabilities); +//typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceFormatsKHR)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pSurfaceFormatCount, VkSurfaceFormatKHR* pSurfaceFormats); +//typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfacePresentModesKHR)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pPresentModeCount, VkPresentModeKHR* pPresentModes); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR( +//VkInstance instance, +//VkSurfaceKHR surface, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR( +//VkPhysicalDevice physicalDevice, +//uint32_t queueFamilyIndex, +//VkSurfaceKHR surface, +//VkBool32* pSupported); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR( +//VkPhysicalDevice physicalDevice, +//VkSurfaceKHR surface, +//VkSurfaceCapabilitiesKHR* pSurfaceCapabilities); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR( +//VkPhysicalDevice physicalDevice, +//VkSurfaceKHR surface, +//uint32_t* pSurfaceFormatCount, +//VkSurfaceFormatKHR* pSurfaceFormats); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR( +//VkPhysicalDevice physicalDevice, +//VkSurfaceKHR surface, +//uint32_t* pPresentModeCount, +//VkPresentModeKHR* pPresentModes); +//#endif +// +//#define VK_KHR_swapchain 1 +//VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSwapchainKHR) +// +//#define VK_KHR_SWAPCHAIN_SPEC_VERSION 68 +//#define VK_KHR_SWAPCHAIN_EXTENSION_NAME "VK_KHR_swapchain" + + +inline var VkSwapchainCreateInfoKHR.type: VkStructureType + get() = VkStructureType of VkSwapchainCreateInfoKHR.nsType(adr) + set(value) = VkSwapchainCreateInfoKHR.nsType(adr, value.i) +inline var VkSwapchainCreateInfoKHR.next: Long + get() = VkSwapchainCreateInfoKHR.npNext(adr) + set(value) = VkSwapchainCreateInfoKHR.npNext(adr, value) +inline var VkSwapchainCreateInfoKHR.flags: VkSwapchainCreateFlagsKHR + get() = VkSwapchainCreateInfoKHR.nflags(adr) + set(value) = VkSwapchainCreateInfoKHR.nflags(adr, value) +inline var VkSwapchainCreateInfoKHR.surface: VkSurface + get() = VkSurface(VkSwapchainCreateInfoKHR.nsurface(adr)) + set(value) = VkSwapchainCreateInfoKHR.nsurface(adr, value.L) +inline var VkSwapchainCreateInfoKHR.minImageCount + get() = VkSwapchainCreateInfoKHR.nminImageCount(adr) + set(value) = VkSwapchainCreateInfoKHR.nminImageCount(adr, value) +inline var VkSwapchainCreateInfoKHR.imageFormat: VkFormat + get() = VkFormat of VkSwapchainCreateInfoKHR.nimageFormat(adr) + set(value) = VkSwapchainCreateInfoKHR.nimageFormat(adr, value.i) +inline var VkSwapchainCreateInfoKHR.imageColorSpace: VkColorSpace + get() = VkColorSpace of VkSwapchainCreateInfoKHR.nimageColorSpace(adr) + set(value) = VkSwapchainCreateInfoKHR.nimageColorSpace(adr, value.i) +inline var VkSwapchainCreateInfoKHR.imageExtent: VkExtent2D + get() = VkSwapchainCreateInfoKHR.nimageExtent(adr) + set(value) = VkSwapchainCreateInfoKHR.nimageExtent(adr, value) + +/** JVM custom */ +fun VkSwapchainCreateInfoKHR.imageExtent(extent: Vec2i) { + imageExtent.width = extent.x + imageExtent.height = extent.y +} + +inline var VkSwapchainCreateInfoKHR.imageArrayLayers + get() = VkSwapchainCreateInfoKHR.nimageArrayLayers(adr) + set(value) = VkSwapchainCreateInfoKHR.nimageArrayLayers(adr, value) +inline var VkSwapchainCreateInfoKHR.imageUsage: VkImageUsageFlags + get() = VkSwapchainCreateInfoKHR.nimageUsage(adr) + set(value) = VkSwapchainCreateInfoKHR.nimageUsage(adr, value) +inline var VkSwapchainCreateInfoKHR.imageSharingMode: VkSharingMode + get() = VkSharingMode of VkSwapchainCreateInfoKHR.nimageSharingMode(adr) + set(value) = VkSwapchainCreateInfoKHR.nimageSharingMode(adr, value.i) +inline val VkSwapchainCreateInfoKHR.queueFamilyIndexCount get() = VkSwapchainCreateInfoKHR.nqueueFamilyIndexCount(adr) +inline var VkSwapchainCreateInfoKHR.queueFamilyIndices + get() = VkSwapchainCreateInfoKHR.npQueueFamilyIndices(adr) + set(value) = VkSwapchainCreateInfoKHR.npQueueFamilyIndices(adr, value) +inline var VkSwapchainCreateInfoKHR.preTransform: VkSurfaceTransform + get() = VkSurfaceTransform of VkSwapchainCreateInfoKHR.npreTransform(adr) + set(value) = VkSwapchainCreateInfoKHR.npreTransform(adr, value.i) +inline var VkSwapchainCreateInfoKHR.compositeAlpha: VkCompositeAlpha + get() = VkCompositeAlpha of VkSwapchainCreateInfoKHR.ncompositeAlpha(adr) + set(value) = VkSwapchainCreateInfoKHR.ncompositeAlpha(adr, value.i) +inline var VkSwapchainCreateInfoKHR.presentMode: VkPresentMode + get() = VkPresentMode of VkSwapchainCreateInfoKHR.npresentMode(adr) + set(value) = VkSwapchainCreateInfoKHR.npresentMode(adr, value.i) +inline var VkSwapchainCreateInfoKHR.clipped + get() = VkSwapchainCreateInfoKHR.nclipped(adr).bool + set(value) = VkSwapchainCreateInfoKHR.nclipped(adr, value.i) +inline var VkSwapchainCreateInfoKHR.oldSwapchain: VkSwapchainKHR + get() = VkSwapchainKHR(VkSwapchainCreateInfoKHR.noldSwapchain(adr)) + set(value) = VkSwapchainCreateInfoKHR.noldSwapchain(adr, value.L) + + +typealias VkSwapchainCreateFlagsKHR = VkFlags + +//typedef struct VkSwapchainCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkSwapchainCreateFlagsKHR flags; +// VkSurfaceKHR surface; +// uint32_t minImageCount; +// VkFormat imageFormat; +// VkColorSpaceKHR imageColorSpace; +// VkExtent2D imageExtent; +// uint32_t imageArrayLayers; +// VkImageUsageFlags imageUsage; +// VkSharingMode imageSharingMode; +// uint32_t queueFamilyIndexCount; +// const uint32_t* pQueueFamilyIndices; +// VkSurfaceTransformFlagBitsKHR preTransform; +// VkCompositeAlphaFlagBitsKHR compositeAlpha; +// VkPresentModeKHR presentMode; +// VkBool32 clipped; +// VkSwapchainKHR oldSwapchain; +//} VkSwapchainCreateInfoKHR; + + +inline var VkPresentInfoKHR.type: VkStructureType + get() = VkStructureType of VkPresentInfoKHR.nsType(adr) + set(value) = VkPresentInfoKHR.nsType(adr, value.i) +inline var VkPresentInfoKHR.next + get() = VkPresentInfoKHR.npNext(adr) + set(value) = VkPresentInfoKHR.npNext(adr, value) +//inline val VkPresentInfoKHR.waitSemaphoreCount get() = VkPresentInfoKHR.nwaitSemaphoreCount(adr) +inline var VkPresentInfoKHR.waitSemaphores: VkSemaphoreBuffer? + get() = VkPresentInfoKHR.npWaitSemaphores(adr) + set(value) = VkPresentInfoKHR.npWaitSemaphores(adr, value) +/** JVM custom */ +inline var VkPresentInfoKHR.waitSemaphore: VkSemaphore? + get() = VkPresentInfoKHR.npWaitSemaphores(adr)?.let { VkSemaphore(it[0]) } + set(value) = when (value) { + null -> { + memPutAddress(adr + VkPresentInfoKHR.PWAITSEMAPHORES, NULL) + VkPresentInfoKHR.nwaitSemaphoreCount(adr, 0) + } + else -> stak.longAddress(value.L) { + memPutAddress(adr + VkPresentInfoKHR.PWAITSEMAPHORES, it) + VkPresentInfoKHR.nwaitSemaphoreCount(adr, 1) + } + } +inline var VkPresentInfoKHR.swapchainCount: Int + get() = VkPresentInfoKHR.nswapchainCount(adr) + set(value) = VkPresentInfoKHR.nswapchainCount(adr, value) +inline var VkPresentInfoKHR.swapchains: VkSwapchainKhrBuffer + get() = VkPresentInfoKHR.npSwapchains(adr) + set(value) = VkPresentInfoKHR.npSwapchains(adr, value) +/** JVM custom */ +inline var VkPresentInfoKHR.swapchain: VkSwapchainKHR + get() = VkSwapchainKHR(VkPresentInfoKHR.npSwapchains(adr)[0]) + set(value) = stak.longAddress(value.L) { memPutAddress(adr + VkPresentInfoKHR.PSWAPCHAINS, it) } +inline var VkPresentInfoKHR.imageIndices: IntBuffer + get() = VkPresentInfoKHR.npImageIndices(adr) + set(value) = VkPresentInfoKHR.npImageIndices(adr, value) +/** JVM custom */ +inline var VkPresentInfoKHR.imageIndex: Int + get() = VkPresentInfoKHR.npImageIndices(adr)[0] + set(value) = stak.intAddress(value) { memPutAddress(adr + VkPresentInfoKHR.PIMAGEINDICES, it) } +inline var VkPresentInfoKHR.results: VkResultBuffer? + get() = VkPresentInfoKHR.npResults(adr) + set(value) = VkPresentInfoKHR.npResults(adr, value) + +//typedef VkResult (VKAPI_PTR *PFN_vkCreateSwapchainKHR)(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain); +//typedef void (VKAPI_PTR *PFN_vkDestroySwapchainKHR)(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainImagesKHR)(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, VkImage* pSwapchainImages); +//typedef VkResult (VKAPI_PTR *PFN_vkAcquireNextImageKHR)(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t* pImageIndex); +//typedef VkResult (VKAPI_PTR *PFN_vkQueuePresentKHR)(VkQueue queue, const VkPresentInfoKHR* pPresentInfo); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR( +//VkDevice device, +//const VkSwapchainCreateInfoKHR* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkSwapchainKHR* pSwapchain); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR( +//VkDevice device, +//VkSwapchainKHR swapchain, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR( +//VkDevice device, +//VkSwapchainKHR swapchain, +//uint32_t* pSwapchainImageCount, +//VkImage* pSwapchainImages); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR( +//VkDevice device, +//VkSwapchainKHR swapchain, +//uint64_t timeout, +//VkSemaphore semaphore, +//VkFence fence, +//uint32_t* pImageIndex); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR( +//VkQueue queue, +//const VkPresentInfoKHR* pPresentInfo); +//#endif +// +//#define VK_KHR_display 1 +//VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDisplayKHR) +//VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDisplayModeKHR) +// +//#define VK_KHR_DISPLAY_SPEC_VERSION 21 +//#define VK_KHR_DISPLAY_EXTENSION_NAME "VK_KHR_display" +// +// +//typedef enum VkDisplayPlaneAlphaFlagBitsKHR { +// VK_DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR = 0x00000001, +// VK_DISPLAY_PLANE_ALPHA_GLOBAL_BIT_KHR = 0x00000002, +// VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_BIT_KHR = 0x00000004, +// VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_PREMULTIPLIED_BIT_KHR = 0x00000008, +// VK_DISPLAY_PLANE_ALPHA_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF +//} VkDisplayPlaneAlphaFlagBitsKHR; +//typedef VkFlags VkDisplayPlaneAlphaFlagsKHR; +//typedef VkFlags VkDisplayModeCreateFlagsKHR; +//typedef VkFlags VkDisplaySurfaceCreateFlagsKHR; +// +//typedef struct VkDisplayPropertiesKHR { +// VkDisplayKHR display; +// const char* displayName; +// VkExtent2D physicalDimensions; +// VkExtent2D physicalResolution; +// VkSurfaceTransformFlagsKHR supportedTransforms; +// VkBool32 planeReorderPossible; +// VkBool32 persistentContent; +//} VkDisplayPropertiesKHR; +// +//typedef struct VkDisplayModeParametersKHR { +// VkExtent2D visibleRegion; +// uint32_t refreshRate; +//} VkDisplayModeParametersKHR; +// +//typedef struct VkDisplayModePropertiesKHR { +// VkDisplayModeKHR displayMode; +// VkDisplayModeParametersKHR parameters; +//} VkDisplayModePropertiesKHR; +// +//typedef struct VkDisplayModeCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkDisplayModeCreateFlagsKHR flags; +// VkDisplayModeParametersKHR parameters; +//} VkDisplayModeCreateInfoKHR; +// +//typedef struct VkDisplayPlaneCapabilitiesKHR { +// VkDisplayPlaneAlphaFlagsKHR supportedAlpha; +// VkOffset2D minSrcPosition; +// VkOffset2D maxSrcPosition; +// VkExtent2D minSrcExtent; +// VkExtent2D maxSrcExtent; +// VkOffset2D minDstPosition; +// VkOffset2D maxDstPosition; +// VkExtent2D minDstExtent; +// VkExtent2D maxDstExtent; +//} VkDisplayPlaneCapabilitiesKHR; +// +//typedef struct VkDisplayPlanePropertiesKHR { +// VkDisplayKHR currentDisplay; +// uint32_t currentStackIndex; +//} VkDisplayPlanePropertiesKHR; +// +//typedef struct VkDisplaySurfaceCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkDisplaySurfaceCreateFlagsKHR flags; +// VkDisplayModeKHR displayMode; +// uint32_t planeIndex; +// uint32_t planeStackIndex; +// VkSurfaceTransformFlagBitsKHR transform; +// float globalAlpha; +// VkDisplayPlaneAlphaFlagBitsKHR alphaMode; +// VkExtent2D imageExtent; +//} VkDisplaySurfaceCreateInfoKHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceDisplayPropertiesKHR)(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayPropertiesKHR* pProperties); +//typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR)(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayPlanePropertiesKHR* pProperties); +//typedef VkResult (VKAPI_PTR *PFN_vkGetDisplayPlaneSupportedDisplaysKHR)(VkPhysicalDevice physicalDevice, uint32_t planeIndex, uint32_t* pDisplayCount, VkDisplayKHR* pDisplays); +//typedef VkResult (VKAPI_PTR *PFN_vkGetDisplayModePropertiesKHR)(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t* pPropertyCount, VkDisplayModePropertiesKHR* pProperties); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateDisplayModeKHR)(VkPhysicalDevice physicalDevice, VkDisplayKHR display, const VkDisplayModeCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDisplayModeKHR* pMode); +//typedef VkResult (VKAPI_PTR *PFN_vkGetDisplayPlaneCapabilitiesKHR)(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, uint32_t planeIndex, VkDisplayPlaneCapabilitiesKHR* pCapabilities); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateDisplayPlaneSurfaceKHR)(VkInstance instance, const VkDisplaySurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPropertiesKHR( +//VkPhysicalDevice physicalDevice, +//uint32_t* pPropertyCount, +//VkDisplayPropertiesKHR* pProperties); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPlanePropertiesKHR( +//VkPhysicalDevice physicalDevice, +//uint32_t* pPropertyCount, +//VkDisplayPlanePropertiesKHR* pProperties); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneSupportedDisplaysKHR( +//VkPhysicalDevice physicalDevice, +//uint32_t planeIndex, +//uint32_t* pDisplayCount, +//VkDisplayKHR* pDisplays); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayModePropertiesKHR( +//VkPhysicalDevice physicalDevice, +//VkDisplayKHR display, +//uint32_t* pPropertyCount, +//VkDisplayModePropertiesKHR* pProperties); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayModeKHR( +//VkPhysicalDevice physicalDevice, +//VkDisplayKHR display, +//const VkDisplayModeCreateInfoKHR* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkDisplayModeKHR* pMode); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneCapabilitiesKHR( +//VkPhysicalDevice physicalDevice, +//VkDisplayModeKHR mode, +//uint32_t planeIndex, +//VkDisplayPlaneCapabilitiesKHR* pCapabilities); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayPlaneSurfaceKHR( +//VkInstance instance, +//const VkDisplaySurfaceCreateInfoKHR* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkSurfaceKHR* pSurface); +//#endif +// +//#define VK_KHR_display_swapchain 1 +//#define VK_KHR_DISPLAY_SWAPCHAIN_SPEC_VERSION 9 +//#define VK_KHR_DISPLAY_SWAPCHAIN_EXTENSION_NAME "VK_KHR_display_swapchain" +// +//typedef struct VkDisplayPresentInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkRect2D srcRect; +// VkRect2D dstRect; +// VkBool32 persistent; +//} VkDisplayPresentInfoKHR; +// +// \ No newline at end of file diff --git a/src/main/kotlin/vkk/direct fields C.kt b/src/main/kotlin/vkk/direct fields C.kt new file mode 100644 index 0000000..13088d9 --- /dev/null +++ b/src/main/kotlin/vkk/direct fields C.kt @@ -0,0 +1,3310 @@ +package vkk + +import glm_.BYTES +import glm_.L +import glm_.i +import glm_.vec4.Vec4 +import kool.adr +import org.lwjgl.system.MemoryUtil.memPutFloat +import org.lwjgl.system.MemoryUtil.memUTF8 +import org.lwjgl.vulkan.* +import java.nio.ByteBuffer + +//typedef VkResult (VKAPI_PTR *PFN_vkCreateSharedSwapchainsKHR)(VkDevice device, uint32_t swapchainCount, const VkSwapchainCreateInfoKHR* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchains); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateSharedSwapchainsKHR( +//VkDevice device, +//uint32_t swapchainCount, +//const VkSwapchainCreateInfoKHR* pCreateInfos, +//const VkAllocationCallbacks* pAllocator, +//VkSwapchainKHR* pSwapchains); +//#endif +// +//#ifdef VK_USE_PLATFORM_XLIB_KHR +//#define VK_KHR_xlib_surface 1 +//#include +// +//#define VK_KHR_XLIB_SURFACE_SPEC_VERSION 6 +//#define VK_KHR_XLIB_SURFACE_EXTENSION_NAME "VK_KHR_xlib_surface" +// +//typedef VkFlags VkXlibSurfaceCreateFlagsKHR; +// +//typedef struct VkXlibSurfaceCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkXlibSurfaceCreateFlagsKHR flags; +// Display* dpy; +// Window window; +//} VkXlibSurfaceCreateInfoKHR; +// +//typedef VkResult (VKAPI_PTR *PFN_vkCreateXlibSurfaceKHR)(VkInstance instance, const VkXlibSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); +//typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, Display* dpy, VisualID visualID); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR( +//VkInstance instance, +//const VkXlibSurfaceCreateInfoKHR* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkSurfaceKHR* pSurface); +// +//VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR( +//VkPhysicalDevice physicalDevice, +//uint32_t queueFamilyIndex, +//Display* dpy, +//VisualID visualID); +//#endif +//#endif /* VK_USE_PLATFORM_XLIB_KHR */ +// +//#ifdef VK_USE_PLATFORM_XCB_KHR +//#define VK_KHR_xcb_surface 1 +//#include +// +//#define VK_KHR_XCB_SURFACE_SPEC_VERSION 6 +//#define VK_KHR_XCB_SURFACE_EXTENSION_NAME "VK_KHR_xcb_surface" +// +//typedef VkFlags VkXcbSurfaceCreateFlagsKHR; +// +//typedef struct VkXcbSurfaceCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkXcbSurfaceCreateFlagsKHR flags; +// xcb_connection_t* connection; +// xcb_window_t window; +//} VkXcbSurfaceCreateInfoKHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkCreateXcbSurfaceKHR)(VkInstance instance, const VkXcbSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); +//typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, xcb_connection_t* connection, xcb_visualid_t visual_id); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR( +//VkInstance instance, +//const VkXcbSurfaceCreateInfoKHR* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkSurfaceKHR* pSurface); +// +//VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR( +//VkPhysicalDevice physicalDevice, +//uint32_t queueFamilyIndex, +//xcb_connection_t* connection, +//xcb_visualid_t visual_id); +//#endif +//#endif /* VK_USE_PLATFORM_XCB_KHR */ +// +//#ifdef VK_USE_PLATFORM_WAYLAND_KHR +//#define VK_KHR_wayland_surface 1 +//#include +// +//#define VK_KHR_WAYLAND_SURFACE_SPEC_VERSION 6 +//#define VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME "VK_KHR_wayland_surface" +// +//typedef VkFlags VkWaylandSurfaceCreateFlagsKHR; +// +//typedef struct VkWaylandSurfaceCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkWaylandSurfaceCreateFlagsKHR flags; +// struct wl_display* display; +// struct wl_surface* surface; +//} VkWaylandSurfaceCreateInfoKHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkCreateWaylandSurfaceKHR)(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); +//typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, struct wl_display* display); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR( +//VkInstance instance, +//const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkSurfaceKHR* pSurface); +// +//VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresentationSupportKHR( +//VkPhysicalDevice physicalDevice, +//uint32_t queueFamilyIndex, +//struct wl_display* display); +//#endif +//#endif /* VK_USE_PLATFORM_WAYLAND_KHR */ +// +//#ifdef VK_USE_PLATFORM_MIR_KHR +//#define VK_KHR_mir_surface 1 +//#include +// +//#define VK_KHR_MIR_SURFACE_SPEC_VERSION 4 +//#define VK_KHR_MIR_SURFACE_EXTENSION_NAME "VK_KHR_mir_surface" +// +//typedef VkFlags VkMirSurfaceCreateFlagsKHR; +// +//typedef struct VkMirSurfaceCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkMirSurfaceCreateFlagsKHR flags; +// MirConnection* connection; +// MirSurface* mirSurface; +//} VkMirSurfaceCreateInfoKHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkCreateMirSurfaceKHR)(VkInstance instance, const VkMirSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); +//typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceMirPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, MirConnection* connection); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateMirSurfaceKHR( +//VkInstance instance, +//const VkMirSurfaceCreateInfoKHR* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkSurfaceKHR* pSurface); +// +//VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceMirPresentationSupportKHR( +//VkPhysicalDevice physicalDevice, +//uint32_t queueFamilyIndex, +//MirConnection* connection); +//#endif +//#endif /* VK_USE_PLATFORM_MIR_KHR */ +// +//#ifdef VK_USE_PLATFORM_ANDROID_KHR +//#define VK_KHR_android_surface 1 +//#include +// +//#define VK_KHR_ANDROID_SURFACE_SPEC_VERSION 6 +//#define VK_KHR_ANDROID_SURFACE_EXTENSION_NAME "VK_KHR_android_surface" +// +//typedef VkFlags VkAndroidSurfaceCreateFlagsKHR; +// +//typedef struct VkAndroidSurfaceCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkAndroidSurfaceCreateFlagsKHR flags; +// ANativeWindow* window; +//} VkAndroidSurfaceCreateInfoKHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkCreateAndroidSurfaceKHR)(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateAndroidSurfaceKHR( +//VkInstance instance, +//const VkAndroidSurfaceCreateInfoKHR* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkSurfaceKHR* pSurface); +//#endif +//#endif /* VK_USE_PLATFORM_ANDROID_KHR */ +// +//#ifdef VK_USE_PLATFORM_WIN32_KHR +//#define VK_KHR_win32_surface 1 +//#include +// +//#define VK_KHR_WIN32_SURFACE_SPEC_VERSION 6 +//#define VK_KHR_WIN32_SURFACE_EXTENSION_NAME "VK_KHR_win32_surface" +// +//typedef VkFlags VkWin32SurfaceCreateFlagsKHR; +// +//typedef struct VkWin32SurfaceCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkWin32SurfaceCreateFlagsKHR flags; +// HINSTANCE hinstance; +// HWND hwnd; +//} VkWin32SurfaceCreateInfoKHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkCreateWin32SurfaceKHR)(VkInstance instance, const VkWin32SurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); +//typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR( +//VkInstance instance, +//const VkWin32SurfaceCreateInfoKHR* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkSurfaceKHR* pSurface); +// +//VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWin32PresentationSupportKHR( +//VkPhysicalDevice physicalDevice, +//uint32_t queueFamilyIndex); +//#endif +//#endif /* VK_USE_PLATFORM_WIN32_KHR */ +// +//#define VK_KHR_sampler_mirror_clamp_to_edge 1 +//#define VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_SPEC_VERSION 1 +//#define VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME "VK_KHR_sampler_mirror_clamp_to_edge" +// +// +//#define VK_KHR_get_physical_device_properties2 1 +//#define VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION 1 +//#define VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME "VK_KHR_get_physical_device_properties2" +// +//typedef struct VkPhysicalDeviceFeatures2KHR { +// VkStructureType sType; +// void* pNext; +// VkPhysicalDeviceFeatures features; +//} VkPhysicalDeviceFeatures2KHR; +// +//typedef struct VkPhysicalDeviceProperties2KHR { +// VkStructureType sType; +// void* pNext; +// VkPhysicalDeviceProperties properties; +//} VkPhysicalDeviceProperties2KHR; +// +//typedef struct VkFormatProperties2KHR { +// VkStructureType sType; +// void* pNext; +// VkFormatProperties formatProperties; +//} VkFormatProperties2KHR; +// +//typedef struct VkImageFormatProperties2KHR { +// VkStructureType sType; +// void* pNext; +// VkImageFormatProperties imageFormatProperties; +//} VkImageFormatProperties2KHR; +// +//typedef struct VkPhysicalDeviceImageFormatInfo2KHR { +// VkStructureType sType; +// const void* pNext; +// VkFormat format; +// VkImageType type; +// VkImageTiling tiling; +// VkImageUsageFlags usage; +// VkImageCreateFlags flags; +//} VkPhysicalDeviceImageFormatInfo2KHR; +// +//typedef struct VkQueueFamilyProperties2KHR { +// VkStructureType sType; +// void* pNext; +// VkQueueFamilyProperties queueFamilyProperties; +//} VkQueueFamilyProperties2KHR; +// +//typedef struct VkPhysicalDeviceMemoryProperties2KHR { +// VkStructureType sType; +// void* pNext; +// VkPhysicalDeviceMemoryProperties memoryProperties; +//} VkPhysicalDeviceMemoryProperties2KHR; +// +//typedef struct VkSparseImageFormatProperties2KHR { +// VkStructureType sType; +// void* pNext; +// VkSparseImageFormatProperties properties; +//} VkSparseImageFormatProperties2KHR; +// +//typedef struct VkPhysicalDeviceSparseImageFormatInfo2KHR { +// VkStructureType sType; +// const void* pNext; +// VkFormat format; +// VkImageType type; +// VkSampleCountFlagBits samples; +// VkImageUsageFlags usage; +// VkImageTiling tiling; +//} VkPhysicalDeviceSparseImageFormatInfo2KHR; +// +// +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceFeatures2KHR)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures2KHR* pFeatures); +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceProperties2KHR)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties2KHR* pProperties); +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceFormatProperties2KHR)(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties2KHR* pFormatProperties); +//typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceImageFormatProperties2KHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2KHR* pImageFormatInfo, VkImageFormatProperties2KHR* pImageFormatProperties); +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceQueueFamilyProperties2KHR)(VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties2KHR* pQueueFamilyProperties); +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceMemoryProperties2KHR)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties2KHR* pMemoryProperties); +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceSparseImageFormatProperties2KHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSparseImageFormatInfo2KHR* pFormatInfo, uint32_t* pPropertyCount, VkSparseImageFormatProperties2KHR* pProperties); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures2KHR( +//VkPhysicalDevice physicalDevice, +//VkPhysicalDeviceFeatures2KHR* pFeatures); +// +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties2KHR( +//VkPhysicalDevice physicalDevice, +//VkPhysicalDeviceProperties2KHR* pProperties); +// +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFormatProperties2KHR( +//VkPhysicalDevice physicalDevice, +//VkFormat format, +//VkFormatProperties2KHR* pFormatProperties); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceImageFormatProperties2KHR( +//VkPhysicalDevice physicalDevice, +//const VkPhysicalDeviceImageFormatInfo2KHR* pImageFormatInfo, +//VkImageFormatProperties2KHR* pImageFormatProperties); +// +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceQueueFamilyProperties2KHR( +//VkPhysicalDevice physicalDevice, +//uint32_t* pQueueFamilyPropertyCount, +//VkQueueFamilyProperties2KHR* pQueueFamilyProperties); +// +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties2KHR( +//VkPhysicalDevice physicalDevice, +//VkPhysicalDeviceMemoryProperties2KHR* pMemoryProperties); +// +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceSparseImageFormatProperties2KHR( +//VkPhysicalDevice physicalDevice, +//const VkPhysicalDeviceSparseImageFormatInfo2KHR* pFormatInfo, +//uint32_t* pPropertyCount, +//VkSparseImageFormatProperties2KHR* pProperties); +//#endif +// +//#define VK_KHR_shader_draw_parameters 1 +//#define VK_KHR_SHADER_DRAW_PARAMETERS_SPEC_VERSION 1 +//#define VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME "VK_KHR_shader_draw_parameters" +// +// +//#define VK_KHR_maintenance1 1 +//#define VK_KHR_MAINTENANCE1_SPEC_VERSION 1 +//#define VK_KHR_MAINTENANCE1_EXTENSION_NAME "VK_KHR_maintenance1" +// +//typedef VkFlags VkCommandPoolTrimFlagsKHR; +// +//typedef void (VKAPI_PTR *PFN_vkTrimCommandPoolKHR)(VkDevice device, VkCommandPool commandPool, VkCommandPoolTrimFlagsKHR flags); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR void VKAPI_CALL vkTrimCommandPoolKHR( +//VkDevice device, +//VkCommandPool commandPool, +//VkCommandPoolTrimFlagsKHR flags); +//#endif +// +//#define VK_KHR_external_memory_capabilities 1 +//#define VK_LUID_SIZE_KHR 8 +//#define VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_SPEC_VERSION 1 +//#define VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME "VK_KHR_external_memory_capabilities" +// +// +//typedef enum VkExternalMemoryHandleTypeFlagBitsKHR { +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR = 0x00000001, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR = 0x00000002, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR = 0x00000004, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT_KHR = 0x00000008, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_KMT_BIT_KHR = 0x00000010, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP_BIT_KHR = 0x00000020, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE_BIT_KHR = 0x00000040, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT = 0x00000200, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT = 0x00000080, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_MAPPED_FOREIGN_MEMORY_BIT_EXT = 0x00000100, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF +//} VkExternalMemoryHandleTypeFlagBitsKHR; +//typedef VkFlags VkExternalMemoryHandleTypeFlagsKHR; +// +//typedef enum VkExternalMemoryFeatureFlagBitsKHR { +// VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT_KHR = 0x00000001, +// VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHR = 0x00000002, +// VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHR = 0x00000004, +// VK_EXTERNAL_MEMORY_FEATURE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF +//} VkExternalMemoryFeatureFlagBitsKHR; +//typedef VkFlags VkExternalMemoryFeatureFlagsKHR; +// +//typedef struct VkExternalMemoryPropertiesKHR { +// VkExternalMemoryFeatureFlagsKHR externalMemoryFeatures; +// VkExternalMemoryHandleTypeFlagsKHR exportFromImportedHandleTypes; +// VkExternalMemoryHandleTypeFlagsKHR compatibleHandleTypes; +//} VkExternalMemoryPropertiesKHR; +// +//typedef struct VkPhysicalDeviceExternalImageFormatInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkExternalMemoryHandleTypeFlagBitsKHR handleType; +//} VkPhysicalDeviceExternalImageFormatInfoKHR; +// +//typedef struct VkExternalImageFormatPropertiesKHR { +// VkStructureType sType; +// void* pNext; +// VkExternalMemoryPropertiesKHR externalMemoryProperties; +//} VkExternalImageFormatPropertiesKHR; +// +//typedef struct VkPhysicalDeviceExternalBufferInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkBufferCreateFlags flags; +// VkBufferUsageFlags usage; +// VkExternalMemoryHandleTypeFlagBitsKHR handleType; +//} VkPhysicalDeviceExternalBufferInfoKHR; +// +//typedef struct VkExternalBufferPropertiesKHR { +// VkStructureType sType; +// void* pNext; +// VkExternalMemoryPropertiesKHR externalMemoryProperties; +//} VkExternalBufferPropertiesKHR; +// +//typedef struct VkPhysicalDeviceIDPropertiesKHR { +// VkStructureType sType; +// void* pNext; +// uint8_t deviceUUID[VK_UUID_SIZE]; +// uint8_t driverUUID[VK_UUID_SIZE]; +// uint8_t deviceLUID[VK_LUID_SIZE_KHR]; +// uint32_t deviceNodeMask; +// VkBool32 deviceLUIDValid; +//} VkPhysicalDeviceIDPropertiesKHR; +// +// +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceExternalBufferPropertiesKHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfoKHR* pExternalBufferInfo, VkExternalBufferPropertiesKHR* pExternalBufferProperties); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalBufferPropertiesKHR( +//VkPhysicalDevice physicalDevice, +//const VkPhysicalDeviceExternalBufferInfoKHR* pExternalBufferInfo, +//VkExternalBufferPropertiesKHR* pExternalBufferProperties); +//#endif +// +//#define VK_KHR_external_memory 1 +//#define VK_KHR_EXTERNAL_MEMORY_SPEC_VERSION 1 +//#define VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME "VK_KHR_external_memory" +//#define VK_QUEUE_FAMILY_EXTERNAL_KHR (~0U-1) +// +//typedef struct VkExternalMemoryImageCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkExternalMemoryHandleTypeFlagsKHR handleTypes; +//} VkExternalMemoryImageCreateInfoKHR; +// +//typedef struct VkExternalMemoryBufferCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkExternalMemoryHandleTypeFlagsKHR handleTypes; +//} VkExternalMemoryBufferCreateInfoKHR; +// +//typedef struct VkExportMemoryAllocateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkExternalMemoryHandleTypeFlagsKHR handleTypes; +//} VkExportMemoryAllocateInfoKHR; +// +// +// +//#ifdef VK_USE_PLATFORM_WIN32_KHR +//#define VK_KHR_external_memory_win32 1 +//#define VK_KHR_EXTERNAL_MEMORY_WIN32_SPEC_VERSION 1 +//#define VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME "VK_KHR_external_memory_win32" +// +//typedef struct VkImportMemoryWin32HandleInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkExternalMemoryHandleTypeFlagBitsKHR handleType; +// HANDLE handle; +// LPCWSTR name; +//} VkImportMemoryWin32HandleInfoKHR; +// +//typedef struct VkExportMemoryWin32HandleInfoKHR { +// VkStructureType sType; +// const void* pNext; +// const SECURITY_ATTRIBUTES* pAttributes; +// DWORD dwAccess; +// LPCWSTR name; +//} VkExportMemoryWin32HandleInfoKHR; +// +//typedef struct VkMemoryWin32HandlePropertiesKHR { +// VkStructureType sType; +// void* pNext; +// uint32_t memoryTypeBits; +//} VkMemoryWin32HandlePropertiesKHR; +// +//typedef struct VkMemoryGetWin32HandleInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkDeviceMemory memory; +// VkExternalMemoryHandleTypeFlagBitsKHR handleType; +//} VkMemoryGetWin32HandleInfoKHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandleKHR)(VkDevice device, const VkMemoryGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle); +//typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandlePropertiesKHR)(VkDevice device, VkExternalMemoryHandleTypeFlagBitsKHR handleType, HANDLE handle, VkMemoryWin32HandlePropertiesKHR* pMemoryWin32HandleProperties); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleKHR( +//VkDevice device, +//const VkMemoryGetWin32HandleInfoKHR* pGetWin32HandleInfo, +//HANDLE* pHandle); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandlePropertiesKHR( +//VkDevice device, +//VkExternalMemoryHandleTypeFlagBitsKHR handleType, +//HANDLE handle, +//VkMemoryWin32HandlePropertiesKHR* pMemoryWin32HandleProperties); +//#endif +//#endif /* VK_USE_PLATFORM_WIN32_KHR */ +// +//#define VK_KHR_external_memory_fd 1 +//#define VK_KHR_EXTERNAL_MEMORY_FD_SPEC_VERSION 1 +//#define VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME "VK_KHR_external_memory_fd" +// +//typedef struct VkImportMemoryFdInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkExternalMemoryHandleTypeFlagBitsKHR handleType; +// int fd; +//} VkImportMemoryFdInfoKHR; +// +//typedef struct VkMemoryFdPropertiesKHR { +// VkStructureType sType; +// void* pNext; +// uint32_t memoryTypeBits; +//} VkMemoryFdPropertiesKHR; +// +//typedef struct VkMemoryGetFdInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkDeviceMemory memory; +// VkExternalMemoryHandleTypeFlagBitsKHR handleType; +//} VkMemoryGetFdInfoKHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryFdKHR)(VkDevice device, const VkMemoryGetFdInfoKHR* pGetFdInfo, int* pFd); +//typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryFdPropertiesKHR)(VkDevice device, VkExternalMemoryHandleTypeFlagBitsKHR handleType, int fd, VkMemoryFdPropertiesKHR* pMemoryFdProperties); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryFdKHR( +//VkDevice device, +//const VkMemoryGetFdInfoKHR* pGetFdInfo, +//int* pFd); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryFdPropertiesKHR( +//VkDevice device, +//VkExternalMemoryHandleTypeFlagBitsKHR handleType, +//int fd, +//VkMemoryFdPropertiesKHR* pMemoryFdProperties); +//#endif +// +//#ifdef VK_USE_PLATFORM_WIN32_KHR +//#define VK_KHR_win32_keyed_mutex 1 +//#define VK_KHR_WIN32_KEYED_MUTEX_SPEC_VERSION 1 +//#define VK_KHR_WIN32_KEYED_MUTEX_EXTENSION_NAME "VK_KHR_win32_keyed_mutex" +// +//typedef struct VkWin32KeyedMutexAcquireReleaseInfoKHR { +// VkStructureType sType; +// const void* pNext; +// uint32_t acquireCount; +// const VkDeviceMemory* pAcquireSyncs; +// const uint64_t* pAcquireKeys; +// const uint32_t* pAcquireTimeouts; +// uint32_t releaseCount; +// const VkDeviceMemory* pReleaseSyncs; +// const uint64_t* pReleaseKeys; +//} VkWin32KeyedMutexAcquireReleaseInfoKHR; +// +// +//#endif /* VK_USE_PLATFORM_WIN32_KHR */ +// +//#define VK_KHR_external_semaphore_capabilities 1 +//#define VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_SPEC_VERSION 1 +//#define VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME "VK_KHR_external_semaphore_capabilities" +// +// +//typedef enum VkExternalSemaphoreHandleTypeFlagBitsKHR { +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR = 0x00000001, +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR = 0x00000002, +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR = 0x00000004, +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT_KHR = 0x00000008, +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR = 0x00000010, +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF +//} VkExternalSemaphoreHandleTypeFlagBitsKHR; +//typedef VkFlags VkExternalSemaphoreHandleTypeFlagsKHR; +// +//typedef enum VkExternalSemaphoreFeatureFlagBitsKHR { +// VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR = 0x00000001, +// VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR = 0x00000002, +// VK_EXTERNAL_SEMAPHORE_FEATURE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF +//} VkExternalSemaphoreFeatureFlagBitsKHR; +//typedef VkFlags VkExternalSemaphoreFeatureFlagsKHR; +// +//typedef struct VkPhysicalDeviceExternalSemaphoreInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkExternalSemaphoreHandleTypeFlagBitsKHR handleType; +//} VkPhysicalDeviceExternalSemaphoreInfoKHR; +// +//typedef struct VkExternalSemaphorePropertiesKHR { +// VkStructureType sType; +// void* pNext; +// VkExternalSemaphoreHandleTypeFlagsKHR exportFromImportedHandleTypes; +// VkExternalSemaphoreHandleTypeFlagsKHR compatibleHandleTypes; +// VkExternalSemaphoreFeatureFlagsKHR externalSemaphoreFeatures; +//} VkExternalSemaphorePropertiesKHR; +// +// +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalSemaphoreInfoKHR* pExternalSemaphoreInfo, VkExternalSemaphorePropertiesKHR* pExternalSemaphoreProperties); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalSemaphorePropertiesKHR( +//VkPhysicalDevice physicalDevice, +//const VkPhysicalDeviceExternalSemaphoreInfoKHR* pExternalSemaphoreInfo, +//VkExternalSemaphorePropertiesKHR* pExternalSemaphoreProperties); +//#endif +// +//#define VK_KHR_external_semaphore 1 +//#define VK_KHR_EXTERNAL_SEMAPHORE_SPEC_VERSION 1 +//#define VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME "VK_KHR_external_semaphore" +// +// +//typedef enum VkSemaphoreImportFlagBitsKHR { +// VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR = 0x00000001, +// VK_SEMAPHORE_IMPORT_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF +//} VkSemaphoreImportFlagBitsKHR; +//typedef VkFlags VkSemaphoreImportFlagsKHR; +// +//typedef struct VkExportSemaphoreCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkExternalSemaphoreHandleTypeFlagsKHR handleTypes; +//} VkExportSemaphoreCreateInfoKHR; +// +// +// +//#ifdef VK_USE_PLATFORM_WIN32_KHR +//#define VK_KHR_external_semaphore_win32 1 +//#define VK_KHR_EXTERNAL_SEMAPHORE_WIN32_SPEC_VERSION 1 +//#define VK_KHR_EXTERNAL_SEMAPHORE_WIN32_EXTENSION_NAME "VK_KHR_external_semaphore_win32" +// +//typedef struct VkImportSemaphoreWin32HandleInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkSemaphore semaphore; +// VkSemaphoreImportFlagsKHR flags; +// VkExternalSemaphoreHandleTypeFlagBitsKHR handleType; +// HANDLE handle; +// LPCWSTR name; +//} VkImportSemaphoreWin32HandleInfoKHR; +// +//typedef struct VkExportSemaphoreWin32HandleInfoKHR { +// VkStructureType sType; +// const void* pNext; +// const SECURITY_ATTRIBUTES* pAttributes; +// DWORD dwAccess; +// LPCWSTR name; +//} VkExportSemaphoreWin32HandleInfoKHR; +// +//typedef struct VkD3D12FenceSubmitInfoKHR { +// VkStructureType sType; +// const void* pNext; +// uint32_t waitSemaphoreValuesCount; +// const uint64_t* pWaitSemaphoreValues; +// uint32_t signalSemaphoreValuesCount; +// const uint64_t* pSignalSemaphoreValues; +//} VkD3D12FenceSubmitInfoKHR; +// +//typedef struct VkSemaphoreGetWin32HandleInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkSemaphore semaphore; +// VkExternalSemaphoreHandleTypeFlagBitsKHR handleType; +//} VkSemaphoreGetWin32HandleInfoKHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkImportSemaphoreWin32HandleKHR)(VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR* pImportSemaphoreWin32HandleInfo); +//typedef VkResult (VKAPI_PTR *PFN_vkGetSemaphoreWin32HandleKHR)(VkDevice device, const VkSemaphoreGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkImportSemaphoreWin32HandleKHR( +//VkDevice device, +//const VkImportSemaphoreWin32HandleInfoKHR* pImportSemaphoreWin32HandleInfo); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetSemaphoreWin32HandleKHR( +//VkDevice device, +//const VkSemaphoreGetWin32HandleInfoKHR* pGetWin32HandleInfo, +//HANDLE* pHandle); +//#endif +//#endif /* VK_USE_PLATFORM_WIN32_KHR */ +// +//#define VK_KHR_external_semaphore_fd 1 +//#define VK_KHR_EXTERNAL_SEMAPHORE_FD_SPEC_VERSION 1 +//#define VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME "VK_KHR_external_semaphore_fd" +// +//typedef struct VkImportSemaphoreFdInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkSemaphore semaphore; +// VkSemaphoreImportFlagsKHR flags; +// VkExternalSemaphoreHandleTypeFlagBitsKHR handleType; +// int fd; +//} VkImportSemaphoreFdInfoKHR; +// +//typedef struct VkSemaphoreGetFdInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkSemaphore semaphore; +// VkExternalSemaphoreHandleTypeFlagBitsKHR handleType; +//} VkSemaphoreGetFdInfoKHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkImportSemaphoreFdKHR)(VkDevice device, const VkImportSemaphoreFdInfoKHR* pImportSemaphoreFdInfo); +//typedef VkResult (VKAPI_PTR *PFN_vkGetSemaphoreFdKHR)(VkDevice device, const VkSemaphoreGetFdInfoKHR* pGetFdInfo, int* pFd); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkImportSemaphoreFdKHR( +//VkDevice device, +//const VkImportSemaphoreFdInfoKHR* pImportSemaphoreFdInfo); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetSemaphoreFdKHR( +//VkDevice device, +//const VkSemaphoreGetFdInfoKHR* pGetFdInfo, +//int* pFd); +//#endif +// +//#define VK_KHR_push_descriptor 1 +//#define VK_KHR_PUSH_DESCRIPTOR_SPEC_VERSION 1 +//#define VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME "VK_KHR_push_descriptor" +// +//typedef struct VkPhysicalDevicePushDescriptorPropertiesKHR { +// VkStructureType sType; +// void* pNext; +// uint32_t maxPushDescriptors; +//} VkPhysicalDevicePushDescriptorPropertiesKHR; +// +// +//typedef void (VKAPI_PTR *PFN_vkCmdPushDescriptorSetKHR)(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t set, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR void VKAPI_CALL vkCmdPushDescriptorSetKHR( +//VkCommandBuffer commandBuffer, +//VkPipelineBindPoint pipelineBindPoint, +//VkPipelineLayout layout, +//uint32_t set, +//uint32_t descriptorWriteCount, +//const VkWriteDescriptorSet* pDescriptorWrites); +//#endif +// +//#define VK_KHR_16bit_storage 1 +//#define VK_KHR_16BIT_STORAGE_SPEC_VERSION 1 +//#define VK_KHR_16BIT_STORAGE_EXTENSION_NAME "VK_KHR_16bit_storage" +// +//typedef struct VkPhysicalDevice16BitStorageFeaturesKHR { +// VkStructureType sType; +// void* pNext; +// VkBool32 storageBuffer16BitAccess; +// VkBool32 uniformAndStorageBuffer16BitAccess; +// VkBool32 storagePushConstant16; +// VkBool32 storageInputOutput16; +//} VkPhysicalDevice16BitStorageFeaturesKHR; +// +// +// +//#define VK_KHR_incremental_present 1 +//#define VK_KHR_INCREMENTAL_PRESENT_SPEC_VERSION 1 +//#define VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME "VK_KHR_incremental_present" +// +//typedef struct VkRectLayerKHR { +// VkOffset2D offset; +// VkExtent2D extent; +// uint32_t layer; +//} VkRectLayerKHR; +// +//typedef struct VkPresentRegionKHR { +// uint32_t rectangleCount; +// const VkRectLayerKHR* pRectangles; +//} VkPresentRegionKHR; +// +//typedef struct VkPresentRegionsKHR { +// VkStructureType sType; +// const void* pNext; +// uint32_t swapchainCount; +// const VkPresentRegionKHR* pRegions; +//} VkPresentRegionsKHR; +// +// +// +//#define VK_KHR_descriptor_update_template 1 +//VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorUpdateTemplateKHR) +// +//#define VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_SPEC_VERSION 1 +//#define VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME "VK_KHR_descriptor_update_template" +// +// +//typedef enum VkDescriptorUpdateTemplateTypeKHR { +// VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR = 0, +// VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR = 1, +// VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_BEGIN_RANGE_KHR = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR, +// VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_END_RANGE_KHR = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR, +// VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_RANGE_SIZE_KHR = (VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR - VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR + 1), +// VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_MAX_ENUM_KHR = 0x7FFFFFFF +//} VkDescriptorUpdateTemplateTypeKHR; +// +//typedef VkFlags VkDescriptorUpdateTemplateCreateFlagsKHR; +// +//typedef struct VkDescriptorUpdateTemplateEntryKHR { +// uint32_t dstBinding; +// uint32_t dstArrayElement; +// uint32_t descriptorCount; +// VkDescriptorType descriptorType; +// size_t offset; +// size_t stride; +//} VkDescriptorUpdateTemplateEntryKHR; +// +//typedef struct VkDescriptorUpdateTemplateCreateInfoKHR { +// VkStructureType sType; +// void* pNext; +// VkDescriptorUpdateTemplateCreateFlagsKHR flags; +// uint32_t descriptorUpdateEntryCount; +// const VkDescriptorUpdateTemplateEntryKHR* pDescriptorUpdateEntries; +// VkDescriptorUpdateTemplateTypeKHR templateType; +// VkDescriptorSetLayout descriptorSetLayout; +// VkPipelineBindPoint pipelineBindPoint; +// VkPipelineLayout pipelineLayout; +// uint32_t set; +//} VkDescriptorUpdateTemplateCreateInfoKHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkCreateDescriptorUpdateTemplateKHR)(VkDevice device, const VkDescriptorUpdateTemplateCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorUpdateTemplateKHR* pDescriptorUpdateTemplate); +//typedef void (VKAPI_PTR *PFN_vkDestroyDescriptorUpdateTemplateKHR)(VkDevice device, VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, const VkAllocationCallbacks* pAllocator); +//typedef void (VKAPI_PTR *PFN_vkUpdateDescriptorSetWithTemplateKHR)(VkDevice device, VkDescriptorSet descriptorSet, VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, const void* pData); +//typedef void (VKAPI_PTR *PFN_vkCmdPushDescriptorSetWithTemplateKHR)(VkCommandBuffer commandBuffer, VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, VkPipelineLayout layout, uint32_t set, const void* pData); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorUpdateTemplateKHR( +//VkDevice device, +//const VkDescriptorUpdateTemplateCreateInfoKHR* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkDescriptorUpdateTemplateKHR* pDescriptorUpdateTemplate); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorUpdateTemplateKHR( +//VkDevice device, +//VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSetWithTemplateKHR( +//VkDevice device, +//VkDescriptorSet descriptorSet, +//VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, +//const void* pData); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdPushDescriptorSetWithTemplateKHR( +//VkCommandBuffer commandBuffer, +//VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate, +//VkPipelineLayout layout, +//uint32_t set, +//const void* pData); +//#endif +// +//#define VK_KHR_shared_presentable_image 1 +//#define VK_KHR_SHARED_PRESENTABLE_IMAGE_SPEC_VERSION 1 +//#define VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME "VK_KHR_shared_presentable_image" +// +//typedef struct VkSharedPresentSurfaceCapabilitiesKHR { +// VkStructureType sType; +// void* pNext; +// VkImageUsageFlags sharedPresentSupportedUsageFlags; +//} VkSharedPresentSurfaceCapabilitiesKHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainStatusKHR)(VkDevice device, VkSwapchainKHR swapchain); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainStatusKHR( +//VkDevice device, +//VkSwapchainKHR swapchain); +//#endif +// +//#define VK_KHR_external_fence_capabilities 1 +//#define VK_KHR_EXTERNAL_FENCE_CAPABILITIES_SPEC_VERSION 1 +//#define VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME "VK_KHR_external_fence_capabilities" +// +// +//typedef enum VkExternalFenceHandleTypeFlagBitsKHR { +// VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR = 0x00000001, +// VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR = 0x00000002, +// VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR = 0x00000004, +// VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR = 0x00000008, +// VK_EXTERNAL_FENCE_HANDLE_TYPE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF +//} VkExternalFenceHandleTypeFlagBitsKHR; +//typedef VkFlags VkExternalFenceHandleTypeFlagsKHR; +// +//typedef enum VkExternalFenceFeatureFlagBitsKHR { +// VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR = 0x00000001, +// VK_EXTERNAL_FENCE_FEATURE_IMPORTABLE_BIT_KHR = 0x00000002, +// VK_EXTERNAL_FENCE_FEATURE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF +//} VkExternalFenceFeatureFlagBitsKHR; +//typedef VkFlags VkExternalFenceFeatureFlagsKHR; +// +//typedef struct VkPhysicalDeviceExternalFenceInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkExternalFenceHandleTypeFlagBitsKHR handleType; +//} VkPhysicalDeviceExternalFenceInfoKHR; +// +//typedef struct VkExternalFencePropertiesKHR { +// VkStructureType sType; +// void* pNext; +// VkExternalFenceHandleTypeFlagsKHR exportFromImportedHandleTypes; +// VkExternalFenceHandleTypeFlagsKHR compatibleHandleTypes; +// VkExternalFenceFeatureFlagsKHR externalFenceFeatures; +//} VkExternalFencePropertiesKHR; +// +// +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalFenceInfoKHR* pExternalFenceInfo, VkExternalFencePropertiesKHR* pExternalFenceProperties); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalFencePropertiesKHR( +//VkPhysicalDevice physicalDevice, +//const VkPhysicalDeviceExternalFenceInfoKHR* pExternalFenceInfo, +//VkExternalFencePropertiesKHR* pExternalFenceProperties); +//#endif +// +//#define VK_KHR_external_fence 1 +//#define VK_KHR_EXTERNAL_FENCE_SPEC_VERSION 1 +//#define VK_KHR_EXTERNAL_FENCE_EXTENSION_NAME "VK_KHR_external_fence" +// +// +//typedef enum VkFenceImportFlagBitsKHR { +// VK_FENCE_IMPORT_TEMPORARY_BIT_KHR = 0x00000001, +// VK_FENCE_IMPORT_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF +//} VkFenceImportFlagBitsKHR; +//typedef VkFlags VkFenceImportFlagsKHR; +// +//typedef struct VkExportFenceCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkExternalFenceHandleTypeFlagsKHR handleTypes; +//} VkExportFenceCreateInfoKHR; +// +// +// +//#ifdef VK_USE_PLATFORM_WIN32_KHR +//#define VK_KHR_external_fence_win32 1 +//#define VK_KHR_EXTERNAL_FENCE_WIN32_SPEC_VERSION 1 +//#define VK_KHR_EXTERNAL_FENCE_WIN32_EXTENSION_NAME "VK_KHR_external_fence_win32" +// +//typedef struct VkImportFenceWin32HandleInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkFence fence; +// VkFenceImportFlagsKHR flags; +// VkExternalFenceHandleTypeFlagBitsKHR handleType; +// HANDLE handle; +// LPCWSTR name; +//} VkImportFenceWin32HandleInfoKHR; +// +//typedef struct VkExportFenceWin32HandleInfoKHR { +// VkStructureType sType; +// const void* pNext; +// const SECURITY_ATTRIBUTES* pAttributes; +// DWORD dwAccess; +// LPCWSTR name; +//} VkExportFenceWin32HandleInfoKHR; +// +//typedef struct VkFenceGetWin32HandleInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkFence fence; +// VkExternalFenceHandleTypeFlagBitsKHR handleType; +//} VkFenceGetWin32HandleInfoKHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkImportFenceWin32HandleKHR)(VkDevice device, const VkImportFenceWin32HandleInfoKHR* pImportFenceWin32HandleInfo); +//typedef VkResult (VKAPI_PTR *PFN_vkGetFenceWin32HandleKHR)(VkDevice device, const VkFenceGetWin32HandleInfoKHR* pGetWin32HandleInfo, HANDLE* pHandle); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkImportFenceWin32HandleKHR( +//VkDevice device, +//const VkImportFenceWin32HandleInfoKHR* pImportFenceWin32HandleInfo); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceWin32HandleKHR( +//VkDevice device, +//const VkFenceGetWin32HandleInfoKHR* pGetWin32HandleInfo, +//HANDLE* pHandle); +//#endif +//#endif /* VK_USE_PLATFORM_WIN32_KHR */ +// +//#define VK_KHR_external_fence_fd 1 +//#define VK_KHR_EXTERNAL_FENCE_FD_SPEC_VERSION 1 +//#define VK_KHR_EXTERNAL_FENCE_FD_EXTENSION_NAME "VK_KHR_external_fence_fd" +// +//typedef struct VkImportFenceFdInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkFence fence; +// VkFenceImportFlagsKHR flags; +// VkExternalFenceHandleTypeFlagBitsKHR handleType; +// int fd; +//} VkImportFenceFdInfoKHR; +// +//typedef struct VkFenceGetFdInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkFence fence; +// VkExternalFenceHandleTypeFlagBitsKHR handleType; +//} VkFenceGetFdInfoKHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkImportFenceFdKHR)(VkDevice device, const VkImportFenceFdInfoKHR* pImportFenceFdInfo); +//typedef VkResult (VKAPI_PTR *PFN_vkGetFenceFdKHR)(VkDevice device, const VkFenceGetFdInfoKHR* pGetFdInfo, int* pFd); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkImportFenceFdKHR( +//VkDevice device, +//const VkImportFenceFdInfoKHR* pImportFenceFdInfo); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceFdKHR( +//VkDevice device, +//const VkFenceGetFdInfoKHR* pGetFdInfo, +//int* pFd); +//#endif +// +//#define VK_KHR_maintenance2 1 +//#define VK_KHR_MAINTENANCE2_SPEC_VERSION 1 +//#define VK_KHR_MAINTENANCE2_EXTENSION_NAME "VK_KHR_maintenance2" +// +// +//typedef enum VkPointClippingBehaviorKHR { +// VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR = 0, +// VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY_KHR = 1, +// VK_POINT_CLIPPING_BEHAVIOR_BEGIN_RANGE_KHR = VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR, +// VK_POINT_CLIPPING_BEHAVIOR_END_RANGE_KHR = VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY_KHR, +// VK_POINT_CLIPPING_BEHAVIOR_RANGE_SIZE_KHR = (VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY_KHR - VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR + 1), +// VK_POINT_CLIPPING_BEHAVIOR_MAX_ENUM_KHR = 0x7FFFFFFF +//} VkPointClippingBehaviorKHR; +// +//typedef enum VkTessellationDomainOriginKHR { +// VK_TESSELLATION_DOMAIN_ORIGIN_UPPER_LEFT_KHR = 0, +// VK_TESSELLATION_DOMAIN_ORIGIN_LOWER_LEFT_KHR = 1, +// VK_TESSELLATION_DOMAIN_ORIGIN_BEGIN_RANGE_KHR = VK_TESSELLATION_DOMAIN_ORIGIN_UPPER_LEFT_KHR, +// VK_TESSELLATION_DOMAIN_ORIGIN_END_RANGE_KHR = VK_TESSELLATION_DOMAIN_ORIGIN_LOWER_LEFT_KHR, +// VK_TESSELLATION_DOMAIN_ORIGIN_RANGE_SIZE_KHR = (VK_TESSELLATION_DOMAIN_ORIGIN_LOWER_LEFT_KHR - VK_TESSELLATION_DOMAIN_ORIGIN_UPPER_LEFT_KHR + 1), +// VK_TESSELLATION_DOMAIN_ORIGIN_MAX_ENUM_KHR = 0x7FFFFFFF +//} VkTessellationDomainOriginKHR; +// +//typedef struct VkPhysicalDevicePointClippingPropertiesKHR { +// VkStructureType sType; +// void* pNext; +// VkPointClippingBehaviorKHR pointClippingBehavior; +//} VkPhysicalDevicePointClippingPropertiesKHR; +// +//typedef struct VkInputAttachmentAspectReferenceKHR { +// uint32_t subpass; +// uint32_t inputAttachmentIndex; +// VkImageAspectFlags aspectMask; +//} VkInputAttachmentAspectReferenceKHR; +// +//typedef struct VkRenderPassInputAttachmentAspectCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// uint32_t aspectReferenceCount; +// const VkInputAttachmentAspectReferenceKHR* pAspectReferences; +//} VkRenderPassInputAttachmentAspectCreateInfoKHR; +// +//typedef struct VkImageViewUsageCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkImageUsageFlags usage; +//} VkImageViewUsageCreateInfoKHR; +// +//typedef struct VkPipelineTessellationDomainOriginStateCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkTessellationDomainOriginKHR domainOrigin; +//} VkPipelineTessellationDomainOriginStateCreateInfoKHR; +// +// +// +//#define VK_KHR_get_surface_capabilities2 1 +//#define VK_KHR_GET_SURFACE_CAPABILITIES_2_SPEC_VERSION 1 +//#define VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME "VK_KHR_get_surface_capabilities2" +// +//typedef struct VkPhysicalDeviceSurfaceInfo2KHR { +// VkStructureType sType; +// const void* pNext; +// VkSurfaceKHR surface; +//} VkPhysicalDeviceSurfaceInfo2KHR; +// +//typedef struct VkSurfaceCapabilities2KHR { +// VkStructureType sType; +// void* pNext; +// VkSurfaceCapabilitiesKHR surfaceCapabilities; +//} VkSurfaceCapabilities2KHR; +// +//typedef struct VkSurfaceFormat2KHR { +// VkStructureType sType; +// void* pNext; +// VkSurfaceFormatKHR surfaceFormat; +//} VkSurfaceFormat2KHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, VkSurfaceCapabilities2KHR* pSurfaceCapabilities); +//typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceFormats2KHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, uint32_t* pSurfaceFormatCount, VkSurfaceFormat2KHR* pSurfaceFormats); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilities2KHR( +//VkPhysicalDevice physicalDevice, +//const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, +//VkSurfaceCapabilities2KHR* pSurfaceCapabilities); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormats2KHR( +//VkPhysicalDevice physicalDevice, +//const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, +//uint32_t* pSurfaceFormatCount, +//VkSurfaceFormat2KHR* pSurfaceFormats); +//#endif +// +//#define VK_KHR_variable_pointers 1 +//#define VK_KHR_VARIABLE_POINTERS_SPEC_VERSION 1 +//#define VK_KHR_VARIABLE_POINTERS_EXTENSION_NAME "VK_KHR_variable_pointers" +// +//typedef struct VkPhysicalDeviceVariablePointerFeaturesKHR { +// VkStructureType sType; +// void* pNext; +// VkBool32 variablePointersStorageBuffer; +// VkBool32 variablePointers; +//} VkPhysicalDeviceVariablePointerFeaturesKHR; +// +// +//#define VK_KHR_get_display_properties2 1 +//#define VK_KHR_GET_DISPLAY_PROPERTIES_2_SPEC_VERSION 1 +//#define VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME "VK_KHR_get_display_properties2" +// +//typedef struct VkDisplayProperties2KHR { +// VkStructureType sType; +// void* pNext; +// VkDisplayPropertiesKHR displayProperties; +//} VkDisplayProperties2KHR; +// +//typedef struct VkDisplayPlaneProperties2KHR { +// VkStructureType sType; +// void* pNext; +// VkDisplayPlanePropertiesKHR displayPlaneProperties; +//} VkDisplayPlaneProperties2KHR; +// +//typedef struct VkDisplayModeProperties2KHR { +// VkStructureType sType; +// void* pNext; +// VkDisplayModePropertiesKHR displayModeProperties; +//} VkDisplayModeProperties2KHR; +// +//typedef struct VkDisplayPlaneInfo2KHR { +// VkStructureType sType; +// const void* pNext; +// VkDisplayModeKHR mode; +// uint32_t planeIndex; +//} VkDisplayPlaneInfo2KHR; +// +//typedef struct VkDisplayPlaneCapabilities2KHR { +// VkStructureType sType; +// void* pNext; +// VkDisplayPlaneCapabilitiesKHR capabilities; +//} VkDisplayPlaneCapabilities2KHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceDisplayProperties2KHR)(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayProperties2KHR* pProperties); +//typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceDisplayPlaneProperties2KHR)(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayPlaneProperties2KHR* pProperties); +//typedef VkResult (VKAPI_PTR *PFN_vkGetDisplayModeProperties2KHR)(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t* pPropertyCount, VkDisplayModeProperties2KHR* pProperties); +//typedef VkResult (VKAPI_PTR *PFN_vkGetDisplayPlaneCapabilities2KHR)(VkPhysicalDevice physicalDevice, const VkDisplayPlaneInfo2KHR* pDisplayPlaneInfo, VkDisplayPlaneCapabilities2KHR* pCapabilities); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayProperties2KHR( +//VkPhysicalDevice physicalDevice, +//uint32_t* pPropertyCount, +//VkDisplayProperties2KHR* pProperties); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPlaneProperties2KHR( +//VkPhysicalDevice physicalDevice, +//uint32_t* pPropertyCount, +//VkDisplayPlaneProperties2KHR* pProperties); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayModeProperties2KHR( +//VkPhysicalDevice physicalDevice, +//VkDisplayKHR display, +//uint32_t* pPropertyCount, +//VkDisplayModeProperties2KHR* pProperties); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneCapabilities2KHR( +//VkPhysicalDevice physicalDevice, +//const VkDisplayPlaneInfo2KHR* pDisplayPlaneInfo, +//VkDisplayPlaneCapabilities2KHR* pCapabilities); +//#endif +// +//#define VK_KHR_dedicated_allocation 1 +//#define VK_KHR_DEDICATED_ALLOCATION_SPEC_VERSION 3 +//#define VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME "VK_KHR_dedicated_allocation" +// +//typedef struct VkMemoryDedicatedRequirementsKHR { +// VkStructureType sType; +// void* pNext; +// VkBool32 prefersDedicatedAllocation; +// VkBool32 requiresDedicatedAllocation; +//} VkMemoryDedicatedRequirementsKHR; +// +//typedef struct VkMemoryDedicatedAllocateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkImage image; +// VkBuffer buffer; +//} VkMemoryDedicatedAllocateInfoKHR; +// +// +// +//#define VK_KHR_storage_buffer_storage_class 1 +//#define VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_SPEC_VERSION 1 +//#define VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_EXTENSION_NAME "VK_KHR_storage_buffer_storage_class" +// +// +//#define VK_KHR_relaxed_block_layout 1 +//#define VK_KHR_RELAXED_BLOCK_LAYOUT_SPEC_VERSION 1 +//#define VK_KHR_RELAXED_BLOCK_LAYOUT_EXTENSION_NAME "VK_KHR_relaxed_block_layout" +// +// +//#define VK_KHR_get_memory_requirements2 1 +//#define VK_KHR_GET_MEMORY_REQUIREMENTS_2_SPEC_VERSION 1 +//#define VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME "VK_KHR_get_memory_requirements2" +// +//typedef struct VkBufferMemoryRequirementsInfo2KHR { +// VkStructureType sType; +// const void* pNext; +// VkBuffer buffer; +//} VkBufferMemoryRequirementsInfo2KHR; +// +//typedef struct VkImageMemoryRequirementsInfo2KHR { +// VkStructureType sType; +// const void* pNext; +// VkImage image; +//} VkImageMemoryRequirementsInfo2KHR; +// +//typedef struct VkImageSparseMemoryRequirementsInfo2KHR { +// VkStructureType sType; +// const void* pNext; +// VkImage image; +//} VkImageSparseMemoryRequirementsInfo2KHR; +// +//typedef struct VkMemoryRequirements2KHR { +// VkStructureType sType; +// void* pNext; +// VkMemoryRequirements memoryRequirements; +//} VkMemoryRequirements2KHR; +// +//typedef struct VkSparseImageMemoryRequirements2KHR { +// VkStructureType sType; +// void* pNext; +// VkSparseImageMemoryRequirements memoryRequirements; +//} VkSparseImageMemoryRequirements2KHR; +// +// +//typedef void (VKAPI_PTR *PFN_vkGetImageMemoryRequirements2KHR)(VkDevice device, const VkImageMemoryRequirementsInfo2KHR* pInfo, VkMemoryRequirements2KHR* pMemoryRequirements); +//typedef void (VKAPI_PTR *PFN_vkGetBufferMemoryRequirements2KHR)(VkDevice device, const VkBufferMemoryRequirementsInfo2KHR* pInfo, VkMemoryRequirements2KHR* pMemoryRequirements); +//typedef void (VKAPI_PTR *PFN_vkGetImageSparseMemoryRequirements2KHR)(VkDevice device, const VkImageSparseMemoryRequirementsInfo2KHR* pInfo, uint32_t* pSparseMemoryRequirementCount, VkSparseImageMemoryRequirements2KHR* pSparseMemoryRequirements); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR void VKAPI_CALL vkGetImageMemoryRequirements2KHR( +//VkDevice device, +//const VkImageMemoryRequirementsInfo2KHR* pInfo, +//VkMemoryRequirements2KHR* pMemoryRequirements); +// +//VKAPI_ATTR void VKAPI_CALL vkGetBufferMemoryRequirements2KHR( +//VkDevice device, +//const VkBufferMemoryRequirementsInfo2KHR* pInfo, +//VkMemoryRequirements2KHR* pMemoryRequirements); +// +//VKAPI_ATTR void VKAPI_CALL vkGetImageSparseMemoryRequirements2KHR( +//VkDevice device, +//const VkImageSparseMemoryRequirementsInfo2KHR* pInfo, +//uint32_t* pSparseMemoryRequirementCount, +//VkSparseImageMemoryRequirements2KHR* pSparseMemoryRequirements); +//#endif +// +//#define VK_KHR_image_format_list 1 +//#define VK_KHR_IMAGE_FORMAT_LIST_SPEC_VERSION 1 +//#define VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME "VK_KHR_image_format_list" +// +//typedef struct VkImageFormatListCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// uint32_t viewFormatCount; +// const VkFormat* pViewFormats; +//} VkImageFormatListCreateInfoKHR; +// +// +// +//#define VK_KHR_sampler_ycbcr_conversion 1 +//VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSamplerYcbcrConversionKHR) +// +//#define VK_KHR_SAMPLER_YCBCR_CONVERSION_SPEC_VERSION 1 +//#define VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME "VK_KHR_sampler_ycbcr_conversion" +// +// +//typedef enum VkSamplerYcbcrModelConversionKHR { +// VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY_KHR = 0, +// VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_IDENTITY_KHR = 1, +// VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709_KHR = 2, +// VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_601_KHR = 3, +// VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_2020_KHR = 4, +// VK_SAMPLER_YCBCR_MODEL_CONVERSION_BEGIN_RANGE_KHR = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY_KHR, +// VK_SAMPLER_YCBCR_MODEL_CONVERSION_END_RANGE_KHR = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_2020_KHR, +// VK_SAMPLER_YCBCR_MODEL_CONVERSION_RANGE_SIZE_KHR = (VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_2020_KHR - VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY_KHR + 1), +// VK_SAMPLER_YCBCR_MODEL_CONVERSION_MAX_ENUM_KHR = 0x7FFFFFFF +//} VkSamplerYcbcrModelConversionKHR; +// +//typedef enum VkSamplerYcbcrRangeKHR { +// VK_SAMPLER_YCBCR_RANGE_ITU_FULL_KHR = 0, +// VK_SAMPLER_YCBCR_RANGE_ITU_NARROW_KHR = 1, +// VK_SAMPLER_YCBCR_RANGE_BEGIN_RANGE_KHR = VK_SAMPLER_YCBCR_RANGE_ITU_FULL_KHR, +// VK_SAMPLER_YCBCR_RANGE_END_RANGE_KHR = VK_SAMPLER_YCBCR_RANGE_ITU_NARROW_KHR, +// VK_SAMPLER_YCBCR_RANGE_RANGE_SIZE_KHR = (VK_SAMPLER_YCBCR_RANGE_ITU_NARROW_KHR - VK_SAMPLER_YCBCR_RANGE_ITU_FULL_KHR + 1), +// VK_SAMPLER_YCBCR_RANGE_MAX_ENUM_KHR = 0x7FFFFFFF +//} VkSamplerYcbcrRangeKHR; +// +//typedef enum VkChromaLocationKHR { +// VK_CHROMA_LOCATION_COSITED_EVEN_KHR = 0, +// VK_CHROMA_LOCATION_MIDPOINT_KHR = 1, +// VK_CHROMA_LOCATION_BEGIN_RANGE_KHR = VK_CHROMA_LOCATION_COSITED_EVEN_KHR, +// VK_CHROMA_LOCATION_END_RANGE_KHR = VK_CHROMA_LOCATION_MIDPOINT_KHR, +// VK_CHROMA_LOCATION_RANGE_SIZE_KHR = (VK_CHROMA_LOCATION_MIDPOINT_KHR - VK_CHROMA_LOCATION_COSITED_EVEN_KHR + 1), +// VK_CHROMA_LOCATION_MAX_ENUM_KHR = 0x7FFFFFFF +//} VkChromaLocationKHR; +// +//typedef struct VkSamplerYcbcrConversionCreateInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkFormat format; +// VkSamplerYcbcrModelConversionKHR ycbcrModel; +// VkSamplerYcbcrRangeKHR ycbcrRange; +// VkComponentMapping components; +// VkChromaLocationKHR xChromaOffset; +// VkChromaLocationKHR yChromaOffset; +// VkFilter chromaFilter; +// VkBool32 forceExplicitReconstruction; +//} VkSamplerYcbcrConversionCreateInfoKHR; +// +//typedef struct VkSamplerYcbcrConversionInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkSamplerYcbcrConversionKHR conversion; +//} VkSamplerYcbcrConversionInfoKHR; +// +//typedef struct VkBindImagePlaneMemoryInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkImageAspectFlagBits planeAspect; +//} VkBindImagePlaneMemoryInfoKHR; +// +//typedef struct VkImagePlaneMemoryRequirementsInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkImageAspectFlagBits planeAspect; +//} VkImagePlaneMemoryRequirementsInfoKHR; +// +//typedef struct VkPhysicalDeviceSamplerYcbcrConversionFeaturesKHR { +// VkStructureType sType; +// void* pNext; +// VkBool32 samplerYcbcrConversion; +//} VkPhysicalDeviceSamplerYcbcrConversionFeaturesKHR; +// +//typedef struct VkSamplerYcbcrConversionImageFormatPropertiesKHR { +// VkStructureType sType; +// void* pNext; +// uint32_t combinedImageSamplerDescriptorCount; +//} VkSamplerYcbcrConversionImageFormatPropertiesKHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkCreateSamplerYcbcrConversionKHR)(VkDevice device, const VkSamplerYcbcrConversionCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSamplerYcbcrConversionKHR* pYcbcrConversion); +//typedef void (VKAPI_PTR *PFN_vkDestroySamplerYcbcrConversionKHR)(VkDevice device, VkSamplerYcbcrConversionKHR ycbcrConversion, const VkAllocationCallbacks* pAllocator); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateSamplerYcbcrConversionKHR( +//VkDevice device, +//const VkSamplerYcbcrConversionCreateInfoKHR* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkSamplerYcbcrConversionKHR* pYcbcrConversion); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroySamplerYcbcrConversionKHR( +//VkDevice device, +//VkSamplerYcbcrConversionKHR ycbcrConversion, +//const VkAllocationCallbacks* pAllocator); +//#endif +// +//#define VK_KHR_bind_memory2 1 +//#define VK_KHR_BIND_MEMORY_2_SPEC_VERSION 1 +//#define VK_KHR_BIND_MEMORY_2_EXTENSION_NAME "VK_KHR_bind_memory2" +// +//typedef struct VkBindBufferMemoryInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkBuffer buffer; +// VkDeviceMemory memory; +// VkDeviceSize memoryOffset; +//} VkBindBufferMemoryInfoKHR; +// +//typedef struct VkBindImageMemoryInfoKHR { +// VkStructureType sType; +// const void* pNext; +// VkImage image; +// VkDeviceMemory memory; +// VkDeviceSize memoryOffset; +//} VkBindImageMemoryInfoKHR; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkBindBufferMemory2KHR)(VkDevice device, uint32_t bindInfoCount, const VkBindBufferMemoryInfoKHR* pBindInfos); +//typedef VkResult (VKAPI_PTR *PFN_vkBindImageMemory2KHR)(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfoKHR* pBindInfos); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkBindBufferMemory2KHR( +//VkDevice device, +//uint32_t bindInfoCount, +//const VkBindBufferMemoryInfoKHR* pBindInfos); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory2KHR( +//VkDevice device, +//uint32_t bindInfoCount, +//const VkBindImageMemoryInfoKHR* pBindInfos); +//#endif +// +//#define VK_KHR_draw_indirect_count 1 +//#define VK_KHR_DRAW_INDIRECT_COUNT_SPEC_VERSION 1 +//#define VK_KHR_DRAW_INDIRECT_COUNT_EXTENSION_NAME "VK_KHR_draw_indirect_count" +// +//typedef void (VKAPI_PTR *PFN_vkCmdDrawIndirectCountKHR)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, uint32_t stride); +//typedef void (VKAPI_PTR *PFN_vkCmdDrawIndexedIndirectCountKHR)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, uint32_t stride); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirectCountKHR( +//VkCommandBuffer commandBuffer, +//VkBuffer buffer, +//VkDeviceSize offset, +//VkBuffer countBuffer, +//VkDeviceSize countBufferOffset, +//uint32_t maxDrawCount, +//uint32_t stride); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirectCountKHR( +//VkCommandBuffer commandBuffer, +//VkBuffer buffer, +//VkDeviceSize offset, +//VkBuffer countBuffer, +//VkDeviceSize countBufferOffset, +//uint32_t maxDrawCount, +//uint32_t stride); +//#endif +// +//#define VK_EXT_debug_report 1 +//VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDebugReportCallbackEXT) +// +//#define VK_EXT_DEBUG_REPORT_SPEC_VERSION 9 +//#define VK_EXT_DEBUG_REPORT_EXTENSION_NAME "VK_EXT_debug_report" +//#define DEBUG_REPORT_CREATE_INFO_EXT DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT +//#define VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT +// + +//typedef VkBool32 (VKAPI_PTR *PFN_vkDebugReportCallbackEXT)( +//VkDebugReportFlagsEXT flags, +//VkDebugReportObjectTypeEXT objectType, +//uint64_t object, +//size_t location, +//int32_t messageCode, +//const char* pLayerPrefix, +//const char* pMessage, +//void* pUserData); + +inline var VkDebugReportCallbackCreateInfoEXT.type + get() = VkStructureType of VkDebugReportCallbackCreateInfoEXT.nsType(adr) + set(value) = VkDebugReportCallbackCreateInfoEXT.nsType(adr, value.i) +inline var VkDebugReportCallbackCreateInfoEXT.next + get() = VkDebugReportCallbackCreateInfoEXT.npNext(adr) + set(value) = VkDebugReportCallbackCreateInfoEXT.npNext(adr, value) +/** JVM custom */ +inline var VkDebugReportCallbackCreateInfoEXT.flag: VkDebugReport + get() = TODO() + set(value) = VkDebugReportCallbackCreateInfoEXT.nflags(adr, value.i) +inline var VkDebugReportCallbackCreateInfoEXT.flags: VkDebugReportFlagsEXT + get() = VkDebugReportCallbackCreateInfoEXT.nflags(adr) + set(value) = VkDebugReportCallbackCreateInfoEXT.nflags(adr, value) +var debugCallback: VkDebugReportCallbackEXT? = null +var VkDebugReportCallbackCreateInfoEXT.callback: VkDebugReportCallbackType + get() = TODO() //VkDebugReportCallbackCreateInfoEXT.npfnCallback(adr) + set(crossinline value) { + debugCallback?.free() + debugCallback = VkDebugReportCallbackEXT.create { flags, objectType, `object`, location, messageCode, pLayerPrefix, pMessage, pUserData -> + val type = VkDebugReportObjectType of objectType + value(flags, type, `object`, location, messageCode, pLayerPrefix.utf8, pMessage.utf8, pUserData as Any).i + }.also { + VkDebugReportCallbackCreateInfoEXT.npfnCallback(adr, it) + } + } +inline var VkDebugReportCallbackCreateInfoEXT.userData + get() = VkDebugReportCallbackCreateInfoEXT.npUserData(adr) + set(value) = VkDebugReportCallbackCreateInfoEXT.npUserData(adr, value) + +// +//typedef VkResult (VKAPI_PTR *PFN_vkCreateDebugReportCallbackEXT)(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback); +//typedef void (VKAPI_PTR *PFN_vkDestroyDebugReportCallbackEXT)(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks* pAllocator); +//typedef void (VKAPI_PTR *PFN_vkDebugReportMessageEXT)(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object, size_t location, int32_t messageCode, const char* pLayerPrefix, const char* pMessage); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT( +//VkInstance instance, +//const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkDebugReportCallbackEXT* pCallback); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT( +//VkInstance instance, +//VkDebugReportCallbackEXT callback, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT( +//VkInstance instance, +//VkDebugReportFlagsEXT flags, +//VkDebugReportObjectTypeEXT objectType, +//uint64_t object, +//size_t location, +//int32_t messageCode, +//const char* pLayerPrefix, +//const char* pMessage); +//#endif +// +//#define VK_NV_glsl_shader 1 +//#define VK_NV_GLSL_SHADER_SPEC_VERSION 1 +//#define VK_NV_GLSL_SHADER_EXTENSION_NAME "VK_NV_glsl_shader" +// +// +//#define VK_EXT_depth_range_unrestricted 1 +//#define VK_EXT_DEPTH_RANGE_UNRESTRICTED_SPEC_VERSION 1 +//#define VK_EXT_DEPTH_RANGE_UNRESTRICTED_EXTENSION_NAME "VK_EXT_depth_range_unrestricted" +// +// +//#define VK_IMG_filter_cubic 1 +//#define VK_IMG_FILTER_CUBIC_SPEC_VERSION 1 +//#define VK_IMG_FILTER_CUBIC_EXTENSION_NAME "VK_IMG_filter_cubic" +// +// +//#define VK_AMD_rasterization_order 1 +//#define VK_AMD_RASTERIZATION_ORDER_SPEC_VERSION 1 +//#define VK_AMD_RASTERIZATION_ORDER_EXTENSION_NAME "VK_AMD_rasterization_order" +// +// +//typedef enum VkRasterizationOrderAMD { +// VK_RASTERIZATION_ORDER_STRICT_AMD = 0, +// VK_RASTERIZATION_ORDER_RELAXED_AMD = 1, +// VK_RASTERIZATION_ORDER_BEGIN_RANGE_AMD = VK_RASTERIZATION_ORDER_STRICT_AMD, +// VK_RASTERIZATION_ORDER_END_RANGE_AMD = VK_RASTERIZATION_ORDER_RELAXED_AMD, +// VK_RASTERIZATION_ORDER_RANGE_SIZE_AMD = (VK_RASTERIZATION_ORDER_RELAXED_AMD - VK_RASTERIZATION_ORDER_STRICT_AMD + 1), +// VK_RASTERIZATION_ORDER_MAX_ENUM_AMD = 0x7FFFFFFF +//} VkRasterizationOrderAMD; +// +//typedef struct VkPipelineRasterizationStateRasterizationOrderAMD { +// VkStructureType sType; +// const void* pNext; +// VkRasterizationOrderAMD rasterizationOrder; +//} VkPipelineRasterizationStateRasterizationOrderAMD; +// +// +// +//#define VK_AMD_shader_trinary_minmax 1 +//#define VK_AMD_SHADER_TRINARY_MINMAX_SPEC_VERSION 1 +//#define VK_AMD_SHADER_TRINARY_MINMAX_EXTENSION_NAME "VK_AMD_shader_trinary_minmax" +// +// +//#define VK_AMD_shader_explicit_vertex_parameter 1 +//#define VK_AMD_SHADER_EXPLICIT_VERTEX_PARAMETER_SPEC_VERSION 1 +//#define VK_AMD_SHADER_EXPLICIT_VERTEX_PARAMETER_EXTENSION_NAME "VK_AMD_shader_explicit_vertex_parameter" +// +// +//#define VK_EXT_debug_marker 1 +//#define VK_EXT_DEBUG_MARKER_SPEC_VERSION 4 +//#define VK_EXT_DEBUG_MARKER_EXTENSION_NAME "VK_EXT_debug_marker" + +inline var VkDebugMarkerObjectNameInfoEXT.type: VkStructureType + get() = VkStructureType of VkDebugMarkerObjectNameInfoEXT.nsType(adr) + set(value) = VkDebugMarkerObjectNameInfoEXT.nsType(adr, value.i) +inline var VkDebugMarkerObjectNameInfoEXT.next: Long + get() = VkDebugMarkerObjectNameInfoEXT.npNext(adr) + set(value) = VkDebugMarkerObjectNameInfoEXT.npNext(adr, value) +inline var VkDebugMarkerObjectNameInfoEXT.objectType: VkDebugReportObjectType + get() = VkDebugReportObjectType of VkDebugMarkerObjectNameInfoEXT.nobjectType(adr) + set(value) = VkDebugMarkerObjectNameInfoEXT.nobjectType(adr, value.i) +inline var VkDebugMarkerObjectNameInfoEXT.`object`: Long + get() = VkDebugMarkerObjectNameInfoEXT.nobject(adr) + set(value) = VkDebugMarkerObjectNameInfoEXT.nobject(adr, value) +inline var VkDebugMarkerObjectNameInfoEXT.objectName: String + get() = VkDebugMarkerObjectNameInfoEXT.npObjectNameString(adr) + set(value) = VkDebugMarkerObjectNameInfoEXT.npObjectName(adr, value.utf8) + + +inline var VkDebugMarkerObjectTagInfoEXT.type: VkStructureType + get() = VkStructureType of VkDebugMarkerObjectTagInfoEXT.nsType(adr) + set(value) = VkDebugMarkerObjectTagInfoEXT.nsType(adr, value.i) +inline var VkDebugMarkerObjectTagInfoEXT.next: Long + get() = VkDebugMarkerObjectTagInfoEXT.npNext(adr) + set(value) = VkDebugMarkerObjectTagInfoEXT.npNext(adr, value) +inline var VkDebugMarkerObjectTagInfoEXT.objectType: VkDebugReportObjectType + get() = VkDebugReportObjectType of VkDebugMarkerObjectTagInfoEXT.nobjectType(adr) + set(value) = VkDebugMarkerObjectTagInfoEXT.nobjectType(adr, value.i) +inline var VkDebugMarkerObjectTagInfoEXT.`object`: Long + get() = VkDebugMarkerObjectTagInfoEXT.nobject(adr) + set(value) = VkDebugMarkerObjectTagInfoEXT.nobject(adr, value) +inline var VkDebugMarkerObjectTagInfoEXT.tagName: String + get() = memUTF8(VkDebugMarkerObjectTagInfoEXT.ntagName(adr)) + set(value) = VkDebugMarkerObjectTagInfoEXT.ntagName(adr, value.utf8.adr) +//inline val VkDebugMarkerObjectTagInfoEXT.tagSize: Long get() = VkDebugMarkerObjectTagInfoEXT.ntagSize(adr) +inline var VkDebugMarkerObjectTagInfoEXT.tag: ByteBuffer + get() = VkDebugMarkerObjectTagInfoEXT.npTag(adr) + set(value) { + VkDebugMarkerObjectTagInfoEXT.npTag(adr, value) + VkDebugMarkerObjectTagInfoEXT.ntagSize(adr, value.remaining().L) + } + + +//typedef struct VkDebugMarkerObjectTagInfoEXT { +// VkStructureType sType; +// const void* pNext; +// VkDebugReportObjectTypeEXT objectType; +// uint64_t object; +// uint64_t tagName; +// size_t tagSize; +// const void* pTag; +//} VkDebugMarkerObjectTagInfoEXT; + + +inline var VkDebugMarkerMarkerInfoEXT.type: VkStructureType + get() = VkStructureType of VkDebugMarkerMarkerInfoEXT.nsType(adr) + set(value) = VkDebugMarkerMarkerInfoEXT.nsType(adr, value.i) +inline var VkDebugMarkerMarkerInfoEXT.next: Long + get() = VkDebugMarkerMarkerInfoEXT.npNext(adr) + set(value) = VkDebugMarkerMarkerInfoEXT.npNext(adr, value) +inline var VkDebugMarkerMarkerInfoEXT.markerName: String + get() = VkDebugMarkerMarkerInfoEXT.npMarkerNameString(adr) + set(value) = VkDebugMarkerMarkerInfoEXT.npMarkerName(adr, value.utf8) +inline var VkDebugMarkerMarkerInfoEXT.color: Vec4 + get() = Vec4(VkDebugMarkerMarkerInfoEXT.ncolor(adr)) + set(value) { + memPutFloat(adr + VkDebugMarkerMarkerInfoEXT.COLOR, value.r) + memPutFloat(adr + VkDebugMarkerMarkerInfoEXT.COLOR + Float.BYTES, value.g) + memPutFloat(adr + VkDebugMarkerMarkerInfoEXT.COLOR + Float.BYTES * 2, value.b) + memPutFloat(adr + VkDebugMarkerMarkerInfoEXT.COLOR + Float.BYTES * 3, value.a) + } + +//typedef struct VkDebugMarkerMarkerInfoEXT { +// VkStructureType sType; +// const void* pNext; +// const char* pMarkerName; +// float color[4]; +//} VkDebugMarkerMarkerInfoEXT; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkDebugMarkerSetObjectTagEXT)(VkDevice device, const VkDebugMarkerObjectTagInfoEXT* pTagInfo); +//typedef VkResult (VKAPI_PTR *PFN_vkDebugMarkerSetObjectNameEXT)(VkDevice device, const VkDebugMarkerObjectNameInfoEXT* pNameInfo); +//typedef void (VKAPI_PTR *PFN_vkCmdDebugMarkerBeginEXT)(VkCommandBuffer commandBuffer, const VkDebugMarkerMarkerInfoEXT* pMarkerInfo); +//typedef void (VKAPI_PTR *PFN_vkCmdDebugMarkerEndEXT)(VkCommandBuffer commandBuffer); +//typedef void (VKAPI_PTR *PFN_vkCmdDebugMarkerInsertEXT)(VkCommandBuffer commandBuffer, const VkDebugMarkerMarkerInfoEXT* pMarkerInfo); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkDebugMarkerSetObjectTagEXT( +//VkDevice device, +//const VkDebugMarkerObjectTagInfoEXT* pTagInfo); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkDebugMarkerSetObjectNameEXT( +//VkDevice device, +//const VkDebugMarkerObjectNameInfoEXT* pNameInfo); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdDebugMarkerBeginEXT( +//VkCommandBuffer commandBuffer, +//const VkDebugMarkerMarkerInfoEXT* pMarkerInfo); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdDebugMarkerEndEXT( +//VkCommandBuffer commandBuffer); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdDebugMarkerInsertEXT( +//VkCommandBuffer commandBuffer, +//const VkDebugMarkerMarkerInfoEXT* pMarkerInfo); +//#endif +// +//#define VK_AMD_gcn_shader 1 +//#define VK_AMD_GCN_SHADER_SPEC_VERSION 1 +//#define VK_AMD_GCN_SHADER_EXTENSION_NAME "VK_AMD_gcn_shader" +// +// +//#define VK_NV_dedicated_allocation 1 +//#define VK_NV_DEDICATED_ALLOCATION_SPEC_VERSION 1 +//#define VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME "VK_NV_dedicated_allocation" +// +//typedef struct VkDedicatedAllocationImageCreateInfoNV { +// VkStructureType sType; +// const void* pNext; +// VkBool32 dedicatedAllocation; +//} VkDedicatedAllocationImageCreateInfoNV; +// +//typedef struct VkDedicatedAllocationBufferCreateInfoNV { +// VkStructureType sType; +// const void* pNext; +// VkBool32 dedicatedAllocation; +//} VkDedicatedAllocationBufferCreateInfoNV; +// +//typedef struct VkDedicatedAllocationMemoryAllocateInfoNV { +// VkStructureType sType; +// const void* pNext; +// VkImage image; +// VkBuffer buffer; +//} VkDedicatedAllocationMemoryAllocateInfoNV; +// +// +// +//#define VK_AMD_draw_indirect_count 1 +//#define VK_AMD_DRAW_INDIRECT_COUNT_SPEC_VERSION 1 +//#define VK_AMD_DRAW_INDIRECT_COUNT_EXTENSION_NAME "VK_AMD_draw_indirect_count" +// +//typedef void (VKAPI_PTR *PFN_vkCmdDrawIndirectCountAMD)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, uint32_t stride); +//typedef void (VKAPI_PTR *PFN_vkCmdDrawIndexedIndirectCountAMD)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, uint32_t stride); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirectCountAMD( +//VkCommandBuffer commandBuffer, +//VkBuffer buffer, +//VkDeviceSize offset, +//VkBuffer countBuffer, +//VkDeviceSize countBufferOffset, +//uint32_t maxDrawCount, +//uint32_t stride); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirectCountAMD( +//VkCommandBuffer commandBuffer, +//VkBuffer buffer, +//VkDeviceSize offset, +//VkBuffer countBuffer, +//VkDeviceSize countBufferOffset, +//uint32_t maxDrawCount, +//uint32_t stride); +//#endif +// +//#define VK_AMD_negative_viewport_height 1 +//#define VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_SPEC_VERSION 1 +//#define VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME "VK_AMD_negative_viewport_height" +// +// +//#define VK_AMD_gpu_shader_half_float 1 +//#define VK_AMD_GPU_SHADER_HALF_FLOAT_SPEC_VERSION 1 +//#define VK_AMD_GPU_SHADER_HALF_FLOAT_EXTENSION_NAME "VK_AMD_gpu_shader_half_float" +// +// +//#define VK_AMD_shader_ballot 1 +//#define VK_AMD_SHADER_BALLOT_SPEC_VERSION 1 +//#define VK_AMD_SHADER_BALLOT_EXTENSION_NAME "VK_AMD_shader_ballot" +// +// +//#define VK_AMD_texture_gather_bias_lod 1 +//#define VK_AMD_TEXTURE_GATHER_BIAS_LOD_SPEC_VERSION 1 +//#define VK_AMD_TEXTURE_GATHER_BIAS_LOD_EXTENSION_NAME "VK_AMD_texture_gather_bias_lod" +// +//typedef struct VkTextureLODGatherFormatPropertiesAMD { +// VkStructureType sType; +// void* pNext; +// VkBool32 supportsTextureGatherLODBiasAMD; +//} VkTextureLODGatherFormatPropertiesAMD; +// +// +// +//#define VK_AMD_shader_info 1 +//#define VK_AMD_SHADER_INFO_SPEC_VERSION 1 +//#define VK_AMD_SHADER_INFO_EXTENSION_NAME "VK_AMD_shader_info" +// +// +//typedef enum VkShaderInfoTypeAMD { +// VK_SHADER_INFO_TYPE_STATISTICS_AMD = 0, +// VK_SHADER_INFO_TYPE_BINARY_AMD = 1, +// VK_SHADER_INFO_TYPE_DISASSEMBLY_AMD = 2, +// VK_SHADER_INFO_TYPE_BEGIN_RANGE_AMD = VK_SHADER_INFO_TYPE_STATISTICS_AMD, +// VK_SHADER_INFO_TYPE_END_RANGE_AMD = VK_SHADER_INFO_TYPE_DISASSEMBLY_AMD, +// VK_SHADER_INFO_TYPE_RANGE_SIZE_AMD = (VK_SHADER_INFO_TYPE_DISASSEMBLY_AMD - VK_SHADER_INFO_TYPE_STATISTICS_AMD + 1), +// VK_SHADER_INFO_TYPE_MAX_ENUM_AMD = 0x7FFFFFFF +//} VkShaderInfoTypeAMD; +// +//typedef struct VkShaderResourceUsageAMD { +// uint32_t numUsedVgprs; +// uint32_t numUsedSgprs; +// uint32_t ldsSizePerLocalWorkGroup; +// size_t ldsUsageSizeInBytes; +// size_t scratchMemUsageInBytes; +//} VkShaderResourceUsageAMD; +// +//typedef struct VkShaderStatisticsInfoAMD { +// VkShaderStageFlags shaderStageMask; +// VkShaderResourceUsageAMD resourceUsage; +// uint32_t numPhysicalVgprs; +// uint32_t numPhysicalSgprs; +// uint32_t numAvailableVgprs; +// uint32_t numAvailableSgprs; +// uint32_t computeWorkGroupSize[3]; +//} VkShaderStatisticsInfoAMD; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkGetShaderInfoAMD)(VkDevice device, VkPipeline pipeline, VkShaderStageFlagBits shaderStage, VkShaderInfoTypeAMD infoType, size_t* pInfoSize, void* pInfo); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkGetShaderInfoAMD( +//VkDevice device, +//VkPipeline pipeline, +//VkShaderStageFlagBits shaderStage, +//VkShaderInfoTypeAMD infoType, +//size_t* pInfoSize, +//void* pInfo); +//#endif +// +//#define VK_AMD_shader_image_load_store_lod 1 +//#define VK_AMD_SHADER_IMAGE_LOAD_STORE_LOD_SPEC_VERSION 1 +//#define VK_AMD_SHADER_IMAGE_LOAD_STORE_LOD_EXTENSION_NAME "VK_AMD_shader_image_load_store_lod" +// +// +//#define VK_KHX_multiview 1 +//#define VK_KHX_MULTIVIEW_SPEC_VERSION 1 +//#define VK_KHX_MULTIVIEW_EXTENSION_NAME "VK_KHX_multiview" +// +//typedef struct VkRenderPassMultiviewCreateInfoKHX { +// VkStructureType sType; +// const void* pNext; +// uint32_t subpassCount; +// const uint32_t* pViewMasks; +// uint32_t dependencyCount; +// const int32_t* pViewOffsets; +// uint32_t correlationMaskCount; +// const uint32_t* pCorrelationMasks; +//} VkRenderPassMultiviewCreateInfoKHX; +// +//typedef struct VkPhysicalDeviceMultiviewFeaturesKHX { +// VkStructureType sType; +// void* pNext; +// VkBool32 multiview; +// VkBool32 multiviewGeometryShader; +// VkBool32 multiviewTessellationShader; +//} VkPhysicalDeviceMultiviewFeaturesKHX; +// +//typedef struct VkPhysicalDeviceMultiviewPropertiesKHX { +// VkStructureType sType; +// void* pNext; +// uint32_t maxMultiviewViewCount; +// uint32_t maxMultiviewInstanceIndex; +//} VkPhysicalDeviceMultiviewPropertiesKHX; +// +// +// +//#define VK_IMG_format_pvrtc 1 +//#define VK_IMG_FORMAT_PVRTC_SPEC_VERSION 1 +//#define VK_IMG_FORMAT_PVRTC_EXTENSION_NAME "VK_IMG_format_pvrtc" +// +// +//#define VK_NV_external_memory_capabilities 1 +//#define VK_NV_EXTERNAL_MEMORY_CAPABILITIES_SPEC_VERSION 1 +//#define VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME "VK_NV_external_memory_capabilities" +// +// +//typedef enum VkExternalMemoryHandleTypeFlagBitsNV { +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_NV = 0x00000001, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_NV = 0x00000002, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_IMAGE_BIT_NV = 0x00000004, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_IMAGE_KMT_BIT_NV = 0x00000008, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_FLAG_BITS_MAX_ENUM_NV = 0x7FFFFFFF +//} VkExternalMemoryHandleTypeFlagBitsNV; +//typedef VkFlags VkExternalMemoryHandleTypeFlagsNV; +// +//typedef enum VkExternalMemoryFeatureFlagBitsNV { +// VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT_NV = 0x00000001, +// VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_NV = 0x00000002, +// VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_NV = 0x00000004, +// VK_EXTERNAL_MEMORY_FEATURE_FLAG_BITS_MAX_ENUM_NV = 0x7FFFFFFF +//} VkExternalMemoryFeatureFlagBitsNV; +//typedef VkFlags VkExternalMemoryFeatureFlagsNV; +// +//typedef struct VkExternalImageFormatPropertiesNV { +// VkImageFormatProperties imageFormatProperties; +// VkExternalMemoryFeatureFlagsNV externalMemoryFeatures; +// VkExternalMemoryHandleTypeFlagsNV exportFromImportedHandleTypes; +// VkExternalMemoryHandleTypeFlagsNV compatibleHandleTypes; +//} VkExternalImageFormatPropertiesNV; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceExternalImageFormatPropertiesNV)(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkExternalMemoryHandleTypeFlagsNV externalHandleType, VkExternalImageFormatPropertiesNV* pExternalImageFormatProperties); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceExternalImageFormatPropertiesNV( +//VkPhysicalDevice physicalDevice, +//VkFormat format, +//VkImageType type, +//VkImageTiling tiling, +//VkImageUsageFlags usage, +//VkImageCreateFlags flags, +//VkExternalMemoryHandleTypeFlagsNV externalHandleType, +//VkExternalImageFormatPropertiesNV* pExternalImageFormatProperties); +//#endif +// +//#define VK_NV_external_memory 1 +//#define VK_NV_EXTERNAL_MEMORY_SPEC_VERSION 1 +//#define VK_NV_EXTERNAL_MEMORY_EXTENSION_NAME "VK_NV_external_memory" +// +//typedef struct VkExternalMemoryImageCreateInfoNV { +// VkStructureType sType; +// const void* pNext; +// VkExternalMemoryHandleTypeFlagsNV handleTypes; +//} VkExternalMemoryImageCreateInfoNV; +// +//typedef struct VkExportMemoryAllocateInfoNV { +// VkStructureType sType; +// const void* pNext; +// VkExternalMemoryHandleTypeFlagsNV handleTypes; +//} VkExportMemoryAllocateInfoNV; +// +// +// +//#ifdef VK_USE_PLATFORM_WIN32_KHR +//#define VK_NV_external_memory_win32 1 +//#define VK_NV_EXTERNAL_MEMORY_WIN32_SPEC_VERSION 1 +//#define VK_NV_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME "VK_NV_external_memory_win32" +// +//typedef struct VkImportMemoryWin32HandleInfoNV { +// VkStructureType sType; +// const void* pNext; +// VkExternalMemoryHandleTypeFlagsNV handleType; +// HANDLE handle; +//} VkImportMemoryWin32HandleInfoNV; +// +//typedef struct VkExportMemoryWin32HandleInfoNV { +// VkStructureType sType; +// const void* pNext; +// const SECURITY_ATTRIBUTES* pAttributes; +// DWORD dwAccess; +//} VkExportMemoryWin32HandleInfoNV; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryWin32HandleNV)(VkDevice device, VkDeviceMemory memory, VkExternalMemoryHandleTypeFlagsNV handleType, HANDLE* pHandle); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleNV( +//VkDevice device, +//VkDeviceMemory memory, +//VkExternalMemoryHandleTypeFlagsNV handleType, +//HANDLE* pHandle); +//#endif +//#endif /* VK_USE_PLATFORM_WIN32_KHR */ +// +//#ifdef VK_USE_PLATFORM_WIN32_KHR +//#define VK_NV_win32_keyed_mutex 1 +//#define VK_NV_WIN32_KEYED_MUTEX_SPEC_VERSION 1 +//#define VK_NV_WIN32_KEYED_MUTEX_EXTENSION_NAME "VK_NV_win32_keyed_mutex" +// +//typedef struct VkWin32KeyedMutexAcquireReleaseInfoNV { +// VkStructureType sType; +// const void* pNext; +// uint32_t acquireCount; +// const VkDeviceMemory* pAcquireSyncs; +// const uint64_t* pAcquireKeys; +// const uint32_t* pAcquireTimeoutMilliseconds; +// uint32_t releaseCount; +// const VkDeviceMemory* pReleaseSyncs; +// const uint64_t* pReleaseKeys; +//} VkWin32KeyedMutexAcquireReleaseInfoNV; +// +// +//#endif /* VK_USE_PLATFORM_WIN32_KHR */ +// +//#define VK_KHX_device_group 1 +//#define VK_KHX_DEVICE_GROUP_SPEC_VERSION 2 +//#define VK_KHX_DEVICE_GROUP_EXTENSION_NAME "VK_KHX_device_group" +//#define VK_MAX_DEVICE_GROUP_SIZE_KHX 32 +// +// +//typedef enum VkPeerMemoryFeatureFlagBitsKHX { +// VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT_KHX = 0x00000001, +// VK_PEER_MEMORY_FEATURE_COPY_DST_BIT_KHX = 0x00000002, +// VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT_KHX = 0x00000004, +// VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT_KHX = 0x00000008, +// VK_PEER_MEMORY_FEATURE_FLAG_BITS_MAX_ENUM_KHX = 0x7FFFFFFF +//} VkPeerMemoryFeatureFlagBitsKHX; +//typedef VkFlags VkPeerMemoryFeatureFlagsKHX; +// +//typedef enum VkMemoryAllocateFlagBitsKHX { +// VK_MEMORY_ALLOCATE_DEVICE_MASK_BIT_KHX = 0x00000001, +// VK_MEMORY_ALLOCATE_FLAG_BITS_MAX_ENUM_KHX = 0x7FFFFFFF +//} VkMemoryAllocateFlagBitsKHX; +//typedef VkFlags VkMemoryAllocateFlagsKHX; +// +//typedef enum VkDeviceGroupPresentModeFlagBitsKHX { +// VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHX = 0x00000001, +// VK_DEVICE_GROUP_PRESENT_MODE_REMOTE_BIT_KHX = 0x00000002, +// VK_DEVICE_GROUP_PRESENT_MODE_SUM_BIT_KHX = 0x00000004, +// VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_MULTI_DEVICE_BIT_KHX = 0x00000008, +// VK_DEVICE_GROUP_PRESENT_MODE_FLAG_BITS_MAX_ENUM_KHX = 0x7FFFFFFF +//} VkDeviceGroupPresentModeFlagBitsKHX; +//typedef VkFlags VkDeviceGroupPresentModeFlagsKHX; +// +//typedef struct VkMemoryAllocateFlagsInfoKHX { +// VkStructureType sType; +// const void* pNext; +// VkMemoryAllocateFlagsKHX flags; +// uint32_t deviceMask; +//} VkMemoryAllocateFlagsInfoKHX; +// +//typedef struct VkDeviceGroupRenderPassBeginInfoKHX { +// VkStructureType sType; +// const void* pNext; +// uint32_t deviceMask; +// uint32_t deviceRenderAreaCount; +// const VkRect2D* pDeviceRenderAreas; +//} VkDeviceGroupRenderPassBeginInfoKHX; +// +//typedef struct VkDeviceGroupCommandBufferBeginInfoKHX { +// VkStructureType sType; +// const void* pNext; +// uint32_t deviceMask; +//} VkDeviceGroupCommandBufferBeginInfoKHX; +// +//typedef struct VkDeviceGroupSubmitInfoKHX { +// VkStructureType sType; +// const void* pNext; +// uint32_t waitSemaphoreCount; +// const uint32_t* pWaitSemaphoreDeviceIndices; +// uint32_t commandBufferCount; +// const uint32_t* pCommandBufferDeviceMasks; +// uint32_t signalSemaphoreCount; +// const uint32_t* pSignalSemaphoreDeviceIndices; +//} VkDeviceGroupSubmitInfoKHX; +// +//typedef struct VkDeviceGroupBindSparseInfoKHX { +// VkStructureType sType; +// const void* pNext; +// uint32_t resourceDeviceIndex; +// uint32_t memoryDeviceIndex; +//} VkDeviceGroupBindSparseInfoKHX; +// +//typedef struct VkBindBufferMemoryDeviceGroupInfoKHX { +// VkStructureType sType; +// const void* pNext; +// uint32_t deviceIndexCount; +// const uint32_t* pDeviceIndices; +//} VkBindBufferMemoryDeviceGroupInfoKHX; +// +//typedef struct VkBindImageMemoryDeviceGroupInfoKHX { +// VkStructureType sType; +// const void* pNext; +// uint32_t deviceIndexCount; +// const uint32_t* pDeviceIndices; +// uint32_t SFRRectCount; +// const VkRect2D* pSFRRects; +//} VkBindImageMemoryDeviceGroupInfoKHX; +// +//typedef struct VkDeviceGroupPresentCapabilitiesKHX { +// VkStructureType sType; +// const void* pNext; +// uint32_t presentMask[VK_MAX_DEVICE_GROUP_SIZE_KHX]; +// VkDeviceGroupPresentModeFlagsKHX modes; +//} VkDeviceGroupPresentCapabilitiesKHX; +// +//typedef struct VkImageSwapchainCreateInfoKHX { +// VkStructureType sType; +// const void* pNext; +// VkSwapchainKHR swapchain; +//} VkImageSwapchainCreateInfoKHX; +// +//typedef struct VkBindImageMemorySwapchainInfoKHX { +// VkStructureType sType; +// const void* pNext; +// VkSwapchainKHR swapchain; +// uint32_t imageIndex; +//} VkBindImageMemorySwapchainInfoKHX; +// +//typedef struct VkAcquireNextImageInfoKHX { +// VkStructureType sType; +// const void* pNext; +// VkSwapchainKHR swapchain; +// uint64_t timeout; +// VkSemaphore semaphore; +// VkFence fence; +// uint32_t deviceMask; +//} VkAcquireNextImageInfoKHX; +// +//typedef struct VkDeviceGroupPresentInfoKHX { +// VkStructureType sType; +// const void* pNext; +// uint32_t swapchainCount; +// const uint32_t* pDeviceMasks; +// VkDeviceGroupPresentModeFlagBitsKHX mode; +//} VkDeviceGroupPresentInfoKHX; +// +//typedef struct VkDeviceGroupSwapchainCreateInfoKHX { +// VkStructureType sType; +// const void* pNext; +// VkDeviceGroupPresentModeFlagsKHX modes; +//} VkDeviceGroupSwapchainCreateInfoKHX; +// +// +//typedef void (VKAPI_PTR *PFN_vkGetDeviceGroupPeerMemoryFeaturesKHX)(VkDevice device, uint32_t heapIndex, uint32_t localDeviceIndex, uint32_t remoteDeviceIndex, VkPeerMemoryFeatureFlagsKHX* pPeerMemoryFeatures); +//typedef void (VKAPI_PTR *PFN_vkCmdSetDeviceMaskKHX)(VkCommandBuffer commandBuffer, uint32_t deviceMask); +//typedef void (VKAPI_PTR *PFN_vkCmdDispatchBaseKHX)(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ); +//typedef VkResult (VKAPI_PTR *PFN_vkGetDeviceGroupPresentCapabilitiesKHX)(VkDevice device, VkDeviceGroupPresentCapabilitiesKHX* pDeviceGroupPresentCapabilities); +//typedef VkResult (VKAPI_PTR *PFN_vkGetDeviceGroupSurfacePresentModesKHX)(VkDevice device, VkSurfaceKHR surface, VkDeviceGroupPresentModeFlagsKHX* pModes); +//typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDevicePresentRectanglesKHX)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pRectCount, VkRect2D* pRects); +//typedef VkResult (VKAPI_PTR *PFN_vkAcquireNextImage2KHX)(VkDevice device, const VkAcquireNextImageInfoKHX* pAcquireInfo, uint32_t* pImageIndex); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR void VKAPI_CALL vkGetDeviceGroupPeerMemoryFeaturesKHX( +//VkDevice device, +//uint32_t heapIndex, +//uint32_t localDeviceIndex, +//uint32_t remoteDeviceIndex, +//VkPeerMemoryFeatureFlagsKHX* pPeerMemoryFeatures); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdSetDeviceMaskKHX( +//VkCommandBuffer commandBuffer, +//uint32_t deviceMask); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdDispatchBaseKHX( +//VkCommandBuffer commandBuffer, +//uint32_t baseGroupX, +//uint32_t baseGroupY, +//uint32_t baseGroupZ, +//uint32_t groupCountX, +//uint32_t groupCountY, +//uint32_t groupCountZ); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupPresentCapabilitiesKHX( +//VkDevice device, +//VkDeviceGroupPresentCapabilitiesKHX* pDeviceGroupPresentCapabilities); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupSurfacePresentModesKHX( +//VkDevice device, +//VkSurfaceKHR surface, +//VkDeviceGroupPresentModeFlagsKHX* pModes); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDevicePresentRectanglesKHX( +//VkPhysicalDevice physicalDevice, +//VkSurfaceKHR surface, +//uint32_t* pRectCount, +//VkRect2D* pRects); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImage2KHX( +//VkDevice device, +//const VkAcquireNextImageInfoKHX* pAcquireInfo, +//uint32_t* pImageIndex); +//#endif +// +//#define VK_EXT_validation_flags 1 +//#define VK_EXT_VALIDATION_FLAGS_SPEC_VERSION 1 +//#define VK_EXT_VALIDATION_FLAGS_EXTENSION_NAME "VK_EXT_validation_flags" +// +// +//typedef enum VkValidationCheckEXT { +// VK_VALIDATION_CHECK_ALL_EXT = 0, +// VK_VALIDATION_CHECK_SHADERS_EXT = 1, +// VK_VALIDATION_CHECK_BEGIN_RANGE_EXT = VK_VALIDATION_CHECK_ALL_EXT, +// VK_VALIDATION_CHECK_END_RANGE_EXT = VK_VALIDATION_CHECK_SHADERS_EXT, +// VK_VALIDATION_CHECK_RANGE_SIZE_EXT = (VK_VALIDATION_CHECK_SHADERS_EXT - VK_VALIDATION_CHECK_ALL_EXT + 1), +// VK_VALIDATION_CHECK_MAX_ENUM_EXT = 0x7FFFFFFF +//} VkValidationCheckEXT; +// +//typedef struct VkValidationFlagsEXT { +// VkStructureType sType; +// const void* pNext; +// uint32_t disabledValidationCheckCount; +// VkValidationCheckEXT* pDisabledValidationChecks; +//} VkValidationFlagsEXT; +// +// +// +//#ifdef VK_USE_PLATFORM_VI_NN +//#define VK_NN_vi_surface 1 +//#define VK_NN_VI_SURFACE_SPEC_VERSION 1 +//#define VK_NN_VI_SURFACE_EXTENSION_NAME "VK_NN_vi_surface" +// +//typedef VkFlags VkViSurfaceCreateFlagsNN; +// +//typedef struct VkViSurfaceCreateInfoNN { +// VkStructureType sType; +// const void* pNext; +// VkViSurfaceCreateFlagsNN flags; +// void* window; +//} VkViSurfaceCreateInfoNN; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkCreateViSurfaceNN)(VkInstance instance, const VkViSurfaceCreateInfoNN* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateViSurfaceNN( +//VkInstance instance, +//const VkViSurfaceCreateInfoNN* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkSurfaceKHR* pSurface); +//#endif +//#endif /* VK_USE_PLATFORM_VI_NN */ +// +//#define VK_EXT_shader_subgroup_ballot 1 +//#define VK_EXT_SHADER_SUBGROUP_BALLOT_SPEC_VERSION 1 +//#define VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME "VK_EXT_shader_subgroup_ballot" +// +// +//#define VK_EXT_shader_subgroup_vote 1 +//#define VK_EXT_SHADER_SUBGROUP_VOTE_SPEC_VERSION 1 +//#define VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME "VK_EXT_shader_subgroup_vote" +// +// +//#define VK_KHX_device_group_creation 1 +//#define VK_KHX_DEVICE_GROUP_CREATION_SPEC_VERSION 1 +//#define VK_KHX_DEVICE_GROUP_CREATION_EXTENSION_NAME "VK_KHX_device_group_creation" +// +//typedef struct VkPhysicalDeviceGroupPropertiesKHX { +// VkStructureType sType; +// void* pNext; +// uint32_t physicalDeviceCount; +// VkPhysicalDevice physicalDevices[VK_MAX_DEVICE_GROUP_SIZE_KHX]; +// VkBool32 subsetAllocation; +//} VkPhysicalDeviceGroupPropertiesKHX; +// +//typedef struct VkDeviceGroupDeviceCreateInfoKHX { +// VkStructureType sType; +// const void* pNext; +// uint32_t physicalDeviceCount; +// const VkPhysicalDevice* pPhysicalDevices; +//} VkDeviceGroupDeviceCreateInfoKHX; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkEnumeratePhysicalDeviceGroupsKHX)(VkInstance instance, uint32_t* pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupPropertiesKHX* pPhysicalDeviceGroupProperties); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDeviceGroupsKHX( +//VkInstance instance, +//uint32_t* pPhysicalDeviceGroupCount, +//VkPhysicalDeviceGroupPropertiesKHX* pPhysicalDeviceGroupProperties); +//#endif +// +//#define VK_NVX_device_generated_commands 1 +//VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkObjectTableNVX) +//VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkIndirectCommandsLayoutNVX) +// +//#define VK_NVX_DEVICE_GENERATED_COMMANDS_SPEC_VERSION 3 +//#define VK_NVX_DEVICE_GENERATED_COMMANDS_EXTENSION_NAME "VK_NVX_device_generated_commands" +// +// +//typedef enum VkIndirectCommandsTokenTypeNVX { +// VK_INDIRECT_COMMANDS_TOKEN_TYPE_PIPELINE_NVX = 0, +// VK_INDIRECT_COMMANDS_TOKEN_TYPE_DESCRIPTOR_SET_NVX = 1, +// VK_INDIRECT_COMMANDS_TOKEN_TYPE_INDEX_BUFFER_NVX = 2, +// VK_INDIRECT_COMMANDS_TOKEN_TYPE_VERTEX_BUFFER_NVX = 3, +// VK_INDIRECT_COMMANDS_TOKEN_TYPE_PUSH_CONSTANT_NVX = 4, +// VK_INDIRECT_COMMANDS_TOKEN_TYPE_DRAW_INDEXED_NVX = 5, +// VK_INDIRECT_COMMANDS_TOKEN_TYPE_DRAW_NVX = 6, +// VK_INDIRECT_COMMANDS_TOKEN_TYPE_DISPATCH_NVX = 7, +// VK_INDIRECT_COMMANDS_TOKEN_TYPE_BEGIN_RANGE_NVX = VK_INDIRECT_COMMANDS_TOKEN_TYPE_PIPELINE_NVX, +// VK_INDIRECT_COMMANDS_TOKEN_TYPE_END_RANGE_NVX = VK_INDIRECT_COMMANDS_TOKEN_TYPE_DISPATCH_NVX, +// VK_INDIRECT_COMMANDS_TOKEN_TYPE_RANGE_SIZE_NVX = (VK_INDIRECT_COMMANDS_TOKEN_TYPE_DISPATCH_NVX - VK_INDIRECT_COMMANDS_TOKEN_TYPE_PIPELINE_NVX + 1), +// VK_INDIRECT_COMMANDS_TOKEN_TYPE_MAX_ENUM_NVX = 0x7FFFFFFF +//} VkIndirectCommandsTokenTypeNVX; +// +//typedef enum VkObjectEntryTypeNVX { +// VK_OBJECT_ENTRY_TYPE_DESCRIPTOR_SET_NVX = 0, +// VK_OBJECT_ENTRY_TYPE_PIPELINE_NVX = 1, +// VK_OBJECT_ENTRY_TYPE_INDEX_BUFFER_NVX = 2, +// VK_OBJECT_ENTRY_TYPE_VERTEX_BUFFER_NVX = 3, +// VK_OBJECT_ENTRY_TYPE_PUSH_CONSTANT_NVX = 4, +// VK_OBJECT_ENTRY_TYPE_BEGIN_RANGE_NVX = VK_OBJECT_ENTRY_TYPE_DESCRIPTOR_SET_NVX, +// VK_OBJECT_ENTRY_TYPE_END_RANGE_NVX = VK_OBJECT_ENTRY_TYPE_PUSH_CONSTANT_NVX, +// VK_OBJECT_ENTRY_TYPE_RANGE_SIZE_NVX = (VK_OBJECT_ENTRY_TYPE_PUSH_CONSTANT_NVX - VK_OBJECT_ENTRY_TYPE_DESCRIPTOR_SET_NVX + 1), +// VK_OBJECT_ENTRY_TYPE_MAX_ENUM_NVX = 0x7FFFFFFF +//} VkObjectEntryTypeNVX; +// +// +//typedef enum VkIndirectCommandsLayoutUsageFlagBitsNVX { +// VK_INDIRECT_COMMANDS_LAYOUT_USAGE_UNORDERED_SEQUENCES_BIT_NVX = 0x00000001, +// VK_INDIRECT_COMMANDS_LAYOUT_USAGE_SPARSE_SEQUENCES_BIT_NVX = 0x00000002, +// VK_INDIRECT_COMMANDS_LAYOUT_USAGE_EMPTY_EXECUTIONS_BIT_NVX = 0x00000004, +// VK_INDIRECT_COMMANDS_LAYOUT_USAGE_INDEXED_SEQUENCES_BIT_NVX = 0x00000008, +// VK_INDIRECT_COMMANDS_LAYOUT_USAGE_FLAG_BITS_MAX_ENUM_NVX = 0x7FFFFFFF +//} VkIndirectCommandsLayoutUsageFlagBitsNVX; +//typedef VkFlags VkIndirectCommandsLayoutUsageFlagsNVX; +// +//typedef enum VkObjectEntryUsageFlagBitsNVX { +// VK_OBJECT_ENTRY_USAGE_GRAPHICS_BIT_NVX = 0x00000001, +// VK_OBJECT_ENTRY_USAGE_COMPUTE_BIT_NVX = 0x00000002, +// VK_OBJECT_ENTRY_USAGE_FLAG_BITS_MAX_ENUM_NVX = 0x7FFFFFFF +//} VkObjectEntryUsageFlagBitsNVX; +//typedef VkFlags VkObjectEntryUsageFlagsNVX; +// +//typedef struct VkDeviceGeneratedCommandsFeaturesNVX { +// VkStructureType sType; +// const void* pNext; +// VkBool32 computeBindingPointSupport; +//} VkDeviceGeneratedCommandsFeaturesNVX; +// +//typedef struct VkDeviceGeneratedCommandsLimitsNVX { +// VkStructureType sType; +// const void* pNext; +// uint32_t maxIndirectCommandsLayoutTokenCount; +// uint32_t maxObjectEntryCounts; +// uint32_t minSequenceCountBufferOffsetAlignment; +// uint32_t minSequenceIndexBufferOffsetAlignment; +// uint32_t minCommandsTokenBufferOffsetAlignment; +//} VkDeviceGeneratedCommandsLimitsNVX; +// +//typedef struct VkIndirectCommandsTokenNVX { +// VkIndirectCommandsTokenTypeNVX tokenType; +// VkBuffer buffer; +// VkDeviceSize offset; +//} VkIndirectCommandsTokenNVX; +// +//typedef struct VkIndirectCommandsLayoutTokenNVX { +// VkIndirectCommandsTokenTypeNVX tokenType; +// uint32_t bindingUnit; +// uint32_t dynamicCount; +// uint32_t divisor; +//} VkIndirectCommandsLayoutTokenNVX; +// +//typedef struct VkIndirectCommandsLayoutCreateInfoNVX { +// VkStructureType sType; +// const void* pNext; +// VkPipelineBindPoint pipelineBindPoint; +// VkIndirectCommandsLayoutUsageFlagsNVX flags; +// uint32_t tokenCount; +// const VkIndirectCommandsLayoutTokenNVX* pTokens; +//} VkIndirectCommandsLayoutCreateInfoNVX; +// +//typedef struct VkCmdProcessCommandsInfoNVX { +// VkStructureType sType; +// const void* pNext; +// VkObjectTableNVX objectTable; +// VkIndirectCommandsLayoutNVX indirectCommandsLayout; +// uint32_t indirectCommandsTokenCount; +// const VkIndirectCommandsTokenNVX* pIndirectCommandsTokens; +// uint32_t maxSequencesCount; +// VkCommandBuffer targetCommandBuffer; +// VkBuffer sequencesCountBuffer; +// VkDeviceSize sequencesCountOffset; +// VkBuffer sequencesIndexBuffer; +// VkDeviceSize sequencesIndexOffset; +//} VkCmdProcessCommandsInfoNVX; +// +//typedef struct VkCmdReserveSpaceForCommandsInfoNVX { +// VkStructureType sType; +// const void* pNext; +// VkObjectTableNVX objectTable; +// VkIndirectCommandsLayoutNVX indirectCommandsLayout; +// uint32_t maxSequencesCount; +//} VkCmdReserveSpaceForCommandsInfoNVX; +// +//typedef struct VkObjectTableCreateInfoNVX { +// VkStructureType sType; +// const void* pNext; +// uint32_t objectCount; +// const VkObjectEntryTypeNVX* pObjectEntryTypes; +// const uint32_t* pObjectEntryCounts; +// const VkObjectEntryUsageFlagsNVX* pObjectEntryUsageFlags; +// uint32_t maxUniformBuffersPerDescriptor; +// uint32_t maxStorageBuffersPerDescriptor; +// uint32_t maxStorageImagesPerDescriptor; +// uint32_t maxSampledImagesPerDescriptor; +// uint32_t maxPipelineLayouts; +//} VkObjectTableCreateInfoNVX; +// +//typedef struct VkObjectTableEntryNVX { +// VkObjectEntryTypeNVX type; +// VkObjectEntryUsageFlagsNVX flags; +//} VkObjectTableEntryNVX; +// +//typedef struct VkObjectTablePipelineEntryNVX { +// VkObjectEntryTypeNVX type; +// VkObjectEntryUsageFlagsNVX flags; +// VkPipeline pipeline; +//} VkObjectTablePipelineEntryNVX; +// +//typedef struct VkObjectTableDescriptorSetEntryNVX { +// VkObjectEntryTypeNVX type; +// VkObjectEntryUsageFlagsNVX flags; +// VkPipelineLayout pipelineLayout; +// VkDescriptorSet descriptorSet; +//} VkObjectTableDescriptorSetEntryNVX; +// +//typedef struct VkObjectTableVertexBufferEntryNVX { +// VkObjectEntryTypeNVX type; +// VkObjectEntryUsageFlagsNVX flags; +// VkBuffer buffer; +//} VkObjectTableVertexBufferEntryNVX; +// +//typedef struct VkObjectTableIndexBufferEntryNVX { +// VkObjectEntryTypeNVX type; +// VkObjectEntryUsageFlagsNVX flags; +// VkBuffer buffer; +// VkIndexType indexType; +//} VkObjectTableIndexBufferEntryNVX; +// +//typedef struct VkObjectTablePushConstantEntryNVX { +// VkObjectEntryTypeNVX type; +// VkObjectEntryUsageFlagsNVX flags; +// VkPipelineLayout pipelineLayout; +// VkShaderStageFlags stageFlags; +//} VkObjectTablePushConstantEntryNVX; +// +// +//typedef void (VKAPI_PTR *PFN_vkCmdProcessCommandsNVX)(VkCommandBuffer commandBuffer, const VkCmdProcessCommandsInfoNVX* pProcessCommandsInfo); +//typedef void (VKAPI_PTR *PFN_vkCmdReserveSpaceForCommandsNVX)(VkCommandBuffer commandBuffer, const VkCmdReserveSpaceForCommandsInfoNVX* pReserveSpaceInfo); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateIndirectCommandsLayoutNVX)(VkDevice device, const VkIndirectCommandsLayoutCreateInfoNVX* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkIndirectCommandsLayoutNVX* pIndirectCommandsLayout); +//typedef void (VKAPI_PTR *PFN_vkDestroyIndirectCommandsLayoutNVX)(VkDevice device, VkIndirectCommandsLayoutNVX indirectCommandsLayout, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkCreateObjectTableNVX)(VkDevice device, const VkObjectTableCreateInfoNVX* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkObjectTableNVX* pObjectTable); +//typedef void (VKAPI_PTR *PFN_vkDestroyObjectTableNVX)(VkDevice device, VkObjectTableNVX objectTable, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkRegisterObjectsNVX)(VkDevice device, VkObjectTableNVX objectTable, uint32_t objectCount, const VkObjectTableEntryNVX* const* ppObjectTableEntries, const uint32_t* pObjectIndices); +//typedef VkResult (VKAPI_PTR *PFN_vkUnregisterObjectsNVX)(VkDevice device, VkObjectTableNVX objectTable, uint32_t objectCount, const VkObjectEntryTypeNVX* pObjectEntryTypes, const uint32_t* pObjectIndices); +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceGeneratedCommandsPropertiesNVX)(VkPhysicalDevice physicalDevice, VkDeviceGeneratedCommandsFeaturesNVX* pFeatures, VkDeviceGeneratedCommandsLimitsNVX* pLimits); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR void VKAPI_CALL vkCmdProcessCommandsNVX( +//VkCommandBuffer commandBuffer, +//const VkCmdProcessCommandsInfoNVX* pProcessCommandsInfo); +// +//VKAPI_ATTR void VKAPI_CALL vkCmdReserveSpaceForCommandsNVX( +//VkCommandBuffer commandBuffer, +//const VkCmdReserveSpaceForCommandsInfoNVX* pReserveSpaceInfo); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateIndirectCommandsLayoutNVX( +//VkDevice device, +//const VkIndirectCommandsLayoutCreateInfoNVX* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkIndirectCommandsLayoutNVX* pIndirectCommandsLayout); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyIndirectCommandsLayoutNVX( +//VkDevice device, +//VkIndirectCommandsLayoutNVX indirectCommandsLayout, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateObjectTableNVX( +//VkDevice device, +//const VkObjectTableCreateInfoNVX* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkObjectTableNVX* pObjectTable); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyObjectTableNVX( +//VkDevice device, +//VkObjectTableNVX objectTable, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkRegisterObjectsNVX( +//VkDevice device, +//VkObjectTableNVX objectTable, +//uint32_t objectCount, +//const VkObjectTableEntryNVX* const* ppObjectTableEntries, +//const uint32_t* pObjectIndices); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkUnregisterObjectsNVX( +//VkDevice device, +//VkObjectTableNVX objectTable, +//uint32_t objectCount, +//const VkObjectEntryTypeNVX* pObjectEntryTypes, +//const uint32_t* pObjectIndices); +// +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceGeneratedCommandsPropertiesNVX( +//VkPhysicalDevice physicalDevice, +//VkDeviceGeneratedCommandsFeaturesNVX* pFeatures, +//VkDeviceGeneratedCommandsLimitsNVX* pLimits); +//#endif +// +//#define VK_NV_clip_space_w_scaling 1 +//#define VK_NV_CLIP_SPACE_W_SCALING_SPEC_VERSION 1 +//#define VK_NV_CLIP_SPACE_W_SCALING_EXTENSION_NAME "VK_NV_clip_space_w_scaling" +// +//typedef struct VkViewportWScalingNV { +// float xcoeff; +// float ycoeff; +//} VkViewportWScalingNV; +// +//typedef struct VkPipelineViewportWScalingStateCreateInfoNV { +// VkStructureType sType; +// const void* pNext; +// VkBool32 viewportWScalingEnable; +// uint32_t viewportCount; +// const VkViewportWScalingNV* pViewportWScalings; +//} VkPipelineViewportWScalingStateCreateInfoNV; +// +// +//typedef void (VKAPI_PTR *PFN_vkCmdSetViewportWScalingNV)(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount, const VkViewportWScalingNV* pViewportWScalings); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR void VKAPI_CALL vkCmdSetViewportWScalingNV( +//VkCommandBuffer commandBuffer, +//uint32_t firstViewport, +//uint32_t viewportCount, +//const VkViewportWScalingNV* pViewportWScalings); +//#endif +// +//#define VK_EXT_direct_mode_display 1 +//#define VK_EXT_DIRECT_MODE_DISPLAY_SPEC_VERSION 1 +//#define VK_EXT_DIRECT_MODE_DISPLAY_EXTENSION_NAME "VK_EXT_direct_mode_display" +// +//typedef VkResult (VKAPI_PTR *PFN_vkReleaseDisplayEXT)(VkPhysicalDevice physicalDevice, VkDisplayKHR display); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkReleaseDisplayEXT( +//VkPhysicalDevice physicalDevice, +//VkDisplayKHR display); +//#endif +// +//#ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT +//#define VK_EXT_acquire_xlib_display 1 +//#include +// +//#define VK_EXT_ACQUIRE_XLIB_DISPLAY_SPEC_VERSION 1 +//#define VK_EXT_ACQUIRE_XLIB_DISPLAY_EXTENSION_NAME "VK_EXT_acquire_xlib_display" +// +//typedef VkResult (VKAPI_PTR *PFN_vkAcquireXlibDisplayEXT)(VkPhysicalDevice physicalDevice, Display* dpy, VkDisplayKHR display); +//typedef VkResult (VKAPI_PTR *PFN_vkGetRandROutputDisplayEXT)(VkPhysicalDevice physicalDevice, Display* dpy, RROutput rrOutput, VkDisplayKHR* pDisplay); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkAcquireXlibDisplayEXT( +//VkPhysicalDevice physicalDevice, +//Display* dpy, +//VkDisplayKHR display); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetRandROutputDisplayEXT( +//VkPhysicalDevice physicalDevice, +//Display* dpy, +//RROutput rrOutput, +//VkDisplayKHR* pDisplay); +//#endif +//#endif /* VK_USE_PLATFORM_XLIB_XRANDR_EXT */ +// +//#define VK_EXT_display_surface_counter 1 +//#define VK_EXT_DISPLAY_SURFACE_COUNTER_SPEC_VERSION 1 +//#define VK_EXT_DISPLAY_SURFACE_COUNTER_EXTENSION_NAME "VK_EXT_display_surface_counter" +//#define SURFACE_CAPABILITIES2_EXT SURFACE_CAPABILITIES_2_EXT +// +// +//typedef enum VkSurfaceCounterFlagBitsEXT { +// VK_SURFACE_COUNTER_VBLANK_EXT = 0x00000001, +// VK_SURFACE_COUNTER_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF +//} VkSurfaceCounterFlagBitsEXT; +//typedef VkFlags VkSurfaceCounterFlagsEXT; +// +//typedef struct VkSurfaceCapabilities2EXT { +// VkStructureType sType; +// void* pNext; +// uint32_t minImageCount; +// uint32_t maxImageCount; +// VkExtent2D currentExtent; +// VkExtent2D minImageExtent; +// VkExtent2D maxImageExtent; +// uint32_t maxImageArrayLayers; +// VkSurfaceTransformFlagsKHR supportedTransforms; +// VkSurfaceTransformFlagBitsKHR currentTransform; +// VkCompositeAlphaFlagsKHR supportedCompositeAlpha; +// VkImageUsageFlags supportedUsageFlags; +// VkSurfaceCounterFlagsEXT supportedSurfaceCounters; +//} VkSurfaceCapabilities2EXT; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceCapabilities2EXT)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilities2EXT* pSurfaceCapabilities); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilities2EXT( +//VkPhysicalDevice physicalDevice, +//VkSurfaceKHR surface, +//VkSurfaceCapabilities2EXT* pSurfaceCapabilities); +//#endif +// +//#define VK_EXT_display_control 1 +//#define VK_EXT_DISPLAY_CONTROL_SPEC_VERSION 1 +//#define VK_EXT_DISPLAY_CONTROL_EXTENSION_NAME "VK_EXT_display_control" +// +// +//typedef enum VkDisplayPowerStateEXT { +// VK_DISPLAY_POWER_STATE_OFF_EXT = 0, +// VK_DISPLAY_POWER_STATE_SUSPEND_EXT = 1, +// VK_DISPLAY_POWER_STATE_ON_EXT = 2, +// VK_DISPLAY_POWER_STATE_BEGIN_RANGE_EXT = VK_DISPLAY_POWER_STATE_OFF_EXT, +// VK_DISPLAY_POWER_STATE_END_RANGE_EXT = VK_DISPLAY_POWER_STATE_ON_EXT, +// VK_DISPLAY_POWER_STATE_RANGE_SIZE_EXT = (VK_DISPLAY_POWER_STATE_ON_EXT - VK_DISPLAY_POWER_STATE_OFF_EXT + 1), +// VK_DISPLAY_POWER_STATE_MAX_ENUM_EXT = 0x7FFFFFFF +//} VkDisplayPowerStateEXT; +// +//typedef enum VkDeviceEventTypeEXT { +// VK_DEVICE_EVENT_TYPE_DISPLAY_HOTPLUG_EXT = 0, +// VK_DEVICE_EVENT_TYPE_BEGIN_RANGE_EXT = VK_DEVICE_EVENT_TYPE_DISPLAY_HOTPLUG_EXT, +// VK_DEVICE_EVENT_TYPE_END_RANGE_EXT = VK_DEVICE_EVENT_TYPE_DISPLAY_HOTPLUG_EXT, +// VK_DEVICE_EVENT_TYPE_RANGE_SIZE_EXT = (VK_DEVICE_EVENT_TYPE_DISPLAY_HOTPLUG_EXT - VK_DEVICE_EVENT_TYPE_DISPLAY_HOTPLUG_EXT + 1), +// VK_DEVICE_EVENT_TYPE_MAX_ENUM_EXT = 0x7FFFFFFF +//} VkDeviceEventTypeEXT; +// +//typedef enum VkDisplayEventTypeEXT { +// VK_DISPLAY_EVENT_TYPE_FIRST_PIXEL_OUT_EXT = 0, +// VK_DISPLAY_EVENT_TYPE_BEGIN_RANGE_EXT = VK_DISPLAY_EVENT_TYPE_FIRST_PIXEL_OUT_EXT, +// VK_DISPLAY_EVENT_TYPE_END_RANGE_EXT = VK_DISPLAY_EVENT_TYPE_FIRST_PIXEL_OUT_EXT, +// VK_DISPLAY_EVENT_TYPE_RANGE_SIZE_EXT = (VK_DISPLAY_EVENT_TYPE_FIRST_PIXEL_OUT_EXT - VK_DISPLAY_EVENT_TYPE_FIRST_PIXEL_OUT_EXT + 1), +// VK_DISPLAY_EVENT_TYPE_MAX_ENUM_EXT = 0x7FFFFFFF +//} VkDisplayEventTypeEXT; +// +//typedef struct VkDisplayPowerInfoEXT { +// VkStructureType sType; +// const void* pNext; +// VkDisplayPowerStateEXT powerState; +//} VkDisplayPowerInfoEXT; +// +//typedef struct VkDeviceEventInfoEXT { +// VkStructureType sType; +// const void* pNext; +// VkDeviceEventTypeEXT deviceEvent; +//} VkDeviceEventInfoEXT; +// +//typedef struct VkDisplayEventInfoEXT { +// VkStructureType sType; +// const void* pNext; +// VkDisplayEventTypeEXT displayEvent; +//} VkDisplayEventInfoEXT; +// +//typedef struct VkSwapchainCounterCreateInfoEXT { +// VkStructureType sType; +// const void* pNext; +// VkSurfaceCounterFlagsEXT surfaceCounters; +//} VkSwapchainCounterCreateInfoEXT; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkDisplayPowerControlEXT)(VkDevice device, VkDisplayKHR display, const VkDisplayPowerInfoEXT* pDisplayPowerInfo); +//typedef VkResult (VKAPI_PTR *PFN_vkRegisterDeviceEventEXT)(VkDevice device, const VkDeviceEventInfoEXT* pDeviceEventInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence); +//typedef VkResult (VKAPI_PTR *PFN_vkRegisterDisplayEventEXT)(VkDevice device, VkDisplayKHR display, const VkDisplayEventInfoEXT* pDisplayEventInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence); +//typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainCounterEXT)(VkDevice device, VkSwapchainKHR swapchain, VkSurfaceCounterFlagBitsEXT counter, uint64_t* pCounterValue); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkDisplayPowerControlEXT( +//VkDevice device, +//VkDisplayKHR display, +//const VkDisplayPowerInfoEXT* pDisplayPowerInfo); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkRegisterDeviceEventEXT( +//VkDevice device, +//const VkDeviceEventInfoEXT* pDeviceEventInfo, +//const VkAllocationCallbacks* pAllocator, +//VkFence* pFence); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkRegisterDisplayEventEXT( +//VkDevice device, +//VkDisplayKHR display, +//const VkDisplayEventInfoEXT* pDisplayEventInfo, +//const VkAllocationCallbacks* pAllocator, +//VkFence* pFence); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainCounterEXT( +//VkDevice device, +//VkSwapchainKHR swapchain, +//VkSurfaceCounterFlagBitsEXT counter, +//uint64_t* pCounterValue); +//#endif +// +//#define VK_GOOGLE_display_timing 1 +//#define VK_GOOGLE_DISPLAY_TIMING_SPEC_VERSION 1 +//#define VK_GOOGLE_DISPLAY_TIMING_EXTENSION_NAME "VK_GOOGLE_display_timing" +// +//typedef struct VkRefreshCycleDurationGOOGLE { +// uint64_t refreshDuration; +//} VkRefreshCycleDurationGOOGLE; +// +//typedef struct VkPastPresentationTimingGOOGLE { +// uint32_t presentID; +// uint64_t desiredPresentTime; +// uint64_t actualPresentTime; +// uint64_t earliestPresentTime; +// uint64_t presentMargin; +//} VkPastPresentationTimingGOOGLE; +// +//typedef struct VkPresentTimeGOOGLE { +// uint32_t presentID; +// uint64_t desiredPresentTime; +//} VkPresentTimeGOOGLE; +// +//typedef struct VkPresentTimesInfoGOOGLE { +// VkStructureType sType; +// const void* pNext; +// uint32_t swapchainCount; +// const VkPresentTimeGOOGLE* pTimes; +//} VkPresentTimesInfoGOOGLE; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkGetRefreshCycleDurationGOOGLE)(VkDevice device, VkSwapchainKHR swapchain, VkRefreshCycleDurationGOOGLE* pDisplayTimingProperties); +//typedef VkResult (VKAPI_PTR *PFN_vkGetPastPresentationTimingGOOGLE)(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pPresentationTimingCount, VkPastPresentationTimingGOOGLE* pPresentationTimings); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkGetRefreshCycleDurationGOOGLE( +//VkDevice device, +//VkSwapchainKHR swapchain, +//VkRefreshCycleDurationGOOGLE* pDisplayTimingProperties); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetPastPresentationTimingGOOGLE( +//VkDevice device, +//VkSwapchainKHR swapchain, +//uint32_t* pPresentationTimingCount, +//VkPastPresentationTimingGOOGLE* pPresentationTimings); +//#endif +// +//#define VK_NV_sample_mask_override_coverage 1 +//#define VK_NV_SAMPLE_MASK_OVERRIDE_COVERAGE_SPEC_VERSION 1 +//#define VK_NV_SAMPLE_MASK_OVERRIDE_COVERAGE_EXTENSION_NAME "VK_NV_sample_mask_override_coverage" +// +// +//#define VK_NV_geometry_shader_passthrough 1 +//#define VK_NV_GEOMETRY_SHADER_PASSTHROUGH_SPEC_VERSION 1 +//#define VK_NV_GEOMETRY_SHADER_PASSTHROUGH_EXTENSION_NAME "VK_NV_geometry_shader_passthrough" +// +// +//#define VK_NV_viewport_array2 1 +//#define VK_NV_VIEWPORT_ARRAY2_SPEC_VERSION 1 +//#define VK_NV_VIEWPORT_ARRAY2_EXTENSION_NAME "VK_NV_viewport_array2" +// +// +//#define VK_NVX_multiview_per_view_attributes 1 +//#define VK_NVX_MULTIVIEW_PER_VIEW_ATTRIBUTES_SPEC_VERSION 1 +//#define VK_NVX_MULTIVIEW_PER_VIEW_ATTRIBUTES_EXTENSION_NAME "VK_NVX_multiview_per_view_attributes" +// +//typedef struct VkPhysicalDeviceMultiviewPerViewAttributesPropertiesNVX { +// VkStructureType sType; +// void* pNext; +// VkBool32 perViewPositionAllComponents; +//} VkPhysicalDeviceMultiviewPerViewAttributesPropertiesNVX; +// +// +// +//#define VK_NV_viewport_swizzle 1 +//#define VK_NV_VIEWPORT_SWIZZLE_SPEC_VERSION 1 +//#define VK_NV_VIEWPORT_SWIZZLE_EXTENSION_NAME "VK_NV_viewport_swizzle" +// +// +//typedef enum VkViewportCoordinateSwizzleNV { +// VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_X_NV = 0, +// VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_X_NV = 1, +// VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_Y_NV = 2, +// VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_Y_NV = 3, +// VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_Z_NV = 4, +// VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_Z_NV = 5, +// VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_W_NV = 6, +// VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_W_NV = 7, +// VK_VIEWPORT_COORDINATE_SWIZZLE_BEGIN_RANGE_NV = VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_X_NV, +// VK_VIEWPORT_COORDINATE_SWIZZLE_END_RANGE_NV = VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_W_NV, +// VK_VIEWPORT_COORDINATE_SWIZZLE_RANGE_SIZE_NV = (VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_W_NV - VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_X_NV + 1), +// VK_VIEWPORT_COORDINATE_SWIZZLE_MAX_ENUM_NV = 0x7FFFFFFF +//} VkViewportCoordinateSwizzleNV; +// +//typedef VkFlags VkPipelineViewportSwizzleStateCreateFlagsNV; +// +//typedef struct VkViewportSwizzleNV { +// VkViewportCoordinateSwizzleNV x; +// VkViewportCoordinateSwizzleNV y; +// VkViewportCoordinateSwizzleNV z; +// VkViewportCoordinateSwizzleNV w; +//} VkViewportSwizzleNV; +// +//typedef struct VkPipelineViewportSwizzleStateCreateInfoNV { +// VkStructureType sType; +// const void* pNext; +// VkPipelineViewportSwizzleStateCreateFlagsNV flags; +// uint32_t viewportCount; +// const VkViewportSwizzleNV* pViewportSwizzles; +//} VkPipelineViewportSwizzleStateCreateInfoNV; +// +// +// +//#define VK_EXT_discard_rectangles 1 +//#define VK_EXT_DISCARD_RECTANGLES_SPEC_VERSION 1 +//#define VK_EXT_DISCARD_RECTANGLES_EXTENSION_NAME "VK_EXT_discard_rectangles" +// +// +//typedef enum VkDiscardRectangleModeEXT { +// VK_DISCARD_RECTANGLE_MODE_INCLUSIVE_EXT = 0, +// VK_DISCARD_RECTANGLE_MODE_EXCLUSIVE_EXT = 1, +// VK_DISCARD_RECTANGLE_MODE_BEGIN_RANGE_EXT = VK_DISCARD_RECTANGLE_MODE_INCLUSIVE_EXT, +// VK_DISCARD_RECTANGLE_MODE_END_RANGE_EXT = VK_DISCARD_RECTANGLE_MODE_EXCLUSIVE_EXT, +// VK_DISCARD_RECTANGLE_MODE_RANGE_SIZE_EXT = (VK_DISCARD_RECTANGLE_MODE_EXCLUSIVE_EXT - VK_DISCARD_RECTANGLE_MODE_INCLUSIVE_EXT + 1), +// VK_DISCARD_RECTANGLE_MODE_MAX_ENUM_EXT = 0x7FFFFFFF +//} VkDiscardRectangleModeEXT; +// +//typedef VkFlags VkPipelineDiscardRectangleStateCreateFlagsEXT; +// +//typedef struct VkPhysicalDeviceDiscardRectanglePropertiesEXT { +// VkStructureType sType; +// void* pNext; +// uint32_t maxDiscardRectangles; +//} VkPhysicalDeviceDiscardRectanglePropertiesEXT; +// +//typedef struct VkPipelineDiscardRectangleStateCreateInfoEXT { +// VkStructureType sType; +// const void* pNext; +// VkPipelineDiscardRectangleStateCreateFlagsEXT flags; +// VkDiscardRectangleModeEXT discardRectangleMode; +// uint32_t discardRectangleCount; +// const VkRect2D* pDiscardRectangles; +//} VkPipelineDiscardRectangleStateCreateInfoEXT; +// +// +//typedef void (VKAPI_PTR *PFN_vkCmdSetDiscardRectangleEXT)(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle, uint32_t discardRectangleCount, const VkRect2D* pDiscardRectangles); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR void VKAPI_CALL vkCmdSetDiscardRectangleEXT( +//VkCommandBuffer commandBuffer, +//uint32_t firstDiscardRectangle, +//uint32_t discardRectangleCount, +//const VkRect2D* pDiscardRectangles); +//#endif +// +//#define VK_EXT_conservative_rasterization 1 +//#define VK_EXT_CONSERVATIVE_RASTERIZATION_SPEC_VERSION 1 +//#define VK_EXT_CONSERVATIVE_RASTERIZATION_EXTENSION_NAME "VK_EXT_conservative_rasterization" +// +// +//typedef enum VkConservativeRasterizationModeEXT { +// VK_CONSERVATIVE_RASTERIZATION_MODE_DISABLED_EXT = 0, +// VK_CONSERVATIVE_RASTERIZATION_MODE_OVERESTIMATE_EXT = 1, +// VK_CONSERVATIVE_RASTERIZATION_MODE_UNDERESTIMATE_EXT = 2, +// VK_CONSERVATIVE_RASTERIZATION_MODE_BEGIN_RANGE_EXT = VK_CONSERVATIVE_RASTERIZATION_MODE_DISABLED_EXT, +// VK_CONSERVATIVE_RASTERIZATION_MODE_END_RANGE_EXT = VK_CONSERVATIVE_RASTERIZATION_MODE_UNDERESTIMATE_EXT, +// VK_CONSERVATIVE_RASTERIZATION_MODE_RANGE_SIZE_EXT = (VK_CONSERVATIVE_RASTERIZATION_MODE_UNDERESTIMATE_EXT - VK_CONSERVATIVE_RASTERIZATION_MODE_DISABLED_EXT + 1), +// VK_CONSERVATIVE_RASTERIZATION_MODE_MAX_ENUM_EXT = 0x7FFFFFFF +//} VkConservativeRasterizationModeEXT; +// +//typedef VkFlags VkPipelineRasterizationConservativeStateCreateFlagsEXT; +// +//typedef struct VkPhysicalDeviceConservativeRasterizationPropertiesEXT { +// VkStructureType sType; +// void* pNext; +// float primitiveOverestimationSize; +// float maxExtraPrimitiveOverestimationSize; +// float extraPrimitiveOverestimationSizeGranularity; +// VkBool32 primitiveUnderestimation; +// VkBool32 conservativePointAndLineRasterization; +// VkBool32 degenerateTrianglesRasterized; +// VkBool32 degenerateLinesRasterized; +// VkBool32 fullyCoveredFragmentShaderInputVariable; +// VkBool32 conservativeRasterizationPostDepthCoverage; +//} VkPhysicalDeviceConservativeRasterizationPropertiesEXT; +// +//typedef struct VkPipelineRasterizationConservativeStateCreateInfoEXT { +// VkStructureType sType; +// const void* pNext; +// VkPipelineRasterizationConservativeStateCreateFlagsEXT flags; +// VkConservativeRasterizationModeEXT conservativeRasterizationMode; +// float extraPrimitiveOverestimationSize; +//} VkPipelineRasterizationConservativeStateCreateInfoEXT; +// +// +// +//#define VK_EXT_swapchain_colorspace 1 +//#define VK_EXT_SWAPCHAIN_COLOR_SPACE_SPEC_VERSION 3 +//#define VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME "VK_EXT_swapchain_colorspace" +// +// +//#define VK_EXT_hdr_metadata 1 +//#define VK_EXT_HDR_METADATA_SPEC_VERSION 1 +//#define VK_EXT_HDR_METADATA_EXTENSION_NAME "VK_EXT_hdr_metadata" +// +//typedef struct VkXYColorEXT { +// float x; +// float y; +//} VkXYColorEXT; +// +//typedef struct VkHdrMetadataEXT { +// VkStructureType sType; +// const void* pNext; +// VkXYColorEXT displayPrimaryRed; +// VkXYColorEXT displayPrimaryGreen; +// VkXYColorEXT displayPrimaryBlue; +// VkXYColorEXT whitePoint; +// float maxLuminance; +// float minLuminance; +// float maxContentLightLevel; +// float maxFrameAverageLightLevel; +//} VkHdrMetadataEXT; +// +// +//typedef void (VKAPI_PTR *PFN_vkSetHdrMetadataEXT)(VkDevice device, uint32_t swapchainCount, const VkSwapchainKHR* pSwapchains, const VkHdrMetadataEXT* pMetadata); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR void VKAPI_CALL vkSetHdrMetadataEXT( +//VkDevice device, +//uint32_t swapchainCount, +//const VkSwapchainKHR* pSwapchains, +//const VkHdrMetadataEXT* pMetadata); +//#endif +// +//#ifdef VK_USE_PLATFORM_IOS_MVK +//#define VK_MVK_ios_surface 1 +//#define VK_MVK_IOS_SURFACE_SPEC_VERSION 2 +//#define VK_MVK_IOS_SURFACE_EXTENSION_NAME "VK_MVK_ios_surface" +// +//typedef VkFlags VkIOSSurfaceCreateFlagsMVK; +// +//typedef struct VkIOSSurfaceCreateInfoMVK { +// VkStructureType sType; +// const void* pNext; +// VkIOSSurfaceCreateFlagsMVK flags; +// const void* pView; +//} VkIOSSurfaceCreateInfoMVK; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkCreateIOSSurfaceMVK)(VkInstance instance, const VkIOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateIOSSurfaceMVK( +//VkInstance instance, +//const VkIOSSurfaceCreateInfoMVK* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkSurfaceKHR* pSurface); +//#endif +//#endif /* VK_USE_PLATFORM_IOS_MVK */ +// +//#ifdef VK_USE_PLATFORM_MACOS_MVK +//#define VK_MVK_macos_surface 1 +//#define VK_MVK_MACOS_SURFACE_SPEC_VERSION 2 +//#define VK_MVK_MACOS_SURFACE_EXTENSION_NAME "VK_MVK_macos_surface" +// +//typedef VkFlags VkMacOSSurfaceCreateFlagsMVK; +// +//typedef struct VkMacOSSurfaceCreateInfoMVK { +// VkStructureType sType; +// const void* pNext; +// VkMacOSSurfaceCreateFlagsMVK flags; +// const void* pView; +//} VkMacOSSurfaceCreateInfoMVK; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkCreateMacOSSurfaceMVK)(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK( +//VkInstance instance, +//const VkMacOSSurfaceCreateInfoMVK* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkSurfaceKHR* pSurface); +//#endif +//#endif /* VK_USE_PLATFORM_MACOS_MVK */ +// +//#define VK_EXT_external_memory_dma_buf 1 +//#define VK_EXT_EXTERNAL_MEMORY_DMA_BUF_SPEC_VERSION 1 +//#define VK_EXT_EXTERNAL_MEMORY_DMA_BUF_EXTENSION_NAME "VK_EXT_external_memory_dma_buf" +// +// +//#define VK_EXT_queue_family_foreign 1 +//#define VK_EXT_QUEUE_FAMILY_FOREIGN_SPEC_VERSION 1 +//#define VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME "VK_EXT_queue_family_foreign" +//#define VK_QUEUE_FAMILY_FOREIGN_EXT (~0U-2) +// +// +//#define VK_EXT_sampler_filter_minmax 1 +//#define VK_EXT_SAMPLER_FILTER_MINMAX_SPEC_VERSION 1 +//#define VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME "VK_EXT_sampler_filter_minmax" +// +// +//typedef enum VkSamplerReductionModeEXT { +// VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT = 0, +// VK_SAMPLER_REDUCTION_MODE_MIN_EXT = 1, +// VK_SAMPLER_REDUCTION_MODE_MAX_EXT = 2, +// VK_SAMPLER_REDUCTION_MODE_BEGIN_RANGE_EXT = VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT, +// VK_SAMPLER_REDUCTION_MODE_END_RANGE_EXT = VK_SAMPLER_REDUCTION_MODE_MAX_EXT, +// VK_SAMPLER_REDUCTION_MODE_RANGE_SIZE_EXT = (VK_SAMPLER_REDUCTION_MODE_MAX_EXT - VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT + 1), +// VK_SAMPLER_REDUCTION_MODE_MAX_ENUM_EXT = 0x7FFFFFFF +//} VkSamplerReductionModeEXT; +// +//typedef struct VkSamplerReductionModeCreateInfoEXT { +// VkStructureType sType; +// const void* pNext; +// VkSamplerReductionModeEXT reductionMode; +//} VkSamplerReductionModeCreateInfoEXT; +// +//typedef struct VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT { +// VkStructureType sType; +// void* pNext; +// VkBool32 filterMinmaxSingleComponentFormats; +// VkBool32 filterMinmaxImageComponentMapping; +//} VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT; +// +// +// +//#define VK_AMD_gpu_shader_int16 1 +//#define VK_AMD_GPU_SHADER_INT16_SPEC_VERSION 1 +//#define VK_AMD_GPU_SHADER_INT16_EXTENSION_NAME "VK_AMD_gpu_shader_int16" +// +// +//#define VK_AMD_mixed_attachment_samples 1 +//#define VK_AMD_MIXED_ATTACHMENT_SAMPLES_SPEC_VERSION 1 +//#define VK_AMD_MIXED_ATTACHMENT_SAMPLES_EXTENSION_NAME "VK_AMD_mixed_attachment_samples" +// +// +//#define VK_AMD_shader_fragment_mask 1 +//#define VK_AMD_SHADER_FRAGMENT_MASK_SPEC_VERSION 1 +//#define VK_AMD_SHADER_FRAGMENT_MASK_EXTENSION_NAME "VK_AMD_shader_fragment_mask" +// +// +//#define VK_EXT_shader_stencil_export 1 +//#define VK_EXT_SHADER_STENCIL_EXPORT_SPEC_VERSION 1 +//#define VK_EXT_SHADER_STENCIL_EXPORT_EXTENSION_NAME "VK_EXT_shader_stencil_export" +// +// +//#define VK_EXT_sample_locations 1 +//#define VK_EXT_SAMPLE_LOCATIONS_SPEC_VERSION 1 +//#define VK_EXT_SAMPLE_LOCATIONS_EXTENSION_NAME "VK_EXT_sample_locations" +// +//typedef struct VkSampleLocationEXT { +// float x; +// float y; +//} VkSampleLocationEXT; +// +//typedef struct VkSampleLocationsInfoEXT { +// VkStructureType sType; +// const void* pNext; +// VkSampleCountFlagBits sampleLocationsPerPixel; +// VkExtent2D sampleLocationGridSize; +// uint32_t sampleLocationsCount; +// const VkSampleLocationEXT* pSampleLocations; +//} VkSampleLocationsInfoEXT; +// +//typedef struct VkAttachmentSampleLocationsEXT { +// uint32_t attachmentIndex; +// VkSampleLocationsInfoEXT sampleLocationsInfo; +//} VkAttachmentSampleLocationsEXT; +// +//typedef struct VkSubpassSampleLocationsEXT { +// uint32_t subpassIndex; +// VkSampleLocationsInfoEXT sampleLocationsInfo; +//} VkSubpassSampleLocationsEXT; +// +//typedef struct VkRenderPassSampleLocationsBeginInfoEXT { +// VkStructureType sType; +// const void* pNext; +// uint32_t attachmentInitialSampleLocationsCount; +// const VkAttachmentSampleLocationsEXT* pAttachmentInitialSampleLocations; +// uint32_t postSubpassSampleLocationsCount; +// const VkSubpassSampleLocationsEXT* pPostSubpassSampleLocations; +//} VkRenderPassSampleLocationsBeginInfoEXT; +// +//typedef struct VkPipelineSampleLocationsStateCreateInfoEXT { +// VkStructureType sType; +// const void* pNext; +// VkBool32 sampleLocationsEnable; +// VkSampleLocationsInfoEXT sampleLocationsInfo; +//} VkPipelineSampleLocationsStateCreateInfoEXT; +// +//typedef struct VkPhysicalDeviceSampleLocationsPropertiesEXT { +// VkStructureType sType; +// void* pNext; +// VkSampleCountFlags sampleLocationSampleCounts; +// VkExtent2D maxSampleLocationGridSize; +// float sampleLocationCoordinateRange[2]; +// uint32_t sampleLocationSubPixelBits; +// VkBool32 variableSampleLocations; +//} VkPhysicalDeviceSampleLocationsPropertiesEXT; +// +//typedef struct VkMultisamplePropertiesEXT { +// VkStructureType sType; +// void* pNext; +// VkExtent2D maxSampleLocationGridSize; +//} VkMultisamplePropertiesEXT; +// +// +//typedef void (VKAPI_PTR *PFN_vkCmdSetSampleLocationsEXT)(VkCommandBuffer commandBuffer, const VkSampleLocationsInfoEXT* pSampleLocationsInfo); +//typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceMultisamplePropertiesEXT)(VkPhysicalDevice physicalDevice, VkSampleCountFlagBits samples, VkMultisamplePropertiesEXT* pMultisampleProperties); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR void VKAPI_CALL vkCmdSetSampleLocationsEXT( +//VkCommandBuffer commandBuffer, +//const VkSampleLocationsInfoEXT* pSampleLocationsInfo); +// +//VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMultisamplePropertiesEXT( +//VkPhysicalDevice physicalDevice, +//VkSampleCountFlagBits samples, +//VkMultisamplePropertiesEXT* pMultisampleProperties); +//#endif +// +//#define VK_EXT_blend_operation_advanced 1 +//#define VK_EXT_BLEND_OPERATION_ADVANCED_SPEC_VERSION 2 +//#define VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME "VK_EXT_blend_operation_advanced" +// +// +//typedef enum VkBlendOverlapEXT { +// VK_BLEND_OVERLAP_UNCORRELATED_EXT = 0, +// VK_BLEND_OVERLAP_DISJOINT_EXT = 1, +// VK_BLEND_OVERLAP_CONJOINT_EXT = 2, +// VK_BLEND_OVERLAP_BEGIN_RANGE_EXT = VK_BLEND_OVERLAP_UNCORRELATED_EXT, +// VK_BLEND_OVERLAP_END_RANGE_EXT = VK_BLEND_OVERLAP_CONJOINT_EXT, +// VK_BLEND_OVERLAP_RANGE_SIZE_EXT = (VK_BLEND_OVERLAP_CONJOINT_EXT - VK_BLEND_OVERLAP_UNCORRELATED_EXT + 1), +// VK_BLEND_OVERLAP_MAX_ENUM_EXT = 0x7FFFFFFF +//} VkBlendOverlapEXT; +// +//typedef struct VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT { +// VkStructureType sType; +// void* pNext; +// VkBool32 advancedBlendCoherentOperations; +//} VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT; +// +//typedef struct VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT { +// VkStructureType sType; +// void* pNext; +// uint32_t advancedBlendMaxColorAttachments; +// VkBool32 advancedBlendIndependentBlend; +// VkBool32 advancedBlendNonPremultipliedSrcColor; +// VkBool32 advancedBlendNonPremultipliedDstColor; +// VkBool32 advancedBlendCorrelatedOverlap; +// VkBool32 advancedBlendAllOperations; +//} VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT; +// +//typedef struct VkPipelineColorBlendAdvancedStateCreateInfoEXT { +// VkStructureType sType; +// const void* pNext; +// VkBool32 srcPremultiplied; +// VkBool32 dstPremultiplied; +// VkBlendOverlapEXT blendOverlap; +//} VkPipelineColorBlendAdvancedStateCreateInfoEXT; +// +// +// +//#define VK_NV_fragment_coverage_to_color 1 +//#define VK_NV_FRAGMENT_COVERAGE_TO_COLOR_SPEC_VERSION 1 +//#define VK_NV_FRAGMENT_COVERAGE_TO_COLOR_EXTENSION_NAME "VK_NV_fragment_coverage_to_color" +// +//typedef VkFlags VkPipelineCoverageToColorStateCreateFlagsNV; +// +//typedef struct VkPipelineCoverageToColorStateCreateInfoNV { +// VkStructureType sType; +// const void* pNext; +// VkPipelineCoverageToColorStateCreateFlagsNV flags; +// VkBool32 coverageToColorEnable; +// uint32_t coverageToColorLocation; +//} VkPipelineCoverageToColorStateCreateInfoNV; +// +// +// +//#define VK_NV_framebuffer_mixed_samples 1 +//#define VK_NV_FRAMEBUFFER_MIXED_SAMPLES_SPEC_VERSION 1 +//#define VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME "VK_NV_framebuffer_mixed_samples" +// +// +//typedef enum VkCoverageModulationModeNV { +// VK_COVERAGE_MODULATION_MODE_NONE_NV = 0, +// VK_COVERAGE_MODULATION_MODE_RGB_NV = 1, +// VK_COVERAGE_MODULATION_MODE_ALPHA_NV = 2, +// VK_COVERAGE_MODULATION_MODE_RGBA_NV = 3, +// VK_COVERAGE_MODULATION_MODE_BEGIN_RANGE_NV = VK_COVERAGE_MODULATION_MODE_NONE_NV, +// VK_COVERAGE_MODULATION_MODE_END_RANGE_NV = VK_COVERAGE_MODULATION_MODE_RGBA_NV, +// VK_COVERAGE_MODULATION_MODE_RANGE_SIZE_NV = (VK_COVERAGE_MODULATION_MODE_RGBA_NV - VK_COVERAGE_MODULATION_MODE_NONE_NV + 1), +// VK_COVERAGE_MODULATION_MODE_MAX_ENUM_NV = 0x7FFFFFFF +//} VkCoverageModulationModeNV; +// +//typedef VkFlags VkPipelineCoverageModulationStateCreateFlagsNV; +// +//typedef struct VkPipelineCoverageModulationStateCreateInfoNV { +// VkStructureType sType; +// const void* pNext; +// VkPipelineCoverageModulationStateCreateFlagsNV flags; +// VkCoverageModulationModeNV coverageModulationMode; +// VkBool32 coverageModulationTableEnable; +// uint32_t coverageModulationTableCount; +// const float* pCoverageModulationTable; +//} VkPipelineCoverageModulationStateCreateInfoNV; +// +// +// +//#define VK_NV_fill_rectangle 1 +//#define VK_NV_FILL_RECTANGLE_SPEC_VERSION 1 +//#define VK_NV_FILL_RECTANGLE_EXTENSION_NAME "VK_NV_fill_rectangle" +// +// +//#define VK_EXT_post_depth_coverage 1 +//#define VK_EXT_POST_DEPTH_COVERAGE_SPEC_VERSION 1 +//#define VK_EXT_POST_DEPTH_COVERAGE_EXTENSION_NAME "VK_EXT_post_depth_coverage" +// +// +//#define VK_EXT_validation_cache 1 +//VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkValidationCacheEXT) +// +//#define VK_EXT_VALIDATION_CACHE_SPEC_VERSION 1 +//#define VK_EXT_VALIDATION_CACHE_EXTENSION_NAME "VK_EXT_validation_cache" +// +// +//typedef enum VkValidationCacheHeaderVersionEXT { +// VK_VALIDATION_CACHE_HEADER_VERSION_ONE_EXT = 1, +// VK_VALIDATION_CACHE_HEADER_VERSION_BEGIN_RANGE_EXT = VK_VALIDATION_CACHE_HEADER_VERSION_ONE_EXT, +// VK_VALIDATION_CACHE_HEADER_VERSION_END_RANGE_EXT = VK_VALIDATION_CACHE_HEADER_VERSION_ONE_EXT, +// VK_VALIDATION_CACHE_HEADER_VERSION_RANGE_SIZE_EXT = (VK_VALIDATION_CACHE_HEADER_VERSION_ONE_EXT - VK_VALIDATION_CACHE_HEADER_VERSION_ONE_EXT + 1), +// VK_VALIDATION_CACHE_HEADER_VERSION_MAX_ENUM_EXT = 0x7FFFFFFF +//} VkValidationCacheHeaderVersionEXT; +// +//typedef VkFlags VkValidationCacheCreateFlagsEXT; +// +//typedef struct VkValidationCacheCreateInfoEXT { +// VkStructureType sType; +// const void* pNext; +// VkValidationCacheCreateFlagsEXT flags; +// size_t initialDataSize; +// const void* pInitialData; +//} VkValidationCacheCreateInfoEXT; +// +//typedef struct VkShaderModuleValidationCacheCreateInfoEXT { +// VkStructureType sType; +// const void* pNext; +// VkValidationCacheEXT validationCache; +//} VkShaderModuleValidationCacheCreateInfoEXT; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkCreateValidationCacheEXT)(VkDevice device, const VkValidationCacheCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkValidationCacheEXT* pValidationCache); +//typedef void (VKAPI_PTR *PFN_vkDestroyValidationCacheEXT)(VkDevice device, VkValidationCacheEXT validationCache, const VkAllocationCallbacks* pAllocator); +//typedef VkResult (VKAPI_PTR *PFN_vkMergeValidationCachesEXT)(VkDevice device, VkValidationCacheEXT dstCache, uint32_t srcCacheCount, const VkValidationCacheEXT* pSrcCaches); +//typedef VkResult (VKAPI_PTR *PFN_vkGetValidationCacheDataEXT)(VkDevice device, VkValidationCacheEXT validationCache, size_t* pDataSize, void* pData); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkCreateValidationCacheEXT( +//VkDevice device, +//const VkValidationCacheCreateInfoEXT* pCreateInfo, +//const VkAllocationCallbacks* pAllocator, +//VkValidationCacheEXT* pValidationCache); +// +//VKAPI_ATTR void VKAPI_CALL vkDestroyValidationCacheEXT( +//VkDevice device, +//VkValidationCacheEXT validationCache, +//const VkAllocationCallbacks* pAllocator); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkMergeValidationCachesEXT( +//VkDevice device, +//VkValidationCacheEXT dstCache, +//uint32_t srcCacheCount, +//const VkValidationCacheEXT* pSrcCaches); +// +//VKAPI_ATTR VkResult VKAPI_CALL vkGetValidationCacheDataEXT( +//VkDevice device, +//VkValidationCacheEXT validationCache, +//size_t* pDataSize, +//void* pData); +//#endif +// +//#define VK_EXT_shader_viewport_index_layer 1 +//#define VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_SPEC_VERSION 1 +//#define VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME "VK_EXT_shader_viewport_index_layer" +// +// +//#define VK_EXT_global_priority 1 +//#define VK_EXT_GLOBAL_PRIORITY_SPEC_VERSION 2 +//#define VK_EXT_GLOBAL_PRIORITY_EXTENSION_NAME "VK_EXT_global_priority" +// +// +//typedef enum VkQueueGlobalPriorityEXT { +// VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT = 128, +// VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT = 256, +// VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT = 512, +// VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT = 1024, +// VK_QUEUE_GLOBAL_PRIORITY_BEGIN_RANGE_EXT = VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT, +// VK_QUEUE_GLOBAL_PRIORITY_END_RANGE_EXT = VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT, +// VK_QUEUE_GLOBAL_PRIORITY_RANGE_SIZE_EXT = (VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT - VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT + 1), +// VK_QUEUE_GLOBAL_PRIORITY_MAX_ENUM_EXT = 0x7FFFFFFF +//} VkQueueGlobalPriorityEXT; +// +//typedef struct VkDeviceQueueGlobalPriorityCreateInfoEXT { +// VkStructureType sType; +// const void* pNext; +// VkQueueGlobalPriorityEXT globalPriority; +//} VkDeviceQueueGlobalPriorityCreateInfoEXT; +// +// +// +//#define VK_EXT_external_memory_host 1 +//#define VK_EXT_EXTERNAL_MEMORY_HOST_SPEC_VERSION 1 +//#define VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME "VK_EXT_external_memory_host" +// +//typedef struct VkImportMemoryHostPointerInfoEXT { +// VkStructureType sType; +// const void* pNext; +// VkExternalMemoryHandleTypeFlagBitsKHR handleType; +// void* pHostPointer; +//} VkImportMemoryHostPointerInfoEXT; +// +//typedef struct VkMemoryHostPointerPropertiesEXT { +// VkStructureType sType; +// void* pNext; +// uint32_t memoryTypeBits; +//} VkMemoryHostPointerPropertiesEXT; +// +//typedef struct VkPhysicalDeviceExternalMemoryHostPropertiesEXT { +// VkStructureType sType; +// void* pNext; +// VkDeviceSize minImportedHostPointerAlignment; +//} VkPhysicalDeviceExternalMemoryHostPropertiesEXT; +// +// +//typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryHostPointerPropertiesEXT)(VkDevice device, VkExternalMemoryHandleTypeFlagBitsKHR handleType, const void* pHostPointer, VkMemoryHostPointerPropertiesEXT* pMemoryHostPointerProperties); +// +//#ifndef VK_NO_PROTOTYPES +//VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryHostPointerPropertiesEXT( +//VkDevice device, +//VkExternalMemoryHandleTypeFlagBitsKHR handleType, +//const void* pHostPointer, +//VkMemoryHostPointerPropertiesEXT* pMemoryHostPointerProperties); +//#endif +// +//#ifdef __cplusplus +//} diff --git a/src/main/kotlin/vkk/enums.kt b/src/main/kotlin/vkk/enums.kt new file mode 100644 index 0000000..4d9b51d --- /dev/null +++ b/src/main/kotlin/vkk/enums.kt @@ -0,0 +1,2008 @@ +package vkk + +const val VK_HEADER_VERSION = 74 + +var DEBUG = java.lang.management.ManagementFactory.getRuntimeMXBean().inputArguments.toString().indexOf("jdwp") >= 0 + + +typealias VkFlags = Int + +class VkPipelineCacheHeaderversion(val i: Int) + +val ONE = VkPipelineCacheHeaderversion(1) + + +var VULKAN_NO_EXCEPTIONS = false + +class OutOfHostMemoryError(message: String) : Error(message) +class OutOfDeviceMemoryError(message: String) : Error(message) +class InitializationFailedError(message: String) : Error(message) +class DeviceLostError(message: String) : Error(message) +class MemoryMapFailedError(message: String) : Error(message) +class LayerNotPresentError(message: String) : Error(message) +class ExtensionNotPresentError(message: String) : Error(message) +class FeatureNotPresentError(message: String) : Error(message) +class IncompatibleDriverError(message: String) : Error(message) +class TooManyObjectsError(message: String) : Error(message) +class FormatNotSupportedError(message: String) : Error(message) +class FragmentedPoolError(message: String) : Error(message) +class SurfaceLostKhrError(message: String) : Error(message) +class NativeWindowInUseKhrError(message: String) : Error(message) +class OutOfDateKhrError(message: String) : Error(message) +class IncompatibleDisplayKhrError(message: String) : Error(message) +class ValidationFailedExtError(message: String) : Error(message) +class InvalidShaderNvError(message: String) : Error(message) +class OutOfPoolMemoryError(message: String) : Error(message) +class InvalidExternalHandleError(message: String) : Error(message) +class NotPermittedError(message: String) : Error(message) + +fun VK_CHECK_RESULT(i: Int) = VkResult(i)() + +inline class VkResult(val i: Int) { + + operator fun invoke() = this != SUCCESS + + fun check(message: String) { + + } + + fun check() { + + } + +// fun check(message: String = "Fatal : VkResult is $this") { +// if (DEBUG && invoke()) +// if (VULKAN_NO_EXCEPTIONS) +// System.err.println(message) +// else +// when (this) { +// ERROR_OUT_OF_HOST_MEMORY -> throw OutOfHostMemoryError(message) +// ERROR_OUT_OF_DEVICE_MEMORY -> throw OutOfDeviceMemoryError(message) +// ERROR_INITIALIZATION_FAILED -> throw InitializationFailedError(message) +// ERROR_DEVICE_LOST -> throw DeviceLostError(message) +// ERROR_MEMORY_MAP_FAILED -> throw MemoryMapFailedError(message) +// ERROR_LAYER_NOT_PRESENT -> throw LayerNotPresentError(message) +// ERROR_EXTENSION_NOT_PRESENT -> throw ExtensionNotPresentError(message) +// ERROR_FEATURE_NOT_PRESENT -> throw FeatureNotPresentError(message) +// ERROR_INCOMPATIBLE_DRIVER -> throw IncompatibleDriverError(message) +// ERROR_TOO_MANY_OBJECTS -> throw TooManyObjectsError(message) +// ERROR_FORMAT_NOT_SUPPORTED -> throw FormatNotSupportedError(message) +// ERROR_FRAGMENTED_POOL -> throw FragmentedPoolError(message) +// ERROR_SURFACE_LOST_KHR -> throw SurfaceLostKhrError(message) +// ERROR_NATIVE_WINDOW_IN_USE_KHR -> throw NativeWindowInUseKhrError(message) +// ERROR_OUT_OF_DATE_KHR -> throw OutOfDateKhrError(message) +// ERROR_INCOMPATIBLE_DISPLAY_KHR -> throw IncompatibleDisplayKhrError(message) +// ERROR_VALIDATION_FAILED_EXT -> throw ValidationFailedExtError(message) +// ERROR_INVALID_SHADER_NV -> throw InvalidShaderNvError(message) +// ERROR_OUT_OF_POOL_MEMORY -> throw OutOfPoolMemoryError(message) +// ERROR_INVALID_EXTERNAL_HANDLE -> throw InvalidExternalHandleError(message) +// ERROR_NOT_PERMITTED_EXT -> throw NotPermittedError(message) +// else -> throw Error(message) +// } +// } +} + +val SUCCESS = VkResult(0) +val NOT_READY = VkResult(1) +val TIMEOUT = VkResult(2) +val EVENT_SET = VkResult(3) +val EVENT_RESET = VkResult(4) +val INCOMPLETE = VkResult(5) +val ERROR_OUT_OF_HOST_MEMORY = VkResult(-1) +val ERROR_OUT_OF_DEVICE_MEMORY = VkResult(-2) +val ERROR_INITIALIZATION_FAILED = VkResult(-3) +val ERROR_DEVICE_LOST = VkResult(-4) +val ERROR_MEMORY_MAP_FAILED = VkResult(-5) +val ERROR_LAYER_NOT_PRESENT = VkResult(-6) +val ERROR_EXTENSION_NOT_PRESENT = VkResult(-7) +val ERROR_FEATURE_NOT_PRESENT = VkResult(-8) +val ERROR_INCOMPATIBLE_DRIVER = VkResult(-9) +val ERROR_TOO_MANY_OBJECTS = VkResult(-10) +val ERROR_FORMAT_NOT_SUPPORTED = VkResult(-11) +val ERROR_FRAGMENTED_POOL = VkResult(-12) +val ERROR_OUT_OF_POOL_MEMORY = VkResult(-1000069000) +val ERROR_INVALID_EXTERNAL_HANDLE = VkResult(-1000072003) +val ERROR_SURFACE_LOST_KHR = VkResult(-1000000000) +val ERROR_NATIVE_WINDOW_IN_USE_KHR = VkResult(-1000000001) +val SUBOPTIMAL_KHR = VkResult(1000001003) +val ERROR_OUT_OF_DATE_KHR = VkResult(-1000001004) +val ERROR_INCOMPATIBLE_DISPLAY_KHR = VkResult(-1000003001) +val ERROR_VALIDATION_FAILED_EXT = VkResult(-1000011001) +val ERROR_INVALID_SHADER_NV = VkResult(-1000012000) +val ERROR_FRAGMENTATION_EXT = VkResult(-1000161000) +val ERROR_NOT_PERMITTED_EXT = VkResult(-1000174001) + + +enum class VkStructureType(val i: Int) { + APPLICATION_INFO(0), + INSTANCE_CREATE_INFO(1), + DEVICE_QUEUE_CREATE_INFO(2), + DEVICE_CREATE_INFO(3), + SUBMIT_INFO(4), + MEMORY_ALLOCATE_INFO(5), + MAPPED_MEMORY_RANGE(6), + BIND_SPARSE_INFO(7), + FENCE_CREATE_INFO(8), + SEMAPHORE_CREATE_INFO(9), + EVENT_CREATE_INFO(10), + QUERY_POOL_CREATE_INFO(11), + BUFFER_CREATE_INFO(12), + BUFFER_VIEW_CREATE_INFO(13), + IMAGE_CREATE_INFO(14), + IMAGE_VIEW_CREATE_INFO(15), + SHADER_MODULE_CREATE_INFO(16), + PIPELINE_CACHE_CREATE_INFO(17), + PIPELINE_SHADER_STAGE_CREATE_INFO(18), + PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO(19), + PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO(20), + PIPELINE_TESSELLATION_STATE_CREATE_INFO(21), + PIPELINE_VIEWPORT_STATE_CREATE_INFO(22), + PIPELINE_RASTERIZATION_STATE_CREATE_INFO(23), + PIPELINE_MULTISAMPLE_STATE_CREATE_INFO(24), + PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO(25), + PIPELINE_COLOR_BLEND_STATE_CREATE_INFO(26), + PIPELINE_DYNAMIC_STATE_CREATE_INFO(27), + GRAPHICS_PIPELINE_CREATE_INFO(28), + COMPUTE_PIPELINE_CREATE_INFO(29), + PIPELINE_LAYOUT_CREATE_INFO(30), + SAMPLER_CREATE_INFO(31), + DESCRIPTOR_SET_LAYOUT_CREATE_INFO(32), + DESCRIPTOR_POOL_CREATE_INFO(33), + DESCRIPTOR_SET_ALLOCATE_INFO(34), + WRITE_DESCRIPTOR_SET(35), + COPY_DESCRIPTOR_SET(36), + FRAMEBUFFER_CREATE_INFO(37), + RENDER_PASS_CREATE_INFO(38), + COMMAND_POOL_CREATE_INFO(39), + COMMAND_BUFFER_ALLOCATE_INFO(40), + COMMAND_BUFFER_INHERITANCE_INFO(41), + COMMAND_BUFFER_BEGIN_INFO(42), + RENDER_PASS_BEGIN_INFO(43), + BUFFER_MEMORY_BARRIER(44), + IMAGE_MEMORY_BARRIER(45), + MEMORY_BARRIER(46), + LOADER_INSTANCE_CREATE_INFO(47), + LOADER_DEVICE_CREATE_INFO(48), + PHYSICAL_DEVICE_SUBGROUP_PROPERTIES(1000094000), + BIND_BUFFER_MEMORY_INFO(1000157000), + BIND_IMAGE_MEMORY_INFO(1000157001), + PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES(1000083000), + MEMORY_DEDICATED_REQUIREMENTS(1000127000), + MEMORY_DEDICATED_ALLOCATE_INFO(1000127001), + MEMORY_ALLOCATE_FLAGS_INFO(1000060000), + DEVICE_GROUP_RENDER_PASS_BEGIN_INFO(1000060003), + DEVICE_GROUP_COMMAND_BUFFER_BEGIN_INFO(1000060004), + DEVICE_GROUP_SUBMIT_INFO(1000060005), + DEVICE_GROUP_BIND_SPARSE_INFO(1000060006), + BIND_BUFFER_MEMORY_DEVICE_GROUP_INFO(1000060013), + BIND_IMAGE_MEMORY_DEVICE_GROUP_INFO(1000060014), + PHYSICAL_DEVICE_GROUP_PROPERTIES(1000070000), + DEVICE_GROUP_DEVICE_CREATE_INFO(1000070001), + BUFFER_MEMORY_REQUIREMENTS_INFO_2(1000146000), + IMAGE_MEMORY_REQUIREMENTS_INFO_2(1000146001), + IMAGE_SPARSE_MEMORY_REQUIREMENTS_INFO_2(1000146002), + MEMORY_REQUIREMENTS_2(1000146003), + SPARSE_IMAGE_MEMORY_REQUIREMENTS_2(1000146004), + PHYSICAL_DEVICE_FEATURES_2(1000059000), + PHYSICAL_DEVICE_PROPERTIES_2(1000059001), + FORMAT_PROPERTIES_2(1000059002), + IMAGE_FORMAT_PROPERTIES_2(1000059003), + PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2(1000059004), + QUEUE_FAMILY_PROPERTIES_2(1000059005), + PHYSICAL_DEVICE_MEMORY_PROPERTIES_2(1000059006), + SPARSE_IMAGE_FORMAT_PROPERTIES_2(1000059007), + PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2(1000059008), + PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES(1000117000), + RENDER_PASS_INPUT_ATTACHMENT_ASPECT_CREATE_INFO(1000117001), + IMAGE_VIEW_USAGE_CREATE_INFO(1000117002), + PIPELINE_TESSELLATION_DOMAIN_ORIGIN_STATE_CREATE_INFO(1000117003), + RENDER_PASS_MULTIVIEW_CREATE_INFO(1000053000), + PHYSICAL_DEVICE_MULTIVIEW_FEATURES(1000053001), + PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES(1000053002), + PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES(1000120000), + PROTECTED_SUBMIT_INFO(1000145000), + PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES(1000145001), + PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES(1000145002), + DEVICE_QUEUE_INFO_2(1000145003), + SAMPLER_YCBCR_CONVERSION_CREATE_INFO(1000156000), + SAMPLER_YCBCR_CONVERSION_INFO(1000156001), + BIND_IMAGE_PLANE_MEMORY_INFO(1000156002), + IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO(1000156003), + PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES(1000156004), + SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES(1000156005), + DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO(1000085000), + PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO(1000071000), + EXTERNAL_IMAGE_FORMAT_PROPERTIES(1000071001), + PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO(1000071002), + EXTERNAL_BUFFER_PROPERTIES(1000071003), + PHYSICAL_DEVICE_ID_PROPERTIES(1000071004), + EXTERNAL_MEMORY_BUFFER_CREATE_INFO(1000072000), + EXTERNAL_MEMORY_IMAGE_CREATE_INFO(1000072001), + EXPORT_MEMORY_ALLOCATE_INFO(1000072002), + PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO(1000112000), + EXTERNAL_FENCE_PROPERTIES(1000112001), + EXPORT_FENCE_CREATE_INFO(1000113000), + EXPORT_SEMAPHORE_CREATE_INFO(1000077000), + PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO(1000076000), + EXTERNAL_SEMAPHORE_PROPERTIES(1000076001), + PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES(1000168000), + DESCRIPTOR_SET_LAYOUT_SUPPORT(1000168001), + PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES(1000063000), + SWAPCHAIN_CREATE_INFO_KHR(1000001000), + PRESENT_INFO_KHR(1000001001), + DEVICE_GROUP_PRESENT_CAPABILITIES_KHR(1000060007), + IMAGE_SWAPCHAIN_CREATE_INFO_KHR(1000060008), + BIND_IMAGE_MEMORY_SWAPCHAIN_INFO_KHR(1000060009), + ACQUIRE_NEXT_IMAGE_INFO_KHR(1000060010), + DEVICE_GROUP_PRESENT_INFO_KHR(1000060011), + DEVICE_GROUP_SWAPCHAIN_CREATE_INFO_KHR(1000060012), + DISPLAY_MODE_CREATE_INFO_KHR(1000002000), + DISPLAY_SURFACE_CREATE_INFO_KHR(1000002001), + DISPLAY_PRESENT_INFO_KHR(1000003000), + XLIB_SURFACE_CREATE_INFO_KHR(1000004000), + XCB_SURFACE_CREATE_INFO_KHR(1000005000), + WAYLAND_SURFACE_CREATE_INFO_KHR(1000006000), + MIR_SURFACE_CREATE_INFO_KHR(1000007000), + ANDROID_SURFACE_CREATE_INFO_KHR(1000008000), + WIN32_SURFACE_CREATE_INFO_KHR(1000009000), + DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT(1000011000), + PIPELINE_RASTERIZATION_STATE_RASTERIZATION_ORDER_AMD(1000018000), + DEBUG_MARKER_OBJECT_NAME_INFO_EXT(1000022000), + DEBUG_MARKER_OBJECT_TAG_INFO_EXT(1000022001), + DEBUG_MARKER_MARKER_INFO_EXT(1000022002), + DEDICATED_ALLOCATION_IMAGE_CREATE_INFO_NV(1000026000), + DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV(1000026001), + DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV(1000026002), + TEXTURE_LOD_GATHER_FORMAT_PROPERTIES_AMD(1000041000), + EXTERNAL_MEMORY_IMAGE_CREATE_INFO_NV(1000056000), + EXPORT_MEMORY_ALLOCATE_INFO_NV(1000056001), + IMPORT_MEMORY_WIN32_HANDLE_INFO_NV(1000057000), + EXPORT_MEMORY_WIN32_HANDLE_INFO_NV(1000057001), + WIN32_KEYED_MUTEX_ACQUIRE_RELEASE_INFO_NV(1000058000), + VALIDATION_FLAGS_EXT(1000061000), + VI_SURFACE_CREATE_INFO_NN(1000062000), + IMAGE_VIEW_ASTC_DECODE_MODE_EXT(1000067000), + PHYSICAL_DEVICE_ASTC_DECODE_FEATURES_EXT(1000067001), + IMPORT_MEMORY_WIN32_HANDLE_INFO_KHR(1000073000), + EXPORT_MEMORY_WIN32_HANDLE_INFO_KHR(1000073001), + MEMORY_WIN32_HANDLE_PROPERTIES_KHR(1000073002), + MEMORY_GET_WIN32_HANDLE_INFO_KHR(1000073003), + IMPORT_MEMORY_FD_INFO_KHR(1000074000), + MEMORY_FD_PROPERTIES_KHR(1000074001), + MEMORY_GET_FD_INFO_KHR(1000074002), + WIN32_KEYED_MUTEX_ACQUIRE_RELEASE_INFO_KHR(1000075000), + IMPORT_SEMAPHORE_WIN32_HANDLE_INFO_KHR(1000078000), + EXPORT_SEMAPHORE_WIN32_HANDLE_INFO_KHR(1000078001), + D3D12_FENCE_SUBMIT_INFO_KHR(1000078002), + SEMAPHORE_GET_WIN32_HANDLE_INFO_KHR(1000078003), + IMPORT_SEMAPHORE_FD_INFO_KHR(1000079000), + SEMAPHORE_GET_FD_INFO_KHR(1000079001), + PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR(1000080000), + COMMAND_BUFFER_INHERITANCE_CONDITIONAL_RENDERING_INFO_EXT(1000081000), + PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT(1000081001), + VK_STRUCTURE_TYPE_CONDITIONAL_RENDERING_BEGIN_INFO_EXT(1000081002), + PRESENT_REGIONS_KHR(1000084000), + OBJECT_TABLE_CREATE_INFO_NVX(1000086000), + INDIRECT_COMMANDS_LAYOUT_CREATE_INFO_NVX(1000086001), + CMD_PROCESS_COMMANDS_INFO_NVX(1000086002), + CMD_RESERVE_SPACE_FOR_COMMANDS_INFO_NVX(1000086003), + DEVICE_GENERATED_COMMANDS_LIMITS_NVX(1000086004), + DEVICE_GENERATED_COMMANDS_FEATURES_NVX(1000086005), + PIPELINE_VIEWPORT_W_SCALING_STATE_CREATE_INFO_NV(1000087000), + SURFACE_CAPABILITIES_2_EXT(1000090000), + DISPLAY_POWER_INFO_EXT(1000091000), + DEVICE_EVENT_INFO_EXT(1000091001), + DISPLAY_EVENT_INFO_EXT(1000091002), + SWAPCHAIN_COUNTER_CREATE_INFO_EXT(1000091003), + PRESENT_TIMES_INFO_GOOGLE(1000092000), + PHYSICAL_DEVICE_MULTIVIEW_PER_VIEW_ATTRIBUTES_PROPERTIES_NVX(1000097000), + PIPELINE_VIEWPORT_SWIZZLE_STATE_CREATE_INFO_NV(1000098000), + PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT(1000099000), + PIPELINE_DISCARD_RECTANGLE_STATE_CREATE_INFO_EXT(1000099001), + PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT(1000101000), + PIPELINE_RASTERIZATION_CONSERVATIVE_STATE_CREATE_INFO_EXT(1000101001), + HDR_METADATA_EXT(1000105000), + ATTACHMENT_DESCRIPTION_2_KHR(1000109000), + ATTACHMENT_REFERENCE_2_KHR(1000109001), + SUBPASS_DESCRIPTION_2_KHR(1000109002), + SUBPASS_DEPENDENCY_2_KHR(1000109003), + RENDER_PASS_CREATE_INFO_2_KHR(1000109004), + SUBPASS_BEGIN_INFO_KHR(1000109005), + SUBPASS_END_INFO_KHR(1000109006), + SHARED_PRESENT_SURFACE_CAPABILITIES_KHR(1000111000), + IMPORT_FENCE_WIN32_HANDLE_INFO_KHR(1000114000), + EXPORT_FENCE_WIN32_HANDLE_INFO_KHR(1000114001), + FENCE_GET_WIN32_HANDLE_INFO_KHR(1000114002), + IMPORT_FENCE_FD_INFO_KHR(1000115000), + FENCE_GET_FD_INFO_KHR(1000115001), + PHYSICAL_DEVICE_SURFACE_INFO_2_KHR(1000119000), + SURFACE_CAPABILITIES_2_KHR(1000119001), + SURFACE_FORMAT_2_KHR(1000119002), + DISPLAY_PROPERTIES_2_KHR(1000121000), + DISPLAY_PLANE_PROPERTIES_2_KHR(1000121001), + DISPLAY_MODE_PROPERTIES_2_KHR(1000121002), + DISPLAY_PLANE_INFO_2_KHR(1000121003), + DISPLAY_PLANE_CAPABILITIES_2_KHR(1000121004), + IOS_SURFACE_CREATE_INFO_MVK(1000122000), + MACOS_SURFACE_CREATE_INFO_MVK(1000123000), + DEBUG_UTILS_OBJECT_NAME_INFO_EXT(1000128000), + DEBUG_UTILS_OBJECT_TAG_INFO_EXT(1000128001), + DEBUG_UTILS_LABEL_EXT(1000128002), + DEBUG_UTILS_MESSENGER_CALLBACK_DATA_EXT(1000128003), + DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT(1000128004), + ANDROID_HARDWARE_BUFFER_USAGE_ANDROID(1000129000), + ANDROID_HARDWARE_BUFFER_PROPERTIES_ANDROID(1000129001), + ANDROID_HARDWARE_BUFFER_FORMAT_PROPERTIES_ANDROID(1000129002), + IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID(1000129003), + MEMORY_GET_ANDROID_HARDWARE_BUFFER_INFO_ANDROID(1000129004), + EXTERNAL_FORMAT_ANDROID(1000129005), + PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT(1000130000), + SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT(1000130001), + PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT(1000138000), + PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT(1000138001), + WRITE_DESCRIPTOR_SET_INLINE_UNIFORM_BLOCK_EXT(1000138002), + DESCRIPTOR_POOL_INLINE_UNIFORM_BLOCK_CREATE_INFO_EXT(1000138003), + SAMPLE_LOCATIONS_INFO_EXT(1000143000), + RENDER_PASS_SAMPLE_LOCATIONS_BEGIN_INFO_EXT(1000143001), + PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT(1000143002), + PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT(1000143003), + MULTISAMPLE_PROPERTIES_EXT(1000143004), + IMAGE_FORMAT_LIST_CREATE_INFO_KHR(1000147000), + PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT(1000148000), + PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_PROPERTIES_EXT(1000148001), + PIPELINE_COLOR_BLEND_ADVANCED_STATE_CREATE_INFO_EXT(1000148002), + PIPELINE_COVERAGE_TO_COLOR_STATE_CREATE_INFO_NV(1000149000), + PIPELINE_COVERAGE_MODULATION_STATE_CREATE_INFO_NV(1000152000), + VALIDATION_CACHE_CREATE_INFO_EXT(1000160000), + SHADER_MODULE_VALIDATION_CACHE_CREATE_INFO_EXT(1000160001), + DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT(1000161000), + PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT(1000161001), + PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT(1000161002), + DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO_EXT(1000161003), + DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_LAYOUT_SUPPORT_EXT(1000161004), + DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT(1000174000), + PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR(1000177000), + IMPORT_MEMORY_HOST_POINTER_INFO_EXT(1000178000), + MEMORY_HOST_POINTER_PROPERTIES_EXT(1000178001), + PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT(1000178002), + PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD(1000185000), + PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT(1000190000), + PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT(1000190001), + PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT(1000190002), + CHECKPOINT_DATA_NV(1000206000), + QUEUE_FAMILY_CHECKPOINT_PROPERTIES_NV(1000206001), + PHYSICAL_DEVICE_VULKAN_MEMORY_MODEL_FEATURES_KHR(1000211000); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkSystemAllocationScope(val i: Int) { + COMMAND(0), + OBJECT(1), + CACHE(2), + DEVICE(3), + INSTANCE(4); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkInternalAllocationType(val i: Int) { + EXECUTABLE(0); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkFormat(val i: Int) { + UNDEFINED(0), + R4G4_UNORM_PACK8(1), + R4G4B4A4_UNORM_PACK16(2), + B4G4R4A4_UNORM_PACK16(3), + R5G6B5_UNORM_PACK16(4), + B5G6R5_UNORM_PACK16(5), + R5G5B5A1_UNORM_PACK16(6), + B5G5R5A1_UNORM_PACK16(7), + A1R5G5B5_UNORM_PACK16(8), + R8_UNORM(9), + R8_SNORM(10), + R8_USCALED(11), + R8_SSCALED(12), + R8_UINT(13), + R8_SINT(14), + R8_SRGB(15), + R8G8_UNORM(16), + R8G8_SNORM(17), + R8G8_USCALED(18), + R8G8_SSCALED(19), + R8G8_UINT(20), + R8G8_SINT(21), + R8G8_SRGB(22), + R8G8B8_UNORM(23), + R8G8B8_SNORM(24), + R8G8B8_USCALED(25), + R8G8B8_SSCALED(26), + R8G8B8_UINT(27), + R8G8B8_SINT(28), + R8G8B8_SRGB(29), + B8G8R8_UNORM(30), + B8G8R8_SNORM(31), + B8G8R8_USCALED(32), + B8G8R8_SSCALED(33), + B8G8R8_UINT(34), + B8G8R8_SINT(35), + B8G8R8_SRGB(36), + R8G8B8A8_UNORM(37), + R8G8B8A8_SNORM(38), + R8G8B8A8_USCALED(39), + R8G8B8A8_SSCALED(40), + R8G8B8A8_UINT(41), + R8G8B8A8_SINT(42), + R8G8B8A8_SRGB(43), + B8G8R8A8_UNORM(44), + B8G8R8A8_SNORM(45), + B8G8R8A8_USCALED(46), + B8G8R8A8_SSCALED(47), + B8G8R8A8_UINT(48), + B8G8R8A8_SINT(49), + B8G8R8A8_SRGB(50), + A8B8G8R8_UNORM_PACK32(51), + A8B8G8R8_SNORM_PACK32(52), + A8B8G8R8_USCALED_PACK32(53), + A8B8G8R8_SSCALED_PACK32(54), + A8B8G8R8_UINT_PACK32(55), + A8B8G8R8_SINT_PACK32(56), + A8B8G8R8_SRGB_PACK32(57), + A2R10G10B10_UNORM_PACK32(58), + A2R10G10B10_SNORM_PACK32(59), + A2R10G10B10_USCALED_PACK32(60), + A2R10G10B10_SSCALED_PACK32(61), + A2R10G10B10_UINT_PACK32(62), + A2R10G10B10_SINT_PACK32(63), + A2B10G10R10_UNORM_PACK32(64), + A2B10G10R10_SNORM_PACK32(65), + A2B10G10R10_USCALED_PACK32(66), + A2B10G10R10_SSCALED_PACK32(67), + A2B10G10R10_UINT_PACK32(68), + A2B10G10R10_SINT_PACK32(69), + R16_UNORM(70), + R16_SNORM(71), + R16_USCALED(72), + R16_SSCALED(73), + R16_UINT(74), + R16_SINT(75), + R16_SFLOAT(76), + R16G16_UNORM(77), + R16G16_SNORM(78), + R16G16_USCALED(79), + R16G16_SSCALED(80), + R16G16_UINT(81), + R16G16_SINT(82), + R16G16_SFLOAT(83), + R16G16B16_UNORM(84), + R16G16B16_SNORM(85), + R16G16B16_USCALED(86), + R16G16B16_SSCALED(87), + R16G16B16_UINT(88), + R16G16B16_SINT(89), + R16G16B16_SFLOAT(90), + R16G16B16A16_UNORM(91), + R16G16B16A16_SNORM(92), + R16G16B16A16_USCALED(93), + R16G16B16A16_SSCALED(94), + R16G16B16A16_UINT(95), + R16G16B16A16_SINT(96), + R16G16B16A16_SFLOAT(97), + R32_UINT(98), + R32_SINT(99), + R32_SFLOAT(100), + R32G32_UINT(101), + R32G32_SINT(102), + R32G32_SFLOAT(103), + R32G32B32_UINT(104), + R32G32B32_SINT(105), + R32G32B32_SFLOAT(106), + R32G32B32A32_UINT(107), + R32G32B32A32_SINT(108), + R32G32B32A32_SFLOAT(109), + R64_UINT(110), + R64_SINT(111), + R64_SFLOAT(112), + R64G64_UINT(113), + R64G64_SINT(114), + R64G64_SFLOAT(115), + R64G64B64_UINT(116), + R64G64B64_SINT(117), + R64G64B64_SFLOAT(118), + R64G64B64A64_UINT(119), + R64G64B64A64_SINT(120), + R64G64B64A64_SFLOAT(121), + B10G11R11_UFLOAT_PACK32(122), + E5B9G9R9_UFLOAT_PACK32(123), + D16_UNORM(124), + X8_D24_UNORM_PACK32(125), + D32_SFLOAT(126), + S8_UINT(127), + D16_UNORM_S8_UINT(128), + D24_UNORM_S8_UINT(129), + D32_SFLOAT_S8_UINT(130), + BC1_RGB_UNORM_BLOCK(131), + BC1_RGB_SRGB_BLOCK(132), + BC1_RGBA_UNORM_BLOCK(133), + BC1_RGBA_SRGB_BLOCK(134), + BC2_UNORM_BLOCK(135), + BC2_SRGB_BLOCK(136), + BC3_UNORM_BLOCK(137), + BC3_SRGB_BLOCK(138), + BC4_UNORM_BLOCK(139), + BC4_SNORM_BLOCK(140), + BC5_UNORM_BLOCK(141), + BC5_SNORM_BLOCK(142), + BC6H_UFLOAT_BLOCK(143), + BC6H_SFLOAT_BLOCK(144), + BC7_UNORM_BLOCK(145), + BC7_SRGB_BLOCK(146), + ETC2_R8G8B8_UNORM_BLOCK(147), + ETC2_R8G8B8_SRGB_BLOCK(148), + ETC2_R8G8B8A1_UNORM_BLOCK(149), + ETC2_R8G8B8A1_SRGB_BLOCK(150), + ETC2_R8G8B8A8_UNORM_BLOCK(151), + ETC2_R8G8B8A8_SRGB_BLOCK(152), + EAC_R11_UNORM_BLOCK(153), + EAC_R11_SNORM_BLOCK(154), + EAC_R11G11_UNORM_BLOCK(155), + EAC_R11G11_SNORM_BLOCK(156), + ASTC_4x4_UNORM_BLOCK(157), + ASTC_4x4_SRGB_BLOCK(158), + ASTC_5x4_UNORM_BLOCK(159), + ASTC_5x4_SRGB_BLOCK(160), + ASTC_5x5_UNORM_BLOCK(161), + ASTC_5x5_SRGB_BLOCK(162), + ASTC_6x5_UNORM_BLOCK(163), + ASTC_6x5_SRGB_BLOCK(164), + ASTC_6x6_UNORM_BLOCK(165), + ASTC_6x6_SRGB_BLOCK(166), + ASTC_8x5_UNORM_BLOCK(167), + ASTC_8x5_SRGB_BLOCK(168), + ASTC_8x6_UNORM_BLOCK(169), + ASTC_8x6_SRGB_BLOCK(170), + ASTC_8x8_UNORM_BLOCK(171), + ASTC_8x8_SRGB_BLOCK(172), + ASTC_10x5_UNORM_BLOCK(173), + ASTC_10x5_SRGB_BLOCK(174), + ASTC_10x6_UNORM_BLOCK(175), + ASTC_10x6_SRGB_BLOCK(176), + ASTC_10x8_UNORM_BLOCK(177), + ASTC_10x8_SRGB_BLOCK(178), + ASTC_10x10_UNORM_BLOCK(179), + ASTC_10x10_SRGB_BLOCK(180), + ASTC_12x10_UNORM_BLOCK(181), + ASTC_12x10_SRGB_BLOCK(182), + ASTC_12x12_UNORM_BLOCK(183), + ASTC_12x12_SRGB_BLOCK(184), + G8B8G8R8_422_UNORM(1000156000), + B8G8R8G8_422_UNORM(1000156001), + G8_B8_R8_3PLANE_420_UNORM(1000156002), + G8_B8R8_2PLANE_420_UNORM(1000156003), + G8_B8_R8_3PLANE_422_UNORM(1000156004), + G8_B8R8_2PLANE_422_UNORM(1000156005), + G8_B8_R8_3PLANE_444_UNORM(1000156006), + R10X6_UNORM_PACK16(1000156007), + R10X6G10X6_UNORM_2PACK16(1000156008), + R10X6G10X6B10X6A10X6_UNORM_4PACK16(1000156009), + G10X6B10X6G10X6R10X6_422_UNORM_4PACK16(1000156010), + B10X6G10X6R10X6G10X6_422_UNORM_4PACK16(1000156011), + G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16(1000156012), + G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16(1000156013), + G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16(1000156014), + G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16(1000156015), + G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16(1000156016), + R12X4_UNORM_PACK16(1000156017), + R12X4G12X4_UNORM_2PACK16(1000156018), + R12X4G12X4B12X4A12X4_UNORM_4PACK16(1000156019), + G12X4B12X4G12X4R12X4_422_UNORM_4PACK16(1000156020), + B12X4G12X4R12X4G12X4_422_UNORM_4PACK16(1000156021), + G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16(1000156022), + G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16(1000156023), + G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16(1000156024), + G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16(1000156025), + G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16(1000156026), + G16B16G16R16_422_UNORM(1000156027), + B16G16R16G16_422_UNORM(1000156028), + G16_B16_R16_3PLANE_420_UNORM(1000156029), + G16_B16R16_2PLANE_420_UNORM(1000156030), + G16_B16_R16_3PLANE_422_UNORM(1000156031), + G16_B16R16_2PLANE_422_UNORM(1000156032), + G16_B16_R16_3PLANE_444_UNORM(1000156033), + PVRTC1_2BPP_UNORM_BLOCK_IMG(1000054000), + PVRTC1_4BPP_UNORM_BLOCK_IMG(1000054001), + PVRTC2_2BPP_UNORM_BLOCK_IMG(1000054002), + PVRTC2_4BPP_UNORM_BLOCK_IMG(1000054003), + PVRTC1_2BPP_SRGB_BLOCK_IMG(1000054004), + PVRTC1_4BPP_SRGB_BLOCK_IMG(1000054005), + PVRTC2_2BPP_SRGB_BLOCK_IMG(1000054006), + PVRTC2_4BPP_SRGB_BLOCK_IMG(1000054007); + + infix operator fun plus(i: Int) = of(this.i + i) + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkImageType(val i: Int) { + `1D`(0), + `2D`(1), + `3D`(2); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkImageTiling(val i: Int) { + OPTIMAL(0), + LINEAR(1); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkPhysicalDeviceType(val i: Int) { + OTHER(0), + INTEGRATED_GPU(1), + DISCRETE_GPU(2), + VIRTUAL_GPU(3), + CPU(4); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkQueryType(val i: Int) { + OCCLUSION(0), + PIPELINE_STATISTICS(1), + TIMESTAMP(2); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkSharingMode(val i: Int) { + EXCLUSIVE(0), + CONCURRENT(1); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkImageLayout(val i: Int) { + UNDEFINED(0), + GENERAL(1), + COLOR_ATTACHMENT_OPTIMAL(2), + DEPTH_STENCIL_ATTACHMENT_OPTIMAL(3), + DEPTH_STENCIL_READ_ONLY_OPTIMAL(4), + SHADER_READ_ONLY_OPTIMAL(5), + TRANSFER_SRC_OPTIMAL(6), + TRANSFER_DST_OPTIMAL(7), + PREINITIALIZED(8), + DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL(1000117000), + DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL(1000117001), + PRESENT_SRC_KHR(1000001002), + SHARED_PRESENT_KHR(1000111000); + + val accessMask: VkAccessFlags + get() = when (this) { + PREINITIALIZED -> VkAccess.HOST_WRITE_BIT.i + COLOR_ATTACHMENT_OPTIMAL -> VkAccess.COLOR_ATTACHMENT_WRITE_BIT.i + DEPTH_STENCIL_ATTACHMENT_OPTIMAL -> VkAccess.DEPTH_STENCIL_ATTACHMENT_WRITE_BIT.i + TRANSFER_SRC_OPTIMAL -> VkAccess.TRANSFER_READ_BIT.i + TRANSFER_DST_OPTIMAL -> VkAccess.TRANSFER_WRITE_BIT.i + SHADER_READ_ONLY_OPTIMAL -> VkAccess.SHADER_READ_BIT.i + else -> 0 + } + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkImageViewType(val i: Int) { + `1D`(0), + `2D`(1), + `3D`(2), + CUBE(3), + `1D_ARRAY`(4), + `2D_ARRAY`(5), + CUBE_ARRAY(6); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkComponentSwizzle(val i: Int) { + IDENTITY(0), + ZERO(1), + ONE(2), + R(3), + G(4), + B(5), + A(6); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkVertexInputRate(val i: Int) { + VERTEX(0), + INSTANCE(1); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkPrimitiveTopology(val i: Int) { + POINT_LIST(0), + LINE_LIST(1), + LINE_STRIP(2), + TRIANGLE_LIST(3), + TRIANGLE_STRIP(4), + TRIANGLE_FAN(5), + LINE_LIST_WITH_ADJACENCY(6), + LINE_STRIP_WITH_ADJACENCY(7), + TRIANGLE_LIST_WITH_ADJACENCY(8), + TRIANGLE_STRIP_WITH_ADJACENCY(9), + PATCH_LIST(10); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkPolygonMode(val i: Int) { + FILL(0), + LINE(1), + POINT(2), + FILL_RECTANGLE_NV(1000153000); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkFrontFace(val i: Int) { + COUNTER_CLOCKWISE(0), + CLOCKWISE(1); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkCompareOp(val i: Int) { + NEVER(0), + LESS(1), + EQUAL(2), + LESS_OR_EQUAL(3), + GREATER(4), + NOT_EQUAL(5), + GREATER_OR_EQUAL(6), + ALWAYS(7); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkStencilOp(val i: Int) { + KEEP(0), + ZERO(1), + REPLACE(2), + INCREMENT_AND_CLAMP(3), + DECREMENT_AND_CLAMP(4), + INVERT(5), + INCREMENT_AND_WRAP(6), + DECREMENT_AND_WRAP(7); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkLogicOp(val i: Int) { + CLEAR(0), + AND(1), + AND_REVERSE(2), + COPY(3), + AND_INVERTED(4), + NO_OP(5), + XOR(6), + OR(7), + NOR(8), + EQUIVALENT(9), + INVERT(10), + OR_REVERSE(11), + COPY_INVERTED(12), + OR_INVERTED(13), + NAND(14), + SET(15); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkBlendFactor(val i: Int) { + ZERO(0), + ONE(1), + SRC_COLOR(2), + ONE_MINUS_SRC_COLOR(3), + DST_COLOR(4), + ONE_MINUS_DST_COLOR(5), + SRC_ALPHA(6), + ONE_MINUS_SRC_ALPHA(7), + DST_ALPHA(8), + ONE_MINUS_DST_ALPHA(9), + CONSTANT_COLOR(10), + ONE_MINUS_CONSTANT_COLOR(11), + CONSTANT_ALPHA(12), + ONE_MINUS_CONSTANT_ALPHA(13), + SRC_ALPHA_SATURATE(14), + SRC1_COLOR(15), + ONE_MINUS_SRC1_COLOR(16), + SRC1_ALPHA(17), + ONE_MINUS_SRC1_ALPHA(18); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkBlendOp(val i: Int) { + ADD(0), + SUBTRACT(1), + REVERSE_SUBTRACT(2), + MIN(3), + MAX(4), + ZERO_EXT(1000148000), + SRC_EXT(1000148001), + DST_EXT(1000148002), + SRC_OVER_EXT(1000148003), + DST_OVER_EXT(1000148004), + SRC_IN_EXT(1000148005), + DST_IN_EXT(1000148006), + SRC_OUT_EXT(1000148007), + DST_OUT_EXT(1000148008), + SRC_ATOP_EXT(1000148009), + DST_ATOP_EXT(1000148010), + XOR_EXT(1000148011), + MULTIPLY_EXT(1000148012), + SCREEN_EXT(1000148013), + OVERLAY_EXT(1000148014), + DARKEN_EXT(1000148015), + LIGHTEN_EXT(1000148016), + COLORDODGE_EXT(1000148017), + COLORBURN_EXT(1000148018), + HARDLIGHT_EXT(1000148019), + SOFTLIGHT_EXT(1000148020), + DIFFERENCE_EXT(1000148021), + EXCLUSION_EXT(1000148022), + INVERT_EXT(1000148023), + INVERT_RGB_EXT(1000148024), + LINEARDODGE_EXT(1000148025), + LINEARBURN_EXT(1000148026), + VIVIDLIGHT_EXT(1000148027), + LINEARLIGHT_EXT(1000148028), + PINLIGHT_EXT(1000148029), + HARDMIX_EXT(1000148030), + HSL_HUE_EXT(1000148031), + HSL_SATURATION_EXT(1000148032), + HSL_COLOR_EXT(1000148033), + HSL_LUMINOSITY_EXT(1000148034), + PLUS_EXT(1000148035), + PLUS_CLAMPED_EXT(1000148036), + PLUS_CLAMPED_ALPHA_EXT(1000148037), + PLUS_DARKER_EXT(1000148038), + MINUS_EXT(1000148039), + MINUS_CLAMPED_EXT(1000148040), + CONTRAST_EXT(1000148041), + INVERT_OVG_EXT(1000148042), + RED_EXT(1000148043), + GREEN_EXT(1000148044), + BLUE_EXT(1000148045); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkDynamicState(val i: Int) { + VIEWPORT(0), + SCISSOR(1), + LINE_WIDTH(2), + DEPTH_BIAS(3), + BLEND_CONSTANTS(4), + DEPTH_BOUNDS(5), + STENCIL_COMPARE_MASK(6), + STENCIL_WRITE_MASK(7), + STENCIL_REFERENCE(8), + VIEWPORT_W_SCALING_NV(1000087000), + DISCARD_RECTANGLE_EXT(1000099000), + SAMPLE_LOCATIONS_EXT(1000143000); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkFilter(val i: Int) { + NEAREST(0), + LINEAR(1), + CUBIC_IMG(1000015000); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkSamplerMipmapMode(val i: Int) { + NEAREST(0), + LINEAR(1); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkSamplerAddressMode(val i: Int) { + REPEAT(0), + MIRRORED_REPEAT(1), + CLAMP_TO_EDGE(2), + CLAMP_TO_BORDER(3), + MIRROR_CLAMP_TO_EDGE(4); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkBorderColor(val i: Int) { + FLOAT_TRANSPARENT_BLACK(0), + INT_TRANSPARENT_BLACK(1), + FLOAT_OPAQUE_BLACK(2), + INT_OPAQUE_BLACK(3), + FLOAT_OPAQUE_WHITE(4), + INT_OPAQUE_WHITE(5); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkDescriptorType(val i: Int) { + SAMPLER(0), + COMBINED_IMAGE_SAMPLER(1), + SAMPLED_IMAGE(2), + STORAGE_IMAGE(3), + UNIFORM_TEXEL_BUFFER(4), + STORAGE_TEXEL_BUFFER(5), + UNIFORM_BUFFER(6), + STORAGE_BUFFER(7), + UNIFORM_BUFFER_DYNAMIC(8), + STORAGE_BUFFER_DYNAMIC(9), + INPUT_ATTACHMENT(10), + INLINE_UNIFORM_BLOCK_EXT(1000138000); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkAttachmentLoadOp(val i: Int) { + LOAD(0), + CLEAR(1), + DONT_CARE(2); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkAttachmentStoreOp(val i: Int) { + STORE(0), + DONT_CARE(1); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkPipelineBindPoint(val i: Int) { + GRAPHICS(0), + COMPUTE(1); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkCommandBufferLevel(val i: Int) { + PRIMARY(0), + SECONDARY(1); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkIndexType(val i: Int) { + UINT16(0), + UINT32(1); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkSubpassContents(val i: Int) { + INLINE(0), + SECONDARY_COMMAND_BUFFERS(1); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkObjectType(val i: Int) { + UNKNOWN(0), + INSTANCE(1), + PHYSICAL_DEVICE(2), + DEVICE(3), + QUEUE(4), + SEMAPHORE(5), + COMMAND_BUFFER(6), + FENCE(7), + DEVICE_MEMORY(8), + BUFFER(9), + IMAGE(10), + EVENT(11), + QUERY_POOL(12), + BUFFER_VIEW(13), + IMAGE_VIEW(14), + SHADER_MODULE(15), + PIPELINE_CACHE(16), + PIPELINE_LAYOUT(17), + RENDER_PASS(18), + PIPELINE(19), + DESCRIPTOR_SET_LAYOUT(20), + SAMPLER(21), + DESCRIPTOR_POOL(22), + DESCRIPTOR_SET(23), + FRAMEBUFFER(24), + COMMAND_POOL(25), + SAMPLER_YCBCR_CONVERSION(1000156000), + DESCRIPTOR_UPDATE_TEMPLATE(1000085000), + SURFACE_KHR(1000000000), + SWAPCHAIN_KHR(1000001000), + DISPLAY_KHR(1000002000), + DISPLAY_MODE_KHR(1000002001), + DEBUG_REPORT_CALLBACK_EXT(1000011000), + OBJECT_TABLE_NVX(1000086000), + INDIRECT_COMMANDS_LAYOUT_NVX(1000086001), + DEBUG_UTILS_MESSENGER_EXT(1000128000), + VALIDATION_CACHE_EXT(1000160000); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkVendorId(val i: Int) { + VIV(0x10001), + VSI(0x10002), + KAZAN(0x10003); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +typealias VkInstanceCreateFlags = VkFlags + +enum class VkFormatFeature(val i: Int) { + SAMPLED_IMAGE_BIT(0x00000001), + STORAGE_IMAGE_BIT(0x00000002), + STORAGE_IMAGE_ATOMIC_BIT(0x00000004), + UNIFORM_TEXEL_BUFFER_BIT(0x00000008), + STORAGE_TEXEL_BUFFER_BIT(0x00000010), + STORAGE_TEXEL_BUFFER_ATOMIC_BIT(0x00000020), + VERTEX_BUFFER_BIT(0x00000040), + COLOR_ATTACHMENT_BIT(0x00000080), + COLOR_ATTACHMENT_BLEND_BIT(0x00000100), + DEPTH_STENCIL_ATTACHMENT_BIT(0x00000200), + BLIT_SRC_BIT(0x00000400), + BLIT_DST_BIT(0x00000800), + SAMPLED_IMAGE_FILTER_LINEAR_BIT(0x00001000), + TRANSFER_SRC_BIT(0x00004000), + TRANSFER_DST_BIT(0x00008000), + MIDPOINT_CHROMA_SAMPLES_BIT(0x00020000), + SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT(0x00040000), + SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT(0x00080000), + SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_BIT(0x00100000), + SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_FORCEABLE_BIT(0x00200000), + DISJOINT_BIT(0x00400000), + COSITED_CHROMA_SAMPLES_BIT(0x00800000), + SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG(0x00002000), + SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT(0x00010000); +} + +infix fun Int.has(f: VkFormatFeature) = and(f.i) != 0 +infix fun Int.hasnt(f: VkFormatFeature) = and(f.i) == 0 + +typealias VkFormatFeatureFlags = VkFlags + +enum class VkImageUsage(val i: Int) { + TRANSFER_SRC_BIT(0x00000001), + TRANSFER_DST_BIT(0x00000002), + SAMPLED_BIT(0x00000004), + STORAGE_BIT(0x00000008), + COLOR_ATTACHMENT_BIT(0x00000010), + DEPTH_STENCIL_ATTACHMENT_BIT(0x00000020), + TRANSIENT_ATTACHMENT_BIT(0x00000040), + INPUT_ATTACHMENT_BIT(0x00000080); + + infix fun or(b: VkImageUsage): VkImageUsageFlags = i or b.i + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +infix fun Int.or(b: VkImageUsage): VkImageUsageFlags = or(b.i) +infix fun Int.has(b: VkImageUsage): Boolean = and(b.i) != 0 +infix fun Int.hasnt(b: VkImageUsage): Boolean = and(b.i) == 0 + +typealias VkImageUsageFlags = VkFlags + +enum class VkImageCreate(val i: Int) { + SPARSE_BINDING_BIT(0x00000001), + SPARSE_RESIDENCY_BIT(0x00000002), + SPARSE_ALIASED_BIT(0x00000004), + MUTABLE_FORMAT_BIT(0x00000008), + CUBE_COMPATIBLE_BIT(0x00000010), + ALIAS_BIT(0x00000400), + SPLIT_INSTANCE_BIND_REGIONS_BIT(0x00000040), + `2D_ARRAY_COMPATIBLE_BIT`(0x00000020), + BLOCK_TEXEL_VIEW_COMPATIBLE_BIT(0x00000080), + EXTENDED_USAGE_BIT(0x00000100), + PROTECTED_BIT(0x00000800), + DISJOINT_BIT(0x00000200), + SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_EXT(0x00001000); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +typealias VkImageCreateFlags = VkFlags + +enum class VkSampleCount(val i: Int) { + `1_BIT`(0x00000001), + `2_BIT`(0x00000002), + `4_BIT`(0x00000004), + `8_BIT`(0x00000008), + `16_BIT`(0x00000010), + `32_BIT`(0x00000020), + `64_BIT`(0x00000040); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +typealias VkSampleCountFlags = VkFlags + +enum class VkQueueFlag(val i: Int) { + GRAPHICS_BIT(0x00000001), + COMPUTE_BIT(0x00000002), + TRANSFER_BIT(0x00000004), + SPARSE_BINDING_BIT(0x00000008), + PROTECTED_BIT(0x00000010); + + infix fun or(b: VkQueueFlag): VkQueueFlags = i or b.i +} + +infix fun Int.has(b: VkQueueFlag) = and(b.i) != 0 +infix fun Int.hasnt(b: VkQueueFlag) = and(b.i) == 0 + +typealias VkQueueFlags = VkFlags + +enum class VkMemoryProperty(val i: Int) { + DEVICE_LOCAL_BIT(0x00000001), + HOST_VISIBLE_BIT(0x00000002), + HOST_COHERENT_BIT(0x00000004), + HOST_CACHED_BIT(0x00000008), + LAZILY_ALLOCATED_BIT(0x00000010), + PROTECTED_BIT(0x00000020); + + infix fun or(b: VkMemoryProperty): VkMemoryPropertyFlags = i or b.i +} + +infix fun Int.has(b: VkMemoryProperty) = and(b.i) != 0 +infix fun Int.hasnt(b: VkMemoryProperty) = and(b.i) == 0 + +typealias VkMemoryPropertyFlags = VkFlags + +enum class VkMemoryHeapFlag(val i: Int) { + DEVICE_LOCAL_BIT(0x00000001), + MULTI_INSTANCE_BIT(0x00000002); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} +typealias VkMemoryHeapFlags = VkFlags +typealias VkDeviceCreateFlags = VkFlags + +enum class VkDeviceQueueCreate(val i: Int) { + CREATE_PROTECTED_BIT(0x00000001) +} + +typealias VkDeviceQueueCreateFlags = VkFlags + +enum class VkPipelineStage(val i: Int) { + TOP_OF_PIPE_BIT(0x00000001), + DRAW_INDIRECT_BIT(0x00000002), + VERTEX_INPUT_BIT(0x00000004), + VERTEX_SHADER_BIT(0x00000008), + TESSELLATION_CONTROL_SHADER_BIT(0x00000010), + TESSELLATION_EVALUATION_SHADER_BIT(0x00000020), + GEOMETRY_SHADER_BIT(0x00000040), + FRAGMENT_SHADER_BIT(0x00000080), + EARLY_FRAGMENT_TESTS_BIT(0x00000100), + LATE_FRAGMENT_TESTS_BIT(0x00000200), + COLOR_ATTACHMENT_OUTPUT_BIT(0x00000400), + COMPUTE_SHADER_BIT(0x00000800), + TRANSFER_BIT(0x00001000), + BOTTOM_OF_PIPE_BIT(0x00002000), + HOST_BIT(0x00004000), + ALL_GRAPHICS_BIT(0x00008000), + ALL_COMMANDS_BIT(0x00010000), + CONDITIONAL_RENDERING_BIT_EXT(0x00040000), + COMMAND_PROCESS_BIT_NVX(0x00020000); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +typealias VkPipelineStageFlags = VkFlags + +typealias VkMemoryMapFlags = VkFlags + +enum class VkImageAspect(val i: Int) { + COLOR_BIT(0x00000001), + DEPTH_BIT(0x00000002), + STENCIL_BIT(0x00000004), + METADATA_BIT(0x00000008), + PLANE_0_BIT(0x00000010), + PLANE_1_BIT(0x00000020), + PLANE_2_BIT(0x00000040); + + infix fun or(f: VkImageAspect) = i or f.i + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +typealias VkImageAspectFlags = VkFlags + +enum class VkSparseImageFormat(val i: Int) { + SINGLE_MIPTAIL_BIT(0x00000001), + ALIGNED_MIP_SIZE_BIT(0x00000002), + NONSTANDARD_BLOCK_SIZE_BIT(0x00000004); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} +typealias VkSparseImageFormatFlags = VkFlags + +enum class VkSparseMemoryBind(val i: Int) { + METADATA_BIT(0x00000001); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} +typealias VkSparseMemoryBindFlags = VkFlags + +enum class VkFenceCreate(val i: Int) { + SIGNALED_BIT(0x00000001); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +typealias VkFenceCreateFlags = VkFlags +typealias VkSemaphoreCreateFlags = VkFlags +typealias VkEventCreateFlags = VkFlags +typealias VkQueryPoolCreateFlags = VkFlags + +enum class VkQueryPipelineStatistic(val i: Int) { + INPUT_ASSEMBLY_VERTICES_BIT(0x00000001), + INPUT_ASSEMBLY_PRIMITIVES_BIT(0x00000002), + VERTEX_SHADER_INVOCATIONS_BIT(0x00000004), + GEOMETRY_SHADER_INVOCATIONS_BIT(0x00000008), + GEOMETRY_SHADER_PRIMITIVES_BIT(0x00000010), + CLIPPING_INVOCATIONS_BIT(0x00000020), + CLIPPING_PRIMITIVES_BIT(0x00000040), + FRAGMENT_SHADER_INVOCATIONS_BIT(0x00000080), + TESSELLATION_CONTROL_SHADER_PATCHES_BIT(0x00000100), + TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT(0x00000200), + COMPUTE_SHADER_INVOCATIONS_BIT(0x00000400); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} +typealias VkQueryPipelineStatisticFlags = VkFlags + +enum class VkQueryResult(val i: Int) { + `64_BIT`(0x00000001), + WAIT_BIT(0x00000002), + WITH_AVAILABILITY_BIT(0x00000004), + PARTIAL_BIT(0x00000008); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} +typealias VkQueryResultFlags = VkFlags + +enum class VkBufferCreate(val i: Int) { + SPARSE_BINDING_BIT(0x00000001), + SPARSE_RESIDENCY_BIT(0x00000002), + SPARSE_ALIASED_BIT(0x00000004), + PROTECTED_BIT(0x00000008); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +typealias VkBufferCreateFlags = VkFlags + +enum class VkBufferUsage(val i: Int) { + TRANSFER_SRC_BIT(0x00000001), + TRANSFER_DST_BIT(0x00000002), + UNIFORM_TEXEL_BUFFER_BIT(0x00000004), + STORAGE_TEXEL_BUFFER_BIT(0x00000008), + UNIFORM_BUFFER_BIT(0x00000010), + STORAGE_BUFFER_BIT(0x00000020), + INDEX_BUFFER_BIT(0x00000040), + VERTEX_BUFFER_BIT(0x00000080), + INDIRECT_BUFFER_BIT(0x00000100), + CONDITIONAL_RENDERING_BIT_EXT(0x00000200); + + infix fun or(f: VkBufferUsage): VkBufferCreateFlags = i or f.i + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +infix fun Int.or(f: VkBufferUsage): VkBufferCreateFlags = or(f.i) + +typealias VkBufferUsageFlags = VkFlags +typealias VkBufferViewCreateFlags = VkFlags +typealias VkImageViewCreateFlags = VkFlags + +typealias VkShaderModuleCreateFlags = VkFlags +typealias VkPipelineCacheCreateFlags = VkFlags + + +enum class VkPipelineCreate(val i: Int) { + DISABLE_OPTIMIZATION_BIT(0x00000001), + ALLOW_DERIVATIVES_BIT(0x00000002), + DERIVATIVE_BIT(0x00000004), + VIEW_INDEX_FROM_DEVICE_INDEX_BIT(0x00000008), + DISPATCH_BASE(0x00000010); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} +typealias VkPipelineCreateFlags = VkFlags + +typealias VkPipelineShaderStageCreateFlags = VkFlags + +enum class VkShaderStage(val i: Int) { + VERTEX_BIT(0x00000001), + TESSELLATION_CONTROL_BIT(0x00000002), + TESSELLATION_EVALUATION_BIT(0x00000004), + GEOMETRY_BIT(0x00000008), + FRAGMENT_BIT(0x00000010), + COMPUTE_BIT(0x00000020), + ALL_GRAPHICS(0x0000001F), + ALL(0x7FFFFFFF); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +typealias VkPipelineVertexInputStateCreateFlags = VkFlags +typealias VkPipelineInputAssemblyStateCreateFlags = VkFlags + +typealias VkPipelineTessellationStateCreateFlags = VkFlags +typealias VkPipelineViewportStateCreateFlags = VkFlags + +typealias VkPipelineRasterizationStateCreateFlags = VkFlags + + +enum class VkCullMode(val i: Int) { + NONE(0), + FRONT_BIT(0x00000001), + BACK_BIT(0x00000002), + FRONT_AND_BACK(0x00000003); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +typealias VkCullModeFlags = VkFlags +typealias VkPipelineMultisampleStateCreateFlags = VkFlags +typealias VkPipelineDepthStencilStateCreateFlags = VkFlags + +typealias VkPipelineColorBlendStateCreateFlags = VkFlags + +enum class VkColorComponent(val i: Int) { + R_BIT(0x00000001), + G_BIT(0x00000002), + B_BIT(0x00000004), + A_BIT(0x00000008); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +infix fun VkColorComponent.or(f: VkColorComponent): VkColorComponentFlags = i or f.i +infix fun Int.or(f: VkColorComponent): VkColorComponentFlags = or(f.i) + +typealias VkColorComponentFlags = VkFlags +typealias VkPipelineDynamicStateCreateFlags = VkFlags +typealias VkPipelineLayoutCreateFlags = VkFlags + +typealias VkShaderStageFlags = VkFlags + +typealias VkSamplerCreateFlags = VkFlags + +enum class VkDescriptorSetLayoutCreate(val i: Int) { + PUSH_DESCRIPTOR_BIT_KHR(0x00000001), + UPDATE_AFTER_BIND_POOL_BIT_EXT(0x00000002); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +typealias VkDescriptorSetLayoutCreateFlags = VkFlags + +enum class VkDescriptorPoolCreate(val i: Int) { + FREE_DESCRIPTOR_SET_BIT(0x00000001), + UPDATE_AFTER_BIND_BIT_EXT(0x00000002); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +typealias VkDescriptorPoolCreateFlags = VkFlags +typealias VkDescriptorPoolResetFlags = VkFlags +typealias VkFramebufferCreateFlags = VkFlags + +typealias VkRenderPassCreateFlags = VkFlags + +enum class VkAttachmentDescriptionFlag(val i: Int) { + MAY_ALIAS_BIT(0x00000001); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +typealias VkAttachmentDescriptionFlags = VkFlags + + +enum class VkSubpassDescriptionFlag(val i: Int) { + PER_VIEW_ATTRIBUTES_BIT_NVX(0x00000001), + PER_VIEW_POSITION_X_ONLY_BIT_NVX(0x00000002); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +typealias VkSubpassDescriptionFlags = VkFlags + +enum class VkAccess(val i: Int) { + INDIRECT_COMMAND_READ_BIT(0x00000001), + INDEX_READ_BIT(0x00000002), + VERTEX_ATTRIBUTE_READ_BIT(0x00000004), + UNIFORM_READ_BIT(0x00000008), + INPUT_ATTACHMENT_READ_BIT(0x00000010), + SHADER_READ_BIT(0x00000020), + SHADER_WRITE_BIT(0x00000040), + COLOR_ATTACHMENT_READ_BIT(0x00000080), + COLOR_ATTACHMENT_WRITE_BIT(0x00000100), + DEPTH_STENCIL_ATTACHMENT_READ_BIT(0x00000200), + DEPTH_STENCIL_ATTACHMENT_WRITE_BIT(0x00000400), + TRANSFER_READ_BIT(0x00000800), + TRANSFER_WRITE_BIT(0x00001000), + HOST_READ_BIT(0x00002000), + HOST_WRITE_BIT(0x00004000), + MEMORY_READ_BIT(0x00008000), + MEMORY_WRITE_BIT(0x00010000), + CONDITIONAL_RENDERING_READ_BIT_EXT(0x00100000), + COMMAND_PROCESS_READ_BIT_NVX(0x00020000), + COMMAND_PROCESS_WRITE_BIT_NVX(0x00040000), + COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT(0x00080000); + + infix fun or(f: VkAccess) = i or f.i + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +infix fun Int.or(f: VkAccess) = or(f.i) + +typealias VkAccessFlags = VkFlags + +enum class VkDependency(val i: Int) { + BY_REGION_BIT(0x00000001), + VIEW_LOCAL_BIT(0x00000002), + DEVICE_GROUP_BIT(0x00000004); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +typealias VkDependencyFlags = VkFlags + +enum class VkCommandPoolCreate(val i: Int) { + TRANSIENT_BIT(0x00000001), + RESET_COMMAND_BUFFER_BIT(0x00000002), + PROTECTED_BIT(0x00000004); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +typealias VkCommandPoolCreateFlags = VkFlags + +enum class VkCommandPoolReset(val i: Int) { + RELEASE_RESOURCES_BIT(0x00000001); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} +typealias VkCommandPoolResetFlags = VkFlags + +enum class VkCommandBufferUsage(val i: Int) { + ONE_TIME_SUBMIT_BIT(0x00000001), + RENDER_PASS_CONTINUE_BIT(0x00000002), + SIMULTANEOUS_USE_BIT(0x00000004); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +infix fun Int.or(f: VkCommandBufferUsage) = or(f.i) + +typealias VkCommandBufferUsageFlags = VkFlags + + +enum class VkQueryControl(val i: Int) { + PRECISE_BIT(0x00000001); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} +typealias VkQueryControlFlags = VkFlags + +enum class VkCommandBufferReset(val i: Int) { + RELEASE_RESOURCES_BIT(0x00000001); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} +typealias VkCommandBufferResetFlags = VkFlags + +enum class VkStencilFace(val i: Int) { + FRONT_BIT(0x00000001), + BACK_BIT(0x00000002), + FRONT_AND_BACK(0x00000003); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} +typealias VkStencilFaceFlags = VkFlags + +// --------------------------------------------------------------------------------------------------------------------- +// line 3669 + + +enum class VkPointClippingBehavior(val i: Int) { + ALL_CLIP_PLANES(0), + USER_CLIP_PLANES_ONLY(1); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkTessellationDomainOrigin(val i: Int) { + UPPER_LEFT(0), + LOWER_LEFT(1); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkSamplerYcbcrModelConversion(val i: Int) { + RGB_IDENTITY(0), + YCBCR_IDENTITY(1), + YCBCR_709(2), + YCBCR_601(3), + YCBCR_2020(4); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkSamplerYcbcrRange(val i: Int) { + ITU_FULL(0), + ITU_NARROW(1); +} + +enum class VkChromaLocation(val i: Int) { + COSITED_EVEN(0), + MIDPOINT(1); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +enum class VkDescriptorUpdateTemplateType(val i: Int) { + DESCRIPTOR_SET(0), + PUSH_DESCRIPTORS_KHR(1); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkSubgroupFeature(val i: Int) { + BASIC_BIT(0x00000001), + VOTE_BIT(0x00000002), + ARITHMETIC_BIT(0x00000004), + BALLOT_BIT(0x00000008), + SHUFFLE_BIT(0x00000010), + SHUFFLE_RELATIVE_BIT(0x00000020), + CLUSTERED_BIT(0x00000040), + QUAD_BIT(0x00000080), + PARTITIONED_BIT_NV(0x00000100); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +typealias VkSubgroupFeatureFlags = VkFlags + +enum class VkPeerMemoryFeature(val i: Int) { + COPY_SRC_BIT(0x00000001), + COPY_DST_BIT(0x00000002), + GENERIC_SRC_BIT(0x00000004), + GENERIC_DST_BIT(0x00000008); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +typealias VkPeerMemoryFeatureFlags = VkFlags + +enum class VkMemoryAllocateFlagBits(val i: Int) { + DEVICE_MASK_BIT(0x00000001); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +typealias VkMemoryAllocateFlags = VkFlags +typealias VkCommandPoolTrimFlags = VkFlags +typealias VkDescriptorUpdateTemplateCreateFlags = VkFlags + +//enum class VkExternalMemoryHandleTypeFlagBits { +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT = 0x00000001, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT = 0x00000002, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT = 0x00000004, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT = 0x00000008, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_KMT_BIT = 0x00000010, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP_BIT = 0x00000020, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE_BIT = 0x00000040, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT = 0x00000200, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID = 0x00000400, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT = 0x00000080, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_MAPPED_FOREIGN_MEMORY_BIT_EXT = 0x00000100, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_KMT_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_KMT_BIT, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP_BIT, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE_BIT, +// VK_EXTERNAL_MEMORY_HANDLE_TYPE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +//} VkExternalMemoryHandleTypeFlagBits; +//typedef VkFlags VkExternalMemoryHandleTypeFlags; +// +//typedef enum VkExternalMemoryFeatureFlagBits { +// VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT = 0x00000001, +// VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT = 0x00000002, +// VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT = 0x00000004, +// VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT_KHR = VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT, +// VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHR = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT, +// VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHR = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT, +// VK_EXTERNAL_MEMORY_FEATURE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +//} VkExternalMemoryFeatureFlagBits; +//typedef VkFlags VkExternalMemoryFeatureFlags; +// +//typedef enum VkExternalFenceHandleTypeFlagBits { +// VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT = 0x00000001, +// VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT = 0x00000002, +// VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT = 0x00000004, +// VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT = 0x00000008, +// VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT, +// VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT, +// VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT, +// VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR = VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT, +// VK_EXTERNAL_FENCE_HANDLE_TYPE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +//} VkExternalFenceHandleTypeFlagBits; +//typedef VkFlags VkExternalFenceHandleTypeFlags; +// +//typedef enum VkExternalFenceFeatureFlagBits { +// VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT = 0x00000001, +// VK_EXTERNAL_FENCE_FEATURE_IMPORTABLE_BIT = 0x00000002, +// VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR = VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT, +// VK_EXTERNAL_FENCE_FEATURE_IMPORTABLE_BIT_KHR = VK_EXTERNAL_FENCE_FEATURE_IMPORTABLE_BIT, +// VK_EXTERNAL_FENCE_FEATURE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +//} VkExternalFenceFeatureFlagBits; +//typedef VkFlags VkExternalFenceFeatureFlags; +// +//typedef enum VkFenceImportFlagBits { +// VK_FENCE_IMPORT_TEMPORARY_BIT = 0x00000001, +// VK_FENCE_IMPORT_TEMPORARY_BIT_KHR = VK_FENCE_IMPORT_TEMPORARY_BIT, +// VK_FENCE_IMPORT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +//} VkFenceImportFlagBits; +//typedef VkFlags VkFenceImportFlags; +// +//typedef enum VkSemaphoreImportFlagBits { +// VK_SEMAPHORE_IMPORT_TEMPORARY_BIT = 0x00000001, +// VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT, +// VK_SEMAPHORE_IMPORT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +//} VkSemaphoreImportFlagBits; +//typedef VkFlags VkSemaphoreImportFlags; +// +//typedef enum VkExternalSemaphoreHandleTypeFlagBits { +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT = 0x00000001, +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT = 0x00000002, +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT = 0x00000004, +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT = 0x00000008, +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT = 0x00000010, +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT, +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT, +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT, +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT_KHR = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT, +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT, +// VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +//} VkExternalSemaphoreHandleTypeFlagBits; +//typedef VkFlags VkExternalSemaphoreHandleTypeFlags; +// +//typedef enum VkExternalSemaphoreFeatureFlagBits { +// VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT = 0x00000001, +// VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT = 0x00000002, +// VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR = VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT, +// VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR = VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT, +// VK_EXTERNAL_SEMAPHORE_FEATURE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +//} VkExternalSemaphoreFeatureFlagBits; +//typedef VkFlags VkExternalSemaphoreFeatureFlags; + +enum class VkColorSpace(val i: Int) { + SRGB_NONLINEAR_KHR(0), + DISPLAY_P3_NONLINEAR_EXT(1000104001), + EXTENDED_SRGB_LINEAR_EXT(1000104002), + DCI_P3_LINEAR_EXT(1000104003), + DCI_P3_NONLINEAR_EXT(1000104004), + BT709_LINEAR_EXT(1000104005), + BT709_NONLINEAR_EXT(1000104006), + BT2020_LINEAR_EXT(1000104007), + HDR10_ST2084_EXT(1000104008), + DOLBYVISION_EXT(1000104009), + HDR10_HLG_EXT(1000104010), + ADOBERGB_LINEAR_EXT(1000104011), + ADOBERGB_NONLINEAR_EXT(1000104012), + PASS_THROUGH_EXT(1000104013), + EXTENDED_SRGB_NONLINEAR_EXT(1000104014); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkPresentMode(val i: Int) { + IMMEDIATE_KHR(0), + MAILBOX_KHR(1), + FIFO_KHR(2), + FIFO_RELAXED_KHR(3), + SHARED_DEMAND_REFRESH_KHR(1000111000), + SHARED_CONTINUOUS_REFRESH_KHR(1000111001); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkSurfaceTransform(val i: Int) { + IDENTITY_BIT_KHR(0x00000001), + ROTATE_90_BIT_KHR(0x00000002), + ROTATE_180_BIT_KHR(0x00000004), + ROTATE_270_BIT_KHR(0x00000008), + HORIZONTAL_MIRROR_BIT_KHR(0x00000010), + HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR(0x00000020), + HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR(0x00000040), + HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR(0x00000080), + INHERIT_BIT_KHR(0x00000100); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +typealias VkSurfaceTransformFlagsKHR = VkFlags + +enum class VkCompositeAlpha(val i: Int) { + OPAQUE_BIT_KHR(0x00000001), + PRE_MULTIPLIED_BIT_KHR(0x00000002), + POST_MULTIPLIED_BIT_KHR(0x00000004), + INHERIT_BIT_KHR(0x00000008); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + +infix fun Int.has(f: VkCompositeAlpha) = and(f.i) != 0 + +typealias VkCompositeAlphaFlagsKHR = VkFlags + + +enum class VkSwapchainCreateKHR(val i: Int) { + BIND_SFR_BIT_KHX(0x00000001); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +enum class VkDebugReportObjectType(val i: Int) { + UNKNOWN_EXT(0), + INSTANCE_EXT(1), + PHYSICAL_DEVICE_EXT(2), + DEVICE_EXT(3), + QUEUE_EXT(4), + SEMAPHORE_EXT(5), + COMMAND_BUFFER_EXT(6), + FENCE_EXT(7), + DEVICE_MEMORY_EXT(8), + BUFFER_EXT(9), + IMAGE_EXT(10), + EVENT_EXT(11), + QUERY_POOL_EXT(12), + BUFFER_VIEW_EXT(13), + IMAGE_VIEW_EXT(14), + SHADER_MODULE_EXT(15), + PIPELINE_CACHE_EXT(16), + PIPELINE_LAYOUT_EXT(17), + RENDER_PASS_EXT(18), + PIPELINE_EXT(19), + DESCRIPTOR_SET_LAYOUT_EXT(20), + SAMPLER_EXT(21), + DESCRIPTOR_POOL_EXT(22), + DESCRIPTOR_SET_EXT(23), + FRAMEBUFFER_EXT(24), + COMMAND_POOL_EXT(25), + SURFACE_KHR_EXT(26), + SWAPCHAIN_KHR_EXT(27), + DEBUG_REPORT_CALLBACK_EXT_EXT(28), + DISPLAY_KHR_EXT(29), + DISPLAY_MODE_KHR_EXT(30), + OBJECT_TABLE_NVX_EXT(31), + INDIRECT_COMMANDS_LAYOUT_NVX_EXT(32), + VALIDATION_CACHE_EXT(33), + DESCRIPTOR_UPDATE_TEMPLATE_EXT(1000085000), + SAMPLER_YCBCR_CONVERSION_KHR_EXT(1000156000); + + companion object { + infix fun of(i: Int) = values().first { it.i == i } + } +} + + +//typealias VkDebugReportFlagBitsEXT = Int + +enum class VkDebugReport(val i: Int) { + INFORMATION_BIT_EXT(0x00000001), + WARNING_BIT_EXT(0x00000002), + PERFORMANCE_WARNING_BIT_EXT(0x00000004), + ERROR_BIT_EXT(0x00000008), + DEBUG_BIT_EXT(0x00000010); + + infix fun or(b: VkDebugReport): VkDebugReportFlagsEXT = i or b.i +} + +infix fun Int.has(f: VkDebugReport) = and(f.i) != 0 +infix fun Int.or(f: VkDebugReport): VkDebugReportFlagsEXT = or(f.i) + +typealias VkDebugReportFlagsEXT = VkFlags + diff --git a/src/main/kotlin/vkk/extension functions.kt b/src/main/kotlin/vkk/extension functions.kt new file mode 100644 index 0000000..36d5f9c --- /dev/null +++ b/src/main/kotlin/vkk/extension functions.kt @@ -0,0 +1,715 @@ +package vkk + +import glm_.* +import glm_.vec2.Vec2i +import kool.Ptr +import kool.stak +import org.lwjgl.PointerBuffer +import org.lwjgl.system.MemoryUtil.* +import org.lwjgl.system.Pointer +import org.lwjgl.system.Pointer.POINTER_SIZE +import org.lwjgl.vulkan.* +import java.nio.ByteBuffer +import java.nio.FloatBuffer + + +/* + VkCommandBuffer + */ + +infix fun VkCommandBuffer.begin(beginInfo: VkCommandBufferBeginInfo) = + VK_CHECK_RESULT(VK10.nvkBeginCommandBuffer(this, beginInfo.adr)) + +fun VkCommandBuffer.begin(flags: VkCommandBufferUsageFlags = VkCommandBufferUsage.SIMULTANEOUS_USE_BIT.i) = + begin(vk.CommandBufferBeginInfo { this.flags = flags }) + +fun VkCommandBuffer.beginRenderPass(renderPassBegin: VkRenderPassBeginInfo, contents: VkSubpassContents) = + VK10.nvkCmdBeginRenderPass(this, renderPassBegin.adr, contents.i) + +fun VkCommandBuffer.bindDescriptorSets(pipelineBindPoint: VkPipelineBindPoint, layout: VkPipelineLayout, descriptorSet: VkDescriptorSet, dynamicOffsets: Int? = null) = + vk.cmdBindDescriptorSets(this, pipelineBindPoint, layout, descriptorSet, dynamicOffsets) + +fun VkCommandBuffer.bindIndexBuffer(buffer: VkBuffer, offset: VkDeviceSize, indexType: VkIndexType) = + VK10.vkCmdBindIndexBuffer(this, buffer.L, offset.L, indexType.i) + +fun VkCommandBuffer.bindPipeline(pipelineBindPoint: VkPipelineBindPoint, pipeline: VkPipeline) = + VK10.vkCmdBindPipeline(this, pipelineBindPoint.i, pipeline.L) + +infix fun VkCommandBuffer.bindVertexBuffers(buffer: VkBuffer) = bindVertexBuffers(0, buffer) + +fun VkCommandBuffer.bindVertexBuffers(firstBinding: Int, buffer: VkBuffer) = + stak { + val pBuffer = nmemAlloc(Long.BYTES.L) + memPutLong(pBuffer, buffer.L) + val pOffset = nmemCalloc(Long.BYTES.L, 1) + VK10.nvkCmdBindVertexBuffers(this, firstBinding, 1, pBuffer, pOffset) + } + +fun VkCommandBuffer.blitImage(srcImage: VkImage, srcImageLayout: VkImageLayout, dstImage: VkImage, dstImageLayout: VkImageLayout, region: VkImageBlit, filter: VkFilter) = + VK10.nvkCmdBlitImage(this, srcImage.L, srcImageLayout.i, dstImage.L, dstImageLayout.i, 1, region.adr, filter.i) + +fun VkCommandBuffer.copyBuffer(srcBuffer: VkBuffer, dstBuffer: VkBuffer, region: VkBufferCopy) = + VK10.nvkCmdCopyBuffer(this, srcBuffer.L, dstBuffer.L, 1, region.adr) + +fun VkCommandBuffer.copyBuffer(srcBuffer: VkBuffer, dstBuffer: VkBuffer, regions: VkBufferCopy.Buffer) = + VK10.nvkCmdCopyBuffer(this, srcBuffer.L, dstBuffer.L, regions.remaining(), regions.adr) + +fun VkCommandBuffer.copyBufferToImage(srcBuffer: VkBuffer, dstImage: VkImage, dstImageLayout: VkImageLayout, region: VkBufferImageCopy) = + VK10.nvkCmdCopyBufferToImage(this, srcBuffer.L, dstImage.L, dstImageLayout.i, 1, region.adr) + +fun VkCommandBuffer.copyBufferToImage(srcBuffer: VkBuffer, dstImage: VkImage, dstImageLayout: VkImageLayout, region: VkBufferImageCopy.Buffer) = + VK10.nvkCmdCopyBufferToImage(this, srcBuffer.L, dstImage.L, dstImageLayout.i, region.remaining(), region.adr) + +fun VkCommandBuffer.copyImage(srcImage: VkImage, srcImageLayout: VkImageLayout, dstImage: VkImage, dstImageLayout: VkImageLayout, region: VkImageCopy) = + VK10.nvkCmdCopyImage(this, srcImage.L, srcImageLayout.i, dstImage.L, dstImageLayout.i, 1, region.adr) + +infix fun VkCommandBuffer.debugMarkerBegin(markerInfo: VkDebugMarkerMarkerInfoEXT) = + EXTDebugMarker.nvkCmdDebugMarkerBeginEXT(this, markerInfo.adr) + +fun VkCommandBuffer.debugMarkerEnd() = EXTDebugMarker.vkCmdDebugMarkerEndEXT(this) + +infix fun VkCommandBuffer.debugMarkerInsert(markerInfo: VkDebugMarkerMarkerInfoEXT) = + EXTDebugMarker.nvkCmdDebugMarkerInsertEXT(this, markerInfo.adr) + +fun VkCommandBuffer.dispatch(groupCountXY: Vec2i, groupCountZ: Int) = + dispatch(groupCountXY.x, groupCountXY.y, groupCountZ) + +fun VkCommandBuffer.dispatch(groupCountX: Int, groupCountY: Int, groupCountZ: Int) = + VK10.vkCmdDispatch(this, groupCountX, groupCountY, groupCountZ) + +fun VkCommandBuffer.draw(vertexCount: Int, instanceCount: Int, firstVertex: Int, firstInstance: Int) = + VK10.vkCmdDraw(this, vertexCount, instanceCount, firstVertex, firstInstance) + +fun VkCommandBuffer.drawIndexed(indexCount: Int, instanceCount: Int, firstIndex: Int, vertexOffset: Int, firstInstance: Int) = + VK10.vkCmdDrawIndexed(this, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance) + +fun VkCommandBuffer.end() = VK_CHECK_RESULT(VK10.vkEndCommandBuffer(this)) + +fun VkCommandBuffer.end(queue: VkQueue, submitInfoPNext: Pointer? = null) { + end() + submit(queue, submitInfoPNext) +} + +fun VkCommandBuffer.end(device: VkDevice, commandPool: VkCommandPool, queue: VkQueue, submitInfoPNext: Pointer? = null) { + end(queue, submitInfoPNext) + device.freeCommandBuffer(commandPool, this) +} + +fun VkCommandBuffer.endRenderPass() = VK10.vkCmdEndRenderPass(this) + +infix fun VkCommandBuffer.nextSubpass(contents: VkSubpassContents) = VK10.vkCmdNextSubpass(this, contents.i) + +fun VkCommandBuffer.pipelineBarrier(srcStageMask: VkPipelineStage, dstStageMask: VkPipelineStage, + dependencyFlags: VkDependencyFlags = 0, + memoryBarrier: VkMemoryBarrier? = null, + bufferMemoryBarrier: VkBufferMemoryBarrier? = null, + imageMemoryBarrier: VkImageMemoryBarrier? = null) = + pipelineBarrier(srcStageMask.i, dstStageMask.i, dependencyFlags, memoryBarrier, bufferMemoryBarrier, imageMemoryBarrier) + +fun VkCommandBuffer.pipelineBarrier(srcStageMask: VkPipelineStageFlags, dstStageMask: VkPipelineStageFlags, + dependencyFlags: VkDependencyFlags = 0, + memoryBarrier: VkMemoryBarrier? = null, + bufferMemoryBarrier: VkBufferMemoryBarrier? = null, + imageMemoryBarrier: VkImageMemoryBarrier? = null) = + VK10.nvkCmdPipelineBarrier(this, srcStageMask, dstStageMask, dependencyFlags, + if (memoryBarrier != null) 1 else 0, memoryBarrier?.adr ?: NULL, + if (bufferMemoryBarrier != null) 1 else 0, bufferMemoryBarrier?.adr ?: NULL, + if (imageMemoryBarrier != null) 1 else 0, imageMemoryBarrier?.adr ?: NULL) + +fun VkCommandBuffer.pushConstants(layout: VkPipelineLayout, stageFlags: VkShaderStageFlags, offset: Int, values: FloatBuffer) = + VK10.nvkCmdPushConstants(this, layout.L, stageFlags, offset, values.size, memAddress(values)) + +fun VkCommandBuffer.pushConstants(layout: VkPipelineLayout, stageFlags: VkShaderStageFlags, offset: Int, values: ByteBuffer) = + VK10.nvkCmdPushConstants(this, layout.L, stageFlags, offset, values.size, memAddress(values)) + +fun VkCommandBuffer.reset(flags: VkCommandBufferResetFlags) = + VK_CHECK_RESULT(VK10.vkResetCommandBuffer(this, flags)) + +fun VkCommandBuffer.setDepthBias(depthBiasConstantFactor: Float, depthBiasClamp: Float, depthBiasSlopeFactor: Float) = + VK10.vkCmdSetDepthBias(this, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor) + +infix fun VkCommandBuffer.setLineWidth(lineWidth: Float) = VK10.vkCmdSetLineWidth(this, lineWidth) + +infix fun VkCommandBuffer.setScissor(size: Vec2i) = setScissor(size, Vec2i()) + +fun VkCommandBuffer.setScissor(size: Vec2i, offset: Vec2i) = setScissor(vk.Rect2D(size, offset)) + +infix fun VkCommandBuffer.setScissor(scissor: VkRect2D) = + VK10.nvkCmdSetScissor(this, 0, 1, scissor.adr) + +infix fun VkCommandBuffer.setScissor(scissors: VkRect2D.Buffer) = + VK10.nvkCmdSetScissor(this, 0, scissors.remaining(), scissors.adr) + +fun VkCommandBuffer.setScissor(firstScissor: Int, scissors: VkRect2D.Buffer) = + VK10.nvkCmdSetScissor(this, firstScissor, scissors.remaining(), scissors.adr) + +infix fun VkCommandBuffer.setViewport(size: Vec2i) = setViewport(size, 0f, 1f) + +fun VkCommandBuffer.setViewport(size: Vec2i, minDepth: Float, maxDepth: Float) = + setViewport(size.x.f, size.y.f, minDepth, maxDepth) + +fun VkCommandBuffer.setViewport(width: Float, height: Float, minDepth: Float = 0f, maxDepth: Float = 1f) = + setViewport(vk.Viewport { + this.width = width + this.height = height + this.minDepth = minDepth + this.maxDepth = maxDepth + }) + +infix fun VkCommandBuffer.setViewport(viewport: VkViewport) = + VK10.nvkCmdSetViewport(this, 0, 1, viewport.adr) + +fun VkCommandBuffer.setViewport(firstViewport: Int, viewports: VkViewport.Buffer) = + VK10.nvkCmdSetViewport(this, firstViewport, viewports.remaining(), viewports.adr) + +fun VkCommandBuffer.submit(queue: VkQueue, submitInfoPNext: Pointer? = null) { + queue submit vk.SubmitInfo { + commandBuffer = this@submit + submitInfoPNext?.let { next = it.adr } + } + queue.waitIdle() +} + +//inline fun VkCommandBuffer.use(block: ()) { +// VK10.nvkCmdSetViewport(this, firstViewport, viewports.remaining(), viewports.adr) +//} +//inline fun VkCommandBuffer.setBlendConstants(depthBiasConstantFactor: Float, depthBiasClamp: Float, depthBiasSlopeFactor: Float) { +// VK10.setBlendConstants(this, depthBiasConstantFactor, depthBiasClamp, depthBiasSlopeFactor) +//} + + +/* + VkDevice + */ + +fun VkDevice.acquireNextImageKHR(swapchain: VkSwapchainKHR, timeout: Long, semaphore: VkSemaphore, fence: VkFence = VkFence(NULL)): Int = + stak.intAddress { imageIndex -> + VK_CHECK_RESULT(KHRSwapchain.nvkAcquireNextImageKHR(this, swapchain.L, timeout, semaphore.L, fence.L, imageIndex)) + } + +infix fun VkDevice.allocateCommandBuffer(allocateInfo: VkCommandBufferAllocateInfo): VkCommandBuffer = + stak { + val pCmdBuffer = it.nmalloc(POINTER_SIZE) + VK_CHECK_RESULT(VK10.nvkAllocateCommandBuffers(this, allocateInfo.adr, pCmdBuffer)) + VkCommandBuffer(memGetAddress(pCmdBuffer), this) + } + +infix fun VkDevice.allocateCommandBuffers(allocateInfo: VkCommandBufferAllocateInfo): ArrayList = stak{ + val count = allocateInfo.commandBufferCount + val pCommandBuffer = it.nmalloc(POINTER_SIZE, count) + val commandBuffers = ArrayList(count) + VK_CHECK_RESULT(VK10.nvkAllocateCommandBuffers(this, allocateInfo.adr, pCommandBuffer)) + for (i in 0 until count) + commandBuffers += VkCommandBuffer(memGetAddress(pCommandBuffer + POINTER_SIZE * i), this) + return commandBuffers +} + +infix fun VkDevice.allocateDescriptorSets(allocateInfo: VkDescriptorSetAllocateInfo): VkDescriptorSet = + VkDescriptorSet(stak.longAddress { descriptorSets -> + VK_CHECK_RESULT(VK10.nvkAllocateDescriptorSets(this, allocateInfo.adr, descriptorSets)) + }) + +infix fun VkDevice.allocateMemory(allocateInfo: VkMemoryAllocateInfo): VkDeviceMemory = + VkDeviceMemory(stak.longAddress { memory -> + VK_CHECK_RESULT(VK10.nvkAllocateMemory(this, allocateInfo.adr, NULL, memory)) + }) + +//inline fun VkDevice.allocateMemory(allocateInfo: VkMemoryAllocateInfo, memory: KMutableProperty0) { +// val pMemory = appBuffer.long +// VK_CHECK_RESULT(VK10.nvkAllocateMemory(this, allocateInfo.adr, NULL, pMemory)) +// memory.set(memGetLong(pMemory)) +//} + +fun VkDevice.bindBufferMemory(buffer: VkBuffer, memory: VkDeviceMemory, memoryOffset: VkDeviceSize = VkDeviceSize(0)) = + VK_CHECK_RESULT(VK10.vkBindBufferMemory(this, buffer.L, memory.L, memoryOffset.L)) + +fun VkDevice.bindImageMemory(image: VkImage, memory: VkDeviceMemory, memoryOffset: VkDeviceSize = VkDeviceSize(0)) = + VK_CHECK_RESULT(VK10.vkBindImageMemory(this, image.L, memory.L, memoryOffset.L)) + +fun VkDevice.createBuffer(usage: VkBufferUsageFlags, size: VkDeviceSize): VkBuffer = + createBuffer(vk.BufferCreateInfo { + this.usage = usage + this.size = size + }) + +infix fun VkDevice.createBuffer(createInfo: VkBufferCreateInfo): VkBuffer = + VkBuffer(stak.longAddress { buffer -> + VK_CHECK_RESULT(VK10.nvkCreateBuffer(this, createInfo.adr, NULL, buffer)) + }) + +//inline fun VkDevice.createBuffer(createInfo: VkBufferCreateInfo, buffer: KMutableProperty0) { +// val pBuffer = appBuffer.long +// VK_CHECK_RESULT(VK10.nvkCreateBuffer(this, createInfo.adr, NULL, pBuffer)) +// buffer.set(memGetLong(pBuffer)) +//} + +infix fun VkDevice.createCommandPool(createInfo: VkCommandPoolCreateInfo): VkCommandPool = + VkCommandPool(stak.longAddress { commandPool -> + VK_CHECK_RESULT(VK10.nvkCreateCommandPool(this, createInfo.adr, NULL, commandPool)) + }) + +fun VkDevice.createComputePipelines(pipelineCache: VkPipelineCache, createInfo: VkComputePipelineCreateInfo): VkPipeline = + VkPipeline(stak.longAddress { pipeline -> + VK_CHECK_RESULT(VK10.nvkCreateComputePipelines(this, pipelineCache.L, 1, createInfo.adr, NULL, pipeline)) + }) + +infix fun VkDevice.createDescriptorPool(createInfo: VkDescriptorPoolCreateInfo): VkDescriptorPool = + VkDescriptorPool(stak.longAddress { descriptorPool -> + VK_CHECK_RESULT(VK10.nvkCreateDescriptorPool(this, createInfo.adr, NULL, descriptorPool)) + }) + +infix fun VkDevice.createDescriptorSetLayout(createInfo: VkDescriptorSetLayoutCreateInfo): VkDescriptorSetLayout = + VkDescriptorSetLayout(stak.longAddress { setLayout -> + VK10.nvkCreateDescriptorSetLayout(this, createInfo.adr, NULL, setLayout) + }) + +infix fun VkDevice.createFence(flag: VkFenceCreate): VkFence = + createFence(vk.FenceCreateInfo { this.flags = flag.i }) + +infix fun VkDevice.createFence(flags: VkFenceCreateFlags): VkFence = + createFence(vk.FenceCreateInfo { this.flags = flags }) + +infix fun VkDevice.createFence(createInfo: VkFenceCreateInfo): VkFence = + VkFence(stak.longAddress { fence -> + VK_CHECK_RESULT(VK10.nvkCreateFence(this, createInfo.adr, NULL, fence)) + }) + +//inline fun VkDevice.createFences(createInfo: VkFenceCreateInfo, fences: ArrayList) { +// val pFence = appBuffer.long +// for (i in fences.indices) { +// VK_CHECK_RESULT(VK10.nvkCreateFence(this, createInfo.adr, NULL, pFence)) +// fences[i] = memGetLong(pFence) +// } +//} + +infix fun VkDevice.createFramebuffer(createInfo: VkFramebufferCreateInfo): VkFramebuffer = + VkFramebuffer(stak.longAddress { framebuffer -> + VK_CHECK_RESULT(VK10.nvkCreateFramebuffer(this, createInfo.adr, NULL, framebuffer)) + }) + +fun VkDevice.createGraphicsPipelines(pipelineCache: VkPipelineCache, createInfo: VkGraphicsPipelineCreateInfo): VkPipeline = + VkPipeline(stak.longAddress { pipelines -> + VK_CHECK_RESULT(VK10.nvkCreateGraphicsPipelines(this, pipelineCache.L, 1, createInfo.adr, NULL, pipelines)) + }) + +infix fun VkDevice.createImage(createInfo: VkImageCreateInfo): VkImage = + VkImage(stak.longAddress { image -> + VK_CHECK_RESULT(VK10.nvkCreateImage(this, createInfo.adr, NULL, image)) + }) + +infix fun VkDevice.createImageView(createInfo: VkImageViewCreateInfo): VkImageView = + VkImageView(stak.longAddress { view -> + VK10.nvkCreateImageView(this, createInfo.adr, NULL, view) + }) + +fun VkDevice.createPipeline(pipelineCache: VkPipelineCache, createInfo: VkGraphicsPipelineCreateInfo): VkPipeline = + VkPipeline(stak.longAddress { pipeline -> + VK_CHECK_RESULT(VK10.nvkCreateGraphicsPipelines(this, pipelineCache.L, 1, createInfo.adr, NULL, pipeline)) + }) + +infix fun VkDevice.createPipelineCache(createInfo: VkPipelineCacheCreateInfo): VkPipelineCache = + VkPipelineCache(stak.longAddress { pipelineCache -> + VK_CHECK_RESULT(VK10.nvkCreatePipelineCache(this, createInfo.adr, NULL, pipelineCache)) + }) + +infix fun VkDevice.createPipelineLayout(createInfo: VkPipelineLayoutCreateInfo): VkPipelineLayout = + VkPipelineLayout(stak.longAddress { pipelineLayout -> + VK_CHECK_RESULT(VK10.nvkCreatePipelineLayout(this, createInfo.adr, NULL, pipelineLayout)) + }) + +fun VkDevice.createQueryPool(createInfo: VkQueryPoolCreateInfo): VkQueryPool = + VkQueryPool(stak.longAddress { queryPool -> + VK_CHECK_RESULT(VK10.nvkCreateQueryPool(this, createInfo.adr, NULL, queryPool)) + }) + +infix fun VkDevice.createRenderPass(createInfo: VkRenderPassCreateInfo): VkRenderPass = + VkRenderPass(stak.longAddress { renderPass -> + VK_CHECK_RESULT(VK10.nvkCreateRenderPass(this, createInfo.adr, NULL, renderPass)) + }) + +infix fun VkDevice.createSampler(createInfo: VkSamplerCreateInfo): VkSampler = + VkSampler(stak.longAddress { sampler -> + VK_CHECK_RESULT(VK10.nvkCreateSampler(this, createInfo.adr, NULL, sampler)) + }) + +infix fun VkDevice.createSemaphore(createInfo: VkSemaphoreCreateInfo): VkSemaphore = + VkSemaphore(stak.longAddress { semaphore -> + VK_CHECK_RESULT(VK10.nvkCreateSemaphore(this, createInfo.adr, NULL, semaphore)) + }) + +infix fun VkDevice.createShaderModule(createInfo: VkShaderModuleCreateInfo): VkShaderModule = + VkShaderModule(stak.longAddress { shaderModule -> + VK_CHECK_RESULT(VK10.nvkCreateShaderModule(this, createInfo.adr, NULL, shaderModule)) + }) + +infix fun VkDevice.createSwapchainKHR(createInfo: VkSwapchainCreateInfoKHR): VkSwapchainKHR = + VkSwapchainKHR(stak.longAddress { swapchain -> + KHRSwapchain.nvkCreateSwapchainKHR(this, createInfo.adr, NULL, swapchain) + }) + +infix fun VkDevice.debugMarkerSetObjectName(nameInfo: VkDebugMarkerObjectNameInfoEXT) = + EXTDebugMarker.nvkDebugMarkerSetObjectNameEXT(this, nameInfo.adr) + +infix fun VkDevice.debugMarkerSetObjectTag(tagInfo: VkDebugMarkerObjectTagInfoEXT) = + EXTDebugMarker.nvkDebugMarkerSetObjectTagEXT(this, tagInfo.adr) + +infix fun VkDevice.destroyBuffer(buffer: VkBuffer) = VK10.nvkDestroyBuffer(this, buffer.L, NULL) + +infix fun VkDevice.destroyCommandPool(commandPool: VkCommandPool) = + VK10.nvkDestroyCommandPool(this, commandPool.L, NULL) + +infix fun VkDevice.destroyDescriptorPool(descriptorPool: VkDescriptorPool) = + VK10.nvkDestroyDescriptorPool(this, descriptorPool.L, NULL) + +infix fun VkDevice.destroyDescriptorSetLayout(descriptorSetLayout: VkDescriptorSetLayout) = + VK10.nvkDestroyDescriptorSetLayout(this, descriptorSetLayout.L, NULL) + +infix fun VkDevice.destroyFence(fence: VkFence) = VK10.nvkDestroyFence(this, fence.L, NULL) + +infix fun VkDevice.destroyFences(fences: ArrayList) { + for (fence in fences) + VK10.nvkDestroyFence(this, fence.L, NULL) +} + +infix fun VkDevice.destroyFences(fences: VkFenceArray) { + for (fence in fences) + VK10.nvkDestroyFence(this, fence.L, NULL) +} + +infix fun VkDevice.destroyFramebuffer(framebuffer: VkFramebuffer) = + VK10.nvkDestroyFramebuffer(this, framebuffer.L, NULL) + +infix fun VkDevice.destroyFramebuffers(framebuffers: Iterable) { + for (i in framebuffers) + VK10.nvkDestroyFramebuffer(this, i.L, NULL) +} + +infix fun VkDevice.destroyImage(image: VkImage) = VK10.nvkDestroyImage(this, image.L, NULL) + +infix fun VkDevice.destroyImageView(imageView: VkImageView) = VK10.nvkDestroyImageView(this, imageView.L, NULL) + +infix fun VkDevice.destroyPipeline(pipeline: VkPipeline) = VK10.nvkDestroyPipeline(this, pipeline.L, NULL) + +infix fun VkDevice.destroyPipelineCache(pipelineCache: VkPipelineCache) = + VK10.nvkDestroyPipelineCache(this, pipelineCache.L, NULL) + +infix fun VkDevice.destroyPipelineLayout(pipelineLayout: VkPipelineLayout) = + VK10.nvkDestroyPipelineLayout(this, pipelineLayout.L, NULL) + +fun VkDevice.destroyQueryPool(queryPool: VkQueryPool) = VK10.nvkDestroyQueryPool(this, queryPool.L, NULL) + +infix fun VkDevice.destroyRenderPass(renderPass: VkRenderPass) = + VK10.nvkDestroyRenderPass(this, renderPass.L, NULL) + +infix fun VkDevice.destroySampler(sampler: VkSampler) = VK10.nvkDestroySampler(this, sampler.L, NULL) + +infix fun VkDevice.destroySemaphore(semaphore: VkSemaphore) = VK10.nvkDestroySemaphore(this, semaphore.L, NULL) + +//inline fun VkDevice.destroySemaphores(vararg semaphores: VkSemaphore) { +// for (semaphore in semaphores) +// VK10.nvkDestroySemaphore(this, semaphore, NULL) +//} + +fun VkDevice.destroySemaphores(semaphore0: VkSemaphore, semaphore1: VkSemaphore) { + VK10.nvkDestroySemaphore(this, semaphore0.L, NULL) + VK10.nvkDestroySemaphore(this, semaphore1.L, NULL) +} + +fun VkDevice.destroySemaphores(semaphore0: VkSemaphore, semaphore1: VkSemaphore, semaphore2: VkSemaphore) { + VK10.nvkDestroySemaphore(this, semaphore0.L, NULL) + VK10.nvkDestroySemaphore(this, semaphore1.L, NULL) + VK10.nvkDestroySemaphore(this, semaphore2.L, NULL) +} + +fun VkDevice.destroy() = VK10.nvkDestroyDevice(this, NULL) + +infix fun VkDevice.destroyShaderModule(shaderModule: VkShaderModule) = + VK10.nvkDestroyShaderModule(this, shaderModule.L, NULL) + +infix fun VkDevice.destroyShaderModules(infos: VkPipelineShaderStageCreateInfo.Buffer) { + for (i in infos) + VK10.nvkDestroyShaderModule(this, i.module.L, NULL) +} + +infix fun VkDevice.destroyShaderModules(modules: Iterable) { + for (i in modules) + VK10.nvkDestroyShaderModule(this, i.L, NULL) +} + +infix fun VkDevice.destroySwapchainKHR(swapchain: VkSwapchainKHR) = + KHRSwapchain.nvkDestroySwapchainKHR(this, swapchain.L, NULL) + +fun VkDevice.freeCommandBuffers(commandPool: VkCommandPool, commandBuffers: ArrayList) = + vk.freeCommandBuffers(this, commandPool, commandBuffers) + +infix fun VkDevice.flushMappedMemoryRanges(memoryRange: VkMappedMemoryRange) = + VK_CHECK_RESULT(VK10.nvkFlushMappedMemoryRanges(this, 1, memoryRange.adr)) + +infix fun VkDevice.flushMappedMemoryRanges(memoryRanges: VkMappedMemoryRange.Buffer) = + VK_CHECK_RESULT(VK10.nvkFlushMappedMemoryRanges(this, memoryRanges.capacity(), memoryRanges.adr)) + +fun VkDevice.freeCommandBuffer(commandPool: VkCommandPool, commandBuffer: VkCommandBuffer): Ptr = + stak.pointerAddress { pCommandBuffer -> + memPutAddress(pCommandBuffer, commandBuffer.adr) + VK10.nvkFreeCommandBuffers(this, commandPool.L, 1, pCommandBuffer) + } + +infix fun VkDevice.freeMemory(memory: VkDeviceMemory) = VK10.nvkFreeMemory(this, memory.L, NULL) + +infix fun VkDevice.getBufferMemoryRequirements(buffer: VkBuffer): VkMemoryRequirements = + getBufferMemoryRequirements(buffer, vk.MemoryRequirements()) + +fun VkDevice.getBufferMemoryRequirements(buffer: VkBuffer, memoryRequirements: VkMemoryRequirements): VkMemoryRequirements { + VK10.nvkGetBufferMemoryRequirements(this, buffer.L, memoryRequirements.adr) + return memoryRequirements +} + +infix fun VkDevice.getCommandBuffer(commandPool: VkCommandPool): VkCommandBuffer = + getCommandBuffer(commandPool, VkCommandBufferLevel.PRIMARY) + +fun VkDevice.getCommandBuffer(commandPool: VkCommandPool, level: VkCommandBufferLevel = VkCommandBufferLevel.PRIMARY, autostart: Boolean = false): VkCommandBuffer { + val cmdBufAllocateInfo = vk.CommandBufferAllocateInfo(commandPool, level, 1) + return allocateCommandBuffer(cmdBufAllocateInfo).apply { if (autostart) begin() } +} + +infix fun VkDevice.getImageMemoryRequirements(image: VkImage): VkMemoryRequirements = + getImageMemoryRequirements(image, vk.MemoryRequirements()) + +fun VkDevice.getImageMemoryRequirements(image: VkImage, memoryRequirements: VkMemoryRequirements): VkMemoryRequirements { + VK10.nvkGetImageMemoryRequirements(this, image.L, memoryRequirements.adr) + return memoryRequirements +} + +fun VkDevice.getImageSubresourceLayout(image: VkImage, subresource: VkImageSubresource): VkSubresourceLayout = + vk.SubresourceLayout().also { VK10.nvkGetImageSubresourceLayout(this, image.L, subresource.adr, it.adr) } + +fun VkDevice.getImageSubresourceLayout(image: VkImage, subresource: VkImageSubresource, layout: VkSubresourceLayout): VkSubresourceLayout { + VK10.nvkGetImageSubresourceLayout(this, image.L, subresource.adr, layout.adr) + return layout +} + +// TODO mappedMemory? +inline fun VkDevice.mappingMemory(memory: VkDeviceMemory, offset: VkDeviceSize, size: VkDeviceSize, flags: VkMemoryMapFlags = 0, block: (Ptr) -> Unit) = + stak.pointerAddress { data -> + VK_CHECK_RESULT(VK10.nvkMapMemory(this, memory.L, offset.L, size.L, flags, data)) + block(memGetAddress(data)) + VK10.vkUnmapMemory(this, memory.L) + } + +fun VkDevice.mapMemory(memory: VkDeviceMemory, offset: VkDeviceSize, size: VkDeviceSize, flags: VkMemoryMapFlags = 0): Ptr = + stak.pointerAddress { data -> + VK_CHECK_RESULT(VK10.nvkMapMemory(this, memory.L, offset.L, size.L, flags, data)) + memGetAddress(data) + } + +fun VkDevice.mapMemory(memory: VkDeviceMemory, offset: VkDeviceSize, size: VkDeviceSize, flags: VkMemoryMapFlags, data: PointerBuffer) = + VK_CHECK_RESULT(VK10.nvkMapMemory(this, memory.L, offset.L, size.L, flags, data.adr)) + +infix fun VkDevice.getQueue(queueFamilyIndex: Int): VkQueue = + getQueue(queueFamilyIndex, 0) + +fun VkDevice.getQueue(queueFamilyIndex: Int, queueIndex: Int): VkQueue = + VkQueue( + stak.pointerAddress { queue -> + VK10.nvkGetDeviceQueue(this, queueFamilyIndex, queueIndex, queue) + }, this) + +infix fun VkDevice.getSwapchainImagesKHR(swapchain: VkSwapchainKHR): VkImageArray = + vk.getSwapchainImagesKHR(this, swapchain) + +infix fun VkDevice.resetCommandPool(commandPool: VkCommandPool) = resetCommandPool(commandPool, 0) + +fun VkDevice.resetCommandPool(commandPool: VkCommandPool, flags: VkCommandPoolResetFlags) = + VK_CHECK_RESULT(VK10.vkResetCommandPool(this, commandPool.L, flags)) + +infix fun VkDevice.resetFence(fence: VkFence) { + stak.longAddress(fence.L) { pFence -> + VK10.nvkResetFences(this, 1, pFence) + } +} + +infix fun VkDevice.unmapMemory(memory: VkDeviceMemory) = VK10.vkUnmapMemory(this, memory.L) + +infix fun VkDevice.updateDescriptorSets(descriptorWrites: VkWriteDescriptorSet) = + VK10.nvkUpdateDescriptorSets(this, 1, descriptorWrites.adr, 0, NULL) + +infix fun VkDevice.updateDescriptorSets(descriptorWrites: VkWriteDescriptorSet.Buffer) = + VK10.nvkUpdateDescriptorSets(this, descriptorWrites.remaining(), descriptorWrites.adr, 0, NULL) + +//inline fun VkDevice.updateDescriptorSets(descriptorWrites: VkWriteDescriptorSet.Buffer, +// descriptorCopies: VkCopyDescriptorSet.Buffer? = null) { +// VK10.nvkUpdateDescriptorSets(device, descriptorWrites.remaining(), descriptorWrites.adr, +// descriptorCopies?.remaining() ?: 0, descriptorCopies?.adr ?: NULL) +//} + +fun VkDevice.waitForFence(fence: VkFence, waitAll: Boolean, timeout: Long) { + stak.longAddress(fence.L) { pFence -> + VK_CHECK_RESULT(VK10.nvkWaitForFences(this, 1, pFence, waitAll.i, timeout)) + } +} + +fun VkDevice.waitIdle() = VK_CHECK_RESULT(VK10.vkDeviceWaitIdle(this)) + +inline fun VkDevice.withFence(flags: VkFenceCreateFlags = 0, block: (VkFence) -> Unit) { + val fence = createFence(flags) + block(fence) + destroyFence(fence) +} + + +/* + VkInstance + */ + +infix fun VkInstance.createDebugReportCallbackEXT(createInfo: VkDebugReportCallbackCreateInfoEXT): VkDebugReportCallback = + VkDebugReportCallback(stak.longAddress { callback -> + VK_CHECK_RESULT(EXTDebugReport.nvkCreateDebugReportCallbackEXT(this, createInfo.adr, NULL, callback)) + callback + }) + +fun VkInstance.destroy() = VK10.nvkDestroyInstance(this, NULL) + +infix fun VkInstance.destroyDebugReportCallbackEXT(debugReportCallback: VkDebugReportCallback) { + EXTDebugReport.nvkDestroyDebugReportCallbackEXT(this, debugReportCallback.L, NULL) +} + +fun VkInstance.enumeratePhysicalDevices(): ArrayList { + return vk.enumeratePhysicalDevices(this) +} + +infix fun VkInstance.destroySurfaceKHR(surface: VkSurface) { + KHRSurface.nvkDestroySurfaceKHR(this, surface.L, NULL) +} + + +/* + VkPhysicalDevice + */ + +inline val VkPhysicalDevice.features: VkPhysicalDeviceFeatures + get() = vk.PhysicalDeviceFeatures().also(::getFeatures) + +infix fun VkPhysicalDevice.getFeatures(features: VkPhysicalDeviceFeatures) = + VK10.nvkGetPhysicalDeviceFeatures(this, features.adr) + +infix fun VkPhysicalDevice.getFormatProperties(format: VkFormat): VkFormatProperties = + getFormatProperties(format, vk.FormatProperties()) + +fun VkPhysicalDevice.getFormatProperties(format: VkFormat, formatProperties: VkFormatProperties): VkFormatProperties { + VK10.nvkGetPhysicalDeviceFormatProperties(this, format.i, formatProperties.adr) + return formatProperties +} + +infix fun VkPhysicalDevice.getSurfaceFormatsKHR(surface: VkSurface): ArrayList = + vk.getPhysicalDeviceSurfaceFormatsKHR(this, surface) + +inline val VkPhysicalDevice.memoryProperties: VkPhysicalDeviceMemoryProperties + get() = vk.PhysicalDeviceMemoryProperties().also(::getMemoryProperties) + +infix fun VkPhysicalDevice.getMemoryProperties(memoryProperties: VkPhysicalDeviceMemoryProperties) = + VK10.nvkGetPhysicalDeviceMemoryProperties(this, memoryProperties.adr) + +inline val VkPhysicalDevice.queueFamilyProperties: ArrayList + get() = vk.getPhysicalDeviceQueueFamilyProperties(this) + +inline val VkPhysicalDevice.properties: VkPhysicalDeviceProperties + get() = vk.PhysicalDeviceProperties().also(::getProperties) + +infix fun VkPhysicalDevice.getProperties(properties: VkPhysicalDeviceProperties) = + VK10.nvkGetPhysicalDeviceProperties(this, properties.adr) + +infix fun VkPhysicalDevice.createDevice(createInfo: VkDeviceCreateInfo): VkDevice = + stak { + val pDevice = it.nmalloc(POINTER_SIZE, POINTER_SIZE) + VK_CHECK_RESULT(VK10.nvkCreateDevice(this, createInfo.adr, NULL, pDevice)) + VkDevice(memGetLong(pDevice), this, createInfo) + } + +infix fun VkPhysicalDevice.getSurfaceCapabilitiesKHR(surface: VkSurface): VkSurfaceCapabilitiesKHR = + vk.SurfaceCapabilitiesKHR { + VK_CHECK_RESULT(KHRSurface.nvkGetPhysicalDeviceSurfaceCapabilitiesKHR(this@getSurfaceCapabilitiesKHR, surface.L, adr)) + } + +fun VkPhysicalDevice.getSurfaceSupportKHR(queueFamily: Int, surface: VkSurface): Boolean = + vk.getPhysicalDeviceSurfaceSupportKHR(this, queueFamily, surface) + +fun VkPhysicalDevice.getSurfaceSupportKHR(queueFamilyProperties: ArrayList, surface: VkSurface): BooleanArray = + vk.getPhysicalDeviceSurfaceSupportKHR(this, queueFamilyProperties, surface) + +infix fun VkPhysicalDevice.getSurfacePresentModesKHR(surface: VkSurface): ArrayList = + vk.getPhysicalDeviceSurfacePresentModesKHR(this, surface) + + +/* + VkQueue + */ + +infix fun VkQueue.presentKHR(presentInfo: VkPresentInfoKHR) = + VK_CHECK_RESULT(KHRSwapchain.vkQueuePresentKHR(this, presentInfo)) + +infix fun VkQueue.submit(submits: VkSubmitInfo) = + VK_CHECK_RESULT(VK10.nvkQueueSubmit(this, 1, submits.adr, NULL)) + +fun VkQueue.submit(submits: VkSubmitInfo, fence: VkFence) = + VK_CHECK_RESULT(VK10.nvkQueueSubmit(this, 1, submits.adr, fence.L)) + +fun VkQueue.waitIdle() = VK_CHECK_RESULT(VK10.vkQueueWaitIdle(this)) + + +/* + Invokes (~set) + */ + + +operator fun VkDescriptorPoolSize.invoke(type: VkDescriptorType, descriptorCount: Int): VkDescriptorPoolSize { + this.type = type + this.descriptorCount = descriptorCount + return this +} + +operator fun VkDescriptorSetLayoutBinding.invoke( + binding: Int, + type: VkDescriptorType, + descriptorCount: Int = 1, + stageFlags: VkShaderStageFlags): VkDescriptorSetLayoutBinding { + this.binding = binding + this.descriptorType = type + this.descriptorCount = descriptorCount + this.stageFlags = stageFlags + return this +} + + +operator fun VkVertexInputAttributeDescription.invoke(location: Int, binding: Int, format: VkFormat, offset: Int): VkVertexInputAttributeDescription { + this.location = location + this.binding = binding + this.format = format + this.offset = offset + return this +} + +operator fun VkVertexInputBindingDescription.invoke(binding: Int, stride: Int, inputRate: VkVertexInputRate): VkVertexInputBindingDescription { + this.binding = binding + this.stride = stride + this.inputRate = inputRate + return this +} + + +operator fun VkWriteDescriptorSet.invoke(dstSet: VkDescriptorSet, descriptorType: VkDescriptorType, dstBinding: Int, + bufferInfo: VkDescriptorBufferInfo): VkWriteDescriptorSet { + this.dstSet = dstSet + this.dstBinding = dstBinding + this.descriptorType = descriptorType + this.bufferInfo_ = bufferInfo + return this +} + +operator fun VkWriteDescriptorSet.invoke(dstSet: VkDescriptorSet, descriptorType: VkDescriptorType, dstBinding: Int, + imageInfo: VkDescriptorImageInfo): VkWriteDescriptorSet { + this.dstSet = dstSet + this.dstBinding = dstBinding + this.descriptorType = descriptorType + this.imageInfo_ = imageInfo + return this +} diff --git a/src/main/kotlin/vkk/imguiVkMain.kt b/src/main/kotlin/vkk/imguiVkMain.kt new file mode 100644 index 0000000..2f98750 --- /dev/null +++ b/src/main/kotlin/vkk/imguiVkMain.kt @@ -0,0 +1,587 @@ +//package vkn +// +//import glfw_.GlfwWindow +//import glfw_.appBuffer +//import glfw_.glfw +//import glm_.i +//import glm_.set +//import glm_.vec2.Vec2 +//import glm_.vec2.Vec2i +//import glm_.vec4.Vec4 +//import imgui.Cond +//import imgui.Context +//import imgui.ImGui +//import org.lwjgl.system.MemoryUtil.NULL +//import org.lwjgl.vulkan.* +//import org.lwjgl.vulkan.VK10.* +//import vkk.* +// +// +//var VULKAN_DEBUG_REPORT = true +//var UNLIMITED_FRAME_RATE = false +//const val MAX_POSSIBLE_BACK_BUFFERS = 16 +// +// +//fun main(args: Array) { +// Example().run() +//} +// +//class Example { +// +// val window: GlfwWindow +// +// ////#define IMGUI_UNLIMITED_FRAME_RATE +////#ifdef _DEBUG +////#define IMGUI_VULKAN_DEBUG_REPORT +////#endif +//// +////static VkAllocationCallbacks* g_Allocator = NULL; +// lateinit var instance: VkInstance +// var surface: VkSurfaceKHR = NULL +// lateinit var gpu: VkPhysicalDevice +// lateinit var device: VkDevice +// var swapchain: VkSwapchainKHR = NULL +// var renderPass: VkRenderPass = NULL +// var queueFamily = 0 +// lateinit var queue: VkQueue +// var debugReport: VkDebugReportCallback = NULL +// +// val surfaceFormat: VkSurfaceFormatKHR = VkSurfaceFormatKHR.calloc() +// val imageRange = cVkImageSubresourceRange(VkImageAspect.COLOR_BIT.i, 0, 1, 0, 1) +// lateinit var presentMode: VkPresentMode +// +// var pipelineCache: VkPipelineCache = NULL +// var descriptorPool: VkDescriptorPool = NULL +// // +// val fbSize = Vec2i() +// var resizeWanted = false +// var resizeSize = Vec2i() +// val backbufferIndices = IntArray(VK_QUEUED_FRAMES) // keep track of recently rendered swapchain frame indices +// // var backBufferCount = 0 +// var backBuffer = VkImageArray(MAX_POSSIBLE_BACK_BUFFERS) +// val backBufferView = VkImageViewArray(MAX_POSSIBLE_BACK_BUFFERS) +// val framebuffer = VkFramebufferArray(MAX_POSSIBLE_BACK_BUFFERS) +// +// var frameIndex = 0 +// val commandPool = VkCommandPoolArray(VK_QUEUED_FRAMES) +// val commandBuffer: Array = Array(VK_QUEUED_FRAMES) { null } +// val fence = VkFenceArray(VK_QUEUED_FRAMES) +// val presentCompleteSemaphore = VkSemaphoreArray(VK_QUEUED_FRAMES) +// val renderCompleteSemaphore = VkSemaphoreArray(VK_QUEUED_FRAMES) +// +// +// var f = 0f +// var showDemoWindow = true +// var showAnotherWindow = false +// val clearColor = Vec4(0.45f, 0.55f, 0.6f, 1f) +// +// init { +// // Setup window +//// glfwSetErrorCallback(glfw_error_callback); +// glfw.init() +// glfw.windowHint { api = "none" } +// +// window = GlfwWindow(1280, 720, "ImGui GLFW+Vulkan example") +// +// // Setup Vulkan +// if (!glfw.vulkanSupported) +// throw Error("GLFW: Vulkan Not Supported") +// setupVulkan(window) +// window.framebufferSizeCallback = { size -> +// resizeWanted = true +// resizeSize put size +// } +// window.show() +// } +// +// fun run() { +// +// // Setup Dear ImGui binding +//// IMGUI_CHECKVERSION() TODO +// val context = Context() +// val initData = ImplGlfwVulkan_InitData( +// gpu, +// device, +// renderPass, +// pipelineCache, +// descriptorPool) +// +// //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls +// ImplGlfwVulkan.init(window, true, initData) +// +// // Setup style +// ImGui.styleColorsDark() +// //ImGui::StyleColorsClassic(); +// +// // Load Fonts +// // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. +// // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. +// // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). +// // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. +// // - Read 'misc/fonts/README.txt' for more instructions and details. +// // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! +// //io.Fonts->AddFontDefault(); +// //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); +// //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); +// //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); +// //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f); +// //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); +// //IM_ASSERT(font != NULL); +// +// // Upload Fonts +// run { +// device resetCommandPool commandPool[frameIndex] +// val beginInfo = vk.CommandBufferBeginInfo { flags = flags or VkCommandBufferUsage.ONE_TIME_SUBMIT_BIT } +// commandBuffer[frameIndex]!! begin beginInfo +// +// ImplGlfwVulkan.createFontsTexture(commandBuffer[frameIndex]!!) +// +// val endInfo = vk.SubmitInfo { commandBuffer = this@Example.commandBuffer[frameIndex]!! } +// commandBuffer[frameIndex]!!.end() +// queue submit endInfo +// +// device.waitIdle() +// ImplGlfwVulkan.invalidateFontUploadObjects() +// } +// +// var counter = 0 +// +// +// // Main loop +// while (!window.shouldClose) { +// // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. +// // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. +// // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. +// // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. +// glfw.pollEvents() +// +// if (resizeWanted) +// resizeVulkan(resizeSize) +// resizeWanted = false +// +// ImplGlfwVulkan.newFrame() +// +// // 1. Show a simple window. +// // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug". +// run { +// ImGui.text("Hello, world!") // Display some text (you can use a format string too) +// ImGui.sliderFloat("float", ::f, 0f, 1f) // Edit 1 float using a slider from 0.0f to 1.0f +// ImGui.colorEdit3("clear color", clearColor) // Edit 3 floats representing a color +// +// ImGui.checkbox("Demo Window", ::showDemoWindow) // Edit bools storing our windows open/close state +// ImGui.checkbox("Another Window", ::showAnotherWindow) +// +// if (ImGui.button("Button")) // Buttons return true when clicked (NB: most widgets return true when edited/activated) +// counter++ +// ImGui.sameLine() +// ImGui.text("counter = %d", counter) +// +// ImGui.text("Application average %.3f ms/frame (%.1f FPS)", 1000f / io.framerate, io.framerate) +// } +// +// // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name your windows. +// if (showAnotherWindow) { +// ImGui._begin("Another Window", ::showAnotherWindow) +// ImGui.text("Hello from another window!") +// if (ImGui.button("Close Me")) +// showAnotherWindow = false +// ImGui.end() +// } +// +// // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). Read its code to learn more about Dear ImGui! +// if (showDemoWindow) { +// ImGui.setNextWindowPos(Vec2(650, 20), Cond.FirstUseEver) // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! +// ImGui.showDemoWindow(::showDemoWindow) +// } +// +// frameBegin() +// ImplGlfwVulkan.render(commandBuffer[frameIndex]!!) +// frameEnd() +// framePresent() +// } +// +// // Cleanup +// device.waitIdle() +// ImplGlfwVulkan.shutdown() +// cleanupVulkan() +// +// window.destroy() +// glfw.terminate() +// } +// +// +// fun setupVulkan(window: GlfwWindow) { +// +// // Create Vulkan Instance +// run { +// val extensions = glfw.requiredInstanceExtensions +// +// val createInfo = vk.InstanceCreateInfo() +// +// if (VULKAN_DEBUG_REPORT) { +// // enabling multiple validation layers grouped as lunarg standard validation +// val layers = listOf("VK_LAYER_LUNARG_standard_validation") +// createInfo.enabledLayerNames = layers +// +// // need additional storage for char pointer to debug report extension +// extensions += "VK_EXT_debug_report" +// createInfo.enabledExtensionNames = extensions +// } +// +// instance = vk.createInstance(createInfo) +// +// if (VULKAN_DEBUG_REPORT) { +// // create the debug report callback +// val debugReportCi = vk.DebugReportCallbackCreateInfoEXT { +// flags = VkDebugReport.ERROR_BIT_EXT or VkDebugReport.WARNING_BIT_EXT or VkDebugReport.PERFORMANCE_WARNING_BIT_EXT +// callback = { _, objType, _, _, _, _, msg, _ -> +// println("[vulkan] ObjectType: $objType\nMessage: $msg\n") +// false +// } +// } +// // get the proc address of the function pointer, required for used extensions +// debugReport = instance createDebugReportCallbackEXT debugReportCi +// } +// } +// +// // Create Window Surface +// surface = window createSurface instance +// +// // Get GPU +// gpu = instance.enumeratePhysicalDevices()[0] +// +// // Get queue +// run { +// val queues = gpu.queueFamilyProperties +// for (i in queues.indices) +// if (queues[i].queueFlags has VkQueueFlag.GRAPHICS_BIT) { +// queueFamily = i +// break +// } +// } +// +// // Check for WSI support +// if (!gpu.getSurfaceSupportKHR(queueFamily, surface)) +// throw Error("Error no WSI support on physical device 0") +// +// // Get Surface Format +// run { +// /* Per Spec Format and View Format are expected to be the same unless VK_IMAGE_CREATE_MUTABLE_BIT was set +// at image creation +// Assuming that the default behavior is without setting this bit, there is no need for separate Spawchain +// image and image view format +// additionally several new color spaces were introduced with Vulkan Spec v1.0.40 +// hence we must make sure that a format with the mostly available color space, +// VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, is found and used */ +// val formats = gpu getSurfaceFormatsKHR surface +// +// // first check if only one format, VK_FORMAT_UNDEFINED, is available, which would imply that any format is available +// if (formats.size == 1) { +// if (formats[0].format == VkFormat.UNDEFINED) { +// surfaceFormat.format = VkFormat.B8G8R8A8_UNORM +// surfaceFormat.colorSpace = VkColorSpace.SRGB_NONLINEAR_KHR +// } else // no point in searching another format +// surfaceFormat(formats[0]) +// } else { +// // request several formats, the first found will be used +// val requestSurfaceImageFormat = arrayOf(VkFormat.B8G8R8A8_UNORM, VkFormat.R8G8B8A8_UNORM, VkFormat.B8G8R8_UNORM, VkFormat.R8G8B8_UNORM) +// val requestSurfaceColorSpace = VkColorSpace.SRGB_NONLINEAR_KHR +// var requestedFound = false +// for (i in requestSurfaceImageFormat.indices) { +// if (requestedFound) +// break +// for (j in formats.indices) +// if (formats[j].format == requestSurfaceImageFormat[i] && formats[j].colorSpace == requestSurfaceColorSpace) { +// surfaceFormat(formats[j]) +// requestedFound = true +// } +// } +// +// // if none of the requested image formats could be found, use the first available +// if (!requestedFound) +// surfaceFormat(formats[0]) +// } +// } +// +// +// // Get Present Mode +// run { +// // Request a certain mode and confirm that it is available. If not use VK_PRESENT_MODE_FIFO_KHR which is mandatory +// presentMode = when { +// UNLIMITED_FRAME_RATE -> VkPresentMode.MAILBOX_KHR //VK_PRESENT_MODE_IMMEDIATE_KHR; +// else -> VkPresentMode.FIFO_KHR +// } +// val presentModes = gpu getSurfaceFormatsKHR surface +// val presentModeAvailable = presentModes.any { it == presentMode } +// if (!presentModeAvailable) +// presentMode = VkPresentMode.FIFO_KHR // always available +// } +// +// +// // Create Logical Device +// run { +// val deviceExtensions = listOf("VK_KHR_swapchain") +// val queueIndex = 0 +// val queueCount = 1 +// val queuePriority = 1f +// val queueInfo = vk.DeviceQueueCreateInfo { +// queueFamilyIndex = queueFamily +// this.queuePriority = queuePriority +// } +// val createInfo = vk.DeviceCreateInfo { +// queueCreateInfo = queueInfo +// enabledExtensionNames = deviceExtensions +// } +// device = gpu createDevice createInfo +// queue = device.getQueue(queueFamily, queueIndex) +// } +// +// // Create Framebuffers +// resizeVulkan(window.framebufferSize) +// +// // Create Command Buffers +// for (i in 0 until VK_QUEUED_FRAMES) { +// +// commandPool[i] = device createCommandPool vk.CommandPoolCreateInfo { +// flags = VkCommandPoolCreate.RESET_COMMAND_BUFFER_BIT.i +// queueFamilyIndex = queueFamily +// } +// +// commandBuffer[i] = device allocateCommandBuffer vk.CommandBufferAllocateInfo { +// commandPool = this@Example.commandPool[i] +// level = VkCommandBufferLevel.PRIMARY +// commandBufferCount = 1 +// } +// +// fence[i] = device createFence vk.FenceCreateInfo { flags = VkFenceCreate.SIGNALED_BIT.i } +// +// val info = vk.SemaphoreCreateInfo() +// presentCompleteSemaphore[i] = device createSemaphore info +// renderCompleteSemaphore[i] = device createSemaphore info +// } +// +// // Create Descriptor Pool +// run { +// val poolSize = vk.DescriptorPoolSize( +// VkDescriptorType.SAMPLER, 1000, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1000, +// VkDescriptorType.SAMPLED_IMAGE, 1000, +// VkDescriptorType.STORAGE_IMAGE, 1000, +// VkDescriptorType.UNIFORM_TEXEL_BUFFER, 1000, +// VkDescriptorType.STORAGE_TEXEL_BUFFER, 1000, +// VkDescriptorType.UNIFORM_BUFFER, 1000, +// VkDescriptorType.STORAGE_BUFFER, 1000, +// VkDescriptorType.UNIFORM_BUFFER_DYNAMIC, 1000, +// VkDescriptorType.STORAGE_BUFFER_DYNAMIC, 1000, +// VkDescriptorType.INPUT_ATTACHMENT, 1000) +// val poolInfo = vk.DescriptorPoolCreateInfo { +// flags = VkDescriptorPoolCreate.FREE_DESCRIPTOR_SET_BIT.i +// maxSets = 1000 * 11 +// poolSizes = poolSize +// } +// descriptorPool = device createDescriptorPool poolInfo +// } +// } +// +// fun resizeVulkan(size: Vec2i) { +// +// val oldSwapchain: VkSwapchainKHR = swapchain +// device.waitIdle() +// +// // Destroy old Framebuffer: +// backBuffer.filter { it != NULL }.forEach { device destroyImageView it } +// framebuffer.filter { it != NULL }.forEach { device destroyFramebuffer it } +// if (renderPass != NULL) +// device destroyRenderPass renderPass +// +// // Create Swapchain: +// run { +// val info = vk.SwapchainCreateInfoKHR { +// surface = this@Example.surface +// imageFormat = surfaceFormat.format +// imageColorSpace = surfaceFormat.colorSpace +// imageArrayLayers = 1 +// imageUsage = imageUsage or VkImageUsage.COLOR_ATTACHMENT_BIT +// imageSharingMode = VkSharingMode.EXCLUSIVE +// preTransform = VkSurfaceTransform.IDENTITY_BIT_KHR +// compositeAlpha = VkCompositeAlpha.OPAQUE_BIT_KHR +// presentMode = this@Example.presentMode +// clipped = true +// this.oldSwapchain = oldSwapchain +// } +// val cap = gpu getSurfaceCapabilitiesKHR surface +// info.minImageCount = when { +// cap.maxImageCount > 0 -> when { +// cap.minImageCount + 2 < cap.maxImageCount -> cap.minImageCount + 2 +// else -> cap.maxImageCount +// } +// else -> cap.minImageCount + 2 +// } +// +// if (cap.currentExtent.width == 0xffffffff.i) { +// fbSize put size +// info.imageExtent(fbSize) +// } else { +// fbSize put cap.currentExtent +// info.imageExtent(fbSize) +// } +// swapchain = device createSwapchainKHR info +// backBuffer = device getSwapchainImagesKHR swapchain +// } +// if (oldSwapchain != NULL) +// device destroySwapchainKHR oldSwapchain +// +// // Create the Render Pass: +// run { +// val attachment = vk.AttachmentDescription { +// format = surfaceFormat.format +// samples = VkSampleCount.`1_BIT` +// loadOp = VkAttachmentLoadOp.CLEAR +// storeOp = VkAttachmentStoreOp.STORE +// stencilLoadOp = VkAttachmentLoadOp.DONT_CARE +// stencilStoreOp = VkAttachmentStoreOp.DONT_CARE +// initialLayout = VkImageLayout.UNDEFINED +// finalLayout = VkImageLayout.PRESENT_SRC_KHR +// } +// val colorAttachment = vk.AttachmentReference { +// this.attachment = 0 +// layout = VkImageLayout.COLOR_ATTACHMENT_OPTIMAL +// } +// val subpass = vk.SubpassDescription { +// pipelineBindPoint = VkPipelineBindPoint.GRAPHICS +// colorAttachmentCount = 1 +// this.colorAttachment = colorAttachment +// } +// val dependency = vk.SubpassDependency { +// srcSubpass = VK_SUBPASS_EXTERNAL +// dstSubpass = 0 +// srcStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i +// dstStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i +// srcAccessMask = 0 +// dstAccessMask = VkAccess.COLOR_ATTACHMENT_WRITE_BIT.i +// } +// val info = vk.RenderPassCreateInfo().also { +// it.attachment = attachment +// it.subpass = subpass +// it.dependency = dependency +// } +// renderPass = device createRenderPass info +// } +// +// // Create The Image Views +// run { +// val info = vk.ImageViewCreateInfo { +// viewType = VkImageViewType.`2D` +// format = surfaceFormat.format +// components(VkComponentSwizzle.R, VkComponentSwizzle.G, VkComponentSwizzle.B, VkComponentSwizzle.A) +// subresourceRange = imageRange +// } +// for (i in backBuffer.indices) { +// info.image = backBuffer[i] +// backBufferView[i] = device createImageView info +// } +// } +// +// // Create Framebuffer: +// run { +// val attachment: VkImageViewBuffer = appBuffer.longBuffer(1) +// val info = vk.FramebufferCreateInfo { +// renderPass = this@Example.renderPass +// attachments = attachment +// width = fbSize.x +// height = fbSize.y // TODO +// layers = 1 +// } +// for (i in backBuffer.indices) { +// attachment[0] = backBufferView[i] +// framebuffer[i] = device createFramebuffer info +// } +// } +// } +// +// fun frameBegin() { +// +// while (true) { +// val err = vkWaitForFences(device, fence[frameIndex], true, 100) +// if (err == VK_SUCCESS) break +// if (err == VK_TIMEOUT) continue +// VK_CHECK_RESULT(err) +// } +// +// backbufferIndices[frameIndex] = device.acquireNextImageKHR(swapchain, UINT64_MAX, presentCompleteSemaphore[frameIndex], NULL) +// +// run { +// device resetCommandPool commandPool[frameIndex] +// val info = vk.CommandBufferBeginInfo { flags = flags or VkCommandBufferUsage.ONE_TIME_SUBMIT_BIT } +// commandBuffer[frameIndex]!! begin info +// } +// +// val info = vk.RenderPassBeginInfo { +// renderPass = this@Example.renderPass +// framebuffer = this@Example.framebuffer[backbufferIndices[frameIndex]] +// renderArea.apply { extent(fbSize) } +// clearValue(clearColor) +// } +// commandBuffer[frameIndex]!!.beginRenderPass(info, VkSubpassContents.INLINE) +// } +// +// fun frameEnd() { +// +// commandBuffer[frameIndex]!!.endRenderPass() +// +// val waitStage: VkPipelineStageFlags = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i +// val info = vk.SubmitInfo { +// waitSemaphoreCount = 1 +// waitSemaphore = presentCompleteSemaphore[frameIndex] +// waitDstStageMask = appBuffer intBufferOf waitStage +// commandBuffer = this@Example.commandBuffer[frameIndex] +// signalSemaphore = renderCompleteSemaphore[frameIndex] +// } +// commandBuffer[frameIndex]!!.end() +// device resetFence fence[frameIndex] +// queue.submit(info, fence[frameIndex]) +// } +// +// fun framePresent() { +// +// val info = vk.PresentInfoKHR { +// waitSemaphores = appBuffer longBufferOf renderCompleteSemaphore[frameIndex] // TODO bug +// swapchainCount = 1 +// swapchain = this@Example.swapchain +// imageIndex = backbufferIndices[frameIndex] +// } +// queue presentKHR info +// +// frameIndex = (frameIndex + 1) % VK_QUEUED_FRAMES +// } +// +// fun cleanupVulkan() { +// +// device.apply { +// +// destroyDescriptorPool(descriptorPool) +// for (i in 0 until VK_QUEUED_FRAMES) { +// destroyFence(fence[i]) +// freeCommandBuffer(commandPool[i], commandBuffer[i]!!) +// destroyCommandPool(commandPool[i]) +// destroySemaphore(presentCompleteSemaphore[i]) +// destroySemaphore(renderCompleteSemaphore[i]) +// } +// for (i in backBuffer.indices) { +// destroyImageView(backBufferView[i]) +// destroyFramebuffer(framebuffer[i]) +// } +// destroyRenderPass(renderPass) +// destroySwapchainKHR(swapchain) +//// destroySurfaceKHR(g_Instance, g_Surface, g_Allocator) TODO +// +// if (VULKAN_DEBUG_REPORT) TODO() +// // get the proc address of the function pointer, required for used extensions +//// auto vkDestroyDebugReportCallbackEXT =(PFN_vkDestroyDebugReportCallbackEXT) vkGetInstanceProcAddr (g_Instance, "vkDestroyDebugReportCallbackEXT") +//// vkDestroyDebugReportCallbackEXT(g_Instance, g_Debug_Report, g_Allocator) +// +// device.destroy() +// instance.destroy() +// } +// } +//} \ No newline at end of file diff --git a/src/main/kotlin/vkk/implGlfwVulkan.kt b/src/main/kotlin/vkk/implGlfwVulkan.kt new file mode 100644 index 0000000..c6b28de --- /dev/null +++ b/src/main/kotlin/vkk/implGlfwVulkan.kt @@ -0,0 +1,809 @@ +///** +// * ImGui GLFW binding with Vulkan + shaders +// * +// * Missing features: +// * [ ] User texture binding. Changes of ImTextureID aren't supported by this binding! See https://github.com/ocornut/imgui/pull/914 +// * +// * You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. +// * If you use this binding you'll need to call 5 functions: ImplXXXX_Init(), ImplXXX_CreateFontsTexture(), ImplXXXX_NewFrame(), +// * ImplXXXX_Render() and ImplXXXX_Shutdown(). +// * If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. +// * https://github.com/ocornut/imgui +// */ +// +//package vkn +// +//import glfw_.GlfwWindow +//import glfw_.appBuffer +//import glfw_.glfw +//import gli_.has +//import glm_.* +//import glm_.buffer.longBufferBig +//import glm_.vec2.Vec2 +//import glm_.vec4.Vec4 +//import imgui.* +//import org.lwjgl.glfw.GLFW.* +//import org.lwjgl.system.MemoryUtil.* +//import org.lwjgl.vulkan.VK10.VK_QUEUE_FAMILY_IGNORED +//import org.lwjgl.vulkan.VK10.VK_WHOLE_SIZE +//import org.lwjgl.vulkan.VkCommandBuffer +//import org.lwjgl.vulkan.VkDevice +//import org.lwjgl.vulkan.VkPhysicalDevice +//import uno.buffer.toBuffer +//import vkk.* +// +//const val VK_QUEUED_FRAMES = 2 +// +//val io = imgui.g.io +// +//class ImplGlfwVulkan_InitData( +//// VkAllocationCallbacks* allocator; +// val gpu: VkPhysicalDevice, +// val device: VkDevice, +// val renderPass: VkRenderPass, +// val pipelineCache: VkPipelineCache, +// val descriptorPool: VkDescriptorPool +//// void (*check_vk_result)(VkResult err); +//) +// +//object ImplGlfwVulkan { +// // GLFW data +// var window: GlfwWindow? = null +// var time = 0.0 +// var mouseJustPressed = BooleanArray(3) +// val mouseCursors = LongArray(MouseCursor.COUNT) +// +// // Vulkan data +////static VkAllocationCallbacks* g_Allocator = NULL; +// lateinit var gpu: VkPhysicalDevice +// lateinit var device: VkDevice +// var renderPass: VkRenderPass = NULL +// var pipelineCache: VkPipelineCache = NULL +// var descriptorPool: VkDescriptorPool = NULL +////static void (*g_CheckVkResult)(VkResult err) = NULL; +// +// var commandBuffer: VkCommandBuffer? = null +// var bufferMemoryAlignment: VkDeviceSize = 256 +// var pipelineCreateFlags: VkPipelineCreateFlags = 0 +// var frameIndex = 0 +// +// var descriptorSetLayout: VkDescriptorSetLayout = NULL +// var pipelineLayout: VkPipelineLayout = NULL +// var descriptorSet: VkDescriptorSet = NULL +// var pipeline: VkPipeline = NULL +// +// var fontSampler: VkSampler = NULL +// var fontMemory: VkDeviceMemory = NULL +// var fontImage: VkImage = NULL +// var fontView: VkImageView = NULL +// +// var vertexBufferMemory: VkDeviceMemoryBuffer = longBufferBig(VK_QUEUED_FRAMES) +// var indexBufferMemory: VkDeviceMemoryBuffer = longBufferBig(VK_QUEUED_FRAMES) +// var vertexBufferSize: VkDeviceSizeBuffer = longBufferBig(VK_QUEUED_FRAMES) +// var indexBufferSize: VkDeviceSizeBuffer = longBufferBig(VK_QUEUED_FRAMES) +// var vertexBuffer: VkBufferBuffer = longBufferBig(VK_QUEUED_FRAMES) +// var indexBuffer: VkBufferBuffer = longBufferBig(VK_QUEUED_FRAMES) +// +// var uploadBufferMemory: VkDeviceMemory = NULL +// var uploadBuffer: VkBuffer = NULL +// +// val glslShaderVertSpv = intArrayOf( +// 0x07230203, 0x00010000, 0x00080001, 0x0000002e, 0x00000000, 0x00020011, 0x00000001, 0x0006000b, +// 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x00000000, 0x00000001, +// 0x000a000f, 0x00000000, 0x00000004, 0x6e69616d, 0x00000000, 0x0000000b, 0x0000000f, 0x00000015, +// 0x0000001b, 0x0000001c, 0x00030003, 0x00000002, 0x000001c2, 0x00040005, 0x00000004, 0x6e69616d, +// 0x00000000, 0x00030005, 0x00000009, 0x00000000, 0x00050006, 0x00000009, 0x00000000, 0x6f6c6f43, +// 0x00000072, 0x00040006, 0x00000009, 0x00000001, 0x00005655, 0x00030005, 0x0000000b, 0x0074754f, +// 0x00040005, 0x0000000f, 0x6c6f4361, 0x0000726f, 0x00030005, 0x00000015, 0x00565561, 0x00060005, +// 0x00000019, 0x505f6c67, 0x65567265, 0x78657472, 0x00000000, 0x00060006, 0x00000019, 0x00000000, +// 0x505f6c67, 0x7469736f, 0x006e6f69, 0x00030005, 0x0000001b, 0x00000000, 0x00040005, 0x0000001c, +// 0x736f5061, 0x00000000, 0x00060005, 0x0000001e, 0x73755075, 0x6e6f4368, 0x6e617473, 0x00000074, +// 0x00050006, 0x0000001e, 0x00000000, 0x61635375, 0x0000656c, 0x00060006, 0x0000001e, 0x00000001, +// 0x61725475, 0x616c736e, 0x00006574, 0x00030005, 0x00000020, 0x00006370, 0x00040047, 0x0000000b, +// 0x0000001e, 0x00000000, 0x00040047, 0x0000000f, 0x0000001e, 0x00000002, 0x00040047, 0x00000015, +// 0x0000001e, 0x00000001, 0x00050048, 0x00000019, 0x00000000, 0x0000000b, 0x00000000, 0x00030047, +// 0x00000019, 0x00000002, 0x00040047, 0x0000001c, 0x0000001e, 0x00000000, 0x00050048, 0x0000001e, +// 0x00000000, 0x00000023, 0x00000000, 0x00050048, 0x0000001e, 0x00000001, 0x00000023, 0x00000008, +// 0x00030047, 0x0000001e, 0x00000002, 0x00020013, 0x00000002, 0x00030021, 0x00000003, 0x00000002, +// 0x00030016, 0x00000006, 0x00000020, 0x00040017, 0x00000007, 0x00000006, 0x00000004, 0x00040017, +// 0x00000008, 0x00000006, 0x00000002, 0x0004001e, 0x00000009, 0x00000007, 0x00000008, 0x00040020, +// 0x0000000a, 0x00000003, 0x00000009, 0x0004003b, 0x0000000a, 0x0000000b, 0x00000003, 0x00040015, +// 0x0000000c, 0x00000020, 0x00000001, 0x0004002b, 0x0000000c, 0x0000000d, 0x00000000, 0x00040020, +// 0x0000000e, 0x00000001, 0x00000007, 0x0004003b, 0x0000000e, 0x0000000f, 0x00000001, 0x00040020, +// 0x00000011, 0x00000003, 0x00000007, 0x0004002b, 0x0000000c, 0x00000013, 0x00000001, 0x00040020, +// 0x00000014, 0x00000001, 0x00000008, 0x0004003b, 0x00000014, 0x00000015, 0x00000001, 0x00040020, +// 0x00000017, 0x00000003, 0x00000008, 0x0003001e, 0x00000019, 0x00000007, 0x00040020, 0x0000001a, +// 0x00000003, 0x00000019, 0x0004003b, 0x0000001a, 0x0000001b, 0x00000003, 0x0004003b, 0x00000014, +// 0x0000001c, 0x00000001, 0x0004001e, 0x0000001e, 0x00000008, 0x00000008, 0x00040020, 0x0000001f, +// 0x00000009, 0x0000001e, 0x0004003b, 0x0000001f, 0x00000020, 0x00000009, 0x00040020, 0x00000021, +// 0x00000009, 0x00000008, 0x0004002b, 0x00000006, 0x00000028, 0x00000000, 0x0004002b, 0x00000006, +// 0x00000029, 0x3f800000, 0x00050036, 0x00000002, 0x00000004, 0x00000000, 0x00000003, 0x000200f8, +// 0x00000005, 0x0004003d, 0x00000007, 0x00000010, 0x0000000f, 0x00050041, 0x00000011, 0x00000012, +// 0x0000000b, 0x0000000d, 0x0003003e, 0x00000012, 0x00000010, 0x0004003d, 0x00000008, 0x00000016, +// 0x00000015, 0x00050041, 0x00000017, 0x00000018, 0x0000000b, 0x00000013, 0x0003003e, 0x00000018, +// 0x00000016, 0x0004003d, 0x00000008, 0x0000001d, 0x0000001c, 0x00050041, 0x00000021, 0x00000022, +// 0x00000020, 0x0000000d, 0x0004003d, 0x00000008, 0x00000023, 0x00000022, 0x00050085, 0x00000008, +// 0x00000024, 0x0000001d, 0x00000023, 0x00050041, 0x00000021, 0x00000025, 0x00000020, 0x00000013, +// 0x0004003d, 0x00000008, 0x00000026, 0x00000025, 0x00050081, 0x00000008, 0x00000027, 0x00000024, +// 0x00000026, 0x00050051, 0x00000006, 0x0000002a, 0x00000027, 0x00000000, 0x00050051, 0x00000006, +// 0x0000002b, 0x00000027, 0x00000001, 0x00070050, 0x00000007, 0x0000002c, 0x0000002a, 0x0000002b, +// 0x00000028, 0x00000029, 0x00050041, 0x00000011, 0x0000002d, 0x0000001b, 0x0000000d, 0x0003003e, +// 0x0000002d, 0x0000002c, 0x000100fd, 0x00010038).toBuffer() +// +// val glslShaderFragSpv = intArrayOf( +// 0x07230203, 0x00010000, 0x00080001, 0x0000001e, 0x00000000, 0x00020011, 0x00000001, 0x0006000b, +// 0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x00000000, 0x00000001, +// 0x0007000f, 0x00000004, 0x00000004, 0x6e69616d, 0x00000000, 0x00000009, 0x0000000d, 0x00030010, +// 0x00000004, 0x00000007, 0x00030003, 0x00000002, 0x000001c2, 0x00040005, 0x00000004, 0x6e69616d, +// 0x00000000, 0x00040005, 0x00000009, 0x6c6f4366, 0x0000726f, 0x00030005, 0x0000000b, 0x00000000, +// 0x00050006, 0x0000000b, 0x00000000, 0x6f6c6f43, 0x00000072, 0x00040006, 0x0000000b, 0x00000001, +// 0x00005655, 0x00030005, 0x0000000d, 0x00006e49, 0x00050005, 0x00000016, 0x78655473, 0x65727574, +// 0x00000000, 0x00040047, 0x00000009, 0x0000001e, 0x00000000, 0x00040047, 0x0000000d, 0x0000001e, +// 0x00000000, 0x00040047, 0x00000016, 0x00000022, 0x00000000, 0x00040047, 0x00000016, 0x00000021, +// 0x00000000, 0x00020013, 0x00000002, 0x00030021, 0x00000003, 0x00000002, 0x00030016, 0x00000006, +// 0x00000020, 0x00040017, 0x00000007, 0x00000006, 0x00000004, 0x00040020, 0x00000008, 0x00000003, +// 0x00000007, 0x0004003b, 0x00000008, 0x00000009, 0x00000003, 0x00040017, 0x0000000a, 0x00000006, +// 0x00000002, 0x0004001e, 0x0000000b, 0x00000007, 0x0000000a, 0x00040020, 0x0000000c, 0x00000001, +// 0x0000000b, 0x0004003b, 0x0000000c, 0x0000000d, 0x00000001, 0x00040015, 0x0000000e, 0x00000020, +// 0x00000001, 0x0004002b, 0x0000000e, 0x0000000f, 0x00000000, 0x00040020, 0x00000010, 0x00000001, +// 0x00000007, 0x00090019, 0x00000013, 0x00000006, 0x00000001, 0x00000000, 0x00000000, 0x00000000, +// 0x00000001, 0x00000000, 0x0003001b, 0x00000014, 0x00000013, 0x00040020, 0x00000015, 0x00000000, +// 0x00000014, 0x0004003b, 0x00000015, 0x00000016, 0x00000000, 0x0004002b, 0x0000000e, 0x00000018, +// 0x00000001, 0x00040020, 0x00000019, 0x00000001, 0x0000000a, 0x00050036, 0x00000002, 0x00000004, +// 0x00000000, 0x00000003, 0x000200f8, 0x00000005, 0x00050041, 0x00000010, 0x00000011, 0x0000000d, +// 0x0000000f, 0x0004003d, 0x00000007, 0x00000012, 0x00000011, 0x0004003d, 0x00000014, 0x00000017, +// 0x00000016, 0x00050041, 0x00000019, 0x0000001a, 0x0000000d, 0x00000018, 0x0004003d, 0x0000000a, +// 0x0000001b, 0x0000001a, 0x00050057, 0x00000007, 0x0000001c, 0x00000017, 0x0000001b, 0x00050085, +// 0x00000007, 0x0000001d, 0x00000012, 0x0000001c, 0x0003003e, 0x00000009, 0x0000001d, 0x000100fd, +// 0x00010038).toBuffer() +// +// fun init(window: GlfwWindow, installCallbacks: Boolean, initData: ImplGlfwVulkan_InitData): Boolean { +//// g_Allocator = init_data->allocator; +// gpu = initData.gpu +// device = initData.device +// renderPass = initData.renderPass +// pipelineCache = initData.pipelineCache +// descriptorPool = initData.descriptorPool +//// CheckVkResult = init_data->check_vk_result +// +// this.window = window +// +// with(io) { +// // TODO remove +// // Setup back-end capabilities flags TODO or .i +// backendFlags = backendFlags or BackendFlag.HasMouseCursors.i // We can honor GetMouseCursor() values (optional) +// +// // Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array. +// keyMap[Key.Tab] = GLFW_KEY_TAB +// keyMap[Key.LeftArrow] = GLFW_KEY_LEFT +// keyMap[Key.RightArrow] = GLFW_KEY_RIGHT +// keyMap[Key.UpArrow] = GLFW_KEY_UP +// keyMap[Key.DownArrow] = GLFW_KEY_DOWN +// keyMap[Key.PageUp] = GLFW_KEY_PAGE_UP +// keyMap[Key.PageDown] = GLFW_KEY_PAGE_DOWN +// keyMap[Key.Home] = GLFW_KEY_HOME +// keyMap[Key.End] = GLFW_KEY_END +// keyMap[Key.Insert] = GLFW_KEY_INSERT +// keyMap[Key.Delete] = GLFW_KEY_DELETE +// keyMap[Key.Backspace] = GLFW_KEY_BACKSPACE +// keyMap[Key.Space] = GLFW_KEY_SPACE +// keyMap[Key.Enter] = GLFW_KEY_ENTER +// keyMap[Key.Escape] = GLFW_KEY_ESCAPE +// keyMap[Key.A] = GLFW_KEY_A +// keyMap[Key.C] = GLFW_KEY_C +// keyMap[Key.V] = GLFW_KEY_V +// keyMap[Key.X] = GLFW_KEY_X +// keyMap[Key.Y] = GLFW_KEY_Y +// keyMap[Key.Z] = GLFW_KEY_Z +// +//// io.SetClipboardTextFn = ImGui_ImplGlfwVulkan_SetClipboardText +//// io.GetClipboardTextFn = ImGui_ImplGlfwVulkan_GetClipboardText +//// io.ClipboardUserData = g_Window +//// #ifdef _WIN32 +//// io.ImeWindowHandle = glfwGetWin32Window(g_Window) +//// #endif +// } +// // Load cursors +// // FIXME: GLFW doesn't expose suitable cursors for ResizeAll, ResizeNESW, ResizeNWSE. We revert to arrow cursor for those. +// mouseCursors[MouseCursor.Arrow.i] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR) +// mouseCursors[MouseCursor.TextInput.i] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR) +// mouseCursors[MouseCursor.ResizeAll.i] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR) +// mouseCursors[MouseCursor.ResizeNS.i] = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR) +// mouseCursors[MouseCursor.ResizeEW.i] = glfwCreateStandardCursor(GLFW_HRESIZE_CURSOR) +// mouseCursors[MouseCursor.ResizeNESW.i] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR) +// mouseCursors[MouseCursor.ResizeNWSE.i] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR) +// +// +// if (installCallbacks) +// installCallbacks() +// +// createDeviceObjects() +// +// return true +// } +// +// fun installCallbacks() { +// window!!.apply { +// mouseButtonCallback = { button, action, _ -> +// if (action == GLFW_PRESS && button in 0..2) +// mouseJustPressed[button] = true +// } +// scrollCallback = { scroll -> +// io.mouseWheelH += scroll.x +// io.mouseWheel += scroll.y +// } +// keyCallback = { key, scanCode, action, mods -> +// if (action == GLFW_PRESS) +// io.keysDown[key] = true +// if (action == GLFW_RELEASE) +// io.keysDown[key] = false +// +// io.keyCtrl = io.keysDown[GLFW_KEY_LEFT_CONTROL] || io.keysDown[GLFW_KEY_RIGHT_CONTROL] +// io.keyShift = io.keysDown[GLFW_KEY_LEFT_SHIFT] || io.keysDown[GLFW_KEY_RIGHT_SHIFT] +// io.keyAlt = io.keysDown[GLFW_KEY_LEFT_ALT] || io.keysDown[GLFW_KEY_RIGHT_ALT] +// io.keySuper = io.keysDown[GLFW_KEY_LEFT_SUPER] || io.keysDown[GLFW_KEY_RIGHT_SUPER] +// } +// charCallback = { codePoint -> +// if (codePoint in 1..65535) +// io.addInputCharacter(codePoint.c) +// } +// } +// } +// +// fun shutdown() { +// // Destroy GLFW mouse cursors +// for (cursorN in 0 until MouseCursor.COUNT) +// glfwDestroyCursor(mouseCursors[cursorN]) +// mouseCursors.fill(NULL) +// +// // Destroy Vulkan objects +// invalidateDeviceObjects() +// } +// +// fun newFrame() { +// +// // Setup display size (every frame to accommodate for window resizing) +// val size = window!!.size +// val displaySize = window!!.framebufferSize +// io.displaySize put size +// io.displayFramebufferScale.put( +// if (size.x > 0) displaySize.x.f / size.x else 0f, +// if (size.y > 0) displaySize.y.f / size.y else 0f) +// +// // Setup time step +// val currentTime = glfw.time +// io.deltaTime = if (time > 0.0) (currentTime - time).f else 1f / 60f +// time = currentTime.d +// +// // Setup inputs +// // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) +// if (window!!.focused) +// io.mousePos put window!!.cursorPos +// else +// io.mousePos put -Float.MAX_VALUE +// +// for (i in 0..2) { +// /* If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events +// that are shorter than 1 frame. */ +// io.mouseDown[i] = mouseJustPressed[i] || window!!.mouseButton(i) != 0 +// mouseJustPressed[i] = false +// } +// +// // Update OS/hardware mouse cursor if imgui isn't drawing a software cursor +// if (io.configFlags hasnt ConfigFlag.NoMouseCursorChange) { +// val cursor = g.mouseCursor // TODO remove .g +// if (io.mouseDrawCursor || cursor == MouseCursor.None) +// window!!.cursor = GlfwWindow.Cursor.Hidden +// else { +// glfwSetCursor(window!!.handle, if (mouseCursors[cursor.i] != 0L) mouseCursors[cursor.i] else mouseCursors[MouseCursor.Arrow.i]) +// window!!.cursor = GlfwWindow.Cursor.Normal +// } +// } +// +// // Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application. +// ImGui.newFrame() +// } +// +// fun render(commandBuffer: VkCommandBuffer) { +// this.commandBuffer = commandBuffer +// ImGui.render() +// renderDrawData(ImGui.drawData!!) +// this.commandBuffer = null +// frameIndex = (frameIndex + 1) % VK_QUEUED_FRAMES +// } +// +// /** This is the main rendering function that you have to implement and provide to ImGui +// * (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) */ +// fun renderDrawData(drawData: DrawData) { +// +// if (drawData.totalVtxCount == 0) return +// +// // Create the Vertex Buffer: +// val vertexSize = drawData.totalVtxCount * DrawVert.size +// if (vertexBuffer[frameIndex] == NULL || vertexBufferSize[frameIndex] < vertexSize) { +// if (vertexBuffer[frameIndex] != NULL) +// device destroyBuffer vertexBuffer[frameIndex] +// if (vertexBufferMemory[frameIndex] != NULL) +// device freeMemory vertexBufferMemory[frameIndex] +// val vertexBufferSize: VkDeviceSize = ((vertexSize - 1) / bufferMemoryAlignment + 1) * bufferMemoryAlignment +// val bufferInfo = vk.BufferCreateInfo { +// size = vertexBufferSize +// usage = VkBufferUsage.VERTEX_BUFFER_BIT.i +// sharingMode = VkSharingMode.EXCLUSIVE +// } +// vertexBuffer[frameIndex] = device createBuffer bufferInfo +// val req = device getBufferMemoryRequirements vertexBuffer[frameIndex] +// bufferMemoryAlignment = if (bufferMemoryAlignment > req.alignment) bufferMemoryAlignment else req.alignment +// val allocInfo = vk.MemoryAllocateInfo { +// allocationSize = req.size +// memoryTypeIndex = memoryType(VkMemoryProperty.HOST_VISIBLE_BIT.i, req.memoryTypeBits) +// } +// vertexBufferMemory[frameIndex] = device allocateMemory allocInfo +// device.bindBufferMemory(vertexBuffer[frameIndex], vertexBufferMemory[frameIndex]) +// this.vertexBufferSize[frameIndex] = vertexBufferSize +// } +// +// // Create the Index Buffer: +// val indexSize = drawData.totalIdxCount * DrawIdx.BYTES +// if (indexBuffer[frameIndex] == NULL || indexBufferSize[frameIndex] < indexSize) { +// if (indexBuffer[frameIndex] != NULL) +// device destroyBuffer indexBuffer[frameIndex] +// if (indexBufferMemory[frameIndex] != NULL) +// device freeMemory indexBufferMemory[frameIndex] +// val indexBufferSize: VkDeviceSize = ((indexSize - 1) / bufferMemoryAlignment + 1) * bufferMemoryAlignment +// val bufferInfo = vk.BufferCreateInfo { +// size = indexBufferSize +// usage = VkBufferUsage.INDEX_BUFFER_BIT.i +// sharingMode = VkSharingMode.EXCLUSIVE +// } +// indexBuffer[frameIndex] = device createBuffer bufferInfo +// val req = device getBufferMemoryRequirements indexBuffer[frameIndex] +// bufferMemoryAlignment = if (bufferMemoryAlignment > req.alignment) bufferMemoryAlignment else req.alignment +// val allocInfo = vk.MemoryAllocateInfo { +// allocationSize = req.size +// memoryTypeIndex = memoryType(VkMemoryProperty.HOST_VISIBLE_BIT.i, req.memoryTypeBits) +// } +// indexBufferMemory[frameIndex] = device allocateMemory allocInfo +// device.bindBufferMemory(indexBuffer[frameIndex], indexBufferMemory[frameIndex]) +// this.indexBufferSize[frameIndex] = indexBufferSize +// } +// +// // Upload Vertex and index Data: +// run { +// val pVtxDst = appBuffer.pointer +// val pIdxDst = appBuffer.pointer +// device.mapMemory(vertexBufferMemory[frameIndex], 0, vertexSize.L, 0, pVtxDst) +// device.mapMemory(indexBufferMemory[frameIndex], 0, indexSize.L, 0, pIdxDst) +// var vtxDst = memGetAddress(pVtxDst) +// var idxDst = memGetAddress(pIdxDst) +// for (cmdList in drawData.cmdLists) { +// for (v in cmdList.vtxBuffer) { +// memPutFloat(vtxDst, v.pos[0]) +// memPutFloat(vtxDst + Float.BYTES, v.pos[1]) +// memPutFloat(vtxDst + Float.BYTES * 2, v.uv[0]) +// memPutFloat(vtxDst + Float.BYTES * 3, v.uv[1]) +// memPutInt(vtxDst + Float.BYTES * 4, v.col) +// vtxDst += DrawVert.size +// } +// for (i in cmdList.idxBuffer) { +// memPutInt(idxDst * Int.BYTES, i) +// idxDst += Int.BYTES +// } +// } +// val range = vk.MappedMemoryRange(2).also { +// it[0].memory = vertexBufferMemory[frameIndex] +// it[0].size = VK_WHOLE_SIZE +// it[1].memory = indexBufferMemory[frameIndex] +// it[1].size = VK_WHOLE_SIZE +// } +// device.flushMappedMemoryRanges(range) +// device unmapMemory vertexBufferMemory[frameIndex] +// device unmapMemory indexBufferMemory[frameIndex] +// } +// +// // Bind pipeline and descriptor sets: +// run { +// commandBuffer!!.bindPipeline(VkPipelineBindPoint.GRAPHICS, pipeline) +// commandBuffer!!.bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) +// } +// +// // Bind Vertex And Index Buffer: +// run { +// commandBuffer!!.bindVertexBuffers(vertexBuffer[frameIndex]) +// commandBuffer!!.bindIndexBuffer(indexBuffer[frameIndex], 0, VkIndexType.UINT32) // TODO VkIndexType.UINT16 +// } +// +// // Setup viewport: +// run { +// val viewport = vk.Viewport { +// offset(0f) +// size(io.displaySize) +// depth(0f, 1f) +// } +// commandBuffer!!.setViewport(viewport) +// } +// +// // Setup scale and translation: +// run { +// val scale = appBuffer.floatBuffer(2) +// scale[0] = 2f / io.displaySize.x +// scale[1] = 2f / io.displaySize.y +// val translate = appBuffer.floatBuffer(2) +// translate[0] = -1f +// translate[1] = -1f +// commandBuffer!!.pushConstants(pipelineLayout, VkShaderStage.VERTEX_BIT.i, 0, scale) +// commandBuffer!!.pushConstants(pipelineLayout, VkShaderStage.VERTEX_BIT.i, scale.size, translate) +// } +// +// // Render the command lists: +// var vtxOffset = 0 +// var idxOffset = 0 +// for (cmdList in drawData.cmdLists) { +// for (cmd in cmdList.cmdBuffer) { +// if (cmd.userCallback != null) +// cmd.userCallback!!(cmdList, cmd) +// else { +// val scissor = vk.Rect2D { +// offset(if (cmd.clipRect.x > 0) cmd.clipRect.x.i else 0, +// if (cmd.clipRect.y > 0) cmd.clipRect.y.i else 0) +// extent(cmd.clipRect.z-cmd.clipRect.x, +// cmd.clipRect.w-cmd.clipRect.y+1) // FIXME: Why +1 here? +// } +// commandBuffer!!.setScissor(scissor) +// commandBuffer!!.drawIndexed(cmd.elemCount, 1, idxOffset, vtxOffset, 0) +// } +// idxOffset += cmd.elemCount * DrawIdx.BYTES +// } +// vtxOffset += cmdList.vtxBuffer.size * DrawVert.size +// } +// } +// +// // Use if you want to reset your rendering device without losing ImGui state. +// fun invalidateFontUploadObjects() { +// if (uploadBuffer != NULL) { +// device destroyBuffer uploadBuffer +// uploadBuffer = NULL +// } +// if (uploadBufferMemory != NULL) { +// device freeMemory uploadBufferMemory +// uploadBufferMemory = NULL +// } +// } +// +// fun invalidateDeviceObjects() { +// +// invalidateFontUploadObjects() +// +// device.apply { +// +// for (i in 0 until VK_QUEUED_FRAMES) { +// +// if (vertexBuffer[i] != NULL) { +// destroyBuffer(vertexBuffer[i]) +// vertexBuffer[i] = NULL +// } +// if (vertexBufferMemory[i] != NULL) { +// freeMemory(vertexBufferMemory[i]) +// vertexBufferMemory[i] = NULL +// } +// if (indexBuffer[i] != NULL) { +// destroyBuffer(indexBuffer[i]) +// indexBuffer[i] = NULL +// } +// if (indexBufferMemory[i] != NULL) { +// freeMemory(indexBufferMemory[i]) +// indexBufferMemory[i] = NULL +// } +// } +// +// if (fontView != NULL) { +// destroyImageView(fontView) +// fontView = NULL +// } +// if (fontImage != NULL) { +// destroyImage(fontImage) +// fontImage = NULL +// } +// if (fontMemory != NULL) { +// freeMemory(fontMemory) +// fontMemory = NULL +// } +// if (fontSampler != NULL) { +// destroySampler(fontSampler) +// fontSampler = NULL +// } +// if (descriptorSetLayout != NULL) { +// destroyDescriptorSetLayout(descriptorSetLayout) +// descriptorSetLayout = NULL +// } +// if (pipelineLayout != NULL) { +// destroyPipelineLayout(pipelineLayout) +// pipelineLayout = NULL +// } +// if (pipeline != NULL) { +// destroyPipeline(pipeline) +// pipeline = NULL +// } +// } +// } +// +// fun createFontsTexture(commandBuffer: VkCommandBuffer): Boolean { +// +// val (pixels, size, _) = io.fonts.getTexDataAsRGBA32() +// val uploadSize = size.x * size.y * 4 +// +// // Create the Image: +// run { +// val info = vk.ImageCreateInfo { +// imageType = VkImageType.`2D` +// format = VkFormat.R8G8B8A8_UNORM +// extent(size, 1) +// mipLevels = 1 +// arrayLayers = 1 +// samples = VkSampleCount.`1_BIT` +// tiling = VkImageTiling.OPTIMAL +// usage = VkImageUsage.SAMPLED_BIT or VkImageUsage.TRANSFER_DST_BIT +// sharingMode = VkSharingMode.EXCLUSIVE +// initialLayout = VkImageLayout.UNDEFINED +// } +// fontImage = device createImage info +// val req = device getImageMemoryRequirements fontImage +// val allocInfo = vk.MemoryAllocateInfo { +// allocationSize = req.size +// memoryTypeIndex = memoryType(VkMemoryProperty.DEVICE_LOCAL_BIT.i, req.memoryTypeBits) +// } +// fontMemory = device allocateMemory allocInfo +// device.bindImageMemory(fontImage, fontMemory) +// } +// +// // Create the Image View: +// run { +// val info = vk.ImageViewCreateInfo { +// image = fontImage +// viewType = VkImageViewType.`2D` +// format = VkFormat.R8G8B8A8_UNORM +// subresourceRange.apply { +// aspectMask = VkImageAspect.COLOR_BIT.i +// levelCount = 1 +// layerCount = 1 +// } +// } +// fontView = device createImageView info +// } +// +// // Update the Descriptor Set: +// run { +// val descImage = vk.DescriptorImageInfo { +// sampler = fontSampler +// imageView = fontView +// imageLayout = VkImageLayout.SHADER_READ_ONLY_OPTIMAL +// } +// val writeDesc = vk.WriteDescriptorSet { +// dstSet = descriptorSet +// descriptorType = VkDescriptorType.COMBINED_IMAGE_SAMPLER +// imageInfo_ = descImage +// } +// device updateDescriptorSets writeDesc +// } +// +// // Create the Upload Buffer: +// run { +// val bufferInfo = vk.BufferCreateInfo { +// this.size = uploadSize.L +// usage = VkBufferUsage.TRANSFER_SRC_BIT.i +// sharingMode = VkSharingMode.EXCLUSIVE +// } +// uploadBuffer = device createBuffer bufferInfo +// val req = device getBufferMemoryRequirements uploadBuffer +// bufferMemoryAlignment = if (bufferMemoryAlignment > req.alignment) bufferMemoryAlignment else req.alignment +// val allocInfo = vk.MemoryAllocateInfo { +// allocationSize = req.size +// memoryTypeIndex = memoryType(VkMemoryProperty.HOST_VISIBLE_BIT.i, req.memoryTypeBits) +// } +// uploadBufferMemory = device allocateMemory allocInfo +// device.bindBufferMemory(uploadBuffer, uploadBufferMemory) +// } +// +// // Upload to Buffer: +// device.mappingMemory(uploadBufferMemory, 0, uploadSize.L) { map -> +// memCopy(pixels.adr, map, uploadSize.L) +// val range = vk.MappedMemoryRange { +// memory = uploadBufferMemory +// this.size = uploadSize.L +// } +// device flushMappedMemoryRanges range +// } +// +// // Copy to Image: +// run { +// val copyBarrier = vk.ImageMemoryBarrier { +// dstAccessMask = VkAccess.TRANSFER_WRITE_BIT.i +// oldLayout = VkImageLayout.UNDEFINED +// newLayout = VkImageLayout.TRANSFER_DST_OPTIMAL +// srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED +// dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED +// image = fontImage +// subresourceRange.apply { +// aspectMask = VkImageAspect.COLOR_BIT.i +// levelCount = 1 +// layerCount = 1 +// } +// } +// commandBuffer.pipelineBarrier(VkPipelineStage.HOST_BIT.i, VkPipelineStage.TRANSFER_BIT.i, 0, imageMemoryBarrier = copyBarrier) +// +// val region = vk.BufferImageCopy { +// imageSubresource.apply { +// aspectMask = VkImageAspect.COLOR_BIT.i +// layerCount = 1 +// } +// imageExtent(size, 1) +// } +// commandBuffer.copyBufferToImage(uploadBuffer, fontImage, VkImageLayout.TRANSFER_DST_OPTIMAL, region) +// +// val useBarrier = vk.ImageMemoryBarrier { +// srcAccessMask = VkAccess.TRANSFER_WRITE_BIT.i +// dstAccessMask = VkAccess.SHADER_READ_BIT.i +// oldLayout = VkImageLayout.TRANSFER_DST_OPTIMAL +// newLayout = VkImageLayout.SHADER_READ_ONLY_OPTIMAL +// srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED +// dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED +// image = fontImage +// subresourceRange.apply { +// aspectMask = VkImageAspect.COLOR_BIT.i +// levelCount = 1 +// layerCount = 1 +// } +// } +// commandBuffer.pipelineBarrier(VkPipelineStage.TRANSFER_BIT.i, VkPipelineStage.FRAGMENT_SHADER_BIT.i, 0, imageMemoryBarrier = useBarrier) +// } +// +// // Store our identifier +// io.fonts.texId = fontImage.i +// +// return true +// } +// +// fun createDeviceObjects(): Boolean { +// +// // Create The Shader Modules: +// val vertInfo = vk.ShaderModuleCreateInfo { code = glslShaderVertSpv } +// val vertModule = device createShaderModule vertInfo +// val fragInfo = vk.ShaderModuleCreateInfo { code = glslShaderFragSpv } +// val fragModule = device createShaderModule fragInfo +// +// if (fontSampler == NULL) { +// val info = vk.SamplerCreateInfo { +// magFilter = VkFilter.LINEAR +// minFilter = VkFilter.LINEAR +// mipmapMode = VkSamplerMipmapMode.LINEAR +// addressModeU = VkSamplerAddressMode.REPEAT +// addressModeV = VkSamplerAddressMode.REPEAT +// addressModeW = VkSamplerAddressMode.REPEAT +// minLod = -1000f +// maxLod = 1000f +// maxAnisotropy = 1f +// } +// fontSampler = device createSampler info +// } +// +// if (descriptorSetLayout == NULL) { +// val binding = vk.DescriptorSetLayoutBinding { +// descriptorType = VkDescriptorType.COMBINED_IMAGE_SAMPLER +// descriptorCount = 1 +// stageFlags = VkShaderStage.FRAGMENT_BIT.i +// immutableSamplers = appBuffer longBufferOf fontSampler//TODO bug +// } +// val info = vk.DescriptorSetLayoutCreateInfo { this.binding = binding } +// descriptorSetLayout = device createDescriptorSetLayout info +// } +// +// // Create Descriptor Set: +// run { +// val allocInfo = vk.DescriptorSetAllocateInfo { +// descriptorPool = this@ImplGlfwVulkan.descriptorPool +// descriptorSetCount = 1 +// setLayout = descriptorSetLayout +// } +// descriptorSet = device allocateDescriptorSets allocInfo +// } +// +// if (pipelineLayout == NULL) { +// val pushConstants = vk.PushConstantRange { +// stageFlags = VkShaderStage.VERTEX_BIT.i +// offset = 0 +// size = Vec4.size +// } +// val layoutInfo = vk.PipelineLayoutCreateInfo { +// setLayout = descriptorSetLayout +// pushConstantRange = pushConstants +// } +// pipelineLayout = device createPipelineLayout layoutInfo +// } +// +// val stage = vk.PipelineShaderStageCreateInfo(2).also { +// it[0].apply { +// stage = VkShaderStage.VERTEX_BIT +// module = vertModule +// name = "main" +// } +// it[1].apply { +// stage = VkShaderStage.FRAGMENT_BIT +// module = fragModule +// name = "main" +// } +// } +// val bindingDesc = vk.VertexInputBindingDescription { +// stride = DrawVert.size +// inputRate = VkVertexInputRate.VERTEX +// } +// val attributeDesc = vk.VertexInputAttributeDescription( +// bindingDesc.binding, 0, VkFormat.R32G32_SFLOAT, 0, +// bindingDesc.binding, 1, VkFormat.R32G32_SFLOAT, Vec2.size, +// bindingDesc.binding, 2, VkFormat.R8G8B8A8_UNORM, Vec2.size * 2) +// +// val vertexInfo = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = bindingDesc +// vertexAttributeDescriptions = attributeDesc +// } +// val iaInfo = vk.PipelineInputAssemblyStateCreateInfo { topology = VkPrimitiveTopology.TRIANGLE_LIST } +// +// val viewportInfo = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val rasterInfo = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.COUNTER_CLOCKWISE) +// +// val msInfo = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val colorAttachment = vk.PipelineColorBlendAttachmentState { +// blendEnable = true +// srcColorBlendFactor = VkBlendFactor.SRC_ALPHA +// dstColorBlendFactor = VkBlendFactor.ONE_MINUS_SRC_ALPHA +// colorBlendOp = VkBlendOp.ADD +// srcAlphaBlendFactor = VkBlendFactor.ONE_MINUS_SRC_ALPHA +// dstAlphaBlendFactor = VkBlendFactor.ZERO +// alphaBlendOp = VkBlendOp.ADD +// colorWriteMask = VkColorComponent.R_BIT or VkColorComponent.G_BIT or VkColorComponent.B_BIT or VkColorComponent.A_BIT +// } +// val depthInfo = vk.PipelineDepthStencilStateCreateInfo() +// +// val blendInfo = vk.PipelineColorBlendStateCreateInfo(colorAttachment) +// +// val dynamicStates = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStates) +// +// val info = vk.GraphicsPipelineCreateInfo { +// flags = pipelineCreateFlags +// stages = stage +// vertexInputState = vertexInfo +// inputAssemblyState = iaInfo +// viewportState = viewportInfo +// rasterizationState = rasterInfo +// multisampleState = msInfo +// depthStencilState = depthInfo +// colorBlendState = blendInfo +// this.dynamicState = dynamicState +// layout = pipelineLayout +// renderPass = this@ImplGlfwVulkan.renderPass +// } +// pipeline = device.createGraphicsPipelines(pipelineCache, info) +// +// device destroyShaderModules stage +// +// return true +// } +// +// fun memoryType(properties: VkMemoryPropertyFlags, typeBits: Int): Int { +// val prop = gpu.memoryProperties +// for (i in 0 until prop.memoryTypeCount) +// if ((prop.memoryTypes[i].propertyFlags and properties) == properties && typeBits has (1 shl i)) +// return i +// return 0xffffffff.i // Unable to find memoryType +// } +// +//// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization) +//// Provided here if you want to chain callbacks. +//// You can also handle inputs yourself and use those as a reference. +//// IMGUI_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods) +//// IMGUI_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset) +//// IMGUI_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) +//// IMGUI_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c) +//} \ No newline at end of file diff --git a/src/main/kotlin/vkk/objects.kt b/src/main/kotlin/vkk/objects.kt new file mode 100644 index 0000000..48b3f65 --- /dev/null +++ b/src/main/kotlin/vkk/objects.kt @@ -0,0 +1,228 @@ +package vkk + +import glm_.i +import glm_.set +import kool.Ptr +import org.lwjgl.system.MemoryStack +import org.lwjgl.system.MemoryUtil.NULL +import org.lwjgl.system.MemoryUtil.memCopy +import org.lwjgl.system.Pointer +import java.nio.ByteBuffer +import java.nio.IntBuffer +import java.nio.LongBuffer + +interface VkObject : Comparable { + val L: Long + +// fun isInvalid(): Boolean = L == NULL +// fun isValid(): Boolean = L != NULL TODO BUG + + infix operator fun plus(other: Long) = L + other + infix operator fun minus(other: Long) = L - other + infix operator fun times(other: Long) = L * other + infix operator fun div(other: Long) = L / other + + override fun compareTo(other: Long): Int = L.compareTo(other) +} + +infix operator fun Long.plus(other: VkObject) = plus(other.L) +infix operator fun Long.minus(other: VkObject) = minus(other.L) +infix operator fun Long.times(other: VkObject) = times(other.L) +infix operator fun Long.div(other: VkObject) = div(other.L) + +fun bufferBig(size: VkDeviceSize): ByteBuffer = kool.bufferBig(size.L.i) + +fun memCopy(src: Ptr, dst: Ptr, bytes: VkDeviceSize) = memCopy(src, dst, bytes.L) + +fun Pointer.isInvalid() = adr == NULL +fun Pointer.isValid() = adr != NULL + +inline class VkBuffer(override val L: Long) : VkObject +inline class VkBufferView(override val L: Long) : VkObject +inline class VkCommandPool(override val L: Long) : VkObject +inline class VkDebugReportCallback(override val L: Long) : VkObject +inline class VkDescriptorPool(override val L: Long) : VkObject +inline class VkDescriptorSet(override val L: Long) : VkObject +inline class VkDescriptorSetLayout(override val L: Long) : VkObject +inline class VkDeviceMemory(override val L: Long) : VkObject +inline class VkDeviceSize(override val L: Long) : VkObject { + + operator fun plus(size: VkDeviceSize) = VkDeviceSize(L + size.L) + operator fun plus(size: Int) = VkDeviceSize(L + size) +} + +inline class VkEvent(override val L: Long) : VkObject +inline class VkFence(override val L: Long) : VkObject +inline class VkFramebuffer(override val L: Long) : VkObject +inline class VkImage(override val L: Long) : VkObject +inline class VkImageView(override val L: Long) : VkObject +inline class VkPipeline(override val L: Long) : VkObject +inline class VkPipelineCache(override val L: Long) : VkObject +inline class VkPipelineLayout(override val L: Long) : VkObject +inline class VkQueryPool(override val L: Long) : VkObject +inline class VkRenderPass(override val L: Long) : VkObject +inline class VkSampler(override val L: Long) : VkObject +inline class VkSemaphore(override val L: Long) : VkObject +inline class VkShaderModule(override val L: Long) : VkObject +inline class VkSurface(override val L: Long) : VkObject // TODO -> KHR +inline class VkSwapchainKHR(override val L: Long) : VkObject + +typealias VkBufferBuffer = LongBuffer +typealias VkDescriptorSetBuffer = LongBuffer +typealias VkDeviceMemoryBuffer = LongBuffer +typealias VkDeviceSizeBuffer = LongBuffer +typealias VkSemaphoreBuffer = LongBuffer +typealias VkSwapchainKhrBuffer = LongBuffer +//typealias VkResultBuffer = IntBuffer +typealias VkSamplerBuffer = LongBuffer + +typealias VkCommandPoolArray = LongArray + +inline class VkFenceArray(val array: LongArray) : Iterable { + + operator fun get(index: Int) = VkFence(array[index]) + operator fun set(index: Int, fence: VkFence) = array.set(index, fence.L) + + val size get() = array.size + val indices get() = array.indices + + override operator fun iterator() = VkFenceArrayIterator() + + inner class VkFenceArrayIterator : Iterator { + private var index = 0 + override fun hasNext() = index < array.size + override fun next() = + try { + VkFence(array[index++]) + } catch (e: ArrayIndexOutOfBoundsException) { + index -= 1 + throw NoSuchElementException(e.message) + } + } +} + +fun initVkFenceArray(size: Int, block: (Int) -> VkFence) = VkFenceArray(LongArray(size) { block(it).L }) +fun vkFenceArrayOf() = VkFenceArray(LongArray(0)) +fun vkFenceArrayBig(size: Int) = VkFenceArray(LongArray(size)) + +inline class VkFramebufferArray(val array: LongArray) : Iterable { + + operator fun get(index: Int) = VkFramebuffer(array[index]) + operator fun set(index: Int, framebuffer: VkFramebuffer) = array.set(index, framebuffer.L) + + val size get() = array.size + val indices get() = array.indices + + override operator fun iterator() = VkFramebufferArrayIterator() + + inner class VkFramebufferArrayIterator : Iterator { + private var index = 0 + override fun hasNext() = index < array.size + override fun next() = + try { + VkFramebuffer(array[index++]) + } catch (e: ArrayIndexOutOfBoundsException) { + index -= 1 + throw NoSuchElementException(e.message) + } + } +} + +fun initVkFramebufferArray(size: Int, block: (Int) -> VkFramebuffer) = VkFramebufferArray(LongArray(size) { block(it).L }) +fun vkFramebufferArrayOf() = VkFramebufferArray(LongArray(0)) + +inline class VkImageArray(val array: LongArray) : Iterable { + + operator fun get(index: Int) = VkImage(array[index]) + operator fun set(index: Int, image: VkImage) = array.set(index, image.L) + + val size get() = array.size + val indices get() = array.indices + + override operator fun iterator() = VkImageArrayIterator() + + inner class VkImageArrayIterator : Iterator { + private var index = 0 + override fun hasNext() = index < array.size + override fun next() = + try { + VkImage(array[index++]) + } catch (e: ArrayIndexOutOfBoundsException) { + index -= 1 + throw NoSuchElementException(e.message) + } + } +} + +fun initVkImageArray(size: Int, block: (Int) -> VkImage) = VkImageArray(LongArray(size) { block(it).L }) +fun vkImageArrayOf() = VkImageArray(LongArray(0)) + +inline class VkImageViewArray(val array: LongArray) : Iterable { + + operator fun get(index: Int) = VkImageView(array[index]) + operator fun set(index: Int, imageView: VkImageView) = array.set(index, imageView.L) + + val size get() = array.size + val indices get() = array.indices + + override operator fun iterator() = VkImageViewArrayIterator() + + inner class VkImageViewArrayIterator : Iterator { + private var index = 0 + override fun hasNext() = index < array.size + override fun next() = + try { + VkImageView(array[index++]) + } catch (e: ArrayIndexOutOfBoundsException) { + index -= 1 + throw NoSuchElementException(e.message) + } + } +} + +fun initVkImageViewArray(size: Int, block: (Int) -> VkImageView) = VkImageViewArray(LongArray(size) { block(it).L }) +fun vkImageViewArrayOf() = VkImageViewArray(LongArray(0)) + +typealias VkSemaphoreArray = LongArray + + +inline class VkImageViewBuffer(val buffer: LongBuffer) { + + operator fun set(index: Int, imageView: VkImageView) { + buffer[index] = imageView.L + } +} + +fun MemoryStack.vkImageViewBufferBig(size: Int) = VkImageViewBuffer(callocLong(size)) +fun MemoryStack.vkImageViewBufferOf(imageView: VkImageView): VkImageViewBuffer = + VkImageViewBuffer(longs(imageView.L)) + +fun MemoryStack.vkImageViewBufferOf(imageView0: VkImageView, + imageView1: VkImageView): VkImageViewBuffer = + VkImageViewBuffer(longs(imageView0.L, imageView1.L)) + +fun MemoryStack.vkImageViewBufferOf(imageView0: VkImageView, + imageView1: VkImageView, + imageView2: VkImageView): VkImageViewBuffer = + VkImageViewBuffer(longs(imageView0.L, imageView1.L, imageView2.L)) + +inline class VkDynamicStateBuffer(val buffer: IntBuffer) { + + operator fun set(index: Int, imageView: VkDynamicState) { + buffer[index] = imageView.i + } +} + +fun MemoryStack.vkDynamicStateBufferBig(size: Int) = VkDynamicStateBuffer(callocInt(size)) +fun MemoryStack.vkDynamicStateBufferOf(dynamicState: VkDynamicState): VkDynamicStateBuffer = + VkDynamicStateBuffer(ints(dynamicState.i)) + +fun MemoryStack.vkDynamicStateBufferOf(dynamicState0: VkDynamicState, + dynamicState1: VkDynamicState): VkDynamicStateBuffer = + VkDynamicStateBuffer(ints(dynamicState0.i, dynamicState1.i)) + +fun MemoryStack.vkDynamicStateBufferOf(dynamicState0: VkDynamicState, + dynamicState1: VkDynamicState, + dynamicState2: VkDynamicState): VkDynamicStateBuffer = + VkDynamicStateBuffer(ints(dynamicState0.i, dynamicState1.i, dynamicState2.i)) + diff --git a/src/main/kotlin/vkk/util.kt b/src/main/kotlin/vkk/util.kt new file mode 100644 index 0000000..268c02a --- /dev/null +++ b/src/main/kotlin/vkk/util.kt @@ -0,0 +1,462 @@ +package vkk + +import gli_.extension +import glm_.BYTES +import glm_.i +import glm_.mat3x3.Mat3 +import glm_.mat4x4.Mat4 +import glm_.set +import glm_.vec2.Vec2 +import glm_.vec2.Vec2i +import glm_.vec3.Vec3 +import glm_.vec4.Vec4 +import graphics.scenery.spirvcrossj.* +import kool.bufferBig +import kool.cap +import kool.intBufferBig +import kool.stak +import org.lwjgl.PointerBuffer +import org.lwjgl.system.MemoryStack +import org.lwjgl.system.MemoryUtil.* +import org.lwjgl.system.Pointer +import org.lwjgl.system.Struct +import org.lwjgl.system.StructBuffer +import org.lwjgl.vulkan.* +import java.nio.ByteBuffer +import java.nio.IntBuffer +import java.nio.LongBuffer +import java.nio.file.Files +import java.nio.file.Path +import kotlin.reflect.KProperty1 +import kotlin.reflect.KType +import kotlin.reflect.full.declaredMemberProperties +import kotlin.reflect.full.defaultType +import kotlin.reflect.full.findAnnotation + + +//fun pointerBufferOf(vararg strings: String): PointerBuffer { +// val buf = pointerBufferBig(strings.size) +// for (i in strings.indices) +// buf[i] = strings[i] +// return buf +//} +// +//operator fun PointerBuffer.set(index: Int, string: String) { +// put(index, string.memUTF16) +//} +operator fun PointerBuffer.set(index: Int, long: Long) { + put(index, long) +} + +operator fun PointerBuffer.set(index: Int, pointer: Pointer) { + put(index, pointer) +} + +//operator fun PointerBuffer.plusAssign(string: String) { +// put(string.stackUTF16) +//} + +//operator fun PointerBuffer.plusAssign(elements: Iterable) { +// for (item in elements) +// if (item is String) +// put(item.memUTF16) +// else +// throw Error() +//} +// +//fun PointerBuffer.isNotEmpty() = position() > 0 + + + +object LongArrayList { + operator fun ArrayList.set(index: Int, long: LongBuffer) { + set(index, long[0]) + } + + infix fun ArrayList.resize(newSize: Int) { + if (size < newSize) + for (i in size until newSize) + add(NULL) + else if (size > newSize) + for (i in size downTo newSize + 1) + removeAt(lastIndex) + } +} + +object VkPhysicalDeviceArrayList { +// operator fun ArrayList.set(index: Int, long: LongBuffer) { +// set(index, long[0]) +// } + + infix fun ArrayList.resize(newSize: Int) { + if (size < newSize) TODO() +// for (i in size until newSize) +// add(VkPhysicalDevice()) + else if (size > newSize) + for (i in size downTo newSize + 1) + removeAt(lastIndex) + } +} + + +fun vkDestroySemaphores(device: VkDevice, semaphores: VkSemaphoreBuffer) { + for (i in 0 until semaphores.remaining()) + VK10.nvkDestroySemaphore(device, semaphores[i], NULL) +} + + +fun vkDestroyBuffer(device: VkDevice, buffer: VkBuffer) = VK10.nvkDestroyBuffer(device, buffer.L, NULL) + + +inline val Pointer.adr get() = address() + + +fun PointerBuffer?.toArrayList(): ArrayList { + val count = this?.remaining() ?: 0 + if (this == null || count == 0) return arrayListOf() + val res = ArrayList(count) + for (i in 0 until count) + res += get(i).utf8 + return res +} + +fun Collection.toPointerBuffer(): PointerBuffer = + stak { + val pointers = it.mallocPointer(size) + for (i in indices) + pointers.put(i, elementAt(i).utf8) + return pointers + } + + +infix fun Vec2i.put(extent: VkExtent2D) { + x = extent.width + y = extent.height +} + + +fun glslToSpirv(path: Path): ByteBuffer { + + var compileFail = false + var linkFail = false + val program = TProgram() + + val code = Files.readAllLines(path).joinToString("\n") + + val extension = path.extension + val shaderType = when (extension) { + "vert" -> EShLanguage.EShLangVertex + "frag" -> EShLanguage.EShLangFragment + "geom" -> EShLanguage.EShLangGeometry + "tesc" -> EShLanguage.EShLangTessControl + "tese" -> EShLanguage.EShLangTessEvaluation + "comp" -> EShLanguage.EShLangCompute + else -> throw RuntimeException("Unknown shader extension .$extension") + } + + println("${path.fileName}: Compiling shader code (${code.length} bytes)... ") + + val shader = TShader(shaderType).apply { + setStrings(arrayOf(code), 1) + setAutoMapBindings(true) + } + + val messages = EShMessages.EShMsgDefault or EShMessages.EShMsgVulkanRules or EShMessages.EShMsgSpvRules + + val resources = libspirvcrossj.getDefaultTBuiltInResource() + if (!shader.parse(resources, 450, false, messages)) + compileFail = true + + if (compileFail) { + println("Info log: " + shader.infoLog) + println("Debug log: " + shader.infoDebugLog) + throw RuntimeException("Compilation of ${path.fileName} failed") + } + + program.addShader(shader) + + if (!program.link(EShMessages.EShMsgDefault) || !program.mapIO()) + linkFail = true + + if (linkFail) { + System.err.println(program.infoLog) + System.err.println(program.infoDebugLog) + + throw RuntimeException("Linking of program ${path.fileName} failed!") + } + + + val spirv = IntVec() + libspirvcrossj.glslangToSpv(program.getIntermediate(shaderType), spirv) + + println("Generated " + spirv.capacity() + " bytes of SPIRV bytecode.") + + //System.out.println(shader); + //System.out.println(program); + + return spirv.toByteBuffer() +} + +private fun IntVec.toByteBuffer(): ByteBuffer = + stak { + val bytes = it.malloc(size().i * Int.BYTES) + val ints = bytes.asIntBuffer() + for (i in 0 until ints.cap) + ints[i] = get(i).i + return bytes + } + + +operator fun > StructBuffer.set(index: Int, value: T) { + put(index, value) +} + +inline fun withAddress(address: Long, block: WithAddress.() -> R): R { + WithAddress.address = address + WithAddress.offset = 0 + return WithAddress.block() +} + +object WithAddress { + + var address = NULL + var offset = 0 + + fun addMat4(mat4: Mat4) { + for (i in 0..3) + for (j in 0..3) { + memPutFloat(address + offset, mat4[i, j]) + offset += Float.BYTES + } + } + + fun addMat3(mat3: Mat3) { + for (i in 0..2) + for (j in 0..2) { + memPutFloat(address + offset, mat3[i, j]) + offset += Float.BYTES + } + } + + fun addVec4(vec4: Vec4) { + for (i in 0..3) { + memPutFloat(address + offset, vec4[i]) + offset += Float.BYTES + } + } + + fun addVec3(vec3: Vec3) { + for (i in 0..2) { + memPutFloat(address + offset, vec3[i]) + offset += Float.BYTES + } + } + + fun addVec2(vec2: Vec2) { + for (i in 0..1) { + memPutFloat(address + offset, vec2[i]) + offset += Float.BYTES + } + } + + fun addFloat(float: Float) { + memPutFloat(address + offset, float) + offset += Float.BYTES + } + + fun addInt(int: Int) { + memPutInt(address + offset, int) + offset += Int.BYTES + } +} + + +abstract class Bufferizable { + + @Retention(AnnotationRetention.RUNTIME) + annotation class Order(val value: Int) + + val fieldOrderDefault: Array by lazy { + val properties = this::class.declaredMemberProperties + val parts = properties.partition { it.findAnnotation() == null } + val plain = parts.first.sortedBy { it.name } + val annotated = parts.second.associateBy { it.findAnnotation()!!.value } + val list = ArrayList>() + var plainIdx = 0 + for (i in properties.indices) + list += annotated[i] ?: plain[plainIdx++] + list.map { it.name }.toTypedArray() + } + + open var fieldOrder = emptyArray() + get() = if (field.isEmpty()) fieldOrderDefault else field + + open val size: Int by lazy { + fieldOrder.sumBy { field -> this::class.declaredMemberProperties.find { it.name == field }!!.returnType.size } + } + + open infix fun to(address: Long) { + + WithAddress.address = address + WithAddress.offset = 0 + + for (i in data.indices) + data[i].first(data[i].second.getter.call(this)!!) + } + + infix fun from(address: Long): Unit = TODO() + + val data: Array by lazy { + Array(fieldOrder.size) { + val field = fieldOrder[it] + val member = this::class.declaredMemberProperties.find { it.name == field }!! + val func = member.returnType.func + func to member + } + } + + val offsets by lazy { + var offset = 0 + MutableList(fieldOrder.size) { i -> + fieldOrder[i] to offset.also { + offset += data[i].second.returnType.size + } + }.toMap() + } + + fun offsetOf(field: String) = offsets[field]!! + + private val KType.size: Int + get() = when (this) { + Mat4::class.defaultType -> Mat4.size + Mat3::class.defaultType -> Mat3.size + Vec4::class.defaultType -> Vec4.size + Vec3::class.defaultType -> Vec3.size + Vec2::class.defaultType -> Vec2.size + Float::class.defaultType -> Float.BYTES + Int::class.defaultType -> Int.BYTES + else -> throw Error(toString()) + } + private val KType.func: BufferizableAddFunctionType + get() = when (this) { + Mat4::class.defaultType -> WithAddress::addMat4 + Mat3::class.defaultType -> WithAddress::addMat3 + Vec4::class.defaultType -> WithAddress::addVec4 + Vec3::class.defaultType -> WithAddress::addVec3 + Vec2::class.defaultType -> WithAddress::addVec2 + Float::class.defaultType -> WithAddress::addFloat + Int::class.defaultType -> WithAddress::addInt + else -> throw Error(toString()) + } as BufferizableAddFunctionType +} + +typealias BufferizableAddFunctionType = (Any) -> Unit +typealias BufferizableData = Pair> + +fun bufferOf(vararg data: Bufferizable): ByteBuffer { + val size = data.sumBy { it.size } + val res = bufferBig(size) + val address = memAddress(res) + var offset = 0 + for (i in data.indices) { + data[i] to address + offset + offset += data[i].size + } + return res +} + +fun bufferOf(data: Collection): ByteBuffer { + val size = data.sumBy { it.size } + val res = bufferBig(size) + val address = memAddress(res) + var offset = 0 + for (i in data.indices) { + data.elementAt(i) to address + offset + offset += data.elementAt(i).size + } + return res +} + +fun intArrayOf(ints: Collection): IntBuffer { + val buffer = intBufferBig(ints.size) + for (i in ints.indices) + buffer[i] = ints.elementAt(i) + return buffer +} + +//object uboVS : Bufferizable() { +// +// var projectionMatrix = Mat4() +// var modelMatrix = Mat4() +// var viewMatrix = Mat4() +// +// override val fieldOrder = arrayOf("projectionMatrix", "modelMatrix", "viewMatrix") +// +// override infix fun to(address: Long) { +// withAddress(address) { +// // add(projectionMatrix); add(modelMatrix); add(viewMatrix) +// } +// } +//} +// +//fun main(args: Array) { +// println(uboVS::class.declaredMemberProperties) +// val member = uboVS::class.declaredMemberProperties.find { it.name == "projectionMatrix" }!! +// println(member.returnType) +// println(member.get(uboVS) as Mat4) +// println(member.returnType == Mat4::class.defaultType) +//} + +class FiledOrder { + @Retention(AnnotationRetention.RUNTIME) + annotation class Order(val value: Int) + + @Order(3) + var field1: Int = 0 + @Order(1) + var field2: Int = 0 + // no annotation + var field4: Int = 0 + var field3: Int = 0 + + @Order(1) + fun start() { + } + + @Order(2) + fun end() { + } +} + +fun main(args: Array) { + val properties = FiledOrder::class.declaredMemberProperties + val parts = properties.partition { it.findAnnotation() == null } + val plain = parts.first.sortedBy { it.name } + val annotated = parts.second.associateBy { it.findAnnotation()!!.value } + val list = ArrayList>() + var plainIdx = 0 + for (i in properties.indices) + list += annotated[i] ?: plain[plainIdx++] + println(list) +} + +typealias VkDebugReportCallbackType = ( + flag: VkDebugReportFlagsEXT, + objType: VkDebugReportObjectType, + scrType: Long, + location: Long, + msgCode: Int, + layerPrefix: String, + msg: String, + userData: Any?) -> Boolean + +operator fun VkAttachmentReference.invoke(attachment: Int, layout: VkImageLayout): VkAttachmentReference { + return attachment(attachment).layout(layout.i) +} + +fun ArrayList.toBufferStack(): VkDeviceQueueCreateInfo.Buffer { + val buffer = VkDeviceQueueCreateInfo.callocStack(size) + for (i in indices) + buffer[i] = get(i) + return buffer +} \ No newline at end of file diff --git a/src/main/kotlin/vkk/vk alloc.kt b/src/main/kotlin/vkk/vk alloc.kt new file mode 100644 index 0000000..e47a5d5 --- /dev/null +++ b/src/main/kotlin/vkk/vk alloc.kt @@ -0,0 +1,151 @@ +//package vkk +// +//import org.lwjgl.vulkan.* +// +// +////fun VmDescriptorBufferInfo(): VkDescriptorBufferInfo = VkDescriptorBufferInfo.malloc() +////fun VmDescriptorBufferInfo(capacity: Int): VkDescriptorBufferInfo.Buffer = VkDescriptorBufferInfo.malloc(capacity) +//fun cVkClearValue(): VkClearValue = VkClearValue.calloc() +// +//fun cVkClearValue(capacity: Int): VkClearValue.Buffer = VkClearValue.calloc(capacity) +// +//fun cVkDescriptorBufferInfo(): VkDescriptorBufferInfo = VkDescriptorBufferInfo.calloc() +// +//fun cVkDescriptorBufferInfo(capacity: Int): VkDescriptorBufferInfo.Buffer = VkDescriptorBufferInfo.calloc(capacity) +// +// +////fun VbApplicationInfo(block: VkApplicationInfo.() -> Unit): VkApplicationInfo = VkApplicationInfo.create(ptr.advance(VkApplicationInfo.SIZEOF)).also(block) +// +// +//inline fun cVkDescriptorSetLayoutCreateInfo(block: VkDescriptorSetLayoutCreateInfo.() -> Unit): VkDescriptorSetLayoutCreateInfo { +// val res = VkDescriptorSetLayoutCreateInfo.calloc() +// res.type = VkStructureType.DESCRIPTOR_SET_LAYOUT_CREATE_INFO +// res.block() +// return res +//} +// +//fun cVkImageSubresourceRange(aspectMask: VkImageAspectFlags, +// baseMipLevel: Int, +// levelCount: Int, +// baseArrayLayer: Int, +// layerCount: Int): VkImageSubresourceRange { +// return VkImageSubresourceRange.calloc().also { +// it.aspectMask = aspectMask +// it.baseMipLevel = baseMipLevel +// it.levelCount = levelCount +// it.baseArrayLayer = baseArrayLayer +// it.layerCount = layerCount +// } +//} +// +//inline fun cVkPipelineColorBlendAttachmentState(block: VkPipelineColorBlendAttachmentState.() -> Unit): VkPipelineColorBlendAttachmentState { +// return VkPipelineColorBlendAttachmentState.calloc().also(block) +//} +// +//fun cVkPipelineColorBlendAttachmentState(capacity: Int): VkPipelineColorBlendAttachmentState.Buffer { +// return VkPipelineColorBlendAttachmentState.calloc(capacity) +//} +// +//inline fun cVkPipelineColorBlendAttachmentState(capacity: Int, block: VkPipelineColorBlendAttachmentState.() -> Unit): VkPipelineColorBlendAttachmentState.Buffer { +// val res = cVkPipelineColorBlendAttachmentState(capacity) +// res[0].block() +// return res +//} +// +//inline fun cVkPipelineColorBlendStateCreateInfo(block: VkPipelineColorBlendStateCreateInfo.() -> Unit): VkPipelineColorBlendStateCreateInfo { +// val res = VkPipelineColorBlendStateCreateInfo.calloc() +// res.type = VkStructureType.PIPELINE_COLOR_BLEND_STATE_CREATE_INFO +// res.block() +// return res +//} +// +//inline fun cVkPipelineDepthStencilStateCreateInfo(block: VkPipelineDepthStencilStateCreateInfo.() -> Unit): VkPipelineDepthStencilStateCreateInfo { +// val res = VkPipelineDepthStencilStateCreateInfo.calloc() +// res.type = VkStructureType.PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO +// res.block() +// return res +//} +// +//inline fun cVkPipelineDynamicStateCreateInfo(block: VkPipelineDynamicStateCreateInfo.() -> Unit): VkPipelineDynamicStateCreateInfo { +// val res = VkPipelineDynamicStateCreateInfo.calloc() +// res.type = VkStructureType.PIPELINE_DYNAMIC_STATE_CREATE_INFO +// res.block() +// return res +//} +// +//inline fun cVkPipelineInputAssemblyStateCreateInfo(block: VkPipelineInputAssemblyStateCreateInfo.() -> Unit): VkPipelineInputAssemblyStateCreateInfo { +// val res = VkPipelineInputAssemblyStateCreateInfo.calloc() +// res.type = VkStructureType.PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO +// res.block() +// return res +//} +// +//inline fun cVkPipelineMultisampleStateCreateInfo(block: VkPipelineMultisampleStateCreateInfo.() -> Unit): VkPipelineMultisampleStateCreateInfo { +// val res = VkPipelineMultisampleStateCreateInfo.calloc() +// res.type = VkStructureType.PIPELINE_MULTISAMPLE_STATE_CREATE_INFO +// res.block() +// return res +//} +// +//inline fun cVkPipelineRasterizationStateCreateInfo(block: VkPipelineRasterizationStateCreateInfo.() -> Unit): VkPipelineRasterizationStateCreateInfo { +// val res = VkPipelineRasterizationStateCreateInfo.calloc() +// res.type = VkStructureType.PIPELINE_RASTERIZATION_STATE_CREATE_INFO +// res.block() +// return res +//} +// +//inline fun cVkPipelineShaderStageCreateInfo(block: VkPipelineShaderStageCreateInfo.() -> Unit): VkPipelineShaderStageCreateInfo { +// val res = VkPipelineShaderStageCreateInfo.calloc() +// res.type = VkStructureType.PIPELINE_SHADER_STAGE_CREATE_INFO +// res.block() +// return res +//} +// +//fun cVkPipelineVertexInputStateCreateInfo(): VkPipelineVertexInputStateCreateInfo { +// return VkPipelineVertexInputStateCreateInfo.calloc().apply { +// type = VkStructureType.PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO +// } +//} +// +//inline fun cVkPipelineVertexInputStateCreateInfo(block: VkPipelineVertexInputStateCreateInfo.() -> Unit): VkPipelineVertexInputStateCreateInfo { +// return cVkPipelineVertexInputStateCreateInfo().also(block) +//} +// +//inline fun cVkPipelineViewportStateCreateInfo(block: VkPipelineViewportStateCreateInfo.() -> Unit): VkPipelineViewportStateCreateInfo { +// val res = VkPipelineViewportStateCreateInfo.calloc() +// res.type = VkStructureType.PIPELINE_VIEWPORT_STATE_CREATE_INFO +// res.block() +// return res +//} +// +//inline fun cVkSemaphoreCreateInfo(block: VkSemaphoreCreateInfo.() -> Unit): VkSemaphoreCreateInfo { +// val res = VkSemaphoreCreateInfo.calloc() +// res.type = VkStructureType.SEMAPHORE_CREATE_INFO +// res.block() +// return res +//} +// +//inline fun cVkSubmitInfo(block: VkSubmitInfo.() -> Unit): VkSubmitInfo { +// val res = VkSubmitInfo.calloc() +// res.type = VkStructureType.SUBMIT_INFO +// res.block() +// return res +//} +// +//fun cVkVertexInputAttributeDescription(): VkVertexInputAttributeDescription { +// return VkVertexInputAttributeDescription.calloc() +//} +// +//fun cVkVertexInputAttributeDescription(capacity: Int): VkVertexInputAttributeDescription.Buffer { +// return VkVertexInputAttributeDescription.calloc(capacity) +//} +// +//fun cVkVertexInputBindingDescription(): VkVertexInputBindingDescription = VkVertexInputBindingDescription.calloc() +//fun cVkVertexInputBindingDescription(block: VkVertexInputBindingDescription.() -> Unit): VkVertexInputBindingDescription { +// return cVkVertexInputBindingDescription().also(block) +//} +// +//fun cVkVertexInputBindingDescription(capacity: Int): VkVertexInputBindingDescription.Buffer = VkVertexInputBindingDescription.calloc(capacity) +//fun cVkVertexInputBindingDescription(capacity: Int, block: VkVertexInputBindingDescription.() -> Unit): VkVertexInputBindingDescription.Buffer { +// return cVkVertexInputBindingDescription(capacity).also { it[0].block() } +//} diff --git a/src/main/kotlin/vkk/vk.kt b/src/main/kotlin/vkk/vk.kt new file mode 100644 index 0000000..c4d959f --- /dev/null +++ b/src/main/kotlin/vkk/vk.kt @@ -0,0 +1,1684 @@ +package vkk + +import glm_.* +import glm_.vec2.Vec2i +import kool.stak +import org.lwjgl.system.MemoryUtil +import org.lwjgl.system.MemoryUtil.* +import org.lwjgl.system.Pointer +import org.lwjgl.system.Struct +import org.lwjgl.vulkan.* +import org.lwjgl.vulkan.VK10.VK_QUEUE_FAMILY_IGNORED +import vkk.VkPhysicalDeviceArrayList.resize +import java.nio.ByteBuffer +import java.nio.LongBuffer +import kotlin.reflect.KMutableProperty0 + + +object vk { + + /* Info constructor functions */ + + inline fun ApplicationInfo(block: VkApplicationInfo.() -> Unit): VkApplicationInfo = + VkApplicationInfo.callocStack().apply { + type = VkStructureType.APPLICATION_INFO + block() + } + + inline fun BufferCreateInfo(block: VkBufferCreateInfo.() -> Unit): VkBufferCreateInfo = + VkBufferCreateInfo.callocStack().apply { + type = VkStructureType.BUFFER_CREATE_INFO + block() + } + + inline fun BufferMemoryBarrier(block: VkBufferMemoryBarrier.() -> Unit): VkBufferMemoryBarrier = + VkBufferMemoryBarrier.callocStack().apply { + type = VkStructureType.BUFFER_MEMORY_BARRIER + block() + } + + fun CommandBufferAllocateInfo(commandPool: VkCommandPool, level: VkCommandBufferLevel, bufferCount: Int): VkCommandBufferAllocateInfo = + CommandBufferAllocateInfo { + this.commandPool = commandPool + this.level = level + commandBufferCount = bufferCount + } + + inline fun CommandBufferAllocateInfo(block: VkCommandBufferAllocateInfo.() -> Unit): VkCommandBufferAllocateInfo = + VkCommandBufferAllocateInfo.callocStack().apply { + type = VkStructureType.COMMAND_BUFFER_ALLOCATE_INFO + block() + } + + fun CommandBufferBeginInfo(): VkCommandBufferBeginInfo = + VkCommandBufferBeginInfo.callocStack().apply { type = VkStructureType.COMMAND_BUFFER_BEGIN_INFO } + + inline fun CommandBufferBeginInfo(block: VkCommandBufferBeginInfo.() -> Unit): VkCommandBufferBeginInfo = + CommandBufferBeginInfo().also(block) + + inline fun CommandPoolCreateInfo(block: VkCommandPoolCreateInfo.() -> Unit): VkCommandPoolCreateInfo = + VkCommandPoolCreateInfo.callocStack().apply { + type = VkStructureType.COMMAND_POOL_CREATE_INFO + block() + } + + inline fun ComputePipelineCreateInfo(block: VkComputePipelineCreateInfo.() -> Unit): VkComputePipelineCreateInfo = + VkComputePipelineCreateInfo.callocStack().apply { + type = VkStructureType.COMPUTE_PIPELINE_CREATE_INFO + block() + } + + inline fun DebugMarkerMarkerInfoEXT(block: VkDebugMarkerMarkerInfoEXT.() -> Unit): VkDebugMarkerMarkerInfoEXT = + VkDebugMarkerMarkerInfoEXT.callocStack().apply { + type = VkStructureType.DEBUG_MARKER_OBJECT_NAME_INFO_EXT + block() + } + + inline fun DebugMarkerObjectNameInfoEXT(block: VkDebugMarkerObjectNameInfoEXT.() -> Unit): VkDebugMarkerObjectNameInfoEXT = + VkDebugMarkerObjectNameInfoEXT.callocStack().apply { + type = VkStructureType.DEBUG_MARKER_OBJECT_NAME_INFO_EXT + block() + } + + inline fun DebugMarkerObjectTagInfoEXT(block: VkDebugMarkerObjectTagInfoEXT .() -> Unit): VkDebugMarkerObjectTagInfoEXT = + VkDebugMarkerObjectTagInfoEXT.callocStack().apply { + type = VkStructureType.DEBUG_MARKER_OBJECT_TAG_INFO_EXT + block() + } + + inline fun DebugReportCallbackCreateInfoEXT(block: VkDebugReportCallbackCreateInfoEXT.() -> Unit): VkDebugReportCallbackCreateInfoEXT = + VkDebugReportCallbackCreateInfoEXT.callocStack().apply { + type = VkStructureType.DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT + block() + } + + inline fun DescriptorBufferInfo(block: VkDescriptorBufferInfo.() -> Unit): VkDescriptorBufferInfo = + VkDescriptorBufferInfo.callocStack().also(block) + +// inline fun DescriptorBufferInfo(capacity: Int, block: VkDescriptorBufferInfo.() -> Unit): VkDescriptorBufferInfo.Buffer = +// VkDescriptorBufferInfo.callocStack(capacity). +// res[0].block() +// return res +// } + + inline fun DescriptorPoolCreateInfo(block: VkDescriptorPoolCreateInfo.() -> Unit): VkDescriptorPoolCreateInfo = + VkDescriptorPoolCreateInfo.callocStack().apply { + type = VkStructureType.DESCRIPTOR_POOL_CREATE_INFO + block() + } + + inline fun DescriptorSetAllocateInfo(block: VkDescriptorSetAllocateInfo.() -> Unit): VkDescriptorSetAllocateInfo = + VkDescriptorSetAllocateInfo.callocStack().apply { + type = VkStructureType.DESCRIPTOR_SET_ALLOCATE_INFO + block() + } + + inline fun DescriptorSetLayoutCreateInfo(block: VkDescriptorSetLayoutCreateInfo.() -> Unit): VkDescriptorSetLayoutCreateInfo = + VkDescriptorSetLayoutCreateInfo.callocStack().apply { + type = VkStructureType.DESCRIPTOR_SET_LAYOUT_CREATE_INFO + block() + } + + inline fun DeviceCreateInfo(block: VkDeviceCreateInfo.() -> Unit): VkDeviceCreateInfo = + VkDeviceCreateInfo.callocStack().apply { + type = VkStructureType.DEVICE_CREATE_INFO + block() + } + + fun DeviceQueueCreateInfo(): VkDeviceQueueCreateInfo = + VkDeviceQueueCreateInfo.callocStack().apply { type = VkStructureType.DEVICE_QUEUE_CREATE_INFO } + + inline fun DeviceQueueCreateInfo(block: VkDeviceQueueCreateInfo.() -> Unit): VkDeviceQueueCreateInfo = + DeviceQueueCreateInfo().also(block) + + inline fun DeviceQueueCreateInfo(capacity: Int, block: VkDeviceQueueCreateInfo.() -> Unit): VkDeviceQueueCreateInfo.Buffer { + val res = VkDeviceQueueCreateInfo.callocStack(capacity) + res.forEach { it.type = VkStructureType.DEVICE_QUEUE_CREATE_INFO } + res[0].block() + return res + } + + inline fun FenceCreateInfo(block: VkFenceCreateInfo.() -> Unit): VkFenceCreateInfo = + VkFenceCreateInfo.callocStack().apply { + type = VkStructureType.FENCE_CREATE_INFO + block() + } + + inline fun FramebufferCreateInfo(block: VkFramebufferCreateInfo.() -> Unit): VkFramebufferCreateInfo = + VkFramebufferCreateInfo.callocStack().apply { + type = VkStructureType.FRAMEBUFFER_CREATE_INFO + block() + } + + fun GraphicsPipelineCreateInfo(): VkGraphicsPipelineCreateInfo = + VkGraphicsPipelineCreateInfo.callocStack().apply { type = VkStructureType.GRAPHICS_PIPELINE_CREATE_INFO } + + inline fun GraphicsPipelineCreateInfo(block: VkGraphicsPipelineCreateInfo.() -> Unit): VkGraphicsPipelineCreateInfo = + GraphicsPipelineCreateInfo().also(block) + + inline fun GraphicsPipelineCreateInfo(capacity: Int, block: VkGraphicsPipelineCreateInfo.() -> Unit): VkGraphicsPipelineCreateInfo.Buffer { + val res = VkGraphicsPipelineCreateInfo.callocStack(capacity) + res.forEach { it.type = VkStructureType.GRAPHICS_PIPELINE_CREATE_INFO } + res[0].block() + return res + } + + inline fun ImageCreateInfo(block: VkImageCreateInfo.() -> Unit): VkImageCreateInfo = + VkImageCreateInfo.callocStack().apply { + type = VkStructureType.IMAGE_CREATE_INFO + block() + } + + inline fun ImageMemoryBarrier(block: VkImageMemoryBarrier.() -> Unit): VkImageMemoryBarrier = + VkImageMemoryBarrier.callocStack().apply { + type = VkStructureType.IMAGE_MEMORY_BARRIER + srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED + dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED + block() + } + + inline fun ImageMemoryBarrier(capacity: Int, block: VkImageMemoryBarrier.() -> Unit): VkImageMemoryBarrier.Buffer { + val res = VkImageMemoryBarrier.callocStack(capacity) + res.forEach { it.type = VkStructureType.IMAGE_MEMORY_BARRIER } + res[0].block() + return res + } + + inline fun ImageViewCreateInfo(block: VkImageViewCreateInfo.() -> Unit): VkImageViewCreateInfo = + VkImageViewCreateInfo.callocStack().apply { + type = VkStructureType.IMAGE_VIEW_CREATE_INFO + block() + } + + fun InstanceCreateInfo(): VkInstanceCreateInfo = + VkInstanceCreateInfo.callocStack().apply { type = VkStructureType.INSTANCE_CREATE_INFO } + + inline fun InstanceCreateInfo(block: VkInstanceCreateInfo.() -> Unit): VkInstanceCreateInfo = + InstanceCreateInfo().also(block) + + fun MappedMemoryRange(): VkMappedMemoryRange = + VkMappedMemoryRange.callocStack().apply { type = VkStructureType.MAPPED_MEMORY_RANGE } + + fun MappedMemoryRange(capacity: Int): VkMappedMemoryRange.Buffer = + VkMappedMemoryRange.callocStack(capacity).also { + for (range in it) + range.type = VkStructureType.MAPPED_MEMORY_RANGE + } + + inline fun MappedMemoryRange(block: VkMappedMemoryRange.() -> Unit): VkMappedMemoryRange = + MappedMemoryRange().also(block) + + inline fun MemoryAllocateInfo(block: VkMemoryAllocateInfo.() -> Unit): VkMemoryAllocateInfo = + VkMemoryAllocateInfo.callocStack().apply { + type = VkStructureType.MEMORY_ALLOCATE_INFO + block() + } + + fun PhysicalDeviceFeatures(): VkPhysicalDeviceFeatures = + VkPhysicalDeviceFeatures.callocStack() + + inline fun PhysicalDeviceFeatures(block: VkPhysicalDeviceFeatures.() -> Unit): VkPhysicalDeviceFeatures = + PhysicalDeviceFeatures().also(block) + + fun PhysicalDeviceMemoryProperties(): VkPhysicalDeviceMemoryProperties = + VkPhysicalDeviceMemoryProperties.callocStack() + + fun PhysicalDeviceProperties(): VkPhysicalDeviceProperties = + VkPhysicalDeviceProperties.callocStack() + + fun PipelineCacheCreateInfo(): VkPipelineCacheCreateInfo = + VkPipelineCacheCreateInfo.callocStack().apply { type = VkStructureType.PIPELINE_CACHE_CREATE_INFO } + + inline fun PipelineCacheCreateInfo(block: VkPipelineCacheCreateInfo.() -> Unit): VkPipelineCacheCreateInfo = + PipelineCacheCreateInfo().also(block) + + inline fun PipelineColorBlendStateCreateInfo(block: VkPipelineColorBlendStateCreateInfo.() -> Unit): VkPipelineColorBlendStateCreateInfo = + VkPipelineColorBlendStateCreateInfo.callocStack().apply { + type = VkStructureType.PIPELINE_COLOR_BLEND_STATE_CREATE_INFO + block() + } + + fun PipelineDepthStencilStateCreateInfo(): VkPipelineDepthStencilStateCreateInfo = + VkPipelineDepthStencilStateCreateInfo.callocStack().apply { type = VkStructureType.PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO } + + inline fun PipelineDepthStencilStateCreateInfo(block: VkPipelineDepthStencilStateCreateInfo.() -> Unit): VkPipelineDepthStencilStateCreateInfo = + PipelineDepthStencilStateCreateInfo().also(block) + + inline fun PipelineDynamicStateCreateInfo(block: VkPipelineDynamicStateCreateInfo.() -> Unit): VkPipelineDynamicStateCreateInfo = + VkPipelineDynamicStateCreateInfo.callocStack().apply { + type = VkStructureType.PIPELINE_DYNAMIC_STATE_CREATE_INFO + block() + } + + inline fun PipelineInputAssemblyStateCreateInfo(block: VkPipelineInputAssemblyStateCreateInfo.() -> Unit): VkPipelineInputAssemblyStateCreateInfo = + VkPipelineInputAssemblyStateCreateInfo.callocStack().apply { + type = VkStructureType.PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO + block() + } + + fun PipelineLayoutCreateInfo(): VkPipelineLayoutCreateInfo = + VkPipelineLayoutCreateInfo.callocStack().apply { type = VkStructureType.PIPELINE_LAYOUT_CREATE_INFO } + + inline fun PipelineLayoutCreateInfo(block: VkPipelineLayoutCreateInfo.() -> Unit): VkPipelineLayoutCreateInfo = + PipelineLayoutCreateInfo().also(block) + + inline fun PipelineMultisampleStateCreateInfo(block: VkPipelineMultisampleStateCreateInfo.() -> Unit): VkPipelineMultisampleStateCreateInfo = + VkPipelineMultisampleStateCreateInfo.callocStack().apply { + type = VkStructureType.PIPELINE_MULTISAMPLE_STATE_CREATE_INFO + block() + } + + inline fun PipelineRasterizationStateCreateInfo(block: VkPipelineRasterizationStateCreateInfo.() -> Unit): VkPipelineRasterizationStateCreateInfo = + VkPipelineRasterizationStateCreateInfo.callocStack().apply { + type = VkStructureType.PIPELINE_RASTERIZATION_STATE_CREATE_INFO + block() + } + + fun PipelineShaderStageCreateInfo(capacity: Int): VkPipelineShaderStageCreateInfo.Buffer = + VkPipelineShaderStageCreateInfo.callocStack(capacity).also { + for (info in it) + info.type = VkStructureType.PIPELINE_SHADER_STAGE_CREATE_INFO + } + + fun PipelineVertexInputStateCreateInfo(): VkPipelineVertexInputStateCreateInfo = + VkPipelineVertexInputStateCreateInfo.callocStack().apply { type = VkStructureType.PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO } + + inline fun PipelineVertexInputStateCreateInfo(block: VkPipelineVertexInputStateCreateInfo.() -> Unit): VkPipelineVertexInputStateCreateInfo = + PipelineVertexInputStateCreateInfo().also(block) + + inline fun PipelineViewportStateCreateInfo(block: VkPipelineViewportStateCreateInfo.() -> Unit): VkPipelineViewportStateCreateInfo = + VkPipelineViewportStateCreateInfo.callocStack().apply { + type = VkStructureType.PIPELINE_VIEWPORT_STATE_CREATE_INFO + block() + } + + inline fun PushConstantRange(block: VkPushConstantRange.() -> Unit): VkPushConstantRange = + VkPushConstantRange.callocStack().also(block) + + inline fun PushConstantRange(capacity: Int, block: VkPushConstantRange.() -> Unit): VkPushConstantRange.Buffer = + VkPushConstantRange.callocStack(capacity).also { it[0].block() } + + inline fun PresentInfoKHR(block: VkPresentInfoKHR.() -> Unit): VkPresentInfoKHR = + VkPresentInfoKHR.callocStack().apply { + type = VkStructureType.PRESENT_INFO_KHR + block() + } + + fun QueryPoolCreateInfo(): VkQueryPoolCreateInfo = + VkQueryPoolCreateInfo.callocStack().apply { type = VkStructureType.QUERY_POOL_CREATE_INFO } + + inline fun QueryPoolCreateInfo(block: VkQueryPoolCreateInfo.() -> Unit): VkQueryPoolCreateInfo = + QueryPoolCreateInfo().also(block) + + inline fun RenderPassBeginInfo(block: VkRenderPassBeginInfo.() -> Unit): VkRenderPassBeginInfo = + VkRenderPassBeginInfo.callocStack().apply { + type = VkStructureType.RENDER_PASS_BEGIN_INFO + block() + } + + fun RenderPassCreateInfo(): VkRenderPassCreateInfo = + VkRenderPassCreateInfo.callocStack().apply { type = VkStructureType.RENDER_PASS_CREATE_INFO } + + inline fun RenderPassCreateInfo(block: VkRenderPassCreateInfo.() -> Unit): VkRenderPassCreateInfo = + RenderPassCreateInfo().also(block) + + inline fun SamplerCreateInfo(block: VkSamplerCreateInfo.() -> Unit): VkSamplerCreateInfo = + VkSamplerCreateInfo.callocStack().apply { + type = VkStructureType.SAMPLER_CREATE_INFO + maxAnisotropy = 1f + block() + } + + fun SemaphoreCreateInfo(): VkSemaphoreCreateInfo = + VkSemaphoreCreateInfo.callocStack().apply { type = VkStructureType.SEMAPHORE_CREATE_INFO } + + inline fun SemaphoreCreateInfo(block: VkSemaphoreCreateInfo.() -> Unit): VkSemaphoreCreateInfo = + SemaphoreCreateInfo().also(block) + + inline fun ShaderModuleCreateInfo(block: VkShaderModuleCreateInfo.() -> Unit): VkShaderModuleCreateInfo = + VkShaderModuleCreateInfo.callocStack().apply { + type = VkStructureType.SHADER_MODULE_CREATE_INFO + block() + } + + fun SubmitInfo(): VkSubmitInfo = + VkSubmitInfo.callocStack().apply { type = VkStructureType.SUBMIT_INFO } + + inline fun SubmitInfo(block: VkSubmitInfo.() -> Unit): VkSubmitInfo = + SubmitInfo().also(block) + + inline fun SwapchainCreateInfoKHR(block: VkSwapchainCreateInfoKHR.() -> Unit): VkSwapchainCreateInfoKHR = + VkSwapchainCreateInfoKHR.callocStack().apply { + type = VkStructureType.SWAPCHAIN_CREATE_INFO_KHR + block() + } + + inline fun WriteDescriptorSet(block: VkWriteDescriptorSet.() -> Unit): VkWriteDescriptorSet = + VkWriteDescriptorSet.callocStack().apply { + type = VkStructureType.WRITE_DESCRIPTOR_SET + block() + } + + fun WriteDescriptorSet(capacity: Int): VkWriteDescriptorSet.Buffer = + VkWriteDescriptorSet.callocStack(capacity).also { + for (set in it) + set.type = VkStructureType.WRITE_DESCRIPTOR_SET + } + + inline fun WriteDescriptorSet(capacity: Int, block: VkWriteDescriptorSet.Buffer.() -> Unit): VkWriteDescriptorSet.Buffer = + WriteDescriptorSet(capacity).also(block) + + fun DescriptorImageInfo(capacity: Int): VkDescriptorImageInfo.Buffer = + VkDescriptorImageInfo.callocStack(capacity) + + inline fun DescriptorImageInfo(block: VkDescriptorImageInfo.() -> Unit): VkDescriptorImageInfo = + VkDescriptorImageInfo.callocStack().also(block) + + inline fun DescriptorImageInfo(capacity: Int, block: VkDescriptorImageInfo.() -> Unit): VkDescriptorImageInfo.Buffer = + DescriptorImageInfo(capacity).also { it[0].block() } + + + /* + normal constructor functions + */ + + fun AttachmentDescription(): VkAttachmentDescription = VkAttachmentDescription.callocStack() + fun AttachmentDescription(capacity: Int): VkAttachmentDescription.Buffer = VkAttachmentDescription.callocStack(capacity) + inline fun AttachmentDescription(block: VkAttachmentDescription.() -> Unit): VkAttachmentDescription = AttachmentDescription().also(block) + + fun AttachmentReference(): VkAttachmentReference = VkAttachmentReference.callocStack() + fun AttachmentReference(capacity: Int): VkAttachmentReference.Buffer = VkAttachmentReference.callocStack(capacity) + inline fun AttachmentReference(block: VkAttachmentReference.() -> Unit): VkAttachmentReference = AttachmentReference().also(block) + inline fun AttachmentReference(capacity: Int, block: VkAttachmentReference.() -> Unit): VkAttachmentReference.Buffer = AttachmentReference(capacity).also { it[0].block() } + + fun BufferCopy(): VkBufferCopy = VkBufferCopy.callocStack() + fun BufferCopy(capacity: Int): VkBufferCopy.Buffer = VkBufferCopy.callocStack(capacity) + inline fun BufferCopy(block: VkBufferCopy.() -> Unit): VkBufferCopy = BufferCopy().also(block) + + fun BufferImageCopy(): VkBufferImageCopy = VkBufferImageCopy.callocStack() + fun BufferImageCopy(capacity: Int): VkBufferImageCopy.Buffer = VkBufferImageCopy.callocStack(capacity) + inline fun BufferImageCopy(block: VkBufferImageCopy.() -> Unit): VkBufferImageCopy = BufferImageCopy().also(block) + inline fun BufferImageCopy(capacity: Int, block: VkBufferImageCopy.() -> Unit): VkBufferImageCopy.Buffer = BufferImageCopy(capacity).also { it[0].block() } + + fun ClearValue(capacity: Int): VkClearValue.Buffer = VkClearValue.callocStack(capacity) + + fun DescriptorPoolSize(): VkDescriptorPoolSize = VkDescriptorPoolSize.callocStack() + fun DescriptorPoolSize(capacity: Int): VkDescriptorPoolSize.Buffer = VkDescriptorPoolSize.callocStack(capacity) + inline fun DescriptorPoolSize(block: VkDescriptorPoolSize.() -> Unit): VkDescriptorPoolSize = DescriptorPoolSize().also(block) + inline fun DescriptorPoolSize(capacity: Int, block: VkDescriptorPoolSize.Buffer.() -> Unit): VkDescriptorPoolSize.Buffer = DescriptorPoolSize(capacity).also(block) + + fun DescriptorSetLayoutBinding(): VkDescriptorSetLayoutBinding = VkDescriptorSetLayoutBinding.callocStack() + fun DescriptorSetLayoutBinding(capacity: Int): VkDescriptorSetLayoutBinding.Buffer = VkDescriptorSetLayoutBinding.callocStack(capacity) + inline fun DescriptorSetLayoutBinding(block: VkDescriptorSetLayoutBinding.() -> Unit): VkDescriptorSetLayoutBinding = DescriptorSetLayoutBinding().also(block) + inline fun DescriptorSetLayoutBinding(capacity: Int, block: VkDescriptorSetLayoutBinding.Buffer.() -> Unit): VkDescriptorSetLayoutBinding.Buffer = DescriptorSetLayoutBinding(capacity).also(block) + + fun ExtensionProperties(capacity: Int): VkExtensionProperties.Buffer = VkExtensionProperties.callocStack(capacity) + + fun Extent2D(): VkExtent2D = VkExtent2D.callocStack() + inline fun Extent2D(block: VkExtent2D.() -> Unit): VkExtent2D = Extent2D().also(block) + + fun Extent3D(): VkExtent3D = VkExtent3D.callocStack() + inline fun Extent3D(block: VkExtent3D.() -> Unit): VkExtent3D = Extent3D().also(block) + + fun FormatProperties(): VkFormatProperties = VkFormatProperties.callocStack() + inline fun FormatProperties(block: VkFormatProperties.() -> Unit): VkFormatProperties = FormatProperties().also(block) + + fun ImageBlit(): VkImageBlit = VkImageBlit.callocStack() + inline fun ImageBlit(block: VkImageBlit.() -> Unit): VkImageBlit = ImageBlit().also(block) + + fun ImageCopy(): VkImageCopy = VkImageCopy.callocStack() + inline fun ImageCopy(block: VkImageCopy.() -> Unit): VkImageCopy = ImageCopy().also(block) + + fun ImageSubresource(): VkImageSubresource = VkImageSubresource.callocStack() + inline fun ImageSubresource(block: VkImageSubresource.() -> Unit): VkImageSubresource = ImageSubresource().also(block) + + fun ImageSubresourceRange(): VkImageSubresourceRange = VkImageSubresourceRange.callocStack() + inline fun ImageSubresourceRange(block: VkImageSubresourceRange.() -> Unit): VkImageSubresourceRange = ImageSubresourceRange().also(block) + + fun ImageSubresourceLayers(): VkImageSubresourceLayers = VkImageSubresourceLayers.callocStack() + inline fun ImageSubresourceLayers(block: VkImageSubresourceLayers.() -> Unit): VkImageSubresourceLayers = ImageSubresourceLayers().also(block) + +// inline fun InstanceCreateInfo(extensions: ArrayList): VkInstanceCreateInfo { +// return InstanceCreateInfo { +// +// } +// } + + fun MemoryRequirements(): VkMemoryRequirements = VkMemoryRequirements.callocStack() + inline fun MemoryRequirements(block: VkMemoryRequirements.() -> Unit): VkMemoryRequirements = MemoryRequirements().also(block) + + fun PipelineColorBlendAttachmentState(): VkPipelineColorBlendAttachmentState = VkPipelineColorBlendAttachmentState.callocStack() + fun PipelineColorBlendAttachmentState(capacity: Int): VkPipelineColorBlendAttachmentState.Buffer = VkPipelineColorBlendAttachmentState.callocStack(capacity) + inline fun PipelineColorBlendAttachmentState(block: VkPipelineColorBlendAttachmentState.() -> Unit): VkPipelineColorBlendAttachmentState = PipelineColorBlendAttachmentState().also(block) + + fun Rect2D(): VkRect2D = VkRect2D.callocStack() + inline fun Rect2D(block: VkRect2D.() -> Unit): VkRect2D = Rect2D().also(block) + inline fun Rect2D(capacity: Int, block: VkRect2D.() -> Unit): VkRect2D.Buffer = VkRect2D.callocStack(capacity).also { it[0].block() } + + fun SpecializationMapEntry(): VkSpecializationMapEntry = VkSpecializationMapEntry.callocStack() + fun SpecializationMapEntry(capacity: Int): VkSpecializationMapEntry.Buffer = VkSpecializationMapEntry.callocStack(capacity) + inline fun SpecializationMapEntry(block: VkSpecializationMapEntry.() -> Unit): VkSpecializationMapEntry = SpecializationMapEntry().also(block) + + fun SpecializationInfo(): VkSpecializationInfo = VkSpecializationInfo.callocStack() + fun SpecializationInfo(capacity: Int): VkSpecializationInfo.Buffer = VkSpecializationInfo.callocStack(capacity) + inline fun SpecializationInfo(block: VkSpecializationInfo.() -> Unit): VkSpecializationInfo = SpecializationInfo().also(block) + + fun SubpassDependency(): VkSubpassDependency = VkSubpassDependency.callocStack() + fun SubpassDependency(capacity: Int): VkSubpassDependency.Buffer = VkSubpassDependency.callocStack(capacity) + inline fun SubpassDependency(block: VkSubpassDependency.() -> Unit): VkSubpassDependency = SubpassDependency().also(block) + + fun SubpassDescription(): VkSubpassDescription = VkSubpassDescription.callocStack() + fun SubpassDescription(capacity: Int): VkSubpassDescription.Buffer = VkSubpassDescription.callocStack(capacity) + inline fun SubpassDescription(block: VkSubpassDescription.() -> Unit): VkSubpassDescription = SubpassDescription().also(block) + + fun SubresourceLayout(): VkSubresourceLayout = VkSubresourceLayout.callocStack() + inline fun SubresourceLayout(capacity: Int, block: VkSubresourceLayout.() -> Unit): VkSubresourceLayout.Buffer = VkSubresourceLayout.callocStack(capacity).also { it[0].block() } + + fun SurfaceCapabilitiesKHR(): VkSurfaceCapabilitiesKHR = VkSurfaceCapabilitiesKHR.callocStack() + inline fun SurfaceCapabilitiesKHR(block: VkSurfaceCapabilitiesKHR.() -> Unit): VkSurfaceCapabilitiesKHR = SurfaceCapabilitiesKHR().also(block) + + fun SurfaceFormatKHR(): VkSurfaceFormatKHR = VkSurfaceFormatKHR.callocStack() + fun SurfaceFormatKHR(capacity: Int): VkSurfaceFormatKHR.Buffer = VkSurfaceFormatKHR.callocStack(capacity) + + fun VertexInputAttributeDescription(): VkVertexInputAttributeDescription = VkVertexInputAttributeDescription.callocStack() + fun VertexInputAttributeDescription(capacity: Int): VkVertexInputAttributeDescription.Buffer = VkVertexInputAttributeDescription.callocStack(capacity) + inline fun VertexInputAttributeDescription(block: VkVertexInputAttributeDescription.() -> Unit): VkVertexInputAttributeDescription = VertexInputAttributeDescription().also(block) + inline fun VertexInputAttributeDescription(capacity: Int, block: VkVertexInputAttributeDescription.Buffer.() -> Unit): VkVertexInputAttributeDescription.Buffer = VertexInputAttributeDescription(capacity).also(block) + + fun VertexInputBindingDescription(): VkVertexInputBindingDescription = VkVertexInputBindingDescription.callocStack() + inline fun VertexInputBindingDescription(block: VkVertexInputBindingDescription.() -> Unit): VkVertexInputBindingDescription = VertexInputBindingDescription().also(block) + inline fun VertexInputBindingDescription(capacity: Int, block: VkVertexInputBindingDescription.() -> Unit): VkVertexInputBindingDescription.Buffer = VkVertexInputBindingDescription.callocStack(capacity).also { it[0].block() } + + fun Viewport(): VkViewport = VkViewport.callocStack() + inline fun Viewport(block: VkViewport.() -> Unit): VkViewport = Viewport().also(block) + inline fun Viewport(capacity: Int, block: VkViewport.() -> Unit): VkViewport.Buffer = VkViewport.callocStack(capacity).also { it[0].block() } + + +/* + Function Constructors + */ + + fun AttachmentReference(attachment: Int, layout: VkImageLayout): VkAttachmentReference = + AttachmentReference().attachment(attachment).layout(layout.i) + + fun AttachmentReference( + attachment0: Int, layout0: VkImageLayout, + attachment1: Int, layout1: VkImageLayout): VkAttachmentReference.Buffer = + AttachmentReference(2).also { + it[0].attachment(attachment0).layout(layout0.i) + it[1].attachment(attachment1).layout(layout1.i) + } + + fun AttachmentReference( + attachment0: Int, layout0: VkImageLayout, + attachment1: Int, layout1: VkImageLayout, + attachment2: Int, layout2: VkImageLayout): VkAttachmentReference.Buffer = + AttachmentReference(3).also { + it[0].attachment(attachment0).layout(layout0.i) + it[1].attachment(attachment1).layout(layout1.i) + it[2].attachment(attachment2).layout(layout2.i) + } + + fun AttachmentReference( + attachment0: Int, layout0: VkImageLayout, + attachment1: Int, layout1: VkImageLayout, + attachment2: Int, layout2: VkImageLayout, + attachment3: Int, layout3: VkImageLayout): VkAttachmentReference.Buffer = + AttachmentReference(4).also { + it[0].attachment(attachment0).layout(layout0.i) + it[1].attachment(attachment1).layout(layout1.i) + it[2].attachment(attachment2).layout(layout2.i) + it[3].attachment(attachment3).layout(layout3.i) + } + + fun AttachmentReference( + attachment0: Int, layout0: VkImageLayout, + attachment1: Int, layout1: VkImageLayout, + attachment2: Int, layout2: VkImageLayout, + attachment3: Int, layout3: VkImageLayout, + attachment4: Int, layout4: VkImageLayout): VkAttachmentReference.Buffer = + AttachmentReference(5).also { + it[0].attachment(attachment0).layout(layout0.i) + it[1].attachment(attachment1).layout(layout1.i) + it[2].attachment(attachment2).layout(layout2.i) + it[3].attachment(attachment3).layout(layout3.i) + it[4].attachment(attachment4).layout(layout4.i) + } + + fun ComputePipelineCreateInfo(layout: VkPipelineLayout, flags: VkPipelineCreateFlags = 0): VkComputePipelineCreateInfo = + ComputePipelineCreateInfo { + this.layout = layout + this.flags = flags + } + + fun DescriptorImageInfo(sampler: VkSampler, imageView: VkImageView, imageLayout: VkImageLayout): VkDescriptorImageInfo = + DescriptorImageInfo { + this.sampler = sampler + this.imageView = imageView + this.imageLayout = imageLayout + } + + fun DescriptorPoolCreateInfo(poolSize: VkDescriptorPoolSize, maxSets: Int): VkDescriptorPoolCreateInfo = + DescriptorPoolCreateInfo { + this.poolSize = poolSize + this.maxSets = maxSets + } + + fun DescriptorPoolCreateInfo(poolSizes: VkDescriptorPoolSize.Buffer, maxSets: Int): VkDescriptorPoolCreateInfo = + DescriptorPoolCreateInfo { + this.poolSizes = poolSizes + this.maxSets = maxSets + } + + fun DescriptorPoolSize(type: VkDescriptorType, descriptorCount: Int): VkDescriptorPoolSize = + DescriptorPoolSize { + this.type = type + this.descriptorCount = descriptorCount + } + + fun DescriptorPoolSize( + type0: VkDescriptorType, descriptorCount0: Int, + type1: VkDescriptorType, descriptorCount1: Int): VkDescriptorPoolSize.Buffer = + DescriptorPoolSize(2) { + this[0].type(type0.i).descriptorCount(descriptorCount0) + this[1].type(type1.i).descriptorCount(descriptorCount1) + } + + fun DescriptorPoolSize( + type0: VkDescriptorType, descriptorCount0: Int, + type1: VkDescriptorType, descriptorCount1: Int, + type2: VkDescriptorType, descriptorCount2: Int): VkDescriptorPoolSize.Buffer = + DescriptorPoolSize(3) { + this[0].type(type0.i).descriptorCount(descriptorCount0) + this[1].type(type1.i).descriptorCount(descriptorCount1) + this[2].type(type2.i).descriptorCount(descriptorCount2) + } + + fun DescriptorPoolSize( + type0: VkDescriptorType, descriptorCount0: Int, + type1: VkDescriptorType, descriptorCount1: Int, + type2: VkDescriptorType, descriptorCount2: Int, + type3: VkDescriptorType, descriptorCount3: Int): VkDescriptorPoolSize.Buffer = + DescriptorPoolSize(4) { + this[0].type(type0.i).descriptorCount(descriptorCount0) + this[1].type(type1.i).descriptorCount(descriptorCount1) + this[2].type(type2.i).descriptorCount(descriptorCount2) + this[3].type(type3.i).descriptorCount(descriptorCount3) + } + + fun DescriptorPoolSize( + type0: VkDescriptorType, descriptorCount0: Int, + type1: VkDescriptorType, descriptorCount1: Int, + type2: VkDescriptorType, descriptorCount2: Int, + type3: VkDescriptorType, descriptorCount3: Int, + type4: VkDescriptorType, descriptorCount4: Int): VkDescriptorPoolSize.Buffer = + DescriptorPoolSize(5) { + this[0].type(type0.i).descriptorCount(descriptorCount0) + this[1].type(type1.i).descriptorCount(descriptorCount1) + this[2].type(type2.i).descriptorCount(descriptorCount2) + this[3].type(type3.i).descriptorCount(descriptorCount3) + this[4].type(type4.i).descriptorCount(descriptorCount4) + } + + fun DescriptorPoolSize( + type0: VkDescriptorType, descriptorCount0: Int, + type1: VkDescriptorType, descriptorCount1: Int, + type2: VkDescriptorType, descriptorCount2: Int, + type3: VkDescriptorType, descriptorCount3: Int, + type4: VkDescriptorType, descriptorCount4: Int, + type5: VkDescriptorType, descriptorCount5: Int): VkDescriptorPoolSize.Buffer = + DescriptorPoolSize(6) { + this[0].type(type0.i).descriptorCount(descriptorCount0) + this[1].type(type1.i).descriptorCount(descriptorCount1) + this[2].type(type2.i).descriptorCount(descriptorCount2) + this[3].type(type3.i).descriptorCount(descriptorCount3) + this[4].type(type4.i).descriptorCount(descriptorCount4) + this[5].type(type5.i).descriptorCount(descriptorCount5) + } + + fun DescriptorPoolSize( + type0: VkDescriptorType, descriptorCount0: Int, + type1: VkDescriptorType, descriptorCount1: Int, + type2: VkDescriptorType, descriptorCount2: Int, + type3: VkDescriptorType, descriptorCount3: Int, + type4: VkDescriptorType, descriptorCount4: Int, + type5: VkDescriptorType, descriptorCount5: Int, + type6: VkDescriptorType, descriptorCount6: Int): VkDescriptorPoolSize.Buffer = + DescriptorPoolSize(7) { + this[0].type(type0.i).descriptorCount(descriptorCount0) + this[1].type(type1.i).descriptorCount(descriptorCount1) + this[2].type(type2.i).descriptorCount(descriptorCount2) + this[3].type(type3.i).descriptorCount(descriptorCount3) + this[4].type(type4.i).descriptorCount(descriptorCount4) + this[5].type(type5.i).descriptorCount(descriptorCount5) + this[6].type(type6.i).descriptorCount(descriptorCount6) + } + + fun DescriptorPoolSize( + type0: VkDescriptorType, descriptorCount0: Int, + type1: VkDescriptorType, descriptorCount1: Int, + type2: VkDescriptorType, descriptorCount2: Int, + type3: VkDescriptorType, descriptorCount3: Int, + type4: VkDescriptorType, descriptorCount4: Int, + type5: VkDescriptorType, descriptorCount5: Int, + type6: VkDescriptorType, descriptorCount6: Int, + type7: VkDescriptorType, descriptorCount7: Int): VkDescriptorPoolSize.Buffer = + DescriptorPoolSize(8) { + this[0].type(type0.i).descriptorCount(descriptorCount0) + this[1].type(type1.i).descriptorCount(descriptorCount1) + this[2].type(type2.i).descriptorCount(descriptorCount2) + this[3].type(type3.i).descriptorCount(descriptorCount3) + this[4].type(type4.i).descriptorCount(descriptorCount4) + this[5].type(type5.i).descriptorCount(descriptorCount5) + this[6].type(type6.i).descriptorCount(descriptorCount6) + this[7].type(type7.i).descriptorCount(descriptorCount7) + } + + fun DescriptorPoolSize( + type0: VkDescriptorType, descriptorCount0: Int, + type1: VkDescriptorType, descriptorCount1: Int, + type2: VkDescriptorType, descriptorCount2: Int, + type3: VkDescriptorType, descriptorCount3: Int, + type4: VkDescriptorType, descriptorCount4: Int, + type5: VkDescriptorType, descriptorCount5: Int, + type6: VkDescriptorType, descriptorCount6: Int, + type7: VkDescriptorType, descriptorCount7: Int, + type8: VkDescriptorType, descriptorCount8: Int): VkDescriptorPoolSize.Buffer = + DescriptorPoolSize(9) { + this[0].type(type0.i).descriptorCount(descriptorCount0) + this[1].type(type1.i).descriptorCount(descriptorCount1) + this[2].type(type2.i).descriptorCount(descriptorCount2) + this[3].type(type3.i).descriptorCount(descriptorCount3) + this[4].type(type4.i).descriptorCount(descriptorCount4) + this[5].type(type5.i).descriptorCount(descriptorCount5) + this[6].type(type6.i).descriptorCount(descriptorCount6) + this[7].type(type7.i).descriptorCount(descriptorCount7) + this[8].type(type8.i).descriptorCount(descriptorCount8) + } + + fun DescriptorPoolSize( + type0: VkDescriptorType, descriptorCount0: Int, + type1: VkDescriptorType, descriptorCount1: Int, + type2: VkDescriptorType, descriptorCount2: Int, + type3: VkDescriptorType, descriptorCount3: Int, + type4: VkDescriptorType, descriptorCount4: Int, + type5: VkDescriptorType, descriptorCount5: Int, + type6: VkDescriptorType, descriptorCount6: Int, + type7: VkDescriptorType, descriptorCount7: Int, + type8: VkDescriptorType, descriptorCount8: Int, + type9: VkDescriptorType, descriptorCount9: Int): VkDescriptorPoolSize.Buffer = + DescriptorPoolSize(10) { + this[0].type(type0.i).descriptorCount(descriptorCount0) + this[1].type(type1.i).descriptorCount(descriptorCount1) + this[2].type(type2.i).descriptorCount(descriptorCount2) + this[3].type(type3.i).descriptorCount(descriptorCount3) + this[4].type(type4.i).descriptorCount(descriptorCount4) + this[5].type(type5.i).descriptorCount(descriptorCount5) + this[6].type(type6.i).descriptorCount(descriptorCount6) + this[7].type(type7.i).descriptorCount(descriptorCount7) + this[8].type(type8.i).descriptorCount(descriptorCount8) + this[9].type(type9.i).descriptorCount(descriptorCount9) + } + + fun DescriptorPoolSize( + type0: VkDescriptorType, descriptorCount0: Int, + type1: VkDescriptorType, descriptorCount1: Int, + type2: VkDescriptorType, descriptorCount2: Int, + type3: VkDescriptorType, descriptorCount3: Int, + type4: VkDescriptorType, descriptorCount4: Int, + type5: VkDescriptorType, descriptorCount5: Int, + type6: VkDescriptorType, descriptorCount6: Int, + type7: VkDescriptorType, descriptorCount7: Int, + type8: VkDescriptorType, descriptorCount8: Int, + type9: VkDescriptorType, descriptorCount9: Int, + type10: VkDescriptorType, descriptorCount10: Int): VkDescriptorPoolSize.Buffer = + DescriptorPoolSize(11) { + this[0].type(type0.i).descriptorCount(descriptorCount0) + this[1].type(type1.i).descriptorCount(descriptorCount1) + this[2].type(type2.i).descriptorCount(descriptorCount2) + this[3].type(type3.i).descriptorCount(descriptorCount3) + this[4].type(type4.i).descriptorCount(descriptorCount4) + this[5].type(type5.i).descriptorCount(descriptorCount5) + this[6].type(type6.i).descriptorCount(descriptorCount6) + this[7].type(type7.i).descriptorCount(descriptorCount7) + this[8].type(type8.i).descriptorCount(descriptorCount8) + this[9].type(type9.i).descriptorCount(descriptorCount9) + this[10].type(type10.i).descriptorCount(descriptorCount10) + } + + fun DescriptorSetAllocateInfo(descriptorPool: VkDescriptorPool, setLayout: VkDescriptorSetLayout): VkDescriptorSetAllocateInfo = + DescriptorSetAllocateInfo { + this.descriptorPool = descriptorPool + this.setLayout = setLayout + } + + fun DescriptorSetLayoutBinding(type: VkDescriptorType, stageFlags: VkShaderStageFlags, binding: Int, descriptorCount: Int = 1): VkDescriptorSetLayoutBinding = + DescriptorSetLayoutBinding { + descriptorType = type + this.stageFlags = stageFlags + this.binding = binding + this.descriptorCount = descriptorCount + } + + fun DescriptorSetLayoutBinding( + type0: VkDescriptorType, stageFlags0: VkShaderStageFlags, binding0: Int, + type1: VkDescriptorType, stageFlags1: VkShaderStageFlags, binding1: Int): VkDescriptorSetLayoutBinding.Buffer = + DescriptorSetLayoutBinding( + type0, stageFlags0, binding0, 1, + type1, stageFlags1, binding1, 1) + + fun DescriptorSetLayoutBinding( + type0: VkDescriptorType, stageFlags0: VkShaderStageFlags, binding0: Int, + type1: VkDescriptorType, stageFlags1: VkShaderStageFlags, binding1: Int, + type2: VkDescriptorType, stageFlags2: VkShaderStageFlags, binding2: Int): VkDescriptorSetLayoutBinding.Buffer = + DescriptorSetLayoutBinding( + type0, stageFlags0, binding0, 1, + type1, stageFlags1, binding1, 1, + type2, stageFlags2, binding2, 1) + + fun DescriptorSetLayoutBinding( + type0: VkDescriptorType, stageFlags0: VkShaderStageFlags, binding0: Int, + type1: VkDescriptorType, stageFlags1: VkShaderStageFlags, binding1: Int, + type2: VkDescriptorType, stageFlags2: VkShaderStageFlags, binding2: Int, + type3: VkDescriptorType, stageFlags3: VkShaderStageFlags, binding3: Int): VkDescriptorSetLayoutBinding.Buffer = + DescriptorSetLayoutBinding( + type0, stageFlags0, binding0, 1, + type1, stageFlags1, binding1, 1, + type2, stageFlags2, binding2, 1, + type3, stageFlags3, binding3, 1) + + fun DescriptorSetLayoutBinding( + type0: VkDescriptorType, stageFlags0: VkShaderStageFlags, binding0: Int, descriptorCount0: Int, + type1: VkDescriptorType, stageFlags1: VkShaderStageFlags, binding1: Int, descriptorCount1: Int): VkDescriptorSetLayoutBinding.Buffer = + DescriptorSetLayoutBinding(2) { + this[0].descriptorType(type0.i).stageFlags(stageFlags0).binding(binding0).descriptorCount(descriptorCount0) + this[1].descriptorType(type1.i).stageFlags(stageFlags1).binding(binding1).descriptorCount(descriptorCount1) + } + + fun DescriptorSetLayoutBinding( + type0: VkDescriptorType, stageFlags0: VkShaderStageFlags, binding0: Int, descriptorCount0: Int, + type1: VkDescriptorType, stageFlags1: VkShaderStageFlags, binding1: Int, descriptorCount1: Int, + type2: VkDescriptorType, stageFlags2: VkShaderStageFlags, binding2: Int, descriptorCount2: Int): VkDescriptorSetLayoutBinding.Buffer = + DescriptorSetLayoutBinding(3) { + this[0].descriptorType(type0.i).stageFlags(stageFlags0).binding(binding0).descriptorCount(descriptorCount0) + this[1].descriptorType(type1.i).stageFlags(stageFlags1).binding(binding1).descriptorCount(descriptorCount1) + this[2].descriptorType(type2.i).stageFlags(stageFlags2).binding(binding2).descriptorCount(descriptorCount2) + } + + fun DescriptorSetLayoutBinding( + type0: VkDescriptorType, stageFlags0: VkShaderStageFlags, binding0: Int, descriptorCount0: Int, + type1: VkDescriptorType, stageFlags1: VkShaderStageFlags, binding1: Int, descriptorCount1: Int, + type2: VkDescriptorType, stageFlags2: VkShaderStageFlags, binding2: Int, descriptorCount2: Int, + type3: VkDescriptorType, stageFlags3: VkShaderStageFlags, binding3: Int, descriptorCount3: Int): VkDescriptorSetLayoutBinding.Buffer = + DescriptorSetLayoutBinding(4) { + this[0].descriptorType(type0.i).stageFlags(stageFlags0).binding(binding0).descriptorCount(descriptorCount0) + this[1].descriptorType(type1.i).stageFlags(stageFlags1).binding(binding1).descriptorCount(descriptorCount1) + this[2].descriptorType(type2.i).stageFlags(stageFlags2).binding(binding2).descriptorCount(descriptorCount2) + this[3].descriptorType(type3.i).stageFlags(stageFlags3).binding(binding3).descriptorCount(descriptorCount3) + } + + fun DescriptorSetLayoutCreateInfo(binding: VkDescriptorSetLayoutBinding): VkDescriptorSetLayoutCreateInfo = + DescriptorSetLayoutCreateInfo { this.binding = binding } + + fun DescriptorSetLayoutCreateInfo(bindings: VkDescriptorSetLayoutBinding.Buffer): VkDescriptorSetLayoutCreateInfo = + DescriptorSetLayoutCreateInfo { this.bindings = bindings } + +// inline fun DeviceCreateInfo(queueCreateInfo: VkDeviceQueueCreateInfo, ): VkDeviceCreateInfo { +// +// } + + fun FenceCreateInfo(flag: VkFenceCreate): VkFenceCreateInfo = + FenceCreateInfo { flags = flag.i } + + fun FenceCreateInfo(flags: VkFenceCreateFlags = 0): VkFenceCreateInfo = + FenceCreateInfo { this.flags = flags } + + fun GraphicsPipelineCreateInfo(layout: VkPipelineLayout, renderPass: VkRenderPass, flags: VkPipelineCreateFlags = 0): VkGraphicsPipelineCreateInfo = + GraphicsPipelineCreateInfo { + this.layout = layout + this.renderPass = renderPass + this.flags = flags + basePipelineIndex = -1 + basePipelineHandle = VkPipeline(NULL) + } + + fun PipelineColorBlendAttachmentState(colorWriteMask: VkColorComponentFlags, blendEnable: Boolean): VkPipelineColorBlendAttachmentState = + PipelineColorBlendAttachmentState().colorWriteMask(colorWriteMask).blendEnable(blendEnable) + + fun PipelineColorBlendAttachmentState( + colorWriteMask0: VkColorComponentFlags, blendEnable0: Boolean, + colorWriteMask1: VkColorComponentFlags, blendEnable1: Boolean): VkPipelineColorBlendAttachmentState.Buffer = + PipelineColorBlendAttachmentState(2).also { + it[0].colorWriteMask(colorWriteMask0).blendEnable(blendEnable0) + it[1].colorWriteMask(colorWriteMask1).blendEnable(blendEnable1) + } + + fun PipelineColorBlendAttachmentState( + colorWriteMask0: VkColorComponentFlags, blendEnable0: Boolean, + colorWriteMask1: VkColorComponentFlags, blendEnable1: Boolean, + colorWriteMask2: VkColorComponentFlags, blendEnable2: Boolean): VkPipelineColorBlendAttachmentState.Buffer = + PipelineColorBlendAttachmentState(3).also { + it[0].colorWriteMask(colorWriteMask0).blendEnable(blendEnable0) + it[1].colorWriteMask(colorWriteMask1).blendEnable(blendEnable1) + it[2].colorWriteMask(colorWriteMask2).blendEnable(blendEnable2) + } + + fun PipelineColorBlendAttachmentState( + colorWriteMask0: VkColorComponentFlags, blendEnable0: Boolean, + colorWriteMask1: VkColorComponentFlags, blendEnable1: Boolean, + colorWriteMask2: VkColorComponentFlags, blendEnable2: Boolean, + colorWriteMask3: VkColorComponentFlags, blendEnable3: Boolean): VkPipelineColorBlendAttachmentState.Buffer = + PipelineColorBlendAttachmentState(4).also { + it[0].colorWriteMask(colorWriteMask0).blendEnable(blendEnable0) + it[1].colorWriteMask(colorWriteMask1).blendEnable(blendEnable1) + it[2].colorWriteMask(colorWriteMask2).blendEnable(blendEnable2) + it[3].colorWriteMask(colorWriteMask3).blendEnable(blendEnable3) + } + + fun PipelineColorBlendAttachmentState( + colorWriteMask0: VkColorComponentFlags, blendEnable0: Boolean, + colorWriteMask1: VkColorComponentFlags, blendEnable1: Boolean, + colorWriteMask2: VkColorComponentFlags, blendEnable2: Boolean, + colorWriteMask3: VkColorComponentFlags, blendEnable3: Boolean, + colorWriteMask4: VkColorComponentFlags, blendEnable4: Boolean): VkPipelineColorBlendAttachmentState.Buffer = + PipelineColorBlendAttachmentState(5).also { + it[0].colorWriteMask(colorWriteMask0).blendEnable(blendEnable0) + it[1].colorWriteMask(colorWriteMask1).blendEnable(blendEnable1) + it[2].colorWriteMask(colorWriteMask2).blendEnable(blendEnable2) + it[3].colorWriteMask(colorWriteMask3).blendEnable(blendEnable3) + it[4].colorWriteMask(colorWriteMask4).blendEnable(blendEnable4) + } + + fun PipelineColorBlendStateCreateInfo(attachment: VkPipelineColorBlendAttachmentState): VkPipelineColorBlendStateCreateInfo = + PipelineColorBlendStateCreateInfo { this.attachment = attachment } + + fun PipelineDepthStencilStateCreateInfo(depthTestEnable: Boolean, + depthWriteEnable: Boolean, + depthCompareOp: VkCompareOp): VkPipelineDepthStencilStateCreateInfo = + PipelineDepthStencilStateCreateInfo { + this.depthTestEnable = depthTestEnable + this.depthWriteEnable = depthWriteEnable + this.depthCompareOp = depthCompareOp + front = back + back.compareOp = VkCompareOp.ALWAYS + } + + fun PipelineDynamicStateCreateInfo(dynamicStates: Collection, flags: VkPipelineDynamicStateCreateFlags = 0): VkPipelineDynamicStateCreateInfo = + PipelineDynamicStateCreateInfo { + stak { + val buf = it.vkDynamicStateBufferBig(dynamicStates.size) + for (i in dynamicStates.indices) + buf[i] = dynamicStates.elementAt(i) + this.dynamicStates = buf + this.flags = flags + } + } + + fun PipelineInputAssemblyStateCreateInfo(topology: VkPrimitiveTopology, + flags: VkPipelineInputAssemblyStateCreateFlags = 0, + primitiveRestartEnable: Boolean = false): VkPipelineInputAssemblyStateCreateInfo = + PipelineInputAssemblyStateCreateInfo { + this.topology = topology + this.flags = flags + this.primitiveRestartEnable = primitiveRestartEnable + } + + fun PipelineLayoutCreateInfo(setLayout: VkDescriptorSetLayout): VkPipelineLayoutCreateInfo = + PipelineLayoutCreateInfo { this.setLayout = setLayout } + + fun PipelineMultisampleStateCreateInfo(rasterizationSamples: VkSampleCount, flags: VkPipelineMultisampleStateCreateFlags = 0): VkPipelineMultisampleStateCreateInfo = + PipelineMultisampleStateCreateInfo { + this.rasterizationSamples = rasterizationSamples + this.flags = flags + } + + fun PipelineRasterizationStateCreateInfo( + polygonMode: VkPolygonMode, + cullMode: VkCullModeFlags, + frontFace: VkFrontFace, + flags: VkPipelineRasterizationStateCreateFlags = 0): VkPipelineRasterizationStateCreateInfo = + PipelineRasterizationStateCreateInfo { + this.polygonMode = polygonMode + this.cullMode = cullMode + this.frontFace = frontFace + this.flags = flags + depthClampEnable = false + lineWidth = 1f + } + + fun PipelineViewportStateCreateInfo(viewportCount: Int, scissorCount: Int, flags: VkPipelineViewportStateCreateFlags = 0): VkPipelineViewportStateCreateInfo = + PipelineViewportStateCreateInfo { + this.viewportCount = viewportCount + this.scissorCount = scissorCount + this.flags = flags + } + + fun PushConstantRange(stageFlag: VkShaderStage, size: Int, offset: Int = 0): VkPushConstantRange = + PushConstantRange(stageFlag.i, size, offset) + + fun PushConstantRange(stageFlags: VkShaderStageFlags, size: Int, offset: Int = 0): VkPushConstantRange = + PushConstantRange { + this.stageFlags = stageFlags + this.size = size + this.offset = offset + } + + fun Rect2D(size: Vec2i, offset: Vec2i = Vec2i()): VkRect2D = + Rect2D(size.x, size.y, offset.x, offset.y) + + fun Rect2D(offsetX: Int, offsetY: Int, width: Int, height: Int): VkRect2D = Rect2D { + offset.x = offsetX + offset.y = offsetY + extent.width = width + extent.height = height + } + + fun SpecializationInfo(mapEntries: VkSpecializationMapEntry.Buffer, data: ByteBuffer): VkSpecializationInfo = + SpecializationInfo().also { + it.mapEntries = mapEntries + it.data = data + } + + fun SpecializationInfo( + mapEntries0: VkSpecializationMapEntry.Buffer, data0: ByteBuffer, + mapEntries1: VkSpecializationMapEntry.Buffer, data1: ByteBuffer): VkSpecializationInfo.Buffer = + SpecializationInfo(2).also { + it[0].apply { + mapEntries = mapEntries0 + data = data0 + } + it[1].apply { + mapEntries = mapEntries1 + data = data1 + } + } + + fun SpecializationMapEntry(constantId: Int, offset: Int, size: Int): VkSpecializationMapEntry = + SpecializationMapEntry().also { + it.constantId = constantId + it.offset = offset + it.size = size.L + } + + fun SpecializationMapEntry( + constantId0: Int, offset0: Int, size0: Int, + constantId1: Int, offset1: Int, size1: Int): VkSpecializationMapEntry.Buffer = + SpecializationMapEntry(2).also { + it[0].constantID(constantId0).offset(offset0).size(size0.L) + it[1].constantID(constantId1).offset(offset1).size(size1.L) + } + + fun SpecializationMapEntry( + constantId0: Int, offset0: Int, size0: Int, + constantId1: Int, offset1: Int, size1: Int, + constantId2: Int, offset2: Int, size2: Int): VkSpecializationMapEntry.Buffer = + SpecializationMapEntry(3).also { + it[0].constantID(constantId0).offset(offset0).size(size0.L) + it[1].constantID(constantId1).offset(offset1).size(size1.L) + it[2].constantID(constantId2).offset(offset2).size(size2.L) + } + + fun SpecializationMapEntry( + constantId0: Int, offset0: Int, size0: Int, + constantId1: Int, offset1: Int, size1: Int, + constantId2: Int, offset2: Int, size2: Int, + constantId3: Int, offset3: Int, size3: Int): VkSpecializationMapEntry.Buffer = + SpecializationMapEntry(4).also { + it[0].constantID(constantId0).offset(offset0).size(size0.L) + it[1].constantID(constantId1).offset(offset1).size(size1.L) + it[2].constantID(constantId2).offset(offset2).size(size2.L) + it[3].constantID(constantId3).offset(offset3).size(size3.L) + } + + fun SurfaceFormatKHR(format: VkFormat, colorSpace: VkColorSpace): VkSurfaceFormatKHR = + SurfaceFormatKHR().also { + it.format = format + it.colorSpace = colorSpace + } + + fun VertexInputBindingDescription(binding: Int, stride: Int, inputRate: VkVertexInputRate): VkVertexInputBindingDescription = + VertexInputBindingDescription { + this.binding = binding + this.stride = stride + this.inputRate = inputRate + } + + fun Viewport(size: Vec2i, minDepth: Float = 0f, maxDepth: Float = 1f): VkViewport = + Viewport(size.x.f, size.y.f, minDepth, maxDepth) + + fun Viewport(width: Float, height: Float, minDepth: Float = 0f, maxDepth: Float = 1f): VkViewport = + Viewport { + this.width = width + this.height = height + this.minDepth = minDepth + this.maxDepth = maxDepth + } + + fun WriteDescriptorSet(dstSet: VkDescriptorSet, type: VkDescriptorType, binding: Int, imageInfo: VkDescriptorImageInfo): VkWriteDescriptorSet = + WriteDescriptorSet { + this.dstSet = dstSet + descriptorType = type + dstBinding = binding + imageInfo_ = imageInfo + } + + fun WriteDescriptorSet(dstSet: VkDescriptorSet, type: VkDescriptorType, binding: Int, bufferInfo: VkDescriptorBufferInfo): VkWriteDescriptorSet = + WriteDescriptorSet { + this.dstSet = dstSet + descriptorType = type + dstBinding = binding + bufferInfo_ = bufferInfo + } + + fun WriteDescriptorSet( + dstSet0: VkDescriptorSet, type0: VkDescriptorType, binding0: Int, info0: Struct, + dstSet1: VkDescriptorSet, type1: VkDescriptorType, binding1: Int, info1: Struct): VkWriteDescriptorSet.Buffer = + WriteDescriptorSet(2) { + this[0].dstSet(dstSet0.L).descriptorType(type0.i).dstBinding(binding0) + if (info0 is VkDescriptorBufferInfo) this[0].bufferInfo_ = info0 else this[0].imageInfo_ = info0 as VkDescriptorImageInfo + this[1].dstSet(dstSet1.L).descriptorType(type1.i).dstBinding(binding1) + if (info1 is VkDescriptorBufferInfo) this[1].bufferInfo_ = info1 else this[1].imageInfo_ = info1 as VkDescriptorImageInfo + } + + fun WriteDescriptorSet( + dstSet0: VkDescriptorSet, type0: VkDescriptorType, binding0: Int, info0: Struct, + dstSet1: VkDescriptorSet, type1: VkDescriptorType, binding1: Int, info1: Struct, + dstSet2: VkDescriptorSet, type2: VkDescriptorType, binding2: Int, info2: Struct): VkWriteDescriptorSet.Buffer = + WriteDescriptorSet(3) { + this[0].dstSet(dstSet0.L).descriptorType(type0.i).dstBinding(binding0) + if (info0 is VkDescriptorBufferInfo) this[0].bufferInfo_ = info0 else this[0].imageInfo_ = info0 as VkDescriptorImageInfo + this[1].dstSet(dstSet1.L).descriptorType(type1.i).dstBinding(binding1) + if (info1 is VkDescriptorBufferInfo) this[1].bufferInfo_ = info1 else this[1].imageInfo_ = info1 as VkDescriptorImageInfo + this[2].dstSet(dstSet2.L).descriptorType(type2.i).dstBinding(binding2) + if (info2 is VkDescriptorBufferInfo) this[2].bufferInfo_ = info2 else this[2].imageInfo_ = info2 as VkDescriptorImageInfo + } + + fun WriteDescriptorSet( + dstSet0: VkDescriptorSet, type0: VkDescriptorType, binding0: Int, info0: Struct, + dstSet1: VkDescriptorSet, type1: VkDescriptorType, binding1: Int, info1: Struct, + dstSet2: VkDescriptorSet, type2: VkDescriptorType, binding2: Int, info2: Struct, + dstSet3: VkDescriptorSet, type3: VkDescriptorType, binding3: Int, info3: Struct): VkWriteDescriptorSet.Buffer = + WriteDescriptorSet(4) { + this[0].dstSet(dstSet0.L).descriptorType(type0.i).dstBinding(binding0) + if (info0 is VkDescriptorBufferInfo) this[0].bufferInfo_ = info0 else this[0].imageInfo_ = info0 as VkDescriptorImageInfo + this[1].dstSet(dstSet1.L).descriptorType(type1.i).dstBinding(binding1) + if (info1 is VkDescriptorBufferInfo) this[1].bufferInfo_ = info1 else this[1].imageInfo_ = info1 as VkDescriptorImageInfo + this[2].dstSet(dstSet2.L).descriptorType(type2.i).dstBinding(binding2) + if (info2 is VkDescriptorBufferInfo) this[2].bufferInfo_ = info2 else this[2].imageInfo_ = info2 as VkDescriptorImageInfo + this[3].dstSet(dstSet3.L).descriptorType(type3.i).dstBinding(binding3) + if (info3 is VkDescriptorBufferInfo) this[3].bufferInfo_ = info3 else this[3].imageInfo_ = info3 as VkDescriptorImageInfo + } + + + /* + Full Constructors + */ + + + fun ImageSubresourceRange( + aspectMask: VkImageAspect, + baseMipLevel: Int, + levelCount: Int, + baseArrayLayer: Int, + layerCount: Int): VkImageSubresourceRange = + ImageSubresourceRange { + this.aspectMask = aspectMask.i + this.baseMipLevel = baseMipLevel + this.levelCount = levelCount + this.baseArrayLayer = baseArrayLayer + this.layerCount = layerCount + } + + fun ImageSubresourceRange( + aspectMask: VkImageAspectFlags, + baseMipLevel: Int, + levelCount: Int, + baseArrayLayer: Int, + layerCount: Int): VkImageSubresourceRange = + ImageSubresourceRange { + this.aspectMask = aspectMask + this.baseMipLevel = baseMipLevel + this.levelCount = levelCount + this.baseArrayLayer = baseArrayLayer + this.layerCount = layerCount + } + + fun VertexInputAttributeDescription(binding: Int, location: Int, format: VkFormat, offset: Int): VkVertexInputAttributeDescription = + VertexInputAttributeDescription { + this.location = location + this.binding = binding + this.format = format + this.offset = offset + } + + fun VertexInputAttributeDescription( + binding0: Int, location0: Int, format0: VkFormat, offset0: Int, + binding1: Int, location1: Int, format1: VkFormat, offset1: Int): VkVertexInputAttributeDescription.Buffer = + VertexInputAttributeDescription(2) { + this[0].location(location0).binding(binding0).format(format0.i).offset(offset0) + this[1].location(location1).binding(binding1).format(format1.i).offset(offset1) + } + + fun VertexInputAttributeDescription( + binding0: Int, location0: Int, format0: VkFormat, offset0: Int, + binding1: Int, location1: Int, format1: VkFormat, offset1: Int, + binding2: Int, location2: Int, format2: VkFormat, offset2: Int): VkVertexInputAttributeDescription.Buffer = + VertexInputAttributeDescription(3) { + this[0].location(location0).binding(binding0).format(format0.i).offset(offset0) + this[1].location(location1).binding(binding1).format(format1.i).offset(offset1) + this[2].location(location2).binding(binding2).format(format2.i).offset(offset2) + } + + fun VertexInputAttributeDescription( + binding0: Int, location0: Int, format0: VkFormat, offset0: Int, + binding1: Int, location1: Int, format1: VkFormat, offset1: Int, + binding2: Int, location2: Int, format2: VkFormat, offset2: Int, + binding3: Int, location3: Int, format3: VkFormat, offset3: Int): VkVertexInputAttributeDescription.Buffer = + VertexInputAttributeDescription(4) { + this[0].location(location0).binding(binding0).format(format0.i).offset(offset0) + this[1].location(location1).binding(binding1).format(format1.i).offset(offset1) + this[2].location(location2).binding(binding2).format(format2.i).offset(offset2) + this[3].location(location3).binding(binding3).format(format3.i).offset(offset3) + } + + fun VertexInputAttributeDescription( + binding0: Int, location0: Int, format0: VkFormat, offset0: Int, + binding1: Int, location1: Int, format1: VkFormat, offset1: Int, + binding2: Int, location2: Int, format2: VkFormat, offset2: Int, + binding3: Int, location3: Int, format3: VkFormat, offset3: Int, + binding4: Int, location4: Int, format4: VkFormat, offset4: Int): VkVertexInputAttributeDescription.Buffer = + VertexInputAttributeDescription(4) { + this[0].location(location0).binding(binding0).format(format0.i).offset(offset0) + this[1].location(location1).binding(binding1).format(format1.i).offset(offset1) + this[2].location(location2).binding(binding2).format(format2.i).offset(offset2) + this[3].location(location3).binding(binding3).format(format3.i).offset(offset3) + this[4].location(location4).binding(binding4).format(format4.i).offset(offset4) + } + + fun VertexInputAttributeDescription( + binding0: Int, location0: Int, format0: VkFormat, offset0: Int, + binding1: Int, location1: Int, format1: VkFormat, offset1: Int, + binding2: Int, location2: Int, format2: VkFormat, offset2: Int, + binding3: Int, location3: Int, format3: VkFormat, offset3: Int, + binding4: Int, location4: Int, format4: VkFormat, offset4: Int, + binding5: Int, location5: Int, format5: VkFormat, offset5: Int): VkVertexInputAttributeDescription.Buffer = + VertexInputAttributeDescription(4) { + this[0].location(location0).binding(binding0).format(format0.i).offset(offset0) + this[1].location(location1).binding(binding1).format(format1.i).offset(offset1) + this[2].location(location2).binding(binding2).format(format2.i).offset(offset2) + this[3].location(location3).binding(binding3).format(format3.i).offset(offset3) + this[4].location(location4).binding(binding4).format(format4.i).offset(offset4) + this[5].location(location5).binding(binding5).format(format5.i).offset(offset5) + } + + fun VertexInputAttributeDescription( + binding0: Int, location0: Int, format0: VkFormat, offset0: Int, + binding1: Int, location1: Int, format1: VkFormat, offset1: Int, + binding2: Int, location2: Int, format2: VkFormat, offset2: Int, + binding3: Int, location3: Int, format3: VkFormat, offset3: Int, + binding4: Int, location4: Int, format4: VkFormat, offset4: Int, + binding5: Int, location5: Int, format5: VkFormat, offset5: Int, + binding6: Int, location6: Int, format6: VkFormat, offset6: Int): VkVertexInputAttributeDescription.Buffer = + VertexInputAttributeDescription(4) { + this[0].location(location0).binding(binding0).format(format0.i).offset(offset0) + this[1].location(location1).binding(binding1).format(format1.i).offset(offset1) + this[2].location(location2).binding(binding2).format(format2.i).offset(offset2) + this[3].location(location3).binding(binding3).format(format3.i).offset(offset3) + this[4].location(location4).binding(binding4).format(format4.i).offset(offset4) + this[5].location(location5).binding(binding5).format(format5.i).offset(offset5) + this[6].location(location6).binding(binding6).format(format6.i).offset(offset6) + } + + /* + functions + */ + + fun acquireNextImageKHR(device: VkDevice, swapchain: VkSwapchainKHR, timeout: Long, semaphore: VkSemaphore, fence: VkFence, imageIndex: KMutableProperty0): VkResult = + stak { + val pImageIndex = it.nmalloc(1, Int.BYTES) + VkResult(KHRSwapchain.nvkAcquireNextImageKHR(device, swapchain.L, timeout, semaphore.L, fence.L, pImageIndex)) + .also { + imageIndex.set(memGetInt(pImageIndex)) + } + } + + fun allocateCommandBuffers(device: VkDevice, allocateInfo: VkCommandBufferAllocateInfo, count: Int, commandBuffers: ArrayList): VkResult = + stak { + commandBuffers.clear() + val pCommandBuffer = it.nmalloc(Pointer.POINTER_SIZE, Pointer.POINTER_SIZE * count) + VkResult(VK10.nvkAllocateCommandBuffers(device, allocateInfo.adr, pCommandBuffer)).also { + for (i in 0 until count) + commandBuffers += VkCommandBuffer(memGetAddress(pCommandBuffer + Pointer.POINTER_SIZE * i), device) + } + } + + fun allocateDescriptorSets(device: VkDevice, allocateInfo: VkDescriptorSetAllocateInfo, descriptorSets: KMutableProperty0): VkResult = + stak { + val pDescriptorSets = it.nmalloc(1, Long.BYTES) + VkResult(VK10.nvkAllocateDescriptorSets(device, allocateInfo.adr, pDescriptorSets)).also { + descriptorSets.set(VkDescriptorSet(memGetLong(pDescriptorSets))) + } + } + + fun allocateMemory(device: VkDevice, allocateInfo: VkMemoryAllocateInfo, memory: KMutableProperty0): VkResult = + stak { + val pMemory = it.nmalloc(1, Long.BYTES) + VkResult(VK10.nvkAllocateMemory(device, allocateInfo.adr, NULL, pMemory)).also { + memory.set(VkDeviceMemory(memGetLong(pMemory))) + } + } + + fun beginCommandBuffer(commandBuffer: VkCommandBuffer, beginInfo: VkCommandBufferBeginInfo): VkResult = + VkResult(VK10.nvkBeginCommandBuffer(commandBuffer, beginInfo.adr)) + + fun cmdBeginRenderPass(commandBuffer: VkCommandBuffer, renderPassBegin: VkRenderPassBeginInfo, contents: VkSubpassContents) = + VK10.nvkCmdBeginRenderPass(commandBuffer, renderPassBegin.adr, contents.i) + + fun cmdBindDescriptorSets(commandBuffer: VkCommandBuffer, pipelineBindPoint: VkPipelineBindPoint, layout: VkPipelineLayout, descriptorSet: VkDescriptorSet, dynamicOffsets: Int? = null) = + stak { + val pDescriptorSets = it.nmalloc(1, Long.BYTES) + memPutLong(pDescriptorSets, descriptorSet.L) + val dynamicOffsetCount: Int + val pDynamicOffset: Long + if (dynamicOffsets != null) { + dynamicOffsetCount = 1 + pDynamicOffset = it.nmalloc(1, Int.BYTES) + memPutInt(pDynamicOffset, dynamicOffsets) + } else { + dynamicOffsetCount = 0 + pDynamicOffset = NULL + } + VK10.nvkCmdBindDescriptorSets(commandBuffer, pipelineBindPoint.i, layout.L, 0, 1, pDescriptorSets, dynamicOffsetCount, pDynamicOffset) + } + + fun cmdBindIndexBuffer(commandBuffer: VkCommandBuffer, buffer: VkBuffer, offset: VkDeviceSize, indexType: VkIndexType) = + VK10.vkCmdBindIndexBuffer(commandBuffer, buffer.L, offset.L, indexType.i) + + fun cmdBindPipeline(commandBuffer: VkCommandBuffer, pipelineBindPoint: VkPipelineBindPoint, pipeline: VkPipeline) = + VK10.vkCmdBindPipeline(commandBuffer, pipelineBindPoint.i, pipeline.L) + + fun cmdBindVertexBuffer(commandBuffer: VkCommandBuffer, firstBinding: Int, buffer: VkBuffer) = + stak { + val pBuffer = it.nmalloc(1, Int.BYTES) + memPutLong(pBuffer, buffer.L) + val pOffset = it.ncalloc(1, Long.BYTES, 1) + VK10.nvkCmdBindVertexBuffers(commandBuffer, firstBinding, 1, pBuffer, pOffset) + } + + fun cmdDrawIndexed(commandBuffer: VkCommandBuffer, indexCount: Int, instanceCount: Int, firstIndex: Int, vertexOffset: Int, firstInstance: Int) = + VK10.vkCmdDrawIndexed(commandBuffer, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance) + + fun cmdEndRenderPass(commandBuffer: VkCommandBuffer) = VK10.vkCmdEndRenderPass(commandBuffer) + + fun cmdSetScissor(commandBuffer: VkCommandBuffer, firstScissor: Int, scissors: VkRect2D.Buffer) = + VK10.nvkCmdSetScissor(commandBuffer, firstScissor, scissors.remaining(), scissors.adr) + + fun cmdSetViewport(commandBuffer: VkCommandBuffer, firstViewport: Int, viewports: VkViewport.Buffer) = + VK10.nvkCmdSetViewport(commandBuffer, firstViewport, viewports.remaining(), viewports.adr) + + fun createBuffer(device: VkDevice, createInfo: VkBufferCreateInfo, buffer: KMutableProperty0): VkResult = + stak { + val pBuffer = it.nmalloc(1, Long.BYTES) + VkResult(VK10.nvkCreateBuffer(device, createInfo.adr, NULL, pBuffer)).also { + buffer.set(VkBuffer(memGetLong(pBuffer))) + } + } + + fun createCommandPool(device: VkDevice, createInfo: VkCommandPoolCreateInfo, commandPool: KMutableProperty0): VkResult = + stak { + val pCommandPool = it.nmalloc(1, Long.BYTES) + VkResult(VK10.nvkCreateCommandPool(device, createInfo.adr, NULL, pCommandPool)).also { + commandPool.set(VkCommandPool(memGetLong(pCommandPool))) + } + } + + fun createCommandPool(device: VkDevice, createInfo: VkCommandPoolCreateInfo, commandPool: LongBuffer): VkResult = + VkResult(VK10.nvkCreateCommandPool(device, createInfo.adr, NULL, memAddress(commandPool))) + + fun createDebugReportCallbackEXT(instance: VkInstance, createInfo: VkDebugReportCallbackCreateInfoEXT, callback: KMutableProperty0): VkResult = + stak { + val long = it.nmalloc(1, Long.BYTES) + VkResult(EXTDebugReport.nvkCreateDebugReportCallbackEXT(instance, createInfo.adr, NULL, long)).also { + callback.set(MemoryUtil.memGetLong(long)) + } + } + + fun createDescriptorPool(device: VkDevice, createInfo: VkDescriptorPoolCreateInfo, descriptorPool: KMutableProperty0): VkResult = + stak { + val pDescriptorPool = it.nmalloc(1, Long.BYTES) + VkResult(VK10.nvkCreateDescriptorPool(device, createInfo.adr, NULL, pDescriptorPool)).also { + descriptorPool.set(VkDescriptorPool(memGetLong(pDescriptorPool))) + } + } + + fun createDescriptorSetLayout(device: VkDevice, createInfo: VkDescriptorSetLayoutCreateInfo, setLayout: KMutableProperty0): VkResult = + stak { + val pSetLayout = it.nmalloc(1, Long.BYTES) + VkResult(VK10.nvkCreateDescriptorSetLayout(device, createInfo.adr, NULL, pSetLayout)).also { + setLayout.set(VkDescriptorSetLayout(memGetLong(pSetLayout))) + } + } + + fun createDevice(physicalDevice: VkPhysicalDevice, createInfo: VkDeviceCreateInfo, device: KMutableProperty0): VkResult = + stak { + val pDevice = it.nmalloc(Pointer.POINTER_SIZE, Pointer.POINTER_SIZE) + VkResult(VK10.nvkCreateDevice(physicalDevice, createInfo.adr, NULL, pDevice)).also { + device.set(VkDevice(memGetLong(pDevice), physicalDevice, createInfo)) + } + } + + fun createFence(device: VkDevice, createInfo: VkFenceCreateInfo, fence: LongBuffer): VkResult = // TODO LongBuffer? + stak { + val pFence = it.nmalloc(1, Long.BYTES) + VkResult(VK10.nvkCreateFence(device, createInfo.adr, NULL, pFence)).also { + fence[0] = memGetLong(pFence) + } + } + + fun createFences(device: VkDevice, createInfo: VkFenceCreateInfo, fences: ArrayList) = + stak { + val pFence = it.nmalloc(1, Long.BYTES) + for (i in fences.indices) { + VK_CHECK_RESULT(VK10.nvkCreateFence(device, createInfo.adr, NULL, pFence)) + fences[i] = VkFence(memGetLong(pFence)) + } + } + + fun createFramebuffer(device: VkDevice, createInfo: VkFramebufferCreateInfo, framebuffer: ArrayList, index: Int): VkResult = + stak { + val pFramebuffer = it.nmalloc(1, Long.BYTES) + VkResult(VK10.nvkCreateFramebuffer(device, createInfo.adr, NULL, pFramebuffer)).also { + framebuffer[index] = VkFramebuffer(memGetLong(pFramebuffer)) + } + } + + fun createGraphicsPipelines(device: VkDevice, pipelineCache: VkPipelineCache, createInfo: VkGraphicsPipelineCreateInfo, pipelines: KMutableProperty0): VkResult = + stak { + val pPipelines = it.nmalloc(1, Long.BYTES) + VkResult(VK10.nvkCreateGraphicsPipelines(device, pipelineCache.L, 1, createInfo.adr, NULL, pPipelines)).also { + pipelines.set(VkPipeline(memGetLong(pPipelines))) + } + } + + fun createGraphicsPipelines(device: VkDevice, pipelineCache: VkPipelineCache, createInfos: VkGraphicsPipelineCreateInfo.Buffer, pipelines: KMutableProperty0): VkResult = + stak { + val pPipelines = it.nmalloc(1, Long.BYTES) + VkResult(VK10.nvkCreateGraphicsPipelines(device, pipelineCache.L, createInfos.remaining(), createInfos.adr, NULL, pPipelines)).also { + pipelines.set(VkPipeline(memGetLong(pPipelines))) + } + } + + fun createImage(device: VkDevice, createInfo: VkImageCreateInfo, image: KMutableProperty0): VkResult = + stak { + val pImage = it.nmalloc(1, Long.BYTES) + VkResult(VK10.nvkCreateImage(device, createInfo.adr, NULL, pImage)).also { + image.set(VkImage(memGetLong(pImage))) + } + } + + fun createImageView(device: VkDevice, createInfo: VkImageViewCreateInfo, view: KMutableProperty0): VkResult = + stak { + val pView = it.nmalloc(1, Long.BYTES) + VkResult(VK10.nvkCreateImageView(device, createInfo.adr, NULL, pView)).also { + view.set(VkImageView(memGetLong(pView))) + } + } + + infix fun createInstance(createInfo: VkInstanceCreateInfo): VkInstance = + stak { + val pInstance = it.nmalloc(Pointer.POINTER_SIZE, Pointer.POINTER_SIZE) + VK_CHECK_RESULT(VK10.nvkCreateInstance(createInfo.adr, NULL, pInstance)) + VkInstance(MemoryUtil.memGetLong(pInstance), createInfo) + } + + fun createInstance(createInfo: VkInstanceCreateInfo, instance: KMutableProperty0): VkResult = + stak { + val pInstance = it.nmalloc(Pointer.POINTER_SIZE, Pointer.POINTER_SIZE) + VkResult(VK10.nvkCreateInstance(createInfo.adr, NULL, pInstance)).also { + instance.set(VkInstance(MemoryUtil.memGetLong(pInstance), createInfo)) + } + } + + fun createPipelineCache(device: VkDevice, createInfo: VkPipelineCacheCreateInfo, pipelineCache: KMutableProperty0): VkResult = + stak { + val pPipelineCache = it.nmalloc(1, Long.BYTES) + VkResult(VK10.nvkCreatePipelineCache(device, createInfo.adr, NULL, pPipelineCache)).also { + pipelineCache.set(VkPipelineCache(memGetLong(pPipelineCache))) + } + } + + fun createPipelineLayout(device: VkDevice, createInfo: VkPipelineLayoutCreateInfo, pipelineLayout: KMutableProperty0): VkResult = + stak { + val pPipelineLayout = it.nmalloc(1, Long.BYTES) + VkResult(VK10.nvkCreatePipelineLayout(device, createInfo.adr, NULL, pPipelineLayout)).also { + pipelineLayout.set(VkPipelineLayout(memGetLong(pPipelineLayout))) + } + } + + fun createRenderPass(device: VkDevice, createInfo: VkRenderPassCreateInfo, renderPass: KMutableProperty0): VkResult = + stak { + val pRenderPass = it.nmalloc(1, Long.BYTES) + VkResult(VK10.nvkCreateRenderPass(device, createInfo.adr, NULL, pRenderPass)).also { + renderPass.set(VkRenderPass(memGetLong(pRenderPass))) + } + } + + fun createSemaphore(device: VkDevice, createInfo: VkSemaphoreCreateInfo, semaphore: KMutableProperty0): VkResult = + stak { + val pSemaphore = it.nmalloc(1, Long.BYTES) + VkResult(VK10.nvkCreateSemaphore(device, createInfo.adr, NULL, pSemaphore)).also { + semaphore.set(VkSemaphore(memGetLong(pSemaphore))) + } + } + + fun createSemaphore(device: VkDevice, createInfo: VkSemaphoreCreateInfo, semaphore: VkSemaphoreBuffer): VkResult = + VkResult(VK10.nvkCreateSemaphore(device, createInfo.adr, NULL, memAddress(semaphore))) + + fun createShaderModule(device: VkDevice, createInfo: VkShaderModuleCreateInfo, shaderModule: LongBuffer): VkResult = + VkResult(VK10.nvkCreateShaderModule(device, createInfo.adr, NULL, memAddress(shaderModule))) + + fun createSwapchainKHR(device: VkDevice, createInfo: VkSwapchainCreateInfoKHR, swapchain: KMutableProperty0): VkResult = + stak { + val pSwapchain = it.nmalloc(1, Long.BYTES) + VkResult(KHRSwapchain.nvkCreateSwapchainKHR(device, createInfo.adr, NULL, pSwapchain)).also { + swapchain.set(VkSwapchainKHR(memGetLong(pSwapchain))) + } + } + + fun destroyDescriptorPool(device: VkDevice, descriptorPool: VkDescriptorPool) = + VK10.nvkDestroyDescriptorPool(device, descriptorPool.L, NULL) + + fun destroyDescriptorSetLayout(device: VkDevice, descriptorSetLayout: VkDescriptorSetLayout) = + VK10.nvkDestroyDescriptorSetLayout(device, descriptorSetLayout.L, NULL) + + fun destroyBuffer(device: VkDevice, buffer: VkBuffer) = VK10.nvkDestroyBuffer(device, buffer.L, NULL) + + fun destroyCommandPool(device: VkDevice, commandPool: VkCommandPool) = + VK10.nvkDestroyCommandPool(device, commandPool.L, NULL) + + fun destroyFence(device: VkDevice, fence: VkFence) = VK10.nvkDestroyFence(device, fence.L, NULL) + + fun destroyFences(device: VkDevice, fences: Iterable) { + for (i in fences) + VK10.nvkDestroyFence(device, i.L, NULL) + } + + fun destroyFramebuffers(device: VkDevice, framebuffers: Iterable) { + for (i in framebuffers) + VK10.nvkDestroyFramebuffer(device, i.L, NULL) + } + + fun destroyImage(device: VkDevice, image: VkImage) = VK10.nvkDestroyImage(device, image.L, NULL) + + fun destroyImageView(device: VkDevice, imageView: VkImageView) = VK10.nvkDestroyImageView(device, imageView.L, NULL) + + fun destroyPipeline(device: VkDevice, pipeline: VkPipeline) = VK10.nvkDestroyPipeline(device, pipeline.L, NULL) + + fun destroyPipelineCache(device: VkDevice, pipelineCache: VkPipelineCache) = + VK10.nvkDestroyPipelineCache(device, pipelineCache.L, NULL) + + fun destroyPipelineLayout(device: VkDevice, pipelineLayout: VkPipelineLayout) = + VK10.nvkDestroyPipelineLayout(device, pipelineLayout.L, NULL) + + fun destroyRenderPass(device: VkDevice, renderPass: VkRenderPass) = + VK10.nvkDestroyRenderPass(device, renderPass.L, NULL) + + fun destroySemaphore(device: VkDevice, semaphore: VkSemaphore) = + VK10.nvkDestroySemaphore(device, semaphore.L, NULL) + + fun destroyShaderModules(device: VkDevice, shaderModules: Iterable, allocator: VkAllocationCallbacks? = null) { + for (i in shaderModules) + VK10.nvkDestroyShaderModule(device, i.L, allocator?.adr ?: NULL) + } + + fun destroyShaderModules(device: VkDevice, shaderModules: VkPipelineShaderStageCreateInfo.Buffer) { + for (i in shaderModules) + VK10.nvkDestroyShaderModule(device, i.module.L, NULL) + } + + fun destroySwapchainKHR(device: VkDevice, swapchain: VkSwapchainKHR) { + KHRSwapchain.nvkDestroySwapchainKHR(device, swapchain.L, NULL) + } + + fun endCommandBuffer(commandBuffer: VkCommandBuffer): VkResult = + VkResult(VK10.vkEndCommandBuffer(commandBuffer)) + + fun enumerateDeviceExtensionProperties(physicalDevice: VkPhysicalDevice, layerName: String? = null): ArrayList = + stak { + val pCount = it.nmalloc(1, Int.BYTES) + val pLayerName = layerName?.utf8?.let(::memAddress) ?: NULL + VK_CHECK_RESULT(VK10.nvkEnumerateDeviceExtensionProperties(physicalDevice, pLayerName, pCount, NULL)) + val count = memGetInt(pCount) + val res = ArrayList(count) + if (count > 0) { + val properties = ExtensionProperties(count) + VK_CHECK_RESULT(VK10.nvkEnumerateDeviceExtensionProperties(physicalDevice, pLayerName, pCount, properties.adr)) + properties.map { it.extensionNameString() }.toCollection(res) + } + res + } + + fun enumeratePhysicalDevices(instance: VkInstance): ArrayList = + stak { + val physicalDevices = ArrayList() + val pPhysicalDeviceCount = it.nmalloc(1, Int.BYTES) + var physicalDeviceCount: Int + var result: VkResult + do { + result = VkResult(VK10.nvkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, NULL)) + physicalDeviceCount = memGetInt(pPhysicalDeviceCount) + if (result == SUCCESS && physicalDeviceCount > 0) { + val pPhysicalDevices = it.nmalloc(Pointer.POINTER_SIZE, physicalDeviceCount * Pointer.POINTER_SIZE) + result = VkResult(VK10.nvkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices)) + for (i in 0 until physicalDeviceCount) + physicalDevices += VkPhysicalDevice(memGetAddress(pPhysicalDevices), instance) + } + } while (result == INCOMPLETE) + assert(physicalDeviceCount <= physicalDevices.size) + physicalDevices resize physicalDeviceCount + physicalDevices + } + + fun flushMappedMemoryRange(device: VkDevice, memoryRange: VkMappedMemoryRange): VkResult = + VkResult(VK10.nvkFlushMappedMemoryRanges(device, 1, memoryRange.adr)) + + fun freeCommandBuffers(device: VkDevice, commandPool: VkCommandPool, commandBuffers: ArrayList) = + stak { + val pointers = it.nmalloc(Pointer.POINTER_SIZE, commandBuffers.size * Pointer.POINTER_SIZE) + for (i in commandBuffers.indices) + memPutAddress(pointers + Pointer.POINTER_SIZE * i, commandBuffers[i].adr) + VK10.nvkFreeCommandBuffers(device, commandPool.L, commandBuffers.size, pointers) + } + + fun freeMemory(device: VkDevice, memory: VkDeviceMemory) = VK10.nvkFreeMemory(device, memory.L, NULL) + + fun getDeviceQueue(device: VkDevice, queueFamilyIndex: Int, queueIndex: Int, queue: KMutableProperty0) = + stak { + val pQueue = it.nmalloc(Pointer.POINTER_SIZE, Pointer.POINTER_SIZE) + VK10.nvkGetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue) + queue.set(VkQueue(memGetLong(pQueue), device)) + } + + fun getPhysicalDeviceFormatProperties(physicalDevice: VkPhysicalDevice, format: VkFormat): VkFormatProperties = + FormatProperties { + VK10.nvkGetPhysicalDeviceFormatProperties(physicalDevice, format.i, adr) + } + + fun getPhysicalDeviceQueueFamilyProperties(physicalDevice: VkPhysicalDevice): ArrayList = + stak { + val pCount = it.nmalloc(1, Int.BYTES) + VK10.nvkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, NULL) + val count = memGetInt(pCount) + val pQueueFamilyProperties = VkQueueFamilyProperties.callocStack(count) + VK10.nvkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties.adr) + pQueueFamilyProperties.toCollection(arrayListOf()) + } + + fun getPhysicalDeviceSurfaceSupportKHR(physicalDevice: VkPhysicalDevice, queueFamily: Int, surface: VkSurface): Boolean = + stak { + val supported = it.nmalloc(1, Int.BYTES) + KHRSurface.nvkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamily, surface.L, supported) + memGetBoolean(supported) + } + + fun getPhysicalDeviceSurfaceSupportKHR(physicalDevice: VkPhysicalDevice, queueFamilyProperties: ArrayList, surface: VkSurface): BooleanArray = + stak { + val supported = it.nmalloc(1, Int.BYTES) + BooleanArray(queueFamilyProperties.size) { + KHRSurface.nvkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, it, surface.L, supported) + memGetBoolean(supported) + } + } + + fun getPhysicalDeviceSurfaceFormatsKHR(physicalDevice: VkPhysicalDevice, surface: VkSurface): ArrayList = + stak { + val pCount = it.nmalloc(1, Int.BYTES) + VK_CHECK_RESULT(KHRSurface.nvkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface.L, pCount, NULL)) + val count = memGetInt(pCount) + assert(count > 0) + val surfaceFormats = SurfaceFormatKHR(count) + VK_CHECK_RESULT(KHRSurface.nvkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface.L, pCount, surfaceFormats.adr)) + return surfaceFormats.toCollection(arrayListOf()) + } + + fun getPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice: VkPhysicalDevice, surface: VkSurface): VkSurfaceCapabilitiesKHR = + SurfaceCapabilitiesKHR { + VK_CHECK_RESULT(KHRSurface.nvkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface.L, adr)) + } + + fun getPhysicalDeviceSurfacePresentModesKHR(physicalDevice: VkPhysicalDevice, surface: VkSurface): ArrayList = + stak { + val pCount = it.nmalloc(1, Int.BYTES) + VK_CHECK_RESULT(KHRSurface.nvkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface.L, pCount, NULL)) + val count = memGetInt(pCount) + assert(count > 0) + val presentModes = it.nmalloc(Int.BYTES, count * Int.BYTES) + KHRSurface.nvkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface.L, pCount, presentModes) + val res = ArrayList() + for (i in 0 until count) + res += VkPresentMode of memGetInt(presentModes + Int.BYTES * i) + return res + } + + fun getSwapchainImagesKHR(device: VkDevice, swapchain: VkSwapchainKHR): VkImageArray = + stak { + val pCount = it.nmalloc(1, Int.BYTES) + VK_CHECK_RESULT(KHRSwapchain.nvkGetSwapchainImagesKHR(device, swapchain.L, pCount, NULL)) + val count = memGetInt(pCount) + val images = it.nmalloc(Long.BYTES, count * Long.BYTES) + VK_CHECK_RESULT(KHRSwapchain.nvkGetSwapchainImagesKHR(device, swapchain.L, pCount, images)) + initVkImageArray(count) { i -> VkImage(memGetLong(images + Long.BYTES * i)) } + } + + fun invalidateMappedMemoryRanges(device: VkDevice, memoryRange: VkMappedMemoryRange): VkResult = + VkResult(VK10.nvkInvalidateMappedMemoryRanges(device, 1, memoryRange.adr)) + + fun queueSubmit(queue: VkQueue, submit: VkSubmitInfo, fence: VkFence = VkFence(NULL)): VkResult = + VkResult(VK10.nvkQueueSubmit(queue, 1, submit.adr, fence.L)) + + fun updateDescriptorSets(device: VkDevice, descriptorWrites: VkWriteDescriptorSet.Buffer, descriptorCopies: VkCopyDescriptorSet.Buffer? = null) = + VK10.nvkUpdateDescriptorSets(device, descriptorWrites.remaining(), descriptorWrites.adr, descriptorCopies?.remaining() + ?: 0, descriptorCopies?.adr ?: NULL) + + val VERSION = "0.2.2" +} diff --git a/src/main/kotlin/vkk/vulcan.h b/src/main/kotlin/vkk/vulcan.h new file mode 100644 index 0000000..d3930cf --- /dev/null +++ b/src/main/kotlin/vkk/vulcan.h @@ -0,0 +1,7884 @@ +#ifndef VULKAN_CORE_H_ +#define VULKAN_CORE_H_ 1 + +#ifdef __cplusplus +extern "C" { +#endif + +/* +** Copyright (c) 2015-2018 The Khronos Group Inc. +** +** 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. +*/ + +/* +** This header is generated from the Khronos Vulkan XML API Registry. +** +*/ + + +#define VK_VERSION_1_0 1 +#include "vk_platform.h" + +#define VK_MAKE_VERSION(major, minor, patch) \ + (((major) << 22) | ((minor) << 12) | (patch)) + +// DEPRECATED: This define has been removed. Specific version defines (e.g. VK_API_VERSION_1_0), or the VK_MAKE_VERSION macro, should be used instead. +//#define VK_API_VERSION VK_MAKE_VERSION(1, 0, 0) // Patch version should always be set to 0 + +// Vulkan 1.0 version number +#define VK_API_VERSION_1_0 VK_MAKE_VERSION(1, 0, 0)// Patch version should always be set to 0 + +#define VK_VERSION_MAJOR(version) ((uint32_t)(version) >> 22) +#define VK_VERSION_MINOR(version) (((uint32_t)(version) >> 12) & 0x3ff) +#define VK_VERSION_PATCH(version) ((uint32_t)(version) & 0xfff) +// Version of this file +#define VK_HEADER_VERSION 84 + + +#define VK_NULL_HANDLE 0 + + + +#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object; + + +#if !defined(VK_DEFINE_NON_DISPATCHABLE_HANDLE) +#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__) + #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object; +#else + #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object; +#endif +#endif + + + +typedef uint32_t VkFlags; +typedef uint32_t VkBool32; +typedef uint64_t VkDeviceSize; +typedef uint32_t VkSampleMask; + +VK_DEFINE_HANDLE(VkInstance) +VK_DEFINE_HANDLE(VkPhysicalDevice) +VK_DEFINE_HANDLE(VkDevice) +VK_DEFINE_HANDLE(VkQueue) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSemaphore) +VK_DEFINE_HANDLE(VkCommandBuffer) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkFence) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDeviceMemory) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkBuffer) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkImage) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkEvent) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkQueryPool) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkBufferView) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkImageView) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkShaderModule) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkPipelineCache) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkPipelineLayout) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkRenderPass) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkPipeline) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorSetLayout) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSampler) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorPool) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorSet) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkFramebuffer) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkCommandPool) + +#define VK_LOD_CLAMP_NONE 1000.0f +#define VK_REMAINING_MIP_LEVELS (~0U) +#define VK_REMAINING_ARRAY_LAYERS (~0U) +#define VK_WHOLE_SIZE (~0ULL) +#define VK_ATTACHMENT_UNUSED (~0U) +#define VK_TRUE 1 +#define VK_FALSE 0 +#define VK_QUEUE_FAMILY_IGNORED (~0U) +#define VK_SUBPASS_EXTERNAL (~0U) +#define VK_MAX_PHYSICAL_DEVICE_NAME_SIZE 256 +#define VK_UUID_SIZE 16 +#define VK_MAX_MEMORY_TYPES 32 +#define VK_MAX_MEMORY_HEAPS 16 +#define VK_MAX_EXTENSION_NAME_SIZE 256 +#define VK_MAX_DESCRIPTION_SIZE 256 + + +typedef enum VkPipelineCacheHeaderVersion { + VK_PIPELINE_CACHE_HEADER_VERSION_ONE = 1, + VK_PIPELINE_CACHE_HEADER_VERSION_BEGIN_RANGE = VK_PIPELINE_CACHE_HEADER_VERSION_ONE, + VK_PIPELINE_CACHE_HEADER_VERSION_END_RANGE = VK_PIPELINE_CACHE_HEADER_VERSION_ONE, + VK_PIPELINE_CACHE_HEADER_VERSION_RANGE_SIZE = (VK_PIPELINE_CACHE_HEADER_VERSION_ONE - VK_PIPELINE_CACHE_HEADER_VERSION_ONE + 1), + VK_PIPELINE_CACHE_HEADER_VERSION_MAX_ENUM = 0x7FFFFFFF +} VkPipelineCacheHeaderVersion; + +typedef enum VkResult { + VK_SUCCESS = 0, + VK_NOT_READY = 1, + VK_TIMEOUT = 2, + VK_EVENT_SET = 3, + VK_EVENT_RESET = 4, + VK_INCOMPLETE = 5, + VK_ERROR_OUT_OF_HOST_MEMORY = -1, + VK_ERROR_OUT_OF_DEVICE_MEMORY = -2, + VK_ERROR_INITIALIZATION_FAILED = -3, + VK_ERROR_DEVICE_LOST = -4, + VK_ERROR_MEMORY_MAP_FAILED = -5, + VK_ERROR_LAYER_NOT_PRESENT = -6, + VK_ERROR_EXTENSION_NOT_PRESENT = -7, + VK_ERROR_FEATURE_NOT_PRESENT = -8, + VK_ERROR_INCOMPATIBLE_DRIVER = -9, + VK_ERROR_TOO_MANY_OBJECTS = -10, + VK_ERROR_FORMAT_NOT_SUPPORTED = -11, + VK_ERROR_FRAGMENTED_POOL = -12, + VK_ERROR_OUT_OF_POOL_MEMORY = -1000069000, + VK_ERROR_INVALID_EXTERNAL_HANDLE = -1000072003, + VK_ERROR_SURFACE_LOST_KHR = -1000000000, + VK_ERROR_NATIVE_WINDOW_IN_USE_KHR = -1000000001, + VK_SUBOPTIMAL_KHR = 1000001003, + VK_ERROR_OUT_OF_DATE_KHR = -1000001004, + VK_ERROR_INCOMPATIBLE_DISPLAY_KHR = -1000003001, + VK_ERROR_VALIDATION_FAILED_EXT = -1000011001, + VK_ERROR_INVALID_SHADER_NV = -1000012000, + VK_ERROR_FRAGMENTATION_EXT = -1000161000, + VK_ERROR_NOT_PERMITTED_EXT = -1000174001, + VK_ERROR_OUT_OF_POOL_MEMORY_KHR = VK_ERROR_OUT_OF_POOL_MEMORY, + VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR = VK_ERROR_INVALID_EXTERNAL_HANDLE, + VK_RESULT_BEGIN_RANGE = VK_ERROR_FRAGMENTED_POOL, + VK_RESULT_END_RANGE = VK_INCOMPLETE, + VK_RESULT_RANGE_SIZE = (VK_INCOMPLETE - VK_ERROR_FRAGMENTED_POOL + 1), + VK_RESULT_MAX_ENUM = 0x7FFFFFFF +} VkResult; + +typedef enum VkStructureType { + VK_STRUCTURE_TYPE_APPLICATION_INFO = 0, + VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO = 1, + VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO = 2, + VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO = 3, + VK_STRUCTURE_TYPE_SUBMIT_INFO = 4, + VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO = 5, + VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE = 6, + VK_STRUCTURE_TYPE_BIND_SPARSE_INFO = 7, + VK_STRUCTURE_TYPE_FENCE_CREATE_INFO = 8, + VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO = 9, + VK_STRUCTURE_TYPE_EVENT_CREATE_INFO = 10, + VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO = 11, + VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO = 12, + VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO = 13, + VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO = 14, + VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO = 15, + VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO = 16, + VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO = 17, + VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO = 18, + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO = 19, + VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO = 20, + VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO = 21, + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO = 22, + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO = 23, + VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO = 24, + VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO = 25, + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO = 26, + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO = 27, + VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO = 28, + VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO = 29, + VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO = 30, + VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO = 31, + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO = 32, + VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO = 33, + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO = 34, + VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET = 35, + VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET = 36, + VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO = 37, + VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO = 38, + VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO = 39, + VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO = 40, + VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO = 41, + VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO = 42, + VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO = 43, + VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER = 44, + VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER = 45, + VK_STRUCTURE_TYPE_MEMORY_BARRIER = 46, + VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO = 47, + VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO = 48, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES = 1000094000, + VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO = 1000157000, + VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO = 1000157001, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES = 1000083000, + VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS = 1000127000, + VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO = 1000127001, + VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO = 1000060000, + VK_STRUCTURE_TYPE_DEVICE_GROUP_RENDER_PASS_BEGIN_INFO = 1000060003, + VK_STRUCTURE_TYPE_DEVICE_GROUP_COMMAND_BUFFER_BEGIN_INFO = 1000060004, + VK_STRUCTURE_TYPE_DEVICE_GROUP_SUBMIT_INFO = 1000060005, + VK_STRUCTURE_TYPE_DEVICE_GROUP_BIND_SPARSE_INFO = 1000060006, + VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_DEVICE_GROUP_INFO = 1000060013, + VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_DEVICE_GROUP_INFO = 1000060014, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES = 1000070000, + VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO = 1000070001, + VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2 = 1000146000, + VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2 = 1000146001, + VK_STRUCTURE_TYPE_IMAGE_SPARSE_MEMORY_REQUIREMENTS_INFO_2 = 1000146002, + VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2 = 1000146003, + VK_STRUCTURE_TYPE_SPARSE_IMAGE_MEMORY_REQUIREMENTS_2 = 1000146004, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2 = 1000059000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 = 1000059001, + VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2 = 1000059002, + VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2 = 1000059003, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2 = 1000059004, + VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2 = 1000059005, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2 = 1000059006, + VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2 = 1000059007, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2 = 1000059008, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES = 1000117000, + VK_STRUCTURE_TYPE_RENDER_PASS_INPUT_ATTACHMENT_ASPECT_CREATE_INFO = 1000117001, + VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO = 1000117002, + VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_DOMAIN_ORIGIN_STATE_CREATE_INFO = 1000117003, + VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO = 1000053000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES = 1000053001, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES = 1000053002, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES = 1000120000, + VK_STRUCTURE_TYPE_PROTECTED_SUBMIT_INFO = 1000145000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES = 1000145001, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES = 1000145002, + VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2 = 1000145003, + VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO = 1000156000, + VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO = 1000156001, + VK_STRUCTURE_TYPE_BIND_IMAGE_PLANE_MEMORY_INFO = 1000156002, + VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO = 1000156003, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES = 1000156004, + VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES = 1000156005, + VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO = 1000085000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO = 1000071000, + VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES = 1000071001, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO = 1000071002, + VK_STRUCTURE_TYPE_EXTERNAL_BUFFER_PROPERTIES = 1000071003, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES = 1000071004, + VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO = 1000072000, + VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO = 1000072001, + VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO = 1000072002, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO = 1000112000, + VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES = 1000112001, + VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO = 1000113000, + VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO = 1000077000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO = 1000076000, + VK_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_PROPERTIES = 1000076001, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES = 1000168000, + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_SUPPORT = 1000168001, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES = 1000063000, + VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR = 1000001000, + VK_STRUCTURE_TYPE_PRESENT_INFO_KHR = 1000001001, + VK_STRUCTURE_TYPE_DEVICE_GROUP_PRESENT_CAPABILITIES_KHR = 1000060007, + VK_STRUCTURE_TYPE_IMAGE_SWAPCHAIN_CREATE_INFO_KHR = 1000060008, + VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_SWAPCHAIN_INFO_KHR = 1000060009, + VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR = 1000060010, + VK_STRUCTURE_TYPE_DEVICE_GROUP_PRESENT_INFO_KHR = 1000060011, + VK_STRUCTURE_TYPE_DEVICE_GROUP_SWAPCHAIN_CREATE_INFO_KHR = 1000060012, + VK_STRUCTURE_TYPE_DISPLAY_MODE_CREATE_INFO_KHR = 1000002000, + VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR = 1000002001, + VK_STRUCTURE_TYPE_DISPLAY_PRESENT_INFO_KHR = 1000003000, + VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR = 1000004000, + VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR = 1000005000, + VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR = 1000006000, + VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR = 1000007000, + VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR = 1000008000, + VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR = 1000009000, + VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT = 1000011000, + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_RASTERIZATION_ORDER_AMD = 1000018000, + VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT = 1000022000, + VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_TAG_INFO_EXT = 1000022001, + VK_STRUCTURE_TYPE_DEBUG_MARKER_MARKER_INFO_EXT = 1000022002, + VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_IMAGE_CREATE_INFO_NV = 1000026000, + VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV = 1000026001, + VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV = 1000026002, + VK_STRUCTURE_TYPE_TEXTURE_LOD_GATHER_FORMAT_PROPERTIES_AMD = 1000041000, + VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO_NV = 1000056000, + VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_NV = 1000056001, + VK_STRUCTURE_TYPE_IMPORT_MEMORY_WIN32_HANDLE_INFO_NV = 1000057000, + VK_STRUCTURE_TYPE_EXPORT_MEMORY_WIN32_HANDLE_INFO_NV = 1000057001, + VK_STRUCTURE_TYPE_WIN32_KEYED_MUTEX_ACQUIRE_RELEASE_INFO_NV = 1000058000, + VK_STRUCTURE_TYPE_VALIDATION_FLAGS_EXT = 1000061000, + VK_STRUCTURE_TYPE_VI_SURFACE_CREATE_INFO_NN = 1000062000, + VK_STRUCTURE_TYPE_IMAGE_VIEW_ASTC_DECODE_MODE_EXT = 1000067000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ASTC_DECODE_FEATURES_EXT = 1000067001, + VK_STRUCTURE_TYPE_IMPORT_MEMORY_WIN32_HANDLE_INFO_KHR = 1000073000, + VK_STRUCTURE_TYPE_EXPORT_MEMORY_WIN32_HANDLE_INFO_KHR = 1000073001, + VK_STRUCTURE_TYPE_MEMORY_WIN32_HANDLE_PROPERTIES_KHR = 1000073002, + VK_STRUCTURE_TYPE_MEMORY_GET_WIN32_HANDLE_INFO_KHR = 1000073003, + VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR = 1000074000, + VK_STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR = 1000074001, + VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR = 1000074002, + VK_STRUCTURE_TYPE_WIN32_KEYED_MUTEX_ACQUIRE_RELEASE_INFO_KHR = 1000075000, + VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_WIN32_HANDLE_INFO_KHR = 1000078000, + VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_WIN32_HANDLE_INFO_KHR = 1000078001, + VK_STRUCTURE_TYPE_D3D12_FENCE_SUBMIT_INFO_KHR = 1000078002, + VK_STRUCTURE_TYPE_SEMAPHORE_GET_WIN32_HANDLE_INFO_KHR = 1000078003, + VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR = 1000079000, + VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR = 1000079001, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR = 1000080000, + VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_CONDITIONAL_RENDERING_INFO_EXT = 1000081000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT = 1000081001, + VK_STRUCTURE_TYPE_CONDITIONAL_RENDERING_BEGIN_INFO_EXT = 1000081002, + VK_STRUCTURE_TYPE_PRESENT_REGIONS_KHR = 1000084000, + VK_STRUCTURE_TYPE_OBJECT_TABLE_CREATE_INFO_NVX = 1000086000, + VK_STRUCTURE_TYPE_INDIRECT_COMMANDS_LAYOUT_CREATE_INFO_NVX = 1000086001, + VK_STRUCTURE_TYPE_CMD_PROCESS_COMMANDS_INFO_NVX = 1000086002, + VK_STRUCTURE_TYPE_CMD_RESERVE_SPACE_FOR_COMMANDS_INFO_NVX = 1000086003, + VK_STRUCTURE_TYPE_DEVICE_GENERATED_COMMANDS_LIMITS_NVX = 1000086004, + VK_STRUCTURE_TYPE_DEVICE_GENERATED_COMMANDS_FEATURES_NVX = 1000086005, + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_W_SCALING_STATE_CREATE_INFO_NV = 1000087000, + VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_EXT = 1000090000, + VK_STRUCTURE_TYPE_DISPLAY_POWER_INFO_EXT = 1000091000, + VK_STRUCTURE_TYPE_DEVICE_EVENT_INFO_EXT = 1000091001, + VK_STRUCTURE_TYPE_DISPLAY_EVENT_INFO_EXT = 1000091002, + VK_STRUCTURE_TYPE_SWAPCHAIN_COUNTER_CREATE_INFO_EXT = 1000091003, + VK_STRUCTURE_TYPE_PRESENT_TIMES_INFO_GOOGLE = 1000092000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PER_VIEW_ATTRIBUTES_PROPERTIES_NVX = 1000097000, + VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SWIZZLE_STATE_CREATE_INFO_NV = 1000098000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT = 1000099000, + VK_STRUCTURE_TYPE_PIPELINE_DISCARD_RECTANGLE_STATE_CREATE_INFO_EXT = 1000099001, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT = 1000101000, + VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_CONSERVATIVE_STATE_CREATE_INFO_EXT = 1000101001, + VK_STRUCTURE_TYPE_HDR_METADATA_EXT = 1000105000, + VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2_KHR = 1000109000, + VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2_KHR = 1000109001, + VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2_KHR = 1000109002, + VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2_KHR = 1000109003, + VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2_KHR = 1000109004, + VK_STRUCTURE_TYPE_SUBPASS_BEGIN_INFO_KHR = 1000109005, + VK_STRUCTURE_TYPE_SUBPASS_END_INFO_KHR = 1000109006, + VK_STRUCTURE_TYPE_SHARED_PRESENT_SURFACE_CAPABILITIES_KHR = 1000111000, + VK_STRUCTURE_TYPE_IMPORT_FENCE_WIN32_HANDLE_INFO_KHR = 1000114000, + VK_STRUCTURE_TYPE_EXPORT_FENCE_WIN32_HANDLE_INFO_KHR = 1000114001, + VK_STRUCTURE_TYPE_FENCE_GET_WIN32_HANDLE_INFO_KHR = 1000114002, + VK_STRUCTURE_TYPE_IMPORT_FENCE_FD_INFO_KHR = 1000115000, + VK_STRUCTURE_TYPE_FENCE_GET_FD_INFO_KHR = 1000115001, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR = 1000119000, + VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR = 1000119001, + VK_STRUCTURE_TYPE_SURFACE_FORMAT_2_KHR = 1000119002, + VK_STRUCTURE_TYPE_DISPLAY_PROPERTIES_2_KHR = 1000121000, + VK_STRUCTURE_TYPE_DISPLAY_PLANE_PROPERTIES_2_KHR = 1000121001, + VK_STRUCTURE_TYPE_DISPLAY_MODE_PROPERTIES_2_KHR = 1000121002, + VK_STRUCTURE_TYPE_DISPLAY_PLANE_INFO_2_KHR = 1000121003, + VK_STRUCTURE_TYPE_DISPLAY_PLANE_CAPABILITIES_2_KHR = 1000121004, + VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK = 1000122000, + VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000123000, + VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT = 1000128000, + VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_TAG_INFO_EXT = 1000128001, + VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT = 1000128002, + VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CALLBACK_DATA_EXT = 1000128003, + VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT = 1000128004, + VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_USAGE_ANDROID = 1000129000, + VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_PROPERTIES_ANDROID = 1000129001, + VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_FORMAT_PROPERTIES_ANDROID = 1000129002, + VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID = 1000129003, + VK_STRUCTURE_TYPE_MEMORY_GET_ANDROID_HARDWARE_BUFFER_INFO_ANDROID = 1000129004, + VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID = 1000129005, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT = 1000130000, + VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT = 1000130001, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT = 1000138000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT = 1000138001, + VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_INLINE_UNIFORM_BLOCK_EXT = 1000138002, + VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_INLINE_UNIFORM_BLOCK_CREATE_INFO_EXT = 1000138003, + VK_STRUCTURE_TYPE_SAMPLE_LOCATIONS_INFO_EXT = 1000143000, + VK_STRUCTURE_TYPE_RENDER_PASS_SAMPLE_LOCATIONS_BEGIN_INFO_EXT = 1000143001, + VK_STRUCTURE_TYPE_PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT = 1000143002, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLE_LOCATIONS_PROPERTIES_EXT = 1000143003, + VK_STRUCTURE_TYPE_MULTISAMPLE_PROPERTIES_EXT = 1000143004, + VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR = 1000147000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT = 1000148000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_PROPERTIES_EXT = 1000148001, + VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_ADVANCED_STATE_CREATE_INFO_EXT = 1000148002, + VK_STRUCTURE_TYPE_PIPELINE_COVERAGE_TO_COLOR_STATE_CREATE_INFO_NV = 1000149000, + VK_STRUCTURE_TYPE_PIPELINE_COVERAGE_MODULATION_STATE_CREATE_INFO_NV = 1000152000, + VK_STRUCTURE_TYPE_VALIDATION_CACHE_CREATE_INFO_EXT = 1000160000, + VK_STRUCTURE_TYPE_SHADER_MODULE_VALIDATION_CACHE_CREATE_INFO_EXT = 1000160001, + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT = 1000161000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT = 1000161001, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT = 1000161002, + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO_EXT = 1000161003, + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_LAYOUT_SUPPORT_EXT = 1000161004, + VK_STRUCTURE_TYPE_DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT = 1000174000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR = 1000177000, + VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT = 1000178000, + VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT = 1000178001, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT = 1000178002, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD = 1000185000, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT = 1000190000, + VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT = 1000190001, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT = 1000190002, + VK_STRUCTURE_TYPE_CHECKPOINT_DATA_NV = 1000206000, + VK_STRUCTURE_TYPE_QUEUE_FAMILY_CHECKPOINT_PROPERTIES_NV = 1000206001, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_MEMORY_MODEL_FEATURES_KHR = 1000211000, + VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT, + VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO_KHR = VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, + VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2_KHR = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, + VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2_KHR = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, + VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2_KHR = VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2, + VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2_KHR = VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2, + VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO_KHR = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO, + VK_STRUCTURE_TYPE_DEVICE_GROUP_RENDER_PASS_BEGIN_INFO_KHR = VK_STRUCTURE_TYPE_DEVICE_GROUP_RENDER_PASS_BEGIN_INFO, + VK_STRUCTURE_TYPE_DEVICE_GROUP_COMMAND_BUFFER_BEGIN_INFO_KHR = VK_STRUCTURE_TYPE_DEVICE_GROUP_COMMAND_BUFFER_BEGIN_INFO, + VK_STRUCTURE_TYPE_DEVICE_GROUP_SUBMIT_INFO_KHR = VK_STRUCTURE_TYPE_DEVICE_GROUP_SUBMIT_INFO, + VK_STRUCTURE_TYPE_DEVICE_GROUP_BIND_SPARSE_INFO_KHR = VK_STRUCTURE_TYPE_DEVICE_GROUP_BIND_SPARSE_INFO, + VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_DEVICE_GROUP_INFO_KHR = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_DEVICE_GROUP_INFO, + VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_DEVICE_GROUP_INFO_KHR = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_DEVICE_GROUP_INFO, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_GROUP_PROPERTIES, + VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO_KHR = VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO, + VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES_KHR = VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO, + VK_STRUCTURE_TYPE_EXTERNAL_BUFFER_PROPERTIES_KHR = VK_STRUCTURE_TYPE_EXTERNAL_BUFFER_PROPERTIES, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES, + VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO, + VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO_KHR = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO, + VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO, + VK_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_PROPERTIES_KHR = VK_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_PROPERTIES, + VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO_KHR = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES, + VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO_KHR = VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO, + VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES2_EXT = VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_EXT, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO, + VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES_KHR = VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES, + VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO_KHR = VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES, + VK_STRUCTURE_TYPE_RENDER_PASS_INPUT_ATTACHMENT_ASPECT_CREATE_INFO_KHR = VK_STRUCTURE_TYPE_RENDER_PASS_INPUT_ATTACHMENT_ASPECT_CREATE_INFO, + VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO_KHR = VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO, + VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_DOMAIN_ORIGIN_STATE_CREATE_INFO_KHR = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_DOMAIN_ORIGIN_STATE_CREATE_INFO, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES, + VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS, + VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO, + VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2_KHR = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2, + VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2_KHR = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2, + VK_STRUCTURE_TYPE_IMAGE_SPARSE_MEMORY_REQUIREMENTS_INFO_2_KHR = VK_STRUCTURE_TYPE_IMAGE_SPARSE_MEMORY_REQUIREMENTS_INFO_2, + VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, + VK_STRUCTURE_TYPE_SPARSE_IMAGE_MEMORY_REQUIREMENTS_2_KHR = VK_STRUCTURE_TYPE_SPARSE_IMAGE_MEMORY_REQUIREMENTS_2, + VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO_KHR = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO, + VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO_KHR = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO, + VK_STRUCTURE_TYPE_BIND_IMAGE_PLANE_MEMORY_INFO_KHR = VK_STRUCTURE_TYPE_BIND_IMAGE_PLANE_MEMORY_INFO, + VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO_KHR = VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES, + VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES_KHR = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_IMAGE_FORMAT_PROPERTIES, + VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO, + VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO_KHR = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO, + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES_KHR = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES, + VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_SUPPORT_KHR = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_SUPPORT, + VK_STRUCTURE_TYPE_BEGIN_RANGE = VK_STRUCTURE_TYPE_APPLICATION_INFO, + VK_STRUCTURE_TYPE_END_RANGE = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO, + VK_STRUCTURE_TYPE_RANGE_SIZE = (VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO - VK_STRUCTURE_TYPE_APPLICATION_INFO + 1), + VK_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF +} VkStructureType; + +typedef enum VkSystemAllocationScope { + VK_SYSTEM_ALLOCATION_SCOPE_COMMAND = 0, + VK_SYSTEM_ALLOCATION_SCOPE_OBJECT = 1, + VK_SYSTEM_ALLOCATION_SCOPE_CACHE = 2, + VK_SYSTEM_ALLOCATION_SCOPE_DEVICE = 3, + VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE = 4, + VK_SYSTEM_ALLOCATION_SCOPE_BEGIN_RANGE = VK_SYSTEM_ALLOCATION_SCOPE_COMMAND, + VK_SYSTEM_ALLOCATION_SCOPE_END_RANGE = VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE, + VK_SYSTEM_ALLOCATION_SCOPE_RANGE_SIZE = (VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE - VK_SYSTEM_ALLOCATION_SCOPE_COMMAND + 1), + VK_SYSTEM_ALLOCATION_SCOPE_MAX_ENUM = 0x7FFFFFFF +} VkSystemAllocationScope; + +typedef enum VkInternalAllocationType { + VK_INTERNAL_ALLOCATION_TYPE_EXECUTABLE = 0, + VK_INTERNAL_ALLOCATION_TYPE_BEGIN_RANGE = VK_INTERNAL_ALLOCATION_TYPE_EXECUTABLE, + VK_INTERNAL_ALLOCATION_TYPE_END_RANGE = VK_INTERNAL_ALLOCATION_TYPE_EXECUTABLE, + VK_INTERNAL_ALLOCATION_TYPE_RANGE_SIZE = (VK_INTERNAL_ALLOCATION_TYPE_EXECUTABLE - VK_INTERNAL_ALLOCATION_TYPE_EXECUTABLE + 1), + VK_INTERNAL_ALLOCATION_TYPE_MAX_ENUM = 0x7FFFFFFF +} VkInternalAllocationType; + +typedef enum VkFormat { + VK_FORMAT_UNDEFINED = 0, + VK_FORMAT_R4G4_UNORM_PACK8 = 1, + VK_FORMAT_R4G4B4A4_UNORM_PACK16 = 2, + VK_FORMAT_B4G4R4A4_UNORM_PACK16 = 3, + VK_FORMAT_R5G6B5_UNORM_PACK16 = 4, + VK_FORMAT_B5G6R5_UNORM_PACK16 = 5, + VK_FORMAT_R5G5B5A1_UNORM_PACK16 = 6, + VK_FORMAT_B5G5R5A1_UNORM_PACK16 = 7, + VK_FORMAT_A1R5G5B5_UNORM_PACK16 = 8, + VK_FORMAT_R8_UNORM = 9, + VK_FORMAT_R8_SNORM = 10, + VK_FORMAT_R8_USCALED = 11, + VK_FORMAT_R8_SSCALED = 12, + VK_FORMAT_R8_UINT = 13, + VK_FORMAT_R8_SINT = 14, + VK_FORMAT_R8_SRGB = 15, + VK_FORMAT_R8G8_UNORM = 16, + VK_FORMAT_R8G8_SNORM = 17, + VK_FORMAT_R8G8_USCALED = 18, + VK_FORMAT_R8G8_SSCALED = 19, + VK_FORMAT_R8G8_UINT = 20, + VK_FORMAT_R8G8_SINT = 21, + VK_FORMAT_R8G8_SRGB = 22, + VK_FORMAT_R8G8B8_UNORM = 23, + VK_FORMAT_R8G8B8_SNORM = 24, + VK_FORMAT_R8G8B8_USCALED = 25, + VK_FORMAT_R8G8B8_SSCALED = 26, + VK_FORMAT_R8G8B8_UINT = 27, + VK_FORMAT_R8G8B8_SINT = 28, + VK_FORMAT_R8G8B8_SRGB = 29, + VK_FORMAT_B8G8R8_UNORM = 30, + VK_FORMAT_B8G8R8_SNORM = 31, + VK_FORMAT_B8G8R8_USCALED = 32, + VK_FORMAT_B8G8R8_SSCALED = 33, + VK_FORMAT_B8G8R8_UINT = 34, + VK_FORMAT_B8G8R8_SINT = 35, + VK_FORMAT_B8G8R8_SRGB = 36, + VK_FORMAT_R8G8B8A8_UNORM = 37, + VK_FORMAT_R8G8B8A8_SNORM = 38, + VK_FORMAT_R8G8B8A8_USCALED = 39, + VK_FORMAT_R8G8B8A8_SSCALED = 40, + VK_FORMAT_R8G8B8A8_UINT = 41, + VK_FORMAT_R8G8B8A8_SINT = 42, + VK_FORMAT_R8G8B8A8_SRGB = 43, + VK_FORMAT_B8G8R8A8_UNORM = 44, + VK_FORMAT_B8G8R8A8_SNORM = 45, + VK_FORMAT_B8G8R8A8_USCALED = 46, + VK_FORMAT_B8G8R8A8_SSCALED = 47, + VK_FORMAT_B8G8R8A8_UINT = 48, + VK_FORMAT_B8G8R8A8_SINT = 49, + VK_FORMAT_B8G8R8A8_SRGB = 50, + VK_FORMAT_A8B8G8R8_UNORM_PACK32 = 51, + VK_FORMAT_A8B8G8R8_SNORM_PACK32 = 52, + VK_FORMAT_A8B8G8R8_USCALED_PACK32 = 53, + VK_FORMAT_A8B8G8R8_SSCALED_PACK32 = 54, + VK_FORMAT_A8B8G8R8_UINT_PACK32 = 55, + VK_FORMAT_A8B8G8R8_SINT_PACK32 = 56, + VK_FORMAT_A8B8G8R8_SRGB_PACK32 = 57, + VK_FORMAT_A2R10G10B10_UNORM_PACK32 = 58, + VK_FORMAT_A2R10G10B10_SNORM_PACK32 = 59, + VK_FORMAT_A2R10G10B10_USCALED_PACK32 = 60, + VK_FORMAT_A2R10G10B10_SSCALED_PACK32 = 61, + VK_FORMAT_A2R10G10B10_UINT_PACK32 = 62, + VK_FORMAT_A2R10G10B10_SINT_PACK32 = 63, + VK_FORMAT_A2B10G10R10_UNORM_PACK32 = 64, + VK_FORMAT_A2B10G10R10_SNORM_PACK32 = 65, + VK_FORMAT_A2B10G10R10_USCALED_PACK32 = 66, + VK_FORMAT_A2B10G10R10_SSCALED_PACK32 = 67, + VK_FORMAT_A2B10G10R10_UINT_PACK32 = 68, + VK_FORMAT_A2B10G10R10_SINT_PACK32 = 69, + VK_FORMAT_R16_UNORM = 70, + VK_FORMAT_R16_SNORM = 71, + VK_FORMAT_R16_USCALED = 72, + VK_FORMAT_R16_SSCALED = 73, + VK_FORMAT_R16_UINT = 74, + VK_FORMAT_R16_SINT = 75, + VK_FORMAT_R16_SFLOAT = 76, + VK_FORMAT_R16G16_UNORM = 77, + VK_FORMAT_R16G16_SNORM = 78, + VK_FORMAT_R16G16_USCALED = 79, + VK_FORMAT_R16G16_SSCALED = 80, + VK_FORMAT_R16G16_UINT = 81, + VK_FORMAT_R16G16_SINT = 82, + VK_FORMAT_R16G16_SFLOAT = 83, + VK_FORMAT_R16G16B16_UNORM = 84, + VK_FORMAT_R16G16B16_SNORM = 85, + VK_FORMAT_R16G16B16_USCALED = 86, + VK_FORMAT_R16G16B16_SSCALED = 87, + VK_FORMAT_R16G16B16_UINT = 88, + VK_FORMAT_R16G16B16_SINT = 89, + VK_FORMAT_R16G16B16_SFLOAT = 90, + VK_FORMAT_R16G16B16A16_UNORM = 91, + VK_FORMAT_R16G16B16A16_SNORM = 92, + VK_FORMAT_R16G16B16A16_USCALED = 93, + VK_FORMAT_R16G16B16A16_SSCALED = 94, + VK_FORMAT_R16G16B16A16_UINT = 95, + VK_FORMAT_R16G16B16A16_SINT = 96, + VK_FORMAT_R16G16B16A16_SFLOAT = 97, + VK_FORMAT_R32_UINT = 98, + VK_FORMAT_R32_SINT = 99, + VK_FORMAT_R32_SFLOAT = 100, + VK_FORMAT_R32G32_UINT = 101, + VK_FORMAT_R32G32_SINT = 102, + VK_FORMAT_R32G32_SFLOAT = 103, + VK_FORMAT_R32G32B32_UINT = 104, + VK_FORMAT_R32G32B32_SINT = 105, + VK_FORMAT_R32G32B32_SFLOAT = 106, + VK_FORMAT_R32G32B32A32_UINT = 107, + VK_FORMAT_R32G32B32A32_SINT = 108, + VK_FORMAT_R32G32B32A32_SFLOAT = 109, + VK_FORMAT_R64_UINT = 110, + VK_FORMAT_R64_SINT = 111, + VK_FORMAT_R64_SFLOAT = 112, + VK_FORMAT_R64G64_UINT = 113, + VK_FORMAT_R64G64_SINT = 114, + VK_FORMAT_R64G64_SFLOAT = 115, + VK_FORMAT_R64G64B64_UINT = 116, + VK_FORMAT_R64G64B64_SINT = 117, + VK_FORMAT_R64G64B64_SFLOAT = 118, + VK_FORMAT_R64G64B64A64_UINT = 119, + VK_FORMAT_R64G64B64A64_SINT = 120, + VK_FORMAT_R64G64B64A64_SFLOAT = 121, + VK_FORMAT_B10G11R11_UFLOAT_PACK32 = 122, + VK_FORMAT_E5B9G9R9_UFLOAT_PACK32 = 123, + VK_FORMAT_D16_UNORM = 124, + VK_FORMAT_X8_D24_UNORM_PACK32 = 125, + VK_FORMAT_D32_SFLOAT = 126, + VK_FORMAT_S8_UINT = 127, + VK_FORMAT_D16_UNORM_S8_UINT = 128, + VK_FORMAT_D24_UNORM_S8_UINT = 129, + VK_FORMAT_D32_SFLOAT_S8_UINT = 130, + VK_FORMAT_BC1_RGB_UNORM_BLOCK = 131, + VK_FORMAT_BC1_RGB_SRGB_BLOCK = 132, + VK_FORMAT_BC1_RGBA_UNORM_BLOCK = 133, + VK_FORMAT_BC1_RGBA_SRGB_BLOCK = 134, + VK_FORMAT_BC2_UNORM_BLOCK = 135, + VK_FORMAT_BC2_SRGB_BLOCK = 136, + VK_FORMAT_BC3_UNORM_BLOCK = 137, + VK_FORMAT_BC3_SRGB_BLOCK = 138, + VK_FORMAT_BC4_UNORM_BLOCK = 139, + VK_FORMAT_BC4_SNORM_BLOCK = 140, + VK_FORMAT_BC5_UNORM_BLOCK = 141, + VK_FORMAT_BC5_SNORM_BLOCK = 142, + VK_FORMAT_BC6H_UFLOAT_BLOCK = 143, + VK_FORMAT_BC6H_SFLOAT_BLOCK = 144, + VK_FORMAT_BC7_UNORM_BLOCK = 145, + VK_FORMAT_BC7_SRGB_BLOCK = 146, + VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK = 147, + VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK = 148, + VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK = 149, + VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK = 150, + VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK = 151, + VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK = 152, + VK_FORMAT_EAC_R11_UNORM_BLOCK = 153, + VK_FORMAT_EAC_R11_SNORM_BLOCK = 154, + VK_FORMAT_EAC_R11G11_UNORM_BLOCK = 155, + VK_FORMAT_EAC_R11G11_SNORM_BLOCK = 156, + VK_FORMAT_ASTC_4x4_UNORM_BLOCK = 157, + VK_FORMAT_ASTC_4x4_SRGB_BLOCK = 158, + VK_FORMAT_ASTC_5x4_UNORM_BLOCK = 159, + VK_FORMAT_ASTC_5x4_SRGB_BLOCK = 160, + VK_FORMAT_ASTC_5x5_UNORM_BLOCK = 161, + VK_FORMAT_ASTC_5x5_SRGB_BLOCK = 162, + VK_FORMAT_ASTC_6x5_UNORM_BLOCK = 163, + VK_FORMAT_ASTC_6x5_SRGB_BLOCK = 164, + VK_FORMAT_ASTC_6x6_UNORM_BLOCK = 165, + VK_FORMAT_ASTC_6x6_SRGB_BLOCK = 166, + VK_FORMAT_ASTC_8x5_UNORM_BLOCK = 167, + VK_FORMAT_ASTC_8x5_SRGB_BLOCK = 168, + VK_FORMAT_ASTC_8x6_UNORM_BLOCK = 169, + VK_FORMAT_ASTC_8x6_SRGB_BLOCK = 170, + VK_FORMAT_ASTC_8x8_UNORM_BLOCK = 171, + VK_FORMAT_ASTC_8x8_SRGB_BLOCK = 172, + VK_FORMAT_ASTC_10x5_UNORM_BLOCK = 173, + VK_FORMAT_ASTC_10x5_SRGB_BLOCK = 174, + VK_FORMAT_ASTC_10x6_UNORM_BLOCK = 175, + VK_FORMAT_ASTC_10x6_SRGB_BLOCK = 176, + VK_FORMAT_ASTC_10x8_UNORM_BLOCK = 177, + VK_FORMAT_ASTC_10x8_SRGB_BLOCK = 178, + VK_FORMAT_ASTC_10x10_UNORM_BLOCK = 179, + VK_FORMAT_ASTC_10x10_SRGB_BLOCK = 180, + VK_FORMAT_ASTC_12x10_UNORM_BLOCK = 181, + VK_FORMAT_ASTC_12x10_SRGB_BLOCK = 182, + VK_FORMAT_ASTC_12x12_UNORM_BLOCK = 183, + VK_FORMAT_ASTC_12x12_SRGB_BLOCK = 184, + VK_FORMAT_G8B8G8R8_422_UNORM = 1000156000, + VK_FORMAT_B8G8R8G8_422_UNORM = 1000156001, + VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM = 1000156002, + VK_FORMAT_G8_B8R8_2PLANE_420_UNORM = 1000156003, + VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM = 1000156004, + VK_FORMAT_G8_B8R8_2PLANE_422_UNORM = 1000156005, + VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM = 1000156006, + VK_FORMAT_R10X6_UNORM_PACK16 = 1000156007, + VK_FORMAT_R10X6G10X6_UNORM_2PACK16 = 1000156008, + VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16 = 1000156009, + VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16 = 1000156010, + VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16 = 1000156011, + VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16 = 1000156012, + VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16 = 1000156013, + VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16 = 1000156014, + VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16 = 1000156015, + VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16 = 1000156016, + VK_FORMAT_R12X4_UNORM_PACK16 = 1000156017, + VK_FORMAT_R12X4G12X4_UNORM_2PACK16 = 1000156018, + VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16 = 1000156019, + VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16 = 1000156020, + VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16 = 1000156021, + VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16 = 1000156022, + VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16 = 1000156023, + VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16 = 1000156024, + VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16 = 1000156025, + VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16 = 1000156026, + VK_FORMAT_G16B16G16R16_422_UNORM = 1000156027, + VK_FORMAT_B16G16R16G16_422_UNORM = 1000156028, + VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM = 1000156029, + VK_FORMAT_G16_B16R16_2PLANE_420_UNORM = 1000156030, + VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM = 1000156031, + VK_FORMAT_G16_B16R16_2PLANE_422_UNORM = 1000156032, + VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM = 1000156033, + VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG = 1000054000, + VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG = 1000054001, + VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG = 1000054002, + VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG = 1000054003, + VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG = 1000054004, + VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG = 1000054005, + VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG = 1000054006, + VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG = 1000054007, + VK_FORMAT_G8B8G8R8_422_UNORM_KHR = VK_FORMAT_G8B8G8R8_422_UNORM, + VK_FORMAT_B8G8R8G8_422_UNORM_KHR = VK_FORMAT_B8G8R8G8_422_UNORM, + VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM, + VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, + VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM_KHR = VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM, + VK_FORMAT_G8_B8R8_2PLANE_422_UNORM_KHR = VK_FORMAT_G8_B8R8_2PLANE_422_UNORM, + VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM_KHR = VK_FORMAT_G8_B8_R8_3PLANE_444_UNORM, + VK_FORMAT_R10X6_UNORM_PACK16_KHR = VK_FORMAT_R10X6_UNORM_PACK16, + VK_FORMAT_R10X6G10X6_UNORM_2PACK16_KHR = VK_FORMAT_R10X6G10X6_UNORM_2PACK16, + VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16_KHR = VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16, + VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16_KHR = VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16, + VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16_KHR = VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16, + VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16_KHR = VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16, + VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16_KHR = VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16, + VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16_KHR = VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16, + VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16_KHR = VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16, + VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16_KHR = VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16, + VK_FORMAT_R12X4_UNORM_PACK16_KHR = VK_FORMAT_R12X4_UNORM_PACK16, + VK_FORMAT_R12X4G12X4_UNORM_2PACK16_KHR = VK_FORMAT_R12X4G12X4_UNORM_2PACK16, + VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16_KHR = VK_FORMAT_R12X4G12X4B12X4A12X4_UNORM_4PACK16, + VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16_KHR = VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16, + VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16_KHR = VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16, + VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16_KHR = VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16, + VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16_KHR = VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16, + VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16_KHR = VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16, + VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16_KHR = VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16, + VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16_KHR = VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16, + VK_FORMAT_G16B16G16R16_422_UNORM_KHR = VK_FORMAT_G16B16G16R16_422_UNORM, + VK_FORMAT_B16G16R16G16_422_UNORM_KHR = VK_FORMAT_B16G16R16G16_422_UNORM, + VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM_KHR = VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM, + VK_FORMAT_G16_B16R16_2PLANE_420_UNORM_KHR = VK_FORMAT_G16_B16R16_2PLANE_420_UNORM, + VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM_KHR = VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM, + VK_FORMAT_G16_B16R16_2PLANE_422_UNORM_KHR = VK_FORMAT_G16_B16R16_2PLANE_422_UNORM, + VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM_KHR = VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM, + VK_FORMAT_BEGIN_RANGE = VK_FORMAT_UNDEFINED, + VK_FORMAT_END_RANGE = VK_FORMAT_ASTC_12x12_SRGB_BLOCK, + VK_FORMAT_RANGE_SIZE = (VK_FORMAT_ASTC_12x12_SRGB_BLOCK - VK_FORMAT_UNDEFINED + 1), + VK_FORMAT_MAX_ENUM = 0x7FFFFFFF +} VkFormat; + +typedef enum VkImageType { + VK_IMAGE_TYPE_1D = 0, + VK_IMAGE_TYPE_2D = 1, + VK_IMAGE_TYPE_3D = 2, + VK_IMAGE_TYPE_BEGIN_RANGE = VK_IMAGE_TYPE_1D, + VK_IMAGE_TYPE_END_RANGE = VK_IMAGE_TYPE_3D, + VK_IMAGE_TYPE_RANGE_SIZE = (VK_IMAGE_TYPE_3D - VK_IMAGE_TYPE_1D + 1), + VK_IMAGE_TYPE_MAX_ENUM = 0x7FFFFFFF +} VkImageType; + +typedef enum VkImageTiling { + VK_IMAGE_TILING_OPTIMAL = 0, + VK_IMAGE_TILING_LINEAR = 1, + VK_IMAGE_TILING_BEGIN_RANGE = VK_IMAGE_TILING_OPTIMAL, + VK_IMAGE_TILING_END_RANGE = VK_IMAGE_TILING_LINEAR, + VK_IMAGE_TILING_RANGE_SIZE = (VK_IMAGE_TILING_LINEAR - VK_IMAGE_TILING_OPTIMAL + 1), + VK_IMAGE_TILING_MAX_ENUM = 0x7FFFFFFF +} VkImageTiling; + +typedef enum VkPhysicalDeviceType { + VK_PHYSICAL_DEVICE_TYPE_OTHER = 0, + VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU = 1, + VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU = 2, + VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU = 3, + VK_PHYSICAL_DEVICE_TYPE_CPU = 4, + VK_PHYSICAL_DEVICE_TYPE_BEGIN_RANGE = VK_PHYSICAL_DEVICE_TYPE_OTHER, + VK_PHYSICAL_DEVICE_TYPE_END_RANGE = VK_PHYSICAL_DEVICE_TYPE_CPU, + VK_PHYSICAL_DEVICE_TYPE_RANGE_SIZE = (VK_PHYSICAL_DEVICE_TYPE_CPU - VK_PHYSICAL_DEVICE_TYPE_OTHER + 1), + VK_PHYSICAL_DEVICE_TYPE_MAX_ENUM = 0x7FFFFFFF +} VkPhysicalDeviceType; + +typedef enum VkQueryType { + VK_QUERY_TYPE_OCCLUSION = 0, + VK_QUERY_TYPE_PIPELINE_STATISTICS = 1, + VK_QUERY_TYPE_TIMESTAMP = 2, + VK_QUERY_TYPE_BEGIN_RANGE = VK_QUERY_TYPE_OCCLUSION, + VK_QUERY_TYPE_END_RANGE = VK_QUERY_TYPE_TIMESTAMP, + VK_QUERY_TYPE_RANGE_SIZE = (VK_QUERY_TYPE_TIMESTAMP - VK_QUERY_TYPE_OCCLUSION + 1), + VK_QUERY_TYPE_MAX_ENUM = 0x7FFFFFFF +} VkQueryType; + +typedef enum VkSharingMode { + VK_SHARING_MODE_EXCLUSIVE = 0, + VK_SHARING_MODE_CONCURRENT = 1, + VK_SHARING_MODE_BEGIN_RANGE = VK_SHARING_MODE_EXCLUSIVE, + VK_SHARING_MODE_END_RANGE = VK_SHARING_MODE_CONCURRENT, + VK_SHARING_MODE_RANGE_SIZE = (VK_SHARING_MODE_CONCURRENT - VK_SHARING_MODE_EXCLUSIVE + 1), + VK_SHARING_MODE_MAX_ENUM = 0x7FFFFFFF +} VkSharingMode; + +typedef enum VkImageLayout { + VK_IMAGE_LAYOUT_UNDEFINED = 0, + VK_IMAGE_LAYOUT_GENERAL = 1, + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL = 2, + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL = 3, + VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL = 4, + VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL = 5, + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL = 6, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL = 7, + VK_IMAGE_LAYOUT_PREINITIALIZED = 8, + VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL = 1000117000, + VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL = 1000117001, + VK_IMAGE_LAYOUT_PRESENT_SRC_KHR = 1000001002, + VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR = 1000111000, + VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL_KHR = VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL, + VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL_KHR = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL, + VK_IMAGE_LAYOUT_BEGIN_RANGE = VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_END_RANGE = VK_IMAGE_LAYOUT_PREINITIALIZED, + VK_IMAGE_LAYOUT_RANGE_SIZE = (VK_IMAGE_LAYOUT_PREINITIALIZED - VK_IMAGE_LAYOUT_UNDEFINED + 1), + VK_IMAGE_LAYOUT_MAX_ENUM = 0x7FFFFFFF +} VkImageLayout; + +typedef enum VkImageViewType { + VK_IMAGE_VIEW_TYPE_1D = 0, + VK_IMAGE_VIEW_TYPE_2D = 1, + VK_IMAGE_VIEW_TYPE_3D = 2, + VK_IMAGE_VIEW_TYPE_CUBE = 3, + VK_IMAGE_VIEW_TYPE_1D_ARRAY = 4, + VK_IMAGE_VIEW_TYPE_2D_ARRAY = 5, + VK_IMAGE_VIEW_TYPE_CUBE_ARRAY = 6, + VK_IMAGE_VIEW_TYPE_BEGIN_RANGE = VK_IMAGE_VIEW_TYPE_1D, + VK_IMAGE_VIEW_TYPE_END_RANGE = VK_IMAGE_VIEW_TYPE_CUBE_ARRAY, + VK_IMAGE_VIEW_TYPE_RANGE_SIZE = (VK_IMAGE_VIEW_TYPE_CUBE_ARRAY - VK_IMAGE_VIEW_TYPE_1D + 1), + VK_IMAGE_VIEW_TYPE_MAX_ENUM = 0x7FFFFFFF +} VkImageViewType; + +typedef enum VkComponentSwizzle { + VK_COMPONENT_SWIZZLE_IDENTITY = 0, + VK_COMPONENT_SWIZZLE_ZERO = 1, + VK_COMPONENT_SWIZZLE_ONE = 2, + VK_COMPONENT_SWIZZLE_R = 3, + VK_COMPONENT_SWIZZLE_G = 4, + VK_COMPONENT_SWIZZLE_B = 5, + VK_COMPONENT_SWIZZLE_A = 6, + VK_COMPONENT_SWIZZLE_BEGIN_RANGE = VK_COMPONENT_SWIZZLE_IDENTITY, + VK_COMPONENT_SWIZZLE_END_RANGE = VK_COMPONENT_SWIZZLE_A, + VK_COMPONENT_SWIZZLE_RANGE_SIZE = (VK_COMPONENT_SWIZZLE_A - VK_COMPONENT_SWIZZLE_IDENTITY + 1), + VK_COMPONENT_SWIZZLE_MAX_ENUM = 0x7FFFFFFF +} VkComponentSwizzle; + +typedef enum VkVertexInputRate { + VK_VERTEX_INPUT_RATE_VERTEX = 0, + VK_VERTEX_INPUT_RATE_INSTANCE = 1, + VK_VERTEX_INPUT_RATE_BEGIN_RANGE = VK_VERTEX_INPUT_RATE_VERTEX, + VK_VERTEX_INPUT_RATE_END_RANGE = VK_VERTEX_INPUT_RATE_INSTANCE, + VK_VERTEX_INPUT_RATE_RANGE_SIZE = (VK_VERTEX_INPUT_RATE_INSTANCE - VK_VERTEX_INPUT_RATE_VERTEX + 1), + VK_VERTEX_INPUT_RATE_MAX_ENUM = 0x7FFFFFFF +} VkVertexInputRate; + +typedef enum VkPrimitiveTopology { + VK_PRIMITIVE_TOPOLOGY_POINT_LIST = 0, + VK_PRIMITIVE_TOPOLOGY_LINE_LIST = 1, + VK_PRIMITIVE_TOPOLOGY_LINE_STRIP = 2, + VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST = 3, + VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP = 4, + VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN = 5, + VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY = 6, + VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY = 7, + VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY = 8, + VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY = 9, + VK_PRIMITIVE_TOPOLOGY_PATCH_LIST = 10, + VK_PRIMITIVE_TOPOLOGY_BEGIN_RANGE = VK_PRIMITIVE_TOPOLOGY_POINT_LIST, + VK_PRIMITIVE_TOPOLOGY_END_RANGE = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, + VK_PRIMITIVE_TOPOLOGY_RANGE_SIZE = (VK_PRIMITIVE_TOPOLOGY_PATCH_LIST - VK_PRIMITIVE_TOPOLOGY_POINT_LIST + 1), + VK_PRIMITIVE_TOPOLOGY_MAX_ENUM = 0x7FFFFFFF +} VkPrimitiveTopology; + +typedef enum VkPolygonMode { + VK_POLYGON_MODE_FILL = 0, + VK_POLYGON_MODE_LINE = 1, + VK_POLYGON_MODE_POINT = 2, + VK_POLYGON_MODE_FILL_RECTANGLE_NV = 1000153000, + VK_POLYGON_MODE_BEGIN_RANGE = VK_POLYGON_MODE_FILL, + VK_POLYGON_MODE_END_RANGE = VK_POLYGON_MODE_POINT, + VK_POLYGON_MODE_RANGE_SIZE = (VK_POLYGON_MODE_POINT - VK_POLYGON_MODE_FILL + 1), + VK_POLYGON_MODE_MAX_ENUM = 0x7FFFFFFF +} VkPolygonMode; + +typedef enum VkFrontFace { + VK_FRONT_FACE_COUNTER_CLOCKWISE = 0, + VK_FRONT_FACE_CLOCKWISE = 1, + VK_FRONT_FACE_BEGIN_RANGE = VK_FRONT_FACE_COUNTER_CLOCKWISE, + VK_FRONT_FACE_END_RANGE = VK_FRONT_FACE_CLOCKWISE, + VK_FRONT_FACE_RANGE_SIZE = (VK_FRONT_FACE_CLOCKWISE - VK_FRONT_FACE_COUNTER_CLOCKWISE + 1), + VK_FRONT_FACE_MAX_ENUM = 0x7FFFFFFF +} VkFrontFace; + +typedef enum VkCompareOp { + VK_COMPARE_OP_NEVER = 0, + VK_COMPARE_OP_LESS = 1, + VK_COMPARE_OP_EQUAL = 2, + VK_COMPARE_OP_LESS_OR_EQUAL = 3, + VK_COMPARE_OP_GREATER = 4, + VK_COMPARE_OP_NOT_EQUAL = 5, + VK_COMPARE_OP_GREATER_OR_EQUAL = 6, + VK_COMPARE_OP_ALWAYS = 7, + VK_COMPARE_OP_BEGIN_RANGE = VK_COMPARE_OP_NEVER, + VK_COMPARE_OP_END_RANGE = VK_COMPARE_OP_ALWAYS, + VK_COMPARE_OP_RANGE_SIZE = (VK_COMPARE_OP_ALWAYS - VK_COMPARE_OP_NEVER + 1), + VK_COMPARE_OP_MAX_ENUM = 0x7FFFFFFF +} VkCompareOp; + +typedef enum VkStencilOp { + VK_STENCIL_OP_KEEP = 0, + VK_STENCIL_OP_ZERO = 1, + VK_STENCIL_OP_REPLACE = 2, + VK_STENCIL_OP_INCREMENT_AND_CLAMP = 3, + VK_STENCIL_OP_DECREMENT_AND_CLAMP = 4, + VK_STENCIL_OP_INVERT = 5, + VK_STENCIL_OP_INCREMENT_AND_WRAP = 6, + VK_STENCIL_OP_DECREMENT_AND_WRAP = 7, + VK_STENCIL_OP_BEGIN_RANGE = VK_STENCIL_OP_KEEP, + VK_STENCIL_OP_END_RANGE = VK_STENCIL_OP_DECREMENT_AND_WRAP, + VK_STENCIL_OP_RANGE_SIZE = (VK_STENCIL_OP_DECREMENT_AND_WRAP - VK_STENCIL_OP_KEEP + 1), + VK_STENCIL_OP_MAX_ENUM = 0x7FFFFFFF +} VkStencilOp; + +typedef enum VkLogicOp { + VK_LOGIC_OP_CLEAR = 0, + VK_LOGIC_OP_AND = 1, + VK_LOGIC_OP_AND_REVERSE = 2, + VK_LOGIC_OP_COPY = 3, + VK_LOGIC_OP_AND_INVERTED = 4, + VK_LOGIC_OP_NO_OP = 5, + VK_LOGIC_OP_XOR = 6, + VK_LOGIC_OP_OR = 7, + VK_LOGIC_OP_NOR = 8, + VK_LOGIC_OP_EQUIVALENT = 9, + VK_LOGIC_OP_INVERT = 10, + VK_LOGIC_OP_OR_REVERSE = 11, + VK_LOGIC_OP_COPY_INVERTED = 12, + VK_LOGIC_OP_OR_INVERTED = 13, + VK_LOGIC_OP_NAND = 14, + VK_LOGIC_OP_SET = 15, + VK_LOGIC_OP_BEGIN_RANGE = VK_LOGIC_OP_CLEAR, + VK_LOGIC_OP_END_RANGE = VK_LOGIC_OP_SET, + VK_LOGIC_OP_RANGE_SIZE = (VK_LOGIC_OP_SET - VK_LOGIC_OP_CLEAR + 1), + VK_LOGIC_OP_MAX_ENUM = 0x7FFFFFFF +} VkLogicOp; + +typedef enum VkBlendFactor { + VK_BLEND_FACTOR_ZERO = 0, + VK_BLEND_FACTOR_ONE = 1, + VK_BLEND_FACTOR_SRC_COLOR = 2, + VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR = 3, + VK_BLEND_FACTOR_DST_COLOR = 4, + VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR = 5, + VK_BLEND_FACTOR_SRC_ALPHA = 6, + VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA = 7, + VK_BLEND_FACTOR_DST_ALPHA = 8, + VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA = 9, + VK_BLEND_FACTOR_CONSTANT_COLOR = 10, + VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR = 11, + VK_BLEND_FACTOR_CONSTANT_ALPHA = 12, + VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA = 13, + VK_BLEND_FACTOR_SRC_ALPHA_SATURATE = 14, + VK_BLEND_FACTOR_SRC1_COLOR = 15, + VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR = 16, + VK_BLEND_FACTOR_SRC1_ALPHA = 17, + VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA = 18, + VK_BLEND_FACTOR_BEGIN_RANGE = VK_BLEND_FACTOR_ZERO, + VK_BLEND_FACTOR_END_RANGE = VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA, + VK_BLEND_FACTOR_RANGE_SIZE = (VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA - VK_BLEND_FACTOR_ZERO + 1), + VK_BLEND_FACTOR_MAX_ENUM = 0x7FFFFFFF +} VkBlendFactor; + +typedef enum VkBlendOp { + VK_BLEND_OP_ADD = 0, + VK_BLEND_OP_SUBTRACT = 1, + VK_BLEND_OP_REVERSE_SUBTRACT = 2, + VK_BLEND_OP_MIN = 3, + VK_BLEND_OP_MAX = 4, + VK_BLEND_OP_ZERO_EXT = 1000148000, + VK_BLEND_OP_SRC_EXT = 1000148001, + VK_BLEND_OP_DST_EXT = 1000148002, + VK_BLEND_OP_SRC_OVER_EXT = 1000148003, + VK_BLEND_OP_DST_OVER_EXT = 1000148004, + VK_BLEND_OP_SRC_IN_EXT = 1000148005, + VK_BLEND_OP_DST_IN_EXT = 1000148006, + VK_BLEND_OP_SRC_OUT_EXT = 1000148007, + VK_BLEND_OP_DST_OUT_EXT = 1000148008, + VK_BLEND_OP_SRC_ATOP_EXT = 1000148009, + VK_BLEND_OP_DST_ATOP_EXT = 1000148010, + VK_BLEND_OP_XOR_EXT = 1000148011, + VK_BLEND_OP_MULTIPLY_EXT = 1000148012, + VK_BLEND_OP_SCREEN_EXT = 1000148013, + VK_BLEND_OP_OVERLAY_EXT = 1000148014, + VK_BLEND_OP_DARKEN_EXT = 1000148015, + VK_BLEND_OP_LIGHTEN_EXT = 1000148016, + VK_BLEND_OP_COLORDODGE_EXT = 1000148017, + VK_BLEND_OP_COLORBURN_EXT = 1000148018, + VK_BLEND_OP_HARDLIGHT_EXT = 1000148019, + VK_BLEND_OP_SOFTLIGHT_EXT = 1000148020, + VK_BLEND_OP_DIFFERENCE_EXT = 1000148021, + VK_BLEND_OP_EXCLUSION_EXT = 1000148022, + VK_BLEND_OP_INVERT_EXT = 1000148023, + VK_BLEND_OP_INVERT_RGB_EXT = 1000148024, + VK_BLEND_OP_LINEARDODGE_EXT = 1000148025, + VK_BLEND_OP_LINEARBURN_EXT = 1000148026, + VK_BLEND_OP_VIVIDLIGHT_EXT = 1000148027, + VK_BLEND_OP_LINEARLIGHT_EXT = 1000148028, + VK_BLEND_OP_PINLIGHT_EXT = 1000148029, + VK_BLEND_OP_HARDMIX_EXT = 1000148030, + VK_BLEND_OP_HSL_HUE_EXT = 1000148031, + VK_BLEND_OP_HSL_SATURATION_EXT = 1000148032, + VK_BLEND_OP_HSL_COLOR_EXT = 1000148033, + VK_BLEND_OP_HSL_LUMINOSITY_EXT = 1000148034, + VK_BLEND_OP_PLUS_EXT = 1000148035, + VK_BLEND_OP_PLUS_CLAMPED_EXT = 1000148036, + VK_BLEND_OP_PLUS_CLAMPED_ALPHA_EXT = 1000148037, + VK_BLEND_OP_PLUS_DARKER_EXT = 1000148038, + VK_BLEND_OP_MINUS_EXT = 1000148039, + VK_BLEND_OP_MINUS_CLAMPED_EXT = 1000148040, + VK_BLEND_OP_CONTRAST_EXT = 1000148041, + VK_BLEND_OP_INVERT_OVG_EXT = 1000148042, + VK_BLEND_OP_RED_EXT = 1000148043, + VK_BLEND_OP_GREEN_EXT = 1000148044, + VK_BLEND_OP_BLUE_EXT = 1000148045, + VK_BLEND_OP_BEGIN_RANGE = VK_BLEND_OP_ADD, + VK_BLEND_OP_END_RANGE = VK_BLEND_OP_MAX, + VK_BLEND_OP_RANGE_SIZE = (VK_BLEND_OP_MAX - VK_BLEND_OP_ADD + 1), + VK_BLEND_OP_MAX_ENUM = 0x7FFFFFFF +} VkBlendOp; + +typedef enum VkDynamicState { + VK_DYNAMIC_STATE_VIEWPORT = 0, + VK_DYNAMIC_STATE_SCISSOR = 1, + VK_DYNAMIC_STATE_LINE_WIDTH = 2, + VK_DYNAMIC_STATE_DEPTH_BIAS = 3, + VK_DYNAMIC_STATE_BLEND_CONSTANTS = 4, + VK_DYNAMIC_STATE_DEPTH_BOUNDS = 5, + VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK = 6, + VK_DYNAMIC_STATE_STENCIL_WRITE_MASK = 7, + VK_DYNAMIC_STATE_STENCIL_REFERENCE = 8, + VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV = 1000087000, + VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT = 1000099000, + VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT = 1000143000, + VK_DYNAMIC_STATE_BEGIN_RANGE = VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_END_RANGE = VK_DYNAMIC_STATE_STENCIL_REFERENCE, + VK_DYNAMIC_STATE_RANGE_SIZE = (VK_DYNAMIC_STATE_STENCIL_REFERENCE - VK_DYNAMIC_STATE_VIEWPORT + 1), + VK_DYNAMIC_STATE_MAX_ENUM = 0x7FFFFFFF +} VkDynamicState; + +typedef enum VkFilter { + VK_FILTER_NEAREST = 0, + VK_FILTER_LINEAR = 1, + VK_FILTER_CUBIC_IMG = 1000015000, + VK_FILTER_BEGIN_RANGE = VK_FILTER_NEAREST, + VK_FILTER_END_RANGE = VK_FILTER_LINEAR, + VK_FILTER_RANGE_SIZE = (VK_FILTER_LINEAR - VK_FILTER_NEAREST + 1), + VK_FILTER_MAX_ENUM = 0x7FFFFFFF +} VkFilter; + +typedef enum VkSamplerMipmapMode { + VK_SAMPLER_MIPMAP_MODE_NEAREST = 0, + VK_SAMPLER_MIPMAP_MODE_LINEAR = 1, + VK_SAMPLER_MIPMAP_MODE_BEGIN_RANGE = VK_SAMPLER_MIPMAP_MODE_NEAREST, + VK_SAMPLER_MIPMAP_MODE_END_RANGE = VK_SAMPLER_MIPMAP_MODE_LINEAR, + VK_SAMPLER_MIPMAP_MODE_RANGE_SIZE = (VK_SAMPLER_MIPMAP_MODE_LINEAR - VK_SAMPLER_MIPMAP_MODE_NEAREST + 1), + VK_SAMPLER_MIPMAP_MODE_MAX_ENUM = 0x7FFFFFFF +} VkSamplerMipmapMode; + +typedef enum VkSamplerAddressMode { + VK_SAMPLER_ADDRESS_MODE_REPEAT = 0, + VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT = 1, + VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE = 2, + VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER = 3, + VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE = 4, + VK_SAMPLER_ADDRESS_MODE_BEGIN_RANGE = VK_SAMPLER_ADDRESS_MODE_REPEAT, + VK_SAMPLER_ADDRESS_MODE_END_RANGE = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, + VK_SAMPLER_ADDRESS_MODE_RANGE_SIZE = (VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER - VK_SAMPLER_ADDRESS_MODE_REPEAT + 1), + VK_SAMPLER_ADDRESS_MODE_MAX_ENUM = 0x7FFFFFFF +} VkSamplerAddressMode; + +typedef enum VkBorderColor { + VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK = 0, + VK_BORDER_COLOR_INT_TRANSPARENT_BLACK = 1, + VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK = 2, + VK_BORDER_COLOR_INT_OPAQUE_BLACK = 3, + VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE = 4, + VK_BORDER_COLOR_INT_OPAQUE_WHITE = 5, + VK_BORDER_COLOR_BEGIN_RANGE = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK, + VK_BORDER_COLOR_END_RANGE = VK_BORDER_COLOR_INT_OPAQUE_WHITE, + VK_BORDER_COLOR_RANGE_SIZE = (VK_BORDER_COLOR_INT_OPAQUE_WHITE - VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK + 1), + VK_BORDER_COLOR_MAX_ENUM = 0x7FFFFFFF +} VkBorderColor; + +typedef enum VkDescriptorType { + VK_DESCRIPTOR_TYPE_SAMPLER = 0, + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER = 1, + VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE = 2, + VK_DESCRIPTOR_TYPE_STORAGE_IMAGE = 3, + VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER = 4, + VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER = 5, + VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER = 6, + VK_DESCRIPTOR_TYPE_STORAGE_BUFFER = 7, + VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC = 8, + VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC = 9, + VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT = 10, + VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT = 1000138000, + VK_DESCRIPTOR_TYPE_BEGIN_RANGE = VK_DESCRIPTOR_TYPE_SAMPLER, + VK_DESCRIPTOR_TYPE_END_RANGE = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, + VK_DESCRIPTOR_TYPE_RANGE_SIZE = (VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT - VK_DESCRIPTOR_TYPE_SAMPLER + 1), + VK_DESCRIPTOR_TYPE_MAX_ENUM = 0x7FFFFFFF +} VkDescriptorType; + +typedef enum VkAttachmentLoadOp { + VK_ATTACHMENT_LOAD_OP_LOAD = 0, + VK_ATTACHMENT_LOAD_OP_CLEAR = 1, + VK_ATTACHMENT_LOAD_OP_DONT_CARE = 2, + VK_ATTACHMENT_LOAD_OP_BEGIN_RANGE = VK_ATTACHMENT_LOAD_OP_LOAD, + VK_ATTACHMENT_LOAD_OP_END_RANGE = VK_ATTACHMENT_LOAD_OP_DONT_CARE, + VK_ATTACHMENT_LOAD_OP_RANGE_SIZE = (VK_ATTACHMENT_LOAD_OP_DONT_CARE - VK_ATTACHMENT_LOAD_OP_LOAD + 1), + VK_ATTACHMENT_LOAD_OP_MAX_ENUM = 0x7FFFFFFF +} VkAttachmentLoadOp; + +typedef enum VkAttachmentStoreOp { + VK_ATTACHMENT_STORE_OP_STORE = 0, + VK_ATTACHMENT_STORE_OP_DONT_CARE = 1, + VK_ATTACHMENT_STORE_OP_BEGIN_RANGE = VK_ATTACHMENT_STORE_OP_STORE, + VK_ATTACHMENT_STORE_OP_END_RANGE = VK_ATTACHMENT_STORE_OP_DONT_CARE, + VK_ATTACHMENT_STORE_OP_RANGE_SIZE = (VK_ATTACHMENT_STORE_OP_DONT_CARE - VK_ATTACHMENT_STORE_OP_STORE + 1), + VK_ATTACHMENT_STORE_OP_MAX_ENUM = 0x7FFFFFFF +} VkAttachmentStoreOp; + +typedef enum VkPipelineBindPoint { + VK_PIPELINE_BIND_POINT_GRAPHICS = 0, + VK_PIPELINE_BIND_POINT_COMPUTE = 1, + VK_PIPELINE_BIND_POINT_BEGIN_RANGE = VK_PIPELINE_BIND_POINT_GRAPHICS, + VK_PIPELINE_BIND_POINT_END_RANGE = VK_PIPELINE_BIND_POINT_COMPUTE, + VK_PIPELINE_BIND_POINT_RANGE_SIZE = (VK_PIPELINE_BIND_POINT_COMPUTE - VK_PIPELINE_BIND_POINT_GRAPHICS + 1), + VK_PIPELINE_BIND_POINT_MAX_ENUM = 0x7FFFFFFF +} VkPipelineBindPoint; + +typedef enum VkCommandBufferLevel { + VK_COMMAND_BUFFER_LEVEL_PRIMARY = 0, + VK_COMMAND_BUFFER_LEVEL_SECONDARY = 1, + VK_COMMAND_BUFFER_LEVEL_BEGIN_RANGE = VK_COMMAND_BUFFER_LEVEL_PRIMARY, + VK_COMMAND_BUFFER_LEVEL_END_RANGE = VK_COMMAND_BUFFER_LEVEL_SECONDARY, + VK_COMMAND_BUFFER_LEVEL_RANGE_SIZE = (VK_COMMAND_BUFFER_LEVEL_SECONDARY - VK_COMMAND_BUFFER_LEVEL_PRIMARY + 1), + VK_COMMAND_BUFFER_LEVEL_MAX_ENUM = 0x7FFFFFFF +} VkCommandBufferLevel; + +typedef enum VkIndexType { + VK_INDEX_TYPE_UINT16 = 0, + VK_INDEX_TYPE_UINT32 = 1, + VK_INDEX_TYPE_BEGIN_RANGE = VK_INDEX_TYPE_UINT16, + VK_INDEX_TYPE_END_RANGE = VK_INDEX_TYPE_UINT32, + VK_INDEX_TYPE_RANGE_SIZE = (VK_INDEX_TYPE_UINT32 - VK_INDEX_TYPE_UINT16 + 1), + VK_INDEX_TYPE_MAX_ENUM = 0x7FFFFFFF +} VkIndexType; + +typedef enum VkSubpassContents { + VK_SUBPASS_CONTENTS_INLINE = 0, + VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS = 1, + VK_SUBPASS_CONTENTS_BEGIN_RANGE = VK_SUBPASS_CONTENTS_INLINE, + VK_SUBPASS_CONTENTS_END_RANGE = VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS, + VK_SUBPASS_CONTENTS_RANGE_SIZE = (VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS - VK_SUBPASS_CONTENTS_INLINE + 1), + VK_SUBPASS_CONTENTS_MAX_ENUM = 0x7FFFFFFF +} VkSubpassContents; + +typedef enum VkObjectType { + VK_OBJECT_TYPE_UNKNOWN = 0, + VK_OBJECT_TYPE_INSTANCE = 1, + VK_OBJECT_TYPE_PHYSICAL_DEVICE = 2, + VK_OBJECT_TYPE_DEVICE = 3, + VK_OBJECT_TYPE_QUEUE = 4, + VK_OBJECT_TYPE_SEMAPHORE = 5, + VK_OBJECT_TYPE_COMMAND_BUFFER = 6, + VK_OBJECT_TYPE_FENCE = 7, + VK_OBJECT_TYPE_DEVICE_MEMORY = 8, + VK_OBJECT_TYPE_BUFFER = 9, + VK_OBJECT_TYPE_IMAGE = 10, + VK_OBJECT_TYPE_EVENT = 11, + VK_OBJECT_TYPE_QUERY_POOL = 12, + VK_OBJECT_TYPE_BUFFER_VIEW = 13, + VK_OBJECT_TYPE_IMAGE_VIEW = 14, + VK_OBJECT_TYPE_SHADER_MODULE = 15, + VK_OBJECT_TYPE_PIPELINE_CACHE = 16, + VK_OBJECT_TYPE_PIPELINE_LAYOUT = 17, + VK_OBJECT_TYPE_RENDER_PASS = 18, + VK_OBJECT_TYPE_PIPELINE = 19, + VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT = 20, + VK_OBJECT_TYPE_SAMPLER = 21, + VK_OBJECT_TYPE_DESCRIPTOR_POOL = 22, + VK_OBJECT_TYPE_DESCRIPTOR_SET = 23, + VK_OBJECT_TYPE_FRAMEBUFFER = 24, + VK_OBJECT_TYPE_COMMAND_POOL = 25, + VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION = 1000156000, + VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE = 1000085000, + VK_OBJECT_TYPE_SURFACE_KHR = 1000000000, + VK_OBJECT_TYPE_SWAPCHAIN_KHR = 1000001000, + VK_OBJECT_TYPE_DISPLAY_KHR = 1000002000, + VK_OBJECT_TYPE_DISPLAY_MODE_KHR = 1000002001, + VK_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT = 1000011000, + VK_OBJECT_TYPE_OBJECT_TABLE_NVX = 1000086000, + VK_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NVX = 1000086001, + VK_OBJECT_TYPE_DEBUG_UTILS_MESSENGER_EXT = 1000128000, + VK_OBJECT_TYPE_VALIDATION_CACHE_EXT = 1000160000, + VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_KHR = VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE, + VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION_KHR = VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION, + VK_OBJECT_TYPE_BEGIN_RANGE = VK_OBJECT_TYPE_UNKNOWN, + VK_OBJECT_TYPE_END_RANGE = VK_OBJECT_TYPE_COMMAND_POOL, + VK_OBJECT_TYPE_RANGE_SIZE = (VK_OBJECT_TYPE_COMMAND_POOL - VK_OBJECT_TYPE_UNKNOWN + 1), + VK_OBJECT_TYPE_MAX_ENUM = 0x7FFFFFFF +} VkObjectType; + +typedef enum VkVendorId { + VK_VENDOR_ID_VIV = 0x10001, + VK_VENDOR_ID_VSI = 0x10002, + VK_VENDOR_ID_KAZAN = 0x10003, + VK_VENDOR_ID_BEGIN_RANGE = VK_VENDOR_ID_VIV, + VK_VENDOR_ID_END_RANGE = VK_VENDOR_ID_KAZAN, + VK_VENDOR_ID_RANGE_SIZE = (VK_VENDOR_ID_KAZAN - VK_VENDOR_ID_VIV + 1), + VK_VENDOR_ID_MAX_ENUM = 0x7FFFFFFF +} VkVendorId; + +typedef VkFlags VkInstanceCreateFlags; + +typedef enum VkFormatFeatureFlagBits { + VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT = 0x00000001, + VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT = 0x00000002, + VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT = 0x00000004, + VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT = 0x00000008, + VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT = 0x00000010, + VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT = 0x00000020, + VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT = 0x00000040, + VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT = 0x00000080, + VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT = 0x00000100, + VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT = 0x00000200, + VK_FORMAT_FEATURE_BLIT_SRC_BIT = 0x00000400, + VK_FORMAT_FEATURE_BLIT_DST_BIT = 0x00000800, + VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT = 0x00001000, + VK_FORMAT_FEATURE_TRANSFER_SRC_BIT = 0x00004000, + VK_FORMAT_FEATURE_TRANSFER_DST_BIT = 0x00008000, + VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT = 0x00020000, + VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT = 0x00040000, + VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT = 0x00080000, + VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_BIT = 0x00100000, + VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_FORCEABLE_BIT = 0x00200000, + VK_FORMAT_FEATURE_DISJOINT_BIT = 0x00400000, + VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT = 0x00800000, + VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG = 0x00002000, + VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT = 0x00010000, + VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR = VK_FORMAT_FEATURE_TRANSFER_SRC_BIT, + VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR = VK_FORMAT_FEATURE_TRANSFER_DST_BIT, + VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT_KHR = VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT, + VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT_KHR = VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT, + VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT_KHR = VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT, + VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_BIT_KHR = VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_BIT, + VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_FORCEABLE_BIT_KHR = VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_FORCEABLE_BIT, + VK_FORMAT_FEATURE_DISJOINT_BIT_KHR = VK_FORMAT_FEATURE_DISJOINT_BIT, + VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT_KHR = VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT, + VK_FORMAT_FEATURE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkFormatFeatureFlagBits; +typedef VkFlags VkFormatFeatureFlags; + +typedef enum VkImageUsageFlagBits { + VK_IMAGE_USAGE_TRANSFER_SRC_BIT = 0x00000001, + VK_IMAGE_USAGE_TRANSFER_DST_BIT = 0x00000002, + VK_IMAGE_USAGE_SAMPLED_BIT = 0x00000004, + VK_IMAGE_USAGE_STORAGE_BIT = 0x00000008, + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT = 0x00000010, + VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT = 0x00000020, + VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT = 0x00000040, + VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT = 0x00000080, + VK_IMAGE_USAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkImageUsageFlagBits; +typedef VkFlags VkImageUsageFlags; + +typedef enum VkImageCreateFlagBits { + VK_IMAGE_CREATE_SPARSE_BINDING_BIT = 0x00000001, + VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT = 0x00000002, + VK_IMAGE_CREATE_SPARSE_ALIASED_BIT = 0x00000004, + VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT = 0x00000008, + VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT = 0x00000010, + VK_IMAGE_CREATE_ALIAS_BIT = 0x00000400, + VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT = 0x00000040, + VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT = 0x00000020, + VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT = 0x00000080, + VK_IMAGE_CREATE_EXTENDED_USAGE_BIT = 0x00000100, + VK_IMAGE_CREATE_PROTECTED_BIT = 0x00000800, + VK_IMAGE_CREATE_DISJOINT_BIT = 0x00000200, + VK_IMAGE_CREATE_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_EXT = 0x00001000, + VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHR = VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT, + VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR = VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT, + VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT_KHR = VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT, + VK_IMAGE_CREATE_EXTENDED_USAGE_BIT_KHR = VK_IMAGE_CREATE_EXTENDED_USAGE_BIT, + VK_IMAGE_CREATE_DISJOINT_BIT_KHR = VK_IMAGE_CREATE_DISJOINT_BIT, + VK_IMAGE_CREATE_ALIAS_BIT_KHR = VK_IMAGE_CREATE_ALIAS_BIT, + VK_IMAGE_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkImageCreateFlagBits; +typedef VkFlags VkImageCreateFlags; + +typedef enum VkSampleCountFlagBits { + VK_SAMPLE_COUNT_1_BIT = 0x00000001, + VK_SAMPLE_COUNT_2_BIT = 0x00000002, + VK_SAMPLE_COUNT_4_BIT = 0x00000004, + VK_SAMPLE_COUNT_8_BIT = 0x00000008, + VK_SAMPLE_COUNT_16_BIT = 0x00000010, + VK_SAMPLE_COUNT_32_BIT = 0x00000020, + VK_SAMPLE_COUNT_64_BIT = 0x00000040, + VK_SAMPLE_COUNT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkSampleCountFlagBits; +typedef VkFlags VkSampleCountFlags; + +typedef enum VkQueueFlagBits { + VK_QUEUE_GRAPHICS_BIT = 0x00000001, + VK_QUEUE_COMPUTE_BIT = 0x00000002, + VK_QUEUE_TRANSFER_BIT = 0x00000004, + VK_QUEUE_SPARSE_BINDING_BIT = 0x00000008, + VK_QUEUE_PROTECTED_BIT = 0x00000010, + VK_QUEUE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkQueueFlagBits; +typedef VkFlags VkQueueFlags; + +typedef enum VkMemoryPropertyFlagBits { + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT = 0x00000001, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT = 0x00000002, + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT = 0x00000004, + VK_MEMORY_PROPERTY_HOST_CACHED_BIT = 0x00000008, + VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT = 0x00000010, + VK_MEMORY_PROPERTY_PROTECTED_BIT = 0x00000020, + VK_MEMORY_PROPERTY_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkMemoryPropertyFlagBits; +typedef VkFlags VkMemoryPropertyFlags; + +typedef enum VkMemoryHeapFlagBits { + VK_MEMORY_HEAP_DEVICE_LOCAL_BIT = 0x00000001, + VK_MEMORY_HEAP_MULTI_INSTANCE_BIT = 0x00000002, + VK_MEMORY_HEAP_MULTI_INSTANCE_BIT_KHR = VK_MEMORY_HEAP_MULTI_INSTANCE_BIT, + VK_MEMORY_HEAP_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkMemoryHeapFlagBits; +typedef VkFlags VkMemoryHeapFlags; +typedef VkFlags VkDeviceCreateFlags; + +typedef enum VkDeviceQueueCreateFlagBits { + VK_DEVICE_QUEUE_CREATE_PROTECTED_BIT = 0x00000001, + VK_DEVICE_QUEUE_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkDeviceQueueCreateFlagBits; +typedef VkFlags VkDeviceQueueCreateFlags; + +typedef enum VkPipelineStageFlagBits { + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT = 0x00000001, + VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT = 0x00000002, + VK_PIPELINE_STAGE_VERTEX_INPUT_BIT = 0x00000004, + VK_PIPELINE_STAGE_VERTEX_SHADER_BIT = 0x00000008, + VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT = 0x00000010, + VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT = 0x00000020, + VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT = 0x00000040, + VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT = 0x00000080, + VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT = 0x00000100, + VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT = 0x00000200, + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT = 0x00000400, + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT = 0x00000800, + VK_PIPELINE_STAGE_TRANSFER_BIT = 0x00001000, + VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT = 0x00002000, + VK_PIPELINE_STAGE_HOST_BIT = 0x00004000, + VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT = 0x00008000, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT = 0x00010000, + VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT = 0x00040000, + VK_PIPELINE_STAGE_COMMAND_PROCESS_BIT_NVX = 0x00020000, + VK_PIPELINE_STAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkPipelineStageFlagBits; +typedef VkFlags VkPipelineStageFlags; +typedef VkFlags VkMemoryMapFlags; + +typedef enum VkImageAspectFlagBits { + VK_IMAGE_ASPECT_COLOR_BIT = 0x00000001, + VK_IMAGE_ASPECT_DEPTH_BIT = 0x00000002, + VK_IMAGE_ASPECT_STENCIL_BIT = 0x00000004, + VK_IMAGE_ASPECT_METADATA_BIT = 0x00000008, + VK_IMAGE_ASPECT_PLANE_0_BIT = 0x00000010, + VK_IMAGE_ASPECT_PLANE_1_BIT = 0x00000020, + VK_IMAGE_ASPECT_PLANE_2_BIT = 0x00000040, + VK_IMAGE_ASPECT_PLANE_0_BIT_KHR = VK_IMAGE_ASPECT_PLANE_0_BIT, + VK_IMAGE_ASPECT_PLANE_1_BIT_KHR = VK_IMAGE_ASPECT_PLANE_1_BIT, + VK_IMAGE_ASPECT_PLANE_2_BIT_KHR = VK_IMAGE_ASPECT_PLANE_2_BIT, + VK_IMAGE_ASPECT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkImageAspectFlagBits; +typedef VkFlags VkImageAspectFlags; + +typedef enum VkSparseImageFormatFlagBits { + VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT = 0x00000001, + VK_SPARSE_IMAGE_FORMAT_ALIGNED_MIP_SIZE_BIT = 0x00000002, + VK_SPARSE_IMAGE_FORMAT_NONSTANDARD_BLOCK_SIZE_BIT = 0x00000004, + VK_SPARSE_IMAGE_FORMAT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkSparseImageFormatFlagBits; +typedef VkFlags VkSparseImageFormatFlags; + +typedef enum VkSparseMemoryBindFlagBits { + VK_SPARSE_MEMORY_BIND_METADATA_BIT = 0x00000001, + VK_SPARSE_MEMORY_BIND_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkSparseMemoryBindFlagBits; +typedef VkFlags VkSparseMemoryBindFlags; + +typedef enum VkFenceCreateFlagBits { + VK_FENCE_CREATE_SIGNALED_BIT = 0x00000001, + VK_FENCE_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkFenceCreateFlagBits; +typedef VkFlags VkFenceCreateFlags; +typedef VkFlags VkSemaphoreCreateFlags; +typedef VkFlags VkEventCreateFlags; +typedef VkFlags VkQueryPoolCreateFlags; + +typedef enum VkQueryPipelineStatisticFlagBits { + VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT = 0x00000001, + VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT = 0x00000002, + VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT = 0x00000004, + VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT = 0x00000008, + VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT = 0x00000010, + VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT = 0x00000020, + VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT = 0x00000040, + VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT = 0x00000080, + VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT = 0x00000100, + VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT = 0x00000200, + VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT = 0x00000400, + VK_QUERY_PIPELINE_STATISTIC_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkQueryPipelineStatisticFlagBits; +typedef VkFlags VkQueryPipelineStatisticFlags; + +typedef enum VkQueryResultFlagBits { + VK_QUERY_RESULT_64_BIT = 0x00000001, + VK_QUERY_RESULT_WAIT_BIT = 0x00000002, + VK_QUERY_RESULT_WITH_AVAILABILITY_BIT = 0x00000004, + VK_QUERY_RESULT_PARTIAL_BIT = 0x00000008, + VK_QUERY_RESULT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkQueryResultFlagBits; +typedef VkFlags VkQueryResultFlags; + +typedef enum VkBufferCreateFlagBits { + VK_BUFFER_CREATE_SPARSE_BINDING_BIT = 0x00000001, + VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT = 0x00000002, + VK_BUFFER_CREATE_SPARSE_ALIASED_BIT = 0x00000004, + VK_BUFFER_CREATE_PROTECTED_BIT = 0x00000008, + VK_BUFFER_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkBufferCreateFlagBits; +typedef VkFlags VkBufferCreateFlags; + +typedef enum VkBufferUsageFlagBits { + VK_BUFFER_USAGE_TRANSFER_SRC_BIT = 0x00000001, + VK_BUFFER_USAGE_TRANSFER_DST_BIT = 0x00000002, + VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT = 0x00000004, + VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT = 0x00000008, + VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT = 0x00000010, + VK_BUFFER_USAGE_STORAGE_BUFFER_BIT = 0x00000020, + VK_BUFFER_USAGE_INDEX_BUFFER_BIT = 0x00000040, + VK_BUFFER_USAGE_VERTEX_BUFFER_BIT = 0x00000080, + VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT = 0x00000100, + VK_BUFFER_USAGE_CONDITIONAL_RENDERING_BIT_EXT = 0x00000200, + VK_BUFFER_USAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkBufferUsageFlagBits; +typedef VkFlags VkBufferUsageFlags; +typedef VkFlags VkBufferViewCreateFlags; +typedef VkFlags VkImageViewCreateFlags; +typedef VkFlags VkShaderModuleCreateFlags; +typedef VkFlags VkPipelineCacheCreateFlags; + +typedef enum VkPipelineCreateFlagBits { + VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT = 0x00000001, + VK_PIPELINE_CREATE_ALLOW_DERIVATIVES_BIT = 0x00000002, + VK_PIPELINE_CREATE_DERIVATIVE_BIT = 0x00000004, + VK_PIPELINE_CREATE_VIEW_INDEX_FROM_DEVICE_INDEX_BIT = 0x00000008, + VK_PIPELINE_CREATE_DISPATCH_BASE = 0x00000010, + VK_PIPELINE_CREATE_VIEW_INDEX_FROM_DEVICE_INDEX_BIT_KHR = VK_PIPELINE_CREATE_VIEW_INDEX_FROM_DEVICE_INDEX_BIT, + VK_PIPELINE_CREATE_DISPATCH_BASE_KHR = VK_PIPELINE_CREATE_DISPATCH_BASE, + VK_PIPELINE_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkPipelineCreateFlagBits; +typedef VkFlags VkPipelineCreateFlags; +typedef VkFlags VkPipelineShaderStageCreateFlags; + +typedef enum VkShaderStageFlagBits { + VK_SHADER_STAGE_VERTEX_BIT = 0x00000001, + VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT = 0x00000002, + VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT = 0x00000004, + VK_SHADER_STAGE_GEOMETRY_BIT = 0x00000008, + VK_SHADER_STAGE_FRAGMENT_BIT = 0x00000010, + VK_SHADER_STAGE_COMPUTE_BIT = 0x00000020, + VK_SHADER_STAGE_ALL_GRAPHICS = 0x0000001F, + VK_SHADER_STAGE_ALL = 0x7FFFFFFF, + VK_SHADER_STAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkShaderStageFlagBits; +typedef VkFlags VkPipelineVertexInputStateCreateFlags; +typedef VkFlags VkPipelineInputAssemblyStateCreateFlags; +typedef VkFlags VkPipelineTessellationStateCreateFlags; +typedef VkFlags VkPipelineViewportStateCreateFlags; +typedef VkFlags VkPipelineRasterizationStateCreateFlags; + +typedef enum VkCullModeFlagBits { + VK_CULL_MODE_NONE = 0, + VK_CULL_MODE_FRONT_BIT = 0x00000001, + VK_CULL_MODE_BACK_BIT = 0x00000002, + VK_CULL_MODE_FRONT_AND_BACK = 0x00000003, + VK_CULL_MODE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkCullModeFlagBits; +typedef VkFlags VkCullModeFlags; +typedef VkFlags VkPipelineMultisampleStateCreateFlags; +typedef VkFlags VkPipelineDepthStencilStateCreateFlags; +typedef VkFlags VkPipelineColorBlendStateCreateFlags; + +typedef enum VkColorComponentFlagBits { + VK_COLOR_COMPONENT_R_BIT = 0x00000001, + VK_COLOR_COMPONENT_G_BIT = 0x00000002, + VK_COLOR_COMPONENT_B_BIT = 0x00000004, + VK_COLOR_COMPONENT_A_BIT = 0x00000008, + VK_COLOR_COMPONENT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkColorComponentFlagBits; +typedef VkFlags VkColorComponentFlags; +typedef VkFlags VkPipelineDynamicStateCreateFlags; +typedef VkFlags VkPipelineLayoutCreateFlags; +typedef VkFlags VkShaderStageFlags; +typedef VkFlags VkSamplerCreateFlags; + +typedef enum VkDescriptorSetLayoutCreateFlagBits { + VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR = 0x00000001, + VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT = 0x00000002, + VK_DESCRIPTOR_SET_LAYOUT_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkDescriptorSetLayoutCreateFlagBits; +typedef VkFlags VkDescriptorSetLayoutCreateFlags; + +typedef enum VkDescriptorPoolCreateFlagBits { + VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT = 0x00000001, + VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT = 0x00000002, + VK_DESCRIPTOR_POOL_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkDescriptorPoolCreateFlagBits; +typedef VkFlags VkDescriptorPoolCreateFlags; +typedef VkFlags VkDescriptorPoolResetFlags; +typedef VkFlags VkFramebufferCreateFlags; +typedef VkFlags VkRenderPassCreateFlags; + +typedef enum VkAttachmentDescriptionFlagBits { + VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT = 0x00000001, + VK_ATTACHMENT_DESCRIPTION_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkAttachmentDescriptionFlagBits; +typedef VkFlags VkAttachmentDescriptionFlags; + +typedef enum VkSubpassDescriptionFlagBits { + VK_SUBPASS_DESCRIPTION_PER_VIEW_ATTRIBUTES_BIT_NVX = 0x00000001, + VK_SUBPASS_DESCRIPTION_PER_VIEW_POSITION_X_ONLY_BIT_NVX = 0x00000002, + VK_SUBPASS_DESCRIPTION_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkSubpassDescriptionFlagBits; +typedef VkFlags VkSubpassDescriptionFlags; + +typedef enum VkAccessFlagBits { + VK_ACCESS_INDIRECT_COMMAND_READ_BIT = 0x00000001, + VK_ACCESS_INDEX_READ_BIT = 0x00000002, + VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT = 0x00000004, + VK_ACCESS_UNIFORM_READ_BIT = 0x00000008, + VK_ACCESS_INPUT_ATTACHMENT_READ_BIT = 0x00000010, + VK_ACCESS_SHADER_READ_BIT = 0x00000020, + VK_ACCESS_SHADER_WRITE_BIT = 0x00000040, + VK_ACCESS_COLOR_ATTACHMENT_READ_BIT = 0x00000080, + VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT = 0x00000100, + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT = 0x00000200, + VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT = 0x00000400, + VK_ACCESS_TRANSFER_READ_BIT = 0x00000800, + VK_ACCESS_TRANSFER_WRITE_BIT = 0x00001000, + VK_ACCESS_HOST_READ_BIT = 0x00002000, + VK_ACCESS_HOST_WRITE_BIT = 0x00004000, + VK_ACCESS_MEMORY_READ_BIT = 0x00008000, + VK_ACCESS_MEMORY_WRITE_BIT = 0x00010000, + VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT = 0x00100000, + VK_ACCESS_COMMAND_PROCESS_READ_BIT_NVX = 0x00020000, + VK_ACCESS_COMMAND_PROCESS_WRITE_BIT_NVX = 0x00040000, + VK_ACCESS_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT = 0x00080000, + VK_ACCESS_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkAccessFlagBits; +typedef VkFlags VkAccessFlags; + +typedef enum VkDependencyFlagBits { + VK_DEPENDENCY_BY_REGION_BIT = 0x00000001, + VK_DEPENDENCY_DEVICE_GROUP_BIT = 0x00000004, + VK_DEPENDENCY_VIEW_LOCAL_BIT = 0x00000002, + VK_DEPENDENCY_VIEW_LOCAL_BIT_KHR = VK_DEPENDENCY_VIEW_LOCAL_BIT, + VK_DEPENDENCY_DEVICE_GROUP_BIT_KHR = VK_DEPENDENCY_DEVICE_GROUP_BIT, + VK_DEPENDENCY_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkDependencyFlagBits; +typedef VkFlags VkDependencyFlags; + +typedef enum VkCommandPoolCreateFlagBits { + VK_COMMAND_POOL_CREATE_TRANSIENT_BIT = 0x00000001, + VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT = 0x00000002, + VK_COMMAND_POOL_CREATE_PROTECTED_BIT = 0x00000004, + VK_COMMAND_POOL_CREATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkCommandPoolCreateFlagBits; +typedef VkFlags VkCommandPoolCreateFlags; + +typedef enum VkCommandPoolResetFlagBits { + VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT = 0x00000001, + VK_COMMAND_POOL_RESET_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkCommandPoolResetFlagBits; +typedef VkFlags VkCommandPoolResetFlags; + +typedef enum VkCommandBufferUsageFlagBits { + VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT = 0x00000001, + VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT = 0x00000002, + VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT = 0x00000004, + VK_COMMAND_BUFFER_USAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkCommandBufferUsageFlagBits; +typedef VkFlags VkCommandBufferUsageFlags; + +typedef enum VkQueryControlFlagBits { + VK_QUERY_CONTROL_PRECISE_BIT = 0x00000001, + VK_QUERY_CONTROL_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkQueryControlFlagBits; +typedef VkFlags VkQueryControlFlags; + +typedef enum VkCommandBufferResetFlagBits { + VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT = 0x00000001, + VK_COMMAND_BUFFER_RESET_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkCommandBufferResetFlagBits; +typedef VkFlags VkCommandBufferResetFlags; + +typedef enum VkStencilFaceFlagBits { + VK_STENCIL_FACE_FRONT_BIT = 0x00000001, + VK_STENCIL_FACE_BACK_BIT = 0x00000002, + VK_STENCIL_FRONT_AND_BACK = 0x00000003, + VK_STENCIL_FACE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkStencilFaceFlagBits; +typedef VkFlags VkStencilFaceFlags; + +typedef struct VkApplicationInfo { + VkStructureType sType; + const void* pNext; + const char* pApplicationName; + uint32_t applicationVersion; + const char* pEngineName; + uint32_t engineVersion; + uint32_t apiVersion; +} VkApplicationInfo; + +typedef struct VkInstanceCreateInfo { + VkStructureType sType; + const void* pNext; + VkInstanceCreateFlags flags; + const VkApplicationInfo* pApplicationInfo; + uint32_t enabledLayerCount; + const char* const* ppEnabledLayerNames; + uint32_t enabledExtensionCount; + const char* const* ppEnabledExtensionNames; +} VkInstanceCreateInfo; + +typedef void* (VKAPI_PTR *PFN_vkAllocationFunction)( + void* pUserData, + size_t size, + size_t alignment, + VkSystemAllocationScope allocationScope); + +typedef void* (VKAPI_PTR *PFN_vkReallocationFunction)( + void* pUserData, + void* pOriginal, + size_t size, + size_t alignment, + VkSystemAllocationScope allocationScope); + +typedef void (VKAPI_PTR *PFN_vkFreeFunction)( + void* pUserData, + void* pMemory); + +typedef void (VKAPI_PTR *PFN_vkInternalAllocationNotification)( + void* pUserData, + size_t size, + VkInternalAllocationType allocationType, + VkSystemAllocationScope allocationScope); + +typedef void (VKAPI_PTR *PFN_vkInternalFreeNotification)( + void* pUserData, + size_t size, + VkInternalAllocationType allocationType, + VkSystemAllocationScope allocationScope); + +typedef struct VkAllocationCallbacks { + void* pUserData; + PFN_vkAllocationFunction pfnAllocation; + PFN_vkReallocationFunction pfnReallocation; + PFN_vkFreeFunction pfnFree; + PFN_vkInternalAllocationNotification pfnInternalAllocation; + PFN_vkInternalFreeNotification pfnInternalFree; +} VkAllocationCallbacks; + +typedef struct VkPhysicalDeviceFeatures { + VkBool32 robustBufferAccess; + VkBool32 fullDrawIndexUint32; + VkBool32 imageCubeArray; + VkBool32 independentBlend; + VkBool32 geometryShader; + VkBool32 tessellationShader; + VkBool32 sampleRateShading; + VkBool32 dualSrcBlend; + VkBool32 logicOp; + VkBool32 multiDrawIndirect; + VkBool32 drawIndirectFirstInstance; + VkBool32 depthClamp; + VkBool32 depthBiasClamp; + VkBool32 fillModeNonSolid; + VkBool32 depthBounds; + VkBool32 wideLines; + VkBool32 largePoints; + VkBool32 alphaToOne; + VkBool32 multiViewport; + VkBool32 samplerAnisotropy; + VkBool32 textureCompressionETC2; + VkBool32 textureCompressionASTC_LDR; + VkBool32 textureCompressionBC; + VkBool32 occlusionQueryPrecise; + VkBool32 pipelineStatisticsQuery; + VkBool32 vertexPipelineStoresAndAtomics; + VkBool32 fragmentStoresAndAtomics; + VkBool32 shaderTessellationAndGeometryPointSize; + VkBool32 shaderImageGatherExtended; + VkBool32 shaderStorageImageExtendedFormats; + VkBool32 shaderStorageImageMultisample; + VkBool32 shaderStorageImageReadWithoutFormat; + VkBool32 shaderStorageImageWriteWithoutFormat; + VkBool32 shaderUniformBufferArrayDynamicIndexing; + VkBool32 shaderSampledImageArrayDynamicIndexing; + VkBool32 shaderStorageBufferArrayDynamicIndexing; + VkBool32 shaderStorageImageArrayDynamicIndexing; + VkBool32 shaderClipDistance; + VkBool32 shaderCullDistance; + VkBool32 shaderFloat64; + VkBool32 shaderInt64; + VkBool32 shaderInt16; + VkBool32 shaderResourceResidency; + VkBool32 shaderResourceMinLod; + VkBool32 sparseBinding; + VkBool32 sparseResidencyBuffer; + VkBool32 sparseResidencyImage2D; + VkBool32 sparseResidencyImage3D; + VkBool32 sparseResidency2Samples; + VkBool32 sparseResidency4Samples; + VkBool32 sparseResidency8Samples; + VkBool32 sparseResidency16Samples; + VkBool32 sparseResidencyAliased; + VkBool32 variableMultisampleRate; + VkBool32 inheritedQueries; +} VkPhysicalDeviceFeatures; + +typedef struct VkFormatProperties { + VkFormatFeatureFlags linearTilingFeatures; + VkFormatFeatureFlags optimalTilingFeatures; + VkFormatFeatureFlags bufferFeatures; +} VkFormatProperties; + +typedef struct VkExtent3D { + uint32_t width; + uint32_t height; + uint32_t depth; +} VkExtent3D; + +typedef struct VkImageFormatProperties { + VkExtent3D maxExtent; + uint32_t maxMipLevels; + uint32_t maxArrayLayers; + VkSampleCountFlags sampleCounts; + VkDeviceSize maxResourceSize; +} VkImageFormatProperties; + +typedef struct VkPhysicalDeviceLimits { + uint32_t maxImageDimension1D; + uint32_t maxImageDimension2D; + uint32_t maxImageDimension3D; + uint32_t maxImageDimensionCube; + uint32_t maxImageArrayLayers; + uint32_t maxTexelBufferElements; + uint32_t maxUniformBufferRange; + uint32_t maxStorageBufferRange; + uint32_t maxPushConstantsSize; + uint32_t maxMemoryAllocationCount; + uint32_t maxSamplerAllocationCount; + VkDeviceSize bufferImageGranularity; + VkDeviceSize sparseAddressSpaceSize; + uint32_t maxBoundDescriptorSets; + uint32_t maxPerStageDescriptorSamplers; + uint32_t maxPerStageDescriptorUniformBuffers; + uint32_t maxPerStageDescriptorStorageBuffers; + uint32_t maxPerStageDescriptorSampledImages; + uint32_t maxPerStageDescriptorStorageImages; + uint32_t maxPerStageDescriptorInputAttachments; + uint32_t maxPerStageResources; + uint32_t maxDescriptorSetSamplers; + uint32_t maxDescriptorSetUniformBuffers; + uint32_t maxDescriptorSetUniformBuffersDynamic; + uint32_t maxDescriptorSetStorageBuffers; + uint32_t maxDescriptorSetStorageBuffersDynamic; + uint32_t maxDescriptorSetSampledImages; + uint32_t maxDescriptorSetStorageImages; + uint32_t maxDescriptorSetInputAttachments; + uint32_t maxVertexInputAttributes; + uint32_t maxVertexInputBindings; + uint32_t maxVertexInputAttributeOffset; + uint32_t maxVertexInputBindingStride; + uint32_t maxVertexOutputComponents; + uint32_t maxTessellationGenerationLevel; + uint32_t maxTessellationPatchSize; + uint32_t maxTessellationControlPerVertexInputComponents; + uint32_t maxTessellationControlPerVertexOutputComponents; + uint32_t maxTessellationControlPerPatchOutputComponents; + uint32_t maxTessellationControlTotalOutputComponents; + uint32_t maxTessellationEvaluationInputComponents; + uint32_t maxTessellationEvaluationOutputComponents; + uint32_t maxGeometryShaderInvocations; + uint32_t maxGeometryInputComponents; + uint32_t maxGeometryOutputComponents; + uint32_t maxGeometryOutputVertices; + uint32_t maxGeometryTotalOutputComponents; + uint32_t maxFragmentInputComponents; + uint32_t maxFragmentOutputAttachments; + uint32_t maxFragmentDualSrcAttachments; + uint32_t maxFragmentCombinedOutputResources; + uint32_t maxComputeSharedMemorySize; + uint32_t maxComputeWorkGroupCount[3]; + uint32_t maxComputeWorkGroupInvocations; + uint32_t maxComputeWorkGroupSize[3]; + uint32_t subPixelPrecisionBits; + uint32_t subTexelPrecisionBits; + uint32_t mipmapPrecisionBits; + uint32_t maxDrawIndexedIndexValue; + uint32_t maxDrawIndirectCount; + float maxSamplerLodBias; + float maxSamplerAnisotropy; + uint32_t maxViewports; + uint32_t maxViewportDimensions[2]; + float viewportBoundsRange[2]; + uint32_t viewportSubPixelBits; + size_t minMemoryMapAlignment; + VkDeviceSize minTexelBufferOffsetAlignment; + VkDeviceSize minUniformBufferOffsetAlignment; + VkDeviceSize minStorageBufferOffsetAlignment; + int32_t minTexelOffset; + uint32_t maxTexelOffset; + int32_t minTexelGatherOffset; + uint32_t maxTexelGatherOffset; + float minInterpolationOffset; + float maxInterpolationOffset; + uint32_t subPixelInterpolationOffsetBits; + uint32_t maxFramebufferWidth; + uint32_t maxFramebufferHeight; + uint32_t maxFramebufferLayers; + VkSampleCountFlags framebufferColorSampleCounts; + VkSampleCountFlags framebufferDepthSampleCounts; + VkSampleCountFlags framebufferStencilSampleCounts; + VkSampleCountFlags framebufferNoAttachmentsSampleCounts; + uint32_t maxColorAttachments; + VkSampleCountFlags sampledImageColorSampleCounts; + VkSampleCountFlags sampledImageIntegerSampleCounts; + VkSampleCountFlags sampledImageDepthSampleCounts; + VkSampleCountFlags sampledImageStencilSampleCounts; + VkSampleCountFlags storageImageSampleCounts; + uint32_t maxSampleMaskWords; + VkBool32 timestampComputeAndGraphics; + float timestampPeriod; + uint32_t maxClipDistances; + uint32_t maxCullDistances; + uint32_t maxCombinedClipAndCullDistances; + uint32_t discreteQueuePriorities; + float pointSizeRange[2]; + float lineWidthRange[2]; + float pointSizeGranularity; + float lineWidthGranularity; + VkBool32 strictLines; + VkBool32 standardSampleLocations; + VkDeviceSize optimalBufferCopyOffsetAlignment; + VkDeviceSize optimalBufferCopyRowPitchAlignment; + VkDeviceSize nonCoherentAtomSize; +} VkPhysicalDeviceLimits; + +typedef struct VkPhysicalDeviceSparseProperties { + VkBool32 residencyStandard2DBlockShape; + VkBool32 residencyStandard2DMultisampleBlockShape; + VkBool32 residencyStandard3DBlockShape; + VkBool32 residencyAlignedMipSize; + VkBool32 residencyNonResidentStrict; +} VkPhysicalDeviceSparseProperties; + +typedef struct VkPhysicalDeviceProperties { + uint32_t apiVersion; + uint32_t driverVersion; + uint32_t vendorID; + uint32_t deviceID; + VkPhysicalDeviceType deviceType; + char deviceName[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE]; + uint8_t pipelineCacheUUID[VK_UUID_SIZE]; + VkPhysicalDeviceLimits limits; + VkPhysicalDeviceSparseProperties sparseProperties; +} VkPhysicalDeviceProperties; + +typedef struct VkQueueFamilyProperties { + VkQueueFlags queueFlags; + uint32_t queueCount; + uint32_t timestampValidBits; + VkExtent3D minImageTransferGranularity; +} VkQueueFamilyProperties; + +typedef struct VkMemoryType { + VkMemoryPropertyFlags propertyFlags; + uint32_t heapIndex; +} VkMemoryType; + +typedef struct VkMemoryHeap { + VkDeviceSize size; + VkMemoryHeapFlags flags; +} VkMemoryHeap; + +typedef struct VkPhysicalDeviceMemoryProperties { + uint32_t memoryTypeCount; + VkMemoryType memoryTypes[VK_MAX_MEMORY_TYPES]; + uint32_t memoryHeapCount; + VkMemoryHeap memoryHeaps[VK_MAX_MEMORY_HEAPS]; +} VkPhysicalDeviceMemoryProperties; + +typedef void (VKAPI_PTR *PFN_vkVoidFunction)(void); +typedef struct VkDeviceQueueCreateInfo { + VkStructureType sType; + const void* pNext; + VkDeviceQueueCreateFlags flags; + uint32_t queueFamilyIndex; + uint32_t queueCount; + const float* pQueuePriorities; +} VkDeviceQueueCreateInfo; + +typedef struct VkDeviceCreateInfo { + VkStructureType sType; + const void* pNext; + VkDeviceCreateFlags flags; + uint32_t queueCreateInfoCount; + const VkDeviceQueueCreateInfo* pQueueCreateInfos; + uint32_t enabledLayerCount; + const char* const* ppEnabledLayerNames; + uint32_t enabledExtensionCount; + const char* const* ppEnabledExtensionNames; + const VkPhysicalDeviceFeatures* pEnabledFeatures; +} VkDeviceCreateInfo; + +typedef struct VkExtensionProperties { + char extensionName[VK_MAX_EXTENSION_NAME_SIZE]; + uint32_t specVersion; +} VkExtensionProperties; + +typedef struct VkLayerProperties { + char layerName[VK_MAX_EXTENSION_NAME_SIZE]; + uint32_t specVersion; + uint32_t implementationVersion; + char description[VK_MAX_DESCRIPTION_SIZE]; +} VkLayerProperties; + +typedef struct VkSubmitInfo { + VkStructureType sType; + const void* pNext; + uint32_t waitSemaphoreCount; + const VkSemaphore* pWaitSemaphores; + const VkPipelineStageFlags* pWaitDstStageMask; + uint32_t commandBufferCount; + const VkCommandBuffer* pCommandBuffers; + uint32_t signalSemaphoreCount; + const VkSemaphore* pSignalSemaphores; +} VkSubmitInfo; + +typedef struct VkMemoryAllocateInfo { + VkStructureType sType; + const void* pNext; + VkDeviceSize allocationSize; + uint32_t memoryTypeIndex; +} VkMemoryAllocateInfo; + +typedef struct VkMappedMemoryRange { + VkStructureType sType; + const void* pNext; + VkDeviceMemory memory; + VkDeviceSize offset; + VkDeviceSize size; +} VkMappedMemoryRange; + +typedef struct VkMemoryRequirements { + VkDeviceSize size; + VkDeviceSize alignment; + uint32_t memoryTypeBits; +} VkMemoryRequirements; + +typedef struct VkSparseImageFormatProperties { + VkImageAspectFlags aspectMask; + VkExtent3D imageGranularity; + VkSparseImageFormatFlags flags; +} VkSparseImageFormatProperties; + +typedef struct VkSparseImageMemoryRequirements { + VkSparseImageFormatProperties formatProperties; + uint32_t imageMipTailFirstLod; + VkDeviceSize imageMipTailSize; + VkDeviceSize imageMipTailOffset; + VkDeviceSize imageMipTailStride; +} VkSparseImageMemoryRequirements; + +typedef struct VkSparseMemoryBind { + VkDeviceSize resourceOffset; + VkDeviceSize size; + VkDeviceMemory memory; + VkDeviceSize memoryOffset; + VkSparseMemoryBindFlags flags; +} VkSparseMemoryBind; + +typedef struct VkSparseBufferMemoryBindInfo { + VkBuffer buffer; + uint32_t bindCount; + const VkSparseMemoryBind* pBinds; +} VkSparseBufferMemoryBindInfo; + +typedef struct VkSparseImageOpaqueMemoryBindInfo { + VkImage image; + uint32_t bindCount; + const VkSparseMemoryBind* pBinds; +} VkSparseImageOpaqueMemoryBindInfo; + +typedef struct VkImageSubresource { + VkImageAspectFlags aspectMask; + uint32_t mipLevel; + uint32_t arrayLayer; +} VkImageSubresource; + +typedef struct VkOffset3D { + int32_t x; + int32_t y; + int32_t z; +} VkOffset3D; + +typedef struct VkSparseImageMemoryBind { + VkImageSubresource subresource; + VkOffset3D offset; + VkExtent3D extent; + VkDeviceMemory memory; + VkDeviceSize memoryOffset; + VkSparseMemoryBindFlags flags; +} VkSparseImageMemoryBind; + +typedef struct VkSparseImageMemoryBindInfo { + VkImage image; + uint32_t bindCount; + const VkSparseImageMemoryBind* pBinds; +} VkSparseImageMemoryBindInfo; + +typedef struct VkBindSparseInfo { + VkStructureType sType; + const void* pNext; + uint32_t waitSemaphoreCount; + const VkSemaphore* pWaitSemaphores; + uint32_t bufferBindCount; + const VkSparseBufferMemoryBindInfo* pBufferBinds; + uint32_t imageOpaqueBindCount; + const VkSparseImageOpaqueMemoryBindInfo* pImageOpaqueBinds; + uint32_t imageBindCount; + const VkSparseImageMemoryBindInfo* pImageBinds; + uint32_t signalSemaphoreCount; + const VkSemaphore* pSignalSemaphores; +} VkBindSparseInfo; + +typedef struct VkFenceCreateInfo { + VkStructureType sType; + const void* pNext; + VkFenceCreateFlags flags; +} VkFenceCreateInfo; + +typedef struct VkSemaphoreCreateInfo { + VkStructureType sType; + const void* pNext; + VkSemaphoreCreateFlags flags; +} VkSemaphoreCreateInfo; + +typedef struct VkEventCreateInfo { + VkStructureType sType; + const void* pNext; + VkEventCreateFlags flags; +} VkEventCreateInfo; + +typedef struct VkQueryPoolCreateInfo { + VkStructureType sType; + const void* pNext; + VkQueryPoolCreateFlags flags; + VkQueryType queryType; + uint32_t queryCount; + VkQueryPipelineStatisticFlags pipelineStatistics; +} VkQueryPoolCreateInfo; + +typedef struct VkBufferCreateInfo { + VkStructureType sType; + const void* pNext; + VkBufferCreateFlags flags; + VkDeviceSize size; + VkBufferUsageFlags usage; + VkSharingMode sharingMode; + uint32_t queueFamilyIndexCount; + const uint32_t* pQueueFamilyIndices; +} VkBufferCreateInfo; + +typedef struct VkBufferViewCreateInfo { + VkStructureType sType; + const void* pNext; + VkBufferViewCreateFlags flags; + VkBuffer buffer; + VkFormat format; + VkDeviceSize offset; + VkDeviceSize range; +} VkBufferViewCreateInfo; + +typedef struct VkImageCreateInfo { + VkStructureType sType; + const void* pNext; + VkImageCreateFlags flags; + VkImageType imageType; + VkFormat format; + VkExtent3D extent; + uint32_t mipLevels; + uint32_t arrayLayers; + VkSampleCountFlagBits samples; + VkImageTiling tiling; + VkImageUsageFlags usage; + VkSharingMode sharingMode; + uint32_t queueFamilyIndexCount; + const uint32_t* pQueueFamilyIndices; + VkImageLayout initialLayout; +} VkImageCreateInfo; + +typedef struct VkSubresourceLayout { + VkDeviceSize offset; + VkDeviceSize size; + VkDeviceSize rowPitch; + VkDeviceSize arrayPitch; + VkDeviceSize depthPitch; +} VkSubresourceLayout; + +typedef struct VkComponentMapping { + VkComponentSwizzle r; + VkComponentSwizzle g; + VkComponentSwizzle b; + VkComponentSwizzle a; +} VkComponentMapping; + +typedef struct VkImageSubresourceRange { + VkImageAspectFlags aspectMask; + uint32_t baseMipLevel; + uint32_t levelCount; + uint32_t baseArrayLayer; + uint32_t layerCount; +} VkImageSubresourceRange; + +typedef struct VkImageViewCreateInfo { + VkStructureType sType; + const void* pNext; + VkImageViewCreateFlags flags; + VkImage image; + VkImageViewType viewType; + VkFormat format; + VkComponentMapping components; + VkImageSubresourceRange subresourceRange; +} VkImageViewCreateInfo; + +typedef struct VkShaderModuleCreateInfo { + VkStructureType sType; + const void* pNext; + VkShaderModuleCreateFlags flags; + size_t codeSize; + const uint32_t* pCode; +} VkShaderModuleCreateInfo; + +typedef struct VkPipelineCacheCreateInfo { + VkStructureType sType; + const void* pNext; + VkPipelineCacheCreateFlags flags; + size_t initialDataSize; + const void* pInitialData; +} VkPipelineCacheCreateInfo; + +typedef struct VkSpecializationMapEntry { + uint32_t constantID; + uint32_t offset; + size_t size; +} VkSpecializationMapEntry; + +typedef struct VkSpecializationInfo { + uint32_t mapEntryCount; + const VkSpecializationMapEntry* pMapEntries; + size_t dataSize; + const void* pData; +} VkSpecializationInfo; + +typedef struct VkPipelineShaderStageCreateInfo { + VkStructureType sType; + const void* pNext; + VkPipelineShaderStageCreateFlags flags; + VkShaderStageFlagBits stage; + VkShaderModule module; + const char* pName; + const VkSpecializationInfo* pSpecializationInfo; +} VkPipelineShaderStageCreateInfo; + +typedef struct VkVertexInputBindingDescription { + uint32_t binding; + uint32_t stride; + VkVertexInputRate inputRate; +} VkVertexInputBindingDescription; + +typedef struct VkVertexInputAttributeDescription { + uint32_t location; + uint32_t binding; + VkFormat format; + uint32_t offset; +} VkVertexInputAttributeDescription; + +typedef struct VkPipelineVertexInputStateCreateInfo { + VkStructureType sType; + const void* pNext; + VkPipelineVertexInputStateCreateFlags flags; + uint32_t vertexBindingDescriptionCount; + const VkVertexInputBindingDescription* pVertexBindingDescriptions; + uint32_t vertexAttributeDescriptionCount; + const VkVertexInputAttributeDescription* pVertexAttributeDescriptions; +} VkPipelineVertexInputStateCreateInfo; + +typedef struct VkPipelineInputAssemblyStateCreateInfo { + VkStructureType sType; + const void* pNext; + VkPipelineInputAssemblyStateCreateFlags flags; + VkPrimitiveTopology topology; + VkBool32 primitiveRestartEnable; +} VkPipelineInputAssemblyStateCreateInfo; + +typedef struct VkPipelineTessellationStateCreateInfo { + VkStructureType sType; + const void* pNext; + VkPipelineTessellationStateCreateFlags flags; + uint32_t patchControlPoints; +} VkPipelineTessellationStateCreateInfo; + +typedef struct VkViewport { + float x; + float y; + float width; + float height; + float minDepth; + float maxDepth; +} VkViewport; + +typedef struct VkOffset2D { + int32_t x; + int32_t y; +} VkOffset2D; + +typedef struct VkExtent2D { + uint32_t width; + uint32_t height; +} VkExtent2D; + +typedef struct VkRect2D { + VkOffset2D offset; + VkExtent2D extent; +} VkRect2D; + +typedef struct VkPipelineViewportStateCreateInfo { + VkStructureType sType; + const void* pNext; + VkPipelineViewportStateCreateFlags flags; + uint32_t viewportCount; + const VkViewport* pViewports; + uint32_t scissorCount; + const VkRect2D* pScissors; +} VkPipelineViewportStateCreateInfo; + +typedef struct VkPipelineRasterizationStateCreateInfo { + VkStructureType sType; + const void* pNext; + VkPipelineRasterizationStateCreateFlags flags; + VkBool32 depthClampEnable; + VkBool32 rasterizerDiscardEnable; + VkPolygonMode polygonMode; + VkCullModeFlags cullMode; + VkFrontFace frontFace; + VkBool32 depthBiasEnable; + float depthBiasConstantFactor; + float depthBiasClamp; + float depthBiasSlopeFactor; + float lineWidth; +} VkPipelineRasterizationStateCreateInfo; + +typedef struct VkPipelineMultisampleStateCreateInfo { + VkStructureType sType; + const void* pNext; + VkPipelineMultisampleStateCreateFlags flags; + VkSampleCountFlagBits rasterizationSamples; + VkBool32 sampleShadingEnable; + float minSampleShading; + const VkSampleMask* pSampleMask; + VkBool32 alphaToCoverageEnable; + VkBool32 alphaToOneEnable; +} VkPipelineMultisampleStateCreateInfo; + +typedef struct VkStencilOpState { + VkStencilOp failOp; + VkStencilOp passOp; + VkStencilOp depthFailOp; + VkCompareOp compareOp; + uint32_t compareMask; + uint32_t writeMask; + uint32_t reference; +} VkStencilOpState; + +typedef struct VkPipelineDepthStencilStateCreateInfo { + VkStructureType sType; + const void* pNext; + VkPipelineDepthStencilStateCreateFlags flags; + VkBool32 depthTestEnable; + VkBool32 depthWriteEnable; + VkCompareOp depthCompareOp; + VkBool32 depthBoundsTestEnable; + VkBool32 stencilTestEnable; + VkStencilOpState front; + VkStencilOpState back; + float minDepthBounds; + float maxDepthBounds; +} VkPipelineDepthStencilStateCreateInfo; + +typedef struct VkPipelineColorBlendAttachmentState { + VkBool32 blendEnable; + VkBlendFactor srcColorBlendFactor; + VkBlendFactor dstColorBlendFactor; + VkBlendOp colorBlendOp; + VkBlendFactor srcAlphaBlendFactor; + VkBlendFactor dstAlphaBlendFactor; + VkBlendOp alphaBlendOp; + VkColorComponentFlags colorWriteMask; +} VkPipelineColorBlendAttachmentState; + +typedef struct VkPipelineColorBlendStateCreateInfo { + VkStructureType sType; + const void* pNext; + VkPipelineColorBlendStateCreateFlags flags; + VkBool32 logicOpEnable; + VkLogicOp logicOp; + uint32_t attachmentCount; + const VkPipelineColorBlendAttachmentState* pAttachments; + float blendConstants[4]; +} VkPipelineColorBlendStateCreateInfo; + +typedef struct VkPipelineDynamicStateCreateInfo { + VkStructureType sType; + const void* pNext; + VkPipelineDynamicStateCreateFlags flags; + uint32_t dynamicStateCount; + const VkDynamicState* pDynamicStates; +} VkPipelineDynamicStateCreateInfo; + +typedef struct VkGraphicsPipelineCreateInfo { + VkStructureType sType; + const void* pNext; + VkPipelineCreateFlags flags; + uint32_t stageCount; + const VkPipelineShaderStageCreateInfo* pStages; + const VkPipelineVertexInputStateCreateInfo* pVertexInputState; + const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState; + const VkPipelineTessellationStateCreateInfo* pTessellationState; + const VkPipelineViewportStateCreateInfo* pViewportState; + const VkPipelineRasterizationStateCreateInfo* pRasterizationState; + const VkPipelineMultisampleStateCreateInfo* pMultisampleState; + const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState; + const VkPipelineColorBlendStateCreateInfo* pColorBlendState; + const VkPipelineDynamicStateCreateInfo* pDynamicState; + VkPipelineLayout layout; + VkRenderPass renderPass; + uint32_t subpass; + VkPipeline basePipelineHandle; + int32_t basePipelineIndex; +} VkGraphicsPipelineCreateInfo; + +typedef struct VkComputePipelineCreateInfo { + VkStructureType sType; + const void* pNext; + VkPipelineCreateFlags flags; + VkPipelineShaderStageCreateInfo stage; + VkPipelineLayout layout; + VkPipeline basePipelineHandle; + int32_t basePipelineIndex; +} VkComputePipelineCreateInfo; + +typedef struct VkPushConstantRange { + VkShaderStageFlags stageFlags; + uint32_t offset; + uint32_t size; +} VkPushConstantRange; + +typedef struct VkPipelineLayoutCreateInfo { + VkStructureType sType; + const void* pNext; + VkPipelineLayoutCreateFlags flags; + uint32_t setLayoutCount; + const VkDescriptorSetLayout* pSetLayouts; + uint32_t pushConstantRangeCount; + const VkPushConstantRange* pPushConstantRanges; +} VkPipelineLayoutCreateInfo; + +typedef struct VkSamplerCreateInfo { + VkStructureType sType; + const void* pNext; + VkSamplerCreateFlags flags; + VkFilter magFilter; + VkFilter minFilter; + VkSamplerMipmapMode mipmapMode; + VkSamplerAddressMode addressModeU; + VkSamplerAddressMode addressModeV; + VkSamplerAddressMode addressModeW; + float mipLodBias; + VkBool32 anisotropyEnable; + float maxAnisotropy; + VkBool32 compareEnable; + VkCompareOp compareOp; + float minLod; + float maxLod; + VkBorderColor borderColor; + VkBool32 unnormalizedCoordinates; +} VkSamplerCreateInfo; + +typedef struct VkDescriptorSetLayoutBinding { + uint32_t binding; + VkDescriptorType descriptorType; + uint32_t descriptorCount; + VkShaderStageFlags stageFlags; + const VkSampler* pImmutableSamplers; +} VkDescriptorSetLayoutBinding; + +typedef struct VkDescriptorSetLayoutCreateInfo { + VkStructureType sType; + const void* pNext; + VkDescriptorSetLayoutCreateFlags flags; + uint32_t bindingCount; + const VkDescriptorSetLayoutBinding* pBindings; +} VkDescriptorSetLayoutCreateInfo; + +typedef struct VkDescriptorPoolSize { + VkDescriptorType type; + uint32_t descriptorCount; +} VkDescriptorPoolSize; + +typedef struct VkDescriptorPoolCreateInfo { + VkStructureType sType; + const void* pNext; + VkDescriptorPoolCreateFlags flags; + uint32_t maxSets; + uint32_t poolSizeCount; + const VkDescriptorPoolSize* pPoolSizes; +} VkDescriptorPoolCreateInfo; + +typedef struct VkDescriptorSetAllocateInfo { + VkStructureType sType; + const void* pNext; + VkDescriptorPool descriptorPool; + uint32_t descriptorSetCount; + const VkDescriptorSetLayout* pSetLayouts; +} VkDescriptorSetAllocateInfo; + +typedef struct VkDescriptorImageInfo { + VkSampler sampler; + VkImageView imageView; + VkImageLayout imageLayout; +} VkDescriptorImageInfo; + +typedef struct VkDescriptorBufferInfo { + VkBuffer buffer; + VkDeviceSize offset; + VkDeviceSize range; +} VkDescriptorBufferInfo; + +typedef struct VkWriteDescriptorSet { + VkStructureType sType; + const void* pNext; + VkDescriptorSet dstSet; + uint32_t dstBinding; + uint32_t dstArrayElement; + uint32_t descriptorCount; + VkDescriptorType descriptorType; + const VkDescriptorImageInfo* pImageInfo; + const VkDescriptorBufferInfo* pBufferInfo; + const VkBufferView* pTexelBufferView; +} VkWriteDescriptorSet; + +typedef struct VkCopyDescriptorSet { + VkStructureType sType; + const void* pNext; + VkDescriptorSet srcSet; + uint32_t srcBinding; + uint32_t srcArrayElement; + VkDescriptorSet dstSet; + uint32_t dstBinding; + uint32_t dstArrayElement; + uint32_t descriptorCount; +} VkCopyDescriptorSet; + +typedef struct VkFramebufferCreateInfo { + VkStructureType sType; + const void* pNext; + VkFramebufferCreateFlags flags; + VkRenderPass renderPass; + uint32_t attachmentCount; + const VkImageView* pAttachments; + uint32_t width; + uint32_t height; + uint32_t layers; +} VkFramebufferCreateInfo; + +typedef struct VkAttachmentDescription { + VkAttachmentDescriptionFlags flags; + VkFormat format; + VkSampleCountFlagBits samples; + VkAttachmentLoadOp loadOp; + VkAttachmentStoreOp storeOp; + VkAttachmentLoadOp stencilLoadOp; + VkAttachmentStoreOp stencilStoreOp; + VkImageLayout initialLayout; + VkImageLayout finalLayout; +} VkAttachmentDescription; + +typedef struct VkAttachmentReference { + uint32_t attachment; + VkImageLayout layout; +} VkAttachmentReference; + +typedef struct VkSubpassDescription { + VkSubpassDescriptionFlags flags; + VkPipelineBindPoint pipelineBindPoint; + uint32_t inputAttachmentCount; + const VkAttachmentReference* pInputAttachments; + uint32_t colorAttachmentCount; + const VkAttachmentReference* pColorAttachments; + const VkAttachmentReference* pResolveAttachments; + const VkAttachmentReference* pDepthStencilAttachment; + uint32_t preserveAttachmentCount; + const uint32_t* pPreserveAttachments; +} VkSubpassDescription; + +typedef struct VkSubpassDependency { + uint32_t srcSubpass; + uint32_t dstSubpass; + VkPipelineStageFlags srcStageMask; + VkPipelineStageFlags dstStageMask; + VkAccessFlags srcAccessMask; + VkAccessFlags dstAccessMask; + VkDependencyFlags dependencyFlags; +} VkSubpassDependency; + +typedef struct VkRenderPassCreateInfo { + VkStructureType sType; + const void* pNext; + VkRenderPassCreateFlags flags; + uint32_t attachmentCount; + const VkAttachmentDescription* pAttachments; + uint32_t subpassCount; + const VkSubpassDescription* pSubpasses; + uint32_t dependencyCount; + const VkSubpassDependency* pDependencies; +} VkRenderPassCreateInfo; + +typedef struct VkCommandPoolCreateInfo { + VkStructureType sType; + const void* pNext; + VkCommandPoolCreateFlags flags; + uint32_t queueFamilyIndex; +} VkCommandPoolCreateInfo; + +typedef struct VkCommandBufferAllocateInfo { + VkStructureType sType; + const void* pNext; + VkCommandPool commandPool; + VkCommandBufferLevel level; + uint32_t commandBufferCount; +} VkCommandBufferAllocateInfo; + +typedef struct VkCommandBufferInheritanceInfo { + VkStructureType sType; + const void* pNext; + VkRenderPass renderPass; + uint32_t subpass; + VkFramebuffer framebuffer; + VkBool32 occlusionQueryEnable; + VkQueryControlFlags queryFlags; + VkQueryPipelineStatisticFlags pipelineStatistics; +} VkCommandBufferInheritanceInfo; + +typedef struct VkCommandBufferBeginInfo { + VkStructureType sType; + const void* pNext; + VkCommandBufferUsageFlags flags; + const VkCommandBufferInheritanceInfo* pInheritanceInfo; +} VkCommandBufferBeginInfo; + +typedef struct VkBufferCopy { + VkDeviceSize srcOffset; + VkDeviceSize dstOffset; + VkDeviceSize size; +} VkBufferCopy; + +typedef struct VkImageSubresourceLayers { + VkImageAspectFlags aspectMask; + uint32_t mipLevel; + uint32_t baseArrayLayer; + uint32_t layerCount; +} VkImageSubresourceLayers; + +typedef struct VkImageCopy { + VkImageSubresourceLayers srcSubresource; + VkOffset3D srcOffset; + VkImageSubresourceLayers dstSubresource; + VkOffset3D dstOffset; + VkExtent3D extent; +} VkImageCopy; + +typedef struct VkImageBlit { + VkImageSubresourceLayers srcSubresource; + VkOffset3D srcOffsets[2]; + VkImageSubresourceLayers dstSubresource; + VkOffset3D dstOffsets[2]; +} VkImageBlit; + +typedef struct VkBufferImageCopy { + VkDeviceSize bufferOffset; + uint32_t bufferRowLength; + uint32_t bufferImageHeight; + VkImageSubresourceLayers imageSubresource; + VkOffset3D imageOffset; + VkExtent3D imageExtent; +} VkBufferImageCopy; + +typedef union VkClearColorValue { + float float32[4]; + int32_t int32[4]; + uint32_t uint32[4]; +} VkClearColorValue; + +typedef struct VkClearDepthStencilValue { + float depth; + uint32_t stencil; +} VkClearDepthStencilValue; + +typedef union VkClearValue { + VkClearColorValue color; + VkClearDepthStencilValue depthStencil; +} VkClearValue; + +typedef struct VkClearAttachment { + VkImageAspectFlags aspectMask; + uint32_t colorAttachment; + VkClearValue clearValue; +} VkClearAttachment; + +typedef struct VkClearRect { + VkRect2D rect; + uint32_t baseArrayLayer; + uint32_t layerCount; +} VkClearRect; + +typedef struct VkImageResolve { + VkImageSubresourceLayers srcSubresource; + VkOffset3D srcOffset; + VkImageSubresourceLayers dstSubresource; + VkOffset3D dstOffset; + VkExtent3D extent; +} VkImageResolve; + +typedef struct VkMemoryBarrier { + VkStructureType sType; + const void* pNext; + VkAccessFlags srcAccessMask; + VkAccessFlags dstAccessMask; +} VkMemoryBarrier; + +typedef struct VkBufferMemoryBarrier { + VkStructureType sType; + const void* pNext; + VkAccessFlags srcAccessMask; + VkAccessFlags dstAccessMask; + uint32_t srcQueueFamilyIndex; + uint32_t dstQueueFamilyIndex; + VkBuffer buffer; + VkDeviceSize offset; + VkDeviceSize size; +} VkBufferMemoryBarrier; + +typedef struct VkImageMemoryBarrier { + VkStructureType sType; + const void* pNext; + VkAccessFlags srcAccessMask; + VkAccessFlags dstAccessMask; + VkImageLayout oldLayout; + VkImageLayout newLayout; + uint32_t srcQueueFamilyIndex; + uint32_t dstQueueFamilyIndex; + VkImage image; + VkImageSubresourceRange subresourceRange; +} VkImageMemoryBarrier; + +typedef struct VkRenderPassBeginInfo { + VkStructureType sType; + const void* pNext; + VkRenderPass renderPass; + VkFramebuffer framebuffer; + VkRect2D renderArea; + uint32_t clearValueCount; + const VkClearValue* pClearValues; +} VkRenderPassBeginInfo; + +typedef struct VkDispatchIndirectCommand { + uint32_t x; + uint32_t y; + uint32_t z; +} VkDispatchIndirectCommand; + +typedef struct VkDrawIndexedIndirectCommand { + uint32_t indexCount; + uint32_t instanceCount; + uint32_t firstIndex; + int32_t vertexOffset; + uint32_t firstInstance; +} VkDrawIndexedIndirectCommand; + +typedef struct VkDrawIndirectCommand { + uint32_t vertexCount; + uint32_t instanceCount; + uint32_t firstVertex; + uint32_t firstInstance; +} VkDrawIndirectCommand; + +typedef struct VkBaseOutStructure { + VkStructureType sType; + struct VkBaseOutStructure* pNext; +} VkBaseOutStructure; + +typedef struct VkBaseInStructure { + VkStructureType sType; + const struct VkBaseInStructure* pNext; +} VkBaseInStructure; + + +typedef VkResult (VKAPI_PTR *PFN_vkCreateInstance)(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance); +typedef void (VKAPI_PTR *PFN_vkDestroyInstance)(VkInstance instance, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkEnumeratePhysicalDevices)(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceFeatures)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceFormatProperties)(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties); +typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceImageFormatProperties)(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceProperties)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceQueueFamilyProperties)(VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties* pQueueFamilyProperties); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceMemoryProperties)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties); +typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vkGetInstanceProcAddr)(VkInstance instance, const char* pName); +typedef PFN_vkVoidFunction (VKAPI_PTR *PFN_vkGetDeviceProcAddr)(VkDevice device, const char* pName); +typedef VkResult (VKAPI_PTR *PFN_vkCreateDevice)(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice); +typedef void (VKAPI_PTR *PFN_vkDestroyDevice)(VkDevice device, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkEnumerateInstanceExtensionProperties)(const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties); +typedef VkResult (VKAPI_PTR *PFN_vkEnumerateDeviceExtensionProperties)(VkPhysicalDevice physicalDevice, const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties); +typedef VkResult (VKAPI_PTR *PFN_vkEnumerateInstanceLayerProperties)(uint32_t* pPropertyCount, VkLayerProperties* pProperties); +typedef VkResult (VKAPI_PTR *PFN_vkEnumerateDeviceLayerProperties)(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkLayerProperties* pProperties); +typedef void (VKAPI_PTR *PFN_vkGetDeviceQueue)(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue); +typedef VkResult (VKAPI_PTR *PFN_vkQueueSubmit)(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence); +typedef VkResult (VKAPI_PTR *PFN_vkQueueWaitIdle)(VkQueue queue); +typedef VkResult (VKAPI_PTR *PFN_vkDeviceWaitIdle)(VkDevice device); +typedef VkResult (VKAPI_PTR *PFN_vkAllocateMemory)(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory); +typedef void (VKAPI_PTR *PFN_vkFreeMemory)(VkDevice device, VkDeviceMemory memory, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkMapMemory)(VkDevice device, VkDeviceMemory memory, VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags, void** ppData); +typedef void (VKAPI_PTR *PFN_vkUnmapMemory)(VkDevice device, VkDeviceMemory memory); +typedef VkResult (VKAPI_PTR *PFN_vkFlushMappedMemoryRanges)(VkDevice device, uint32_t memoryRangeCount, const VkMappedMemoryRange* pMemoryRanges); +typedef VkResult (VKAPI_PTR *PFN_vkInvalidateMappedMemoryRanges)(VkDevice device, uint32_t memoryRangeCount, const VkMappedMemoryRange* pMemoryRanges); +typedef void (VKAPI_PTR *PFN_vkGetDeviceMemoryCommitment)(VkDevice device, VkDeviceMemory memory, VkDeviceSize* pCommittedMemoryInBytes); +typedef VkResult (VKAPI_PTR *PFN_vkBindBufferMemory)(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize memoryOffset); +typedef VkResult (VKAPI_PTR *PFN_vkBindImageMemory)(VkDevice device, VkImage image, VkDeviceMemory memory, VkDeviceSize memoryOffset); +typedef void (VKAPI_PTR *PFN_vkGetBufferMemoryRequirements)(VkDevice device, VkBuffer buffer, VkMemoryRequirements* pMemoryRequirements); +typedef void (VKAPI_PTR *PFN_vkGetImageMemoryRequirements)(VkDevice device, VkImage image, VkMemoryRequirements* pMemoryRequirements); +typedef void (VKAPI_PTR *PFN_vkGetImageSparseMemoryRequirements)(VkDevice device, VkImage image, uint32_t* pSparseMemoryRequirementCount, VkSparseImageMemoryRequirements* pSparseMemoryRequirements); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceSparseImageFormatProperties)(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pPropertyCount, VkSparseImageFormatProperties* pProperties); +typedef VkResult (VKAPI_PTR *PFN_vkQueueBindSparse)(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, VkFence fence); +typedef VkResult (VKAPI_PTR *PFN_vkCreateFence)(VkDevice device, const VkFenceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence); +typedef void (VKAPI_PTR *PFN_vkDestroyFence)(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkResetFences)(VkDevice device, uint32_t fenceCount, const VkFence* pFences); +typedef VkResult (VKAPI_PTR *PFN_vkGetFenceStatus)(VkDevice device, VkFence fence); +typedef VkResult (VKAPI_PTR *PFN_vkWaitForFences)(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout); +typedef VkResult (VKAPI_PTR *PFN_vkCreateSemaphore)(VkDevice device, const VkSemaphoreCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSemaphore* pSemaphore); +typedef void (VKAPI_PTR *PFN_vkDestroySemaphore)(VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkCreateEvent)(VkDevice device, const VkEventCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkEvent* pEvent); +typedef void (VKAPI_PTR *PFN_vkDestroyEvent)(VkDevice device, VkEvent event, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkGetEventStatus)(VkDevice device, VkEvent event); +typedef VkResult (VKAPI_PTR *PFN_vkSetEvent)(VkDevice device, VkEvent event); +typedef VkResult (VKAPI_PTR *PFN_vkResetEvent)(VkDevice device, VkEvent event); +typedef VkResult (VKAPI_PTR *PFN_vkCreateQueryPool)(VkDevice device, const VkQueryPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkQueryPool* pQueryPool); +typedef void (VKAPI_PTR *PFN_vkDestroyQueryPool)(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkGetQueryPoolResults)(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags); +typedef VkResult (VKAPI_PTR *PFN_vkCreateBuffer)(VkDevice device, const VkBufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer); +typedef void (VKAPI_PTR *PFN_vkDestroyBuffer)(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkCreateBufferView)(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBufferView* pView); +typedef void (VKAPI_PTR *PFN_vkDestroyBufferView)(VkDevice device, VkBufferView bufferView, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkCreateImage)(VkDevice device, const VkImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImage* pImage); +typedef void (VKAPI_PTR *PFN_vkDestroyImage)(VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator); +typedef void (VKAPI_PTR *PFN_vkGetImageSubresourceLayout)(VkDevice device, VkImage image, const VkImageSubresource* pSubresource, VkSubresourceLayout* pLayout); +typedef VkResult (VKAPI_PTR *PFN_vkCreateImageView)(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImageView* pView); +typedef void (VKAPI_PTR *PFN_vkDestroyImageView)(VkDevice device, VkImageView imageView, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkCreateShaderModule)(VkDevice device, const VkShaderModuleCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkShaderModule* pShaderModule); +typedef void (VKAPI_PTR *PFN_vkDestroyShaderModule)(VkDevice device, VkShaderModule shaderModule, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkCreatePipelineCache)(VkDevice device, const VkPipelineCacheCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineCache* pPipelineCache); +typedef void (VKAPI_PTR *PFN_vkDestroyPipelineCache)(VkDevice device, VkPipelineCache pipelineCache, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkGetPipelineCacheData)(VkDevice device, VkPipelineCache pipelineCache, size_t* pDataSize, void* pData); +typedef VkResult (VKAPI_PTR *PFN_vkMergePipelineCaches)(VkDevice device, VkPipelineCache dstCache, uint32_t srcCacheCount, const VkPipelineCache* pSrcCaches); +typedef VkResult (VKAPI_PTR *PFN_vkCreateGraphicsPipelines)(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, const VkGraphicsPipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines); +typedef VkResult (VKAPI_PTR *PFN_vkCreateComputePipelines)(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount, const VkComputePipelineCreateInfo* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkPipeline* pPipelines); +typedef void (VKAPI_PTR *PFN_vkDestroyPipeline)(VkDevice device, VkPipeline pipeline, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkCreatePipelineLayout)(VkDevice device, const VkPipelineLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkPipelineLayout* pPipelineLayout); +typedef void (VKAPI_PTR *PFN_vkDestroyPipelineLayout)(VkDevice device, VkPipelineLayout pipelineLayout, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkCreateSampler)(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSampler* pSampler); +typedef void (VKAPI_PTR *PFN_vkDestroySampler)(VkDevice device, VkSampler sampler, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkCreateDescriptorSetLayout)(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorSetLayout* pSetLayout); +typedef void (VKAPI_PTR *PFN_vkDestroyDescriptorSetLayout)(VkDevice device, VkDescriptorSetLayout descriptorSetLayout, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkCreateDescriptorPool)(VkDevice device, const VkDescriptorPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorPool* pDescriptorPool); +typedef void (VKAPI_PTR *PFN_vkDestroyDescriptorPool)(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkResetDescriptorPool)(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorPoolResetFlags flags); +typedef VkResult (VKAPI_PTR *PFN_vkAllocateDescriptorSets)(VkDevice device, const VkDescriptorSetAllocateInfo* pAllocateInfo, VkDescriptorSet* pDescriptorSets); +typedef VkResult (VKAPI_PTR *PFN_vkFreeDescriptorSets)(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount, const VkDescriptorSet* pDescriptorSets); +typedef void (VKAPI_PTR *PFN_vkUpdateDescriptorSets)(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites, uint32_t descriptorCopyCount, const VkCopyDescriptorSet* pDescriptorCopies); +typedef VkResult (VKAPI_PTR *PFN_vkCreateFramebuffer)(VkDevice device, const VkFramebufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFramebuffer* pFramebuffer); +typedef void (VKAPI_PTR *PFN_vkDestroyFramebuffer)(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkCreateRenderPass)(VkDevice device, const VkRenderPassCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass); +typedef void (VKAPI_PTR *PFN_vkDestroyRenderPass)(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks* pAllocator); +typedef void (VKAPI_PTR *PFN_vkGetRenderAreaGranularity)(VkDevice device, VkRenderPass renderPass, VkExtent2D* pGranularity); +typedef VkResult (VKAPI_PTR *PFN_vkCreateCommandPool)(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool); +typedef void (VKAPI_PTR *PFN_vkDestroyCommandPool)(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkResetCommandPool)(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags); +typedef VkResult (VKAPI_PTR *PFN_vkAllocateCommandBuffers)(VkDevice device, const VkCommandBufferAllocateInfo* pAllocateInfo, VkCommandBuffer* pCommandBuffers); +typedef void (VKAPI_PTR *PFN_vkFreeCommandBuffers)(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers); +typedef VkResult (VKAPI_PTR *PFN_vkBeginCommandBuffer)(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo* pBeginInfo); +typedef VkResult (VKAPI_PTR *PFN_vkEndCommandBuffer)(VkCommandBuffer commandBuffer); +typedef VkResult (VKAPI_PTR *PFN_vkResetCommandBuffer)(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags); +typedef void (VKAPI_PTR *PFN_vkCmdBindPipeline)(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline); +typedef void (VKAPI_PTR *PFN_vkCmdSetViewport)(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount, const VkViewport* pViewports); +typedef void (VKAPI_PTR *PFN_vkCmdSetScissor)(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D* pScissors); +typedef void (VKAPI_PTR *PFN_vkCmdSetLineWidth)(VkCommandBuffer commandBuffer, float lineWidth); +typedef void (VKAPI_PTR *PFN_vkCmdSetDepthBias)(VkCommandBuffer commandBuffer, float depthBiasConstantFactor, float depthBiasClamp, float depthBiasSlopeFactor); +typedef void (VKAPI_PTR *PFN_vkCmdSetBlendConstants)(VkCommandBuffer commandBuffer, const float blendConstants[4]); +typedef void (VKAPI_PTR *PFN_vkCmdSetDepthBounds)(VkCommandBuffer commandBuffer, float minDepthBounds, float maxDepthBounds); +typedef void (VKAPI_PTR *PFN_vkCmdSetStencilCompareMask)(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t compareMask); +typedef void (VKAPI_PTR *PFN_vkCmdSetStencilWriteMask)(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t writeMask); +typedef void (VKAPI_PTR *PFN_vkCmdSetStencilReference)(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, uint32_t reference); +typedef void (VKAPI_PTR *PFN_vkCmdBindDescriptorSets)(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t firstSet, uint32_t descriptorSetCount, const VkDescriptorSet* pDescriptorSets, uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets); +typedef void (VKAPI_PTR *PFN_vkCmdBindIndexBuffer)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkIndexType indexType); +typedef void (VKAPI_PTR *PFN_vkCmdBindVertexBuffers)(VkCommandBuffer commandBuffer, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers, const VkDeviceSize* pOffsets); +typedef void (VKAPI_PTR *PFN_vkCmdDraw)(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance); +typedef void (VKAPI_PTR *PFN_vkCmdDrawIndexed)(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance); +typedef void (VKAPI_PTR *PFN_vkCmdDrawIndirect)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride); +typedef void (VKAPI_PTR *PFN_vkCmdDrawIndexedIndirect)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t drawCount, uint32_t stride); +typedef void (VKAPI_PTR *PFN_vkCmdDispatch)(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ); +typedef void (VKAPI_PTR *PFN_vkCmdDispatchIndirect)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset); +typedef void (VKAPI_PTR *PFN_vkCmdCopyBuffer)(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferCopy* pRegions); +typedef void (VKAPI_PTR *PFN_vkCmdCopyImage)(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy* pRegions); +typedef void (VKAPI_PTR *PFN_vkCmdBlitImage)(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit* pRegions, VkFilter filter); +typedef void (VKAPI_PTR *PFN_vkCmdCopyBufferToImage)(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkBufferImageCopy* pRegions); +typedef void (VKAPI_PTR *PFN_vkCmdCopyImageToBuffer)(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy* pRegions); +typedef void (VKAPI_PTR *PFN_vkCmdUpdateBuffer)(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize, const void* pData); +typedef void (VKAPI_PTR *PFN_vkCmdFillBuffer)(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data); +typedef void (VKAPI_PTR *PFN_vkCmdClearColorImage)(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearColorValue* pColor, uint32_t rangeCount, const VkImageSubresourceRange* pRanges); +typedef void (VKAPI_PTR *PFN_vkCmdClearDepthStencilImage)(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue* pDepthStencil, uint32_t rangeCount, const VkImageSubresourceRange* pRanges); +typedef void (VKAPI_PTR *PFN_vkCmdClearAttachments)(VkCommandBuffer commandBuffer, uint32_t attachmentCount, const VkClearAttachment* pAttachments, uint32_t rectCount, const VkClearRect* pRects); +typedef void (VKAPI_PTR *PFN_vkCmdResolveImage)(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageResolve* pRegions); +typedef void (VKAPI_PTR *PFN_vkCmdSetEvent)(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask); +typedef void (VKAPI_PTR *PFN_vkCmdResetEvent)(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags stageMask); +typedef void (VKAPI_PTR *PFN_vkCmdWaitEvents)(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers); +typedef void (VKAPI_PTR *PFN_vkCmdPipelineBarrier)(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers); +typedef void (VKAPI_PTR *PFN_vkCmdBeginQuery)(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t query, VkQueryControlFlags flags); +typedef void (VKAPI_PTR *PFN_vkCmdEndQuery)(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t query); +typedef void (VKAPI_PTR *PFN_vkCmdResetQueryPool)(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount); +typedef void (VKAPI_PTR *PFN_vkCmdWriteTimestamp)(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t query); +typedef void (VKAPI_PTR *PFN_vkCmdCopyQueryPoolResults)(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize stride, VkQueryResultFlags flags); +typedef void (VKAPI_PTR *PFN_vkCmdPushConstants)(VkCommandBuffer commandBuffer, VkPipelineLayout layout, VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size, const void* pValues); +typedef void (VKAPI_PTR *PFN_vkCmdBeginRenderPass)(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, VkSubpassContents contents); +typedef void (VKAPI_PTR *PFN_vkCmdNextSubpass)(VkCommandBuffer commandBuffer, VkSubpassContents contents); +typedef void (VKAPI_PTR *PFN_vkCmdEndRenderPass)(VkCommandBuffer commandBuffer); +typedef void (VKAPI_PTR *PFN_vkCmdExecuteCommands)(VkCommandBuffer commandBuffer, uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance( + const VkInstanceCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkInstance* pInstance); + +VKAPI_ATTR void VKAPI_CALL vkDestroyInstance( + VkInstance instance, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices( + VkInstance instance, + uint32_t* pPhysicalDeviceCount, + VkPhysicalDevice* pPhysicalDevices); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures( + VkPhysicalDevice physicalDevice, + VkPhysicalDeviceFeatures* pFeatures); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFormatProperties( + VkPhysicalDevice physicalDevice, + VkFormat format, + VkFormatProperties* pFormatProperties); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceImageFormatProperties( + VkPhysicalDevice physicalDevice, + VkFormat format, + VkImageType type, + VkImageTiling tiling, + VkImageUsageFlags usage, + VkImageCreateFlags flags, + VkImageFormatProperties* pImageFormatProperties); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties( + VkPhysicalDevice physicalDevice, + VkPhysicalDeviceProperties* pProperties); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceQueueFamilyProperties( + VkPhysicalDevice physicalDevice, + uint32_t* pQueueFamilyPropertyCount, + VkQueueFamilyProperties* pQueueFamilyProperties); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties( + VkPhysicalDevice physicalDevice, + VkPhysicalDeviceMemoryProperties* pMemoryProperties); + +VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr( + VkInstance instance, + const char* pName); + +VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr( + VkDevice device, + const char* pName); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice( + VkPhysicalDevice physicalDevice, + const VkDeviceCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkDevice* pDevice); + +VKAPI_ATTR void VKAPI_CALL vkDestroyDevice( + VkDevice device, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties( + const char* pLayerName, + uint32_t* pPropertyCount, + VkExtensionProperties* pProperties); + +VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties( + VkPhysicalDevice physicalDevice, + const char* pLayerName, + uint32_t* pPropertyCount, + VkExtensionProperties* pProperties); + +VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties( + uint32_t* pPropertyCount, + VkLayerProperties* pProperties); + +VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties( + VkPhysicalDevice physicalDevice, + uint32_t* pPropertyCount, + VkLayerProperties* pProperties); + +VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue( + VkDevice device, + uint32_t queueFamilyIndex, + uint32_t queueIndex, + VkQueue* pQueue); + +VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit( + VkQueue queue, + uint32_t submitCount, + const VkSubmitInfo* pSubmits, + VkFence fence); + +VKAPI_ATTR VkResult VKAPI_CALL vkQueueWaitIdle( + VkQueue queue); + +VKAPI_ATTR VkResult VKAPI_CALL vkDeviceWaitIdle( + VkDevice device); + +VKAPI_ATTR VkResult VKAPI_CALL vkAllocateMemory( + VkDevice device, + const VkMemoryAllocateInfo* pAllocateInfo, + const VkAllocationCallbacks* pAllocator, + VkDeviceMemory* pMemory); + +VKAPI_ATTR void VKAPI_CALL vkFreeMemory( + VkDevice device, + VkDeviceMemory memory, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkMapMemory( + VkDevice device, + VkDeviceMemory memory, + VkDeviceSize offset, + VkDeviceSize size, + VkMemoryMapFlags flags, + void** ppData); + +VKAPI_ATTR void VKAPI_CALL vkUnmapMemory( + VkDevice device, + VkDeviceMemory memory); + +VKAPI_ATTR VkResult VKAPI_CALL vkFlushMappedMemoryRanges( + VkDevice device, + uint32_t memoryRangeCount, + const VkMappedMemoryRange* pMemoryRanges); + +VKAPI_ATTR VkResult VKAPI_CALL vkInvalidateMappedMemoryRanges( + VkDevice device, + uint32_t memoryRangeCount, + const VkMappedMemoryRange* pMemoryRanges); + +VKAPI_ATTR void VKAPI_CALL vkGetDeviceMemoryCommitment( + VkDevice device, + VkDeviceMemory memory, + VkDeviceSize* pCommittedMemoryInBytes); + +VKAPI_ATTR VkResult VKAPI_CALL vkBindBufferMemory( + VkDevice device, + VkBuffer buffer, + VkDeviceMemory memory, + VkDeviceSize memoryOffset); + +VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory( + VkDevice device, + VkImage image, + VkDeviceMemory memory, + VkDeviceSize memoryOffset); + +VKAPI_ATTR void VKAPI_CALL vkGetBufferMemoryRequirements( + VkDevice device, + VkBuffer buffer, + VkMemoryRequirements* pMemoryRequirements); + +VKAPI_ATTR void VKAPI_CALL vkGetImageMemoryRequirements( + VkDevice device, + VkImage image, + VkMemoryRequirements* pMemoryRequirements); + +VKAPI_ATTR void VKAPI_CALL vkGetImageSparseMemoryRequirements( + VkDevice device, + VkImage image, + uint32_t* pSparseMemoryRequirementCount, + VkSparseImageMemoryRequirements* pSparseMemoryRequirements); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceSparseImageFormatProperties( + VkPhysicalDevice physicalDevice, + VkFormat format, + VkImageType type, + VkSampleCountFlagBits samples, + VkImageUsageFlags usage, + VkImageTiling tiling, + uint32_t* pPropertyCount, + VkSparseImageFormatProperties* pProperties); + +VKAPI_ATTR VkResult VKAPI_CALL vkQueueBindSparse( + VkQueue queue, + uint32_t bindInfoCount, + const VkBindSparseInfo* pBindInfo, + VkFence fence); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateFence( + VkDevice device, + const VkFenceCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkFence* pFence); + +VKAPI_ATTR void VKAPI_CALL vkDestroyFence( + VkDevice device, + VkFence fence, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkResetFences( + VkDevice device, + uint32_t fenceCount, + const VkFence* pFences); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceStatus( + VkDevice device, + VkFence fence); + +VKAPI_ATTR VkResult VKAPI_CALL vkWaitForFences( + VkDevice device, + uint32_t fenceCount, + const VkFence* pFences, + VkBool32 waitAll, + uint64_t timeout); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateSemaphore( + VkDevice device, + const VkSemaphoreCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkSemaphore* pSemaphore); + +VKAPI_ATTR void VKAPI_CALL vkDestroySemaphore( + VkDevice device, + VkSemaphore semaphore, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateEvent( + VkDevice device, + const VkEventCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkEvent* pEvent); + +VKAPI_ATTR void VKAPI_CALL vkDestroyEvent( + VkDevice device, + VkEvent event, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetEventStatus( + VkDevice device, + VkEvent event); + +VKAPI_ATTR VkResult VKAPI_CALL vkSetEvent( + VkDevice device, + VkEvent event); + +VKAPI_ATTR VkResult VKAPI_CALL vkResetEvent( + VkDevice device, + VkEvent event); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateQueryPool( + VkDevice device, + const VkQueryPoolCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkQueryPool* pQueryPool); + +VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool( + VkDevice device, + VkQueryPool queryPool, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults( + VkDevice device, + VkQueryPool queryPool, + uint32_t firstQuery, + uint32_t queryCount, + size_t dataSize, + void* pData, + VkDeviceSize stride, + VkQueryResultFlags flags); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateBuffer( + VkDevice device, + const VkBufferCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkBuffer* pBuffer); + +VKAPI_ATTR void VKAPI_CALL vkDestroyBuffer( + VkDevice device, + VkBuffer buffer, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateBufferView( + VkDevice device, + const VkBufferViewCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkBufferView* pView); + +VKAPI_ATTR void VKAPI_CALL vkDestroyBufferView( + VkDevice device, + VkBufferView bufferView, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage( + VkDevice device, + const VkImageCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkImage* pImage); + +VKAPI_ATTR void VKAPI_CALL vkDestroyImage( + VkDevice device, + VkImage image, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR void VKAPI_CALL vkGetImageSubresourceLayout( + VkDevice device, + VkImage image, + const VkImageSubresource* pSubresource, + VkSubresourceLayout* pLayout); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateImageView( + VkDevice device, + const VkImageViewCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkImageView* pView); + +VKAPI_ATTR void VKAPI_CALL vkDestroyImageView( + VkDevice device, + VkImageView imageView, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateShaderModule( + VkDevice device, + const VkShaderModuleCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkShaderModule* pShaderModule); + +VKAPI_ATTR void VKAPI_CALL vkDestroyShaderModule( + VkDevice device, + VkShaderModule shaderModule, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineCache( + VkDevice device, + const VkPipelineCacheCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkPipelineCache* pPipelineCache); + +VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineCache( + VkDevice device, + VkPipelineCache pipelineCache, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetPipelineCacheData( + VkDevice device, + VkPipelineCache pipelineCache, + size_t* pDataSize, + void* pData); + +VKAPI_ATTR VkResult VKAPI_CALL vkMergePipelineCaches( + VkDevice device, + VkPipelineCache dstCache, + uint32_t srcCacheCount, + const VkPipelineCache* pSrcCaches); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateGraphicsPipelines( + VkDevice device, + VkPipelineCache pipelineCache, + uint32_t createInfoCount, + const VkGraphicsPipelineCreateInfo* pCreateInfos, + const VkAllocationCallbacks* pAllocator, + VkPipeline* pPipelines); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateComputePipelines( + VkDevice device, + VkPipelineCache pipelineCache, + uint32_t createInfoCount, + const VkComputePipelineCreateInfo* pCreateInfos, + const VkAllocationCallbacks* pAllocator, + VkPipeline* pPipelines); + +VKAPI_ATTR void VKAPI_CALL vkDestroyPipeline( + VkDevice device, + VkPipeline pipeline, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreatePipelineLayout( + VkDevice device, + const VkPipelineLayoutCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkPipelineLayout* pPipelineLayout); + +VKAPI_ATTR void VKAPI_CALL vkDestroyPipelineLayout( + VkDevice device, + VkPipelineLayout pipelineLayout, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateSampler( + VkDevice device, + const VkSamplerCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkSampler* pSampler); + +VKAPI_ATTR void VKAPI_CALL vkDestroySampler( + VkDevice device, + VkSampler sampler, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorSetLayout( + VkDevice device, + const VkDescriptorSetLayoutCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkDescriptorSetLayout* pSetLayout); + +VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorSetLayout( + VkDevice device, + VkDescriptorSetLayout descriptorSetLayout, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorPool( + VkDevice device, + const VkDescriptorPoolCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkDescriptorPool* pDescriptorPool); + +VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorPool( + VkDevice device, + VkDescriptorPool descriptorPool, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkResetDescriptorPool( + VkDevice device, + VkDescriptorPool descriptorPool, + VkDescriptorPoolResetFlags flags); + +VKAPI_ATTR VkResult VKAPI_CALL vkAllocateDescriptorSets( + VkDevice device, + const VkDescriptorSetAllocateInfo* pAllocateInfo, + VkDescriptorSet* pDescriptorSets); + +VKAPI_ATTR VkResult VKAPI_CALL vkFreeDescriptorSets( + VkDevice device, + VkDescriptorPool descriptorPool, + uint32_t descriptorSetCount, + const VkDescriptorSet* pDescriptorSets); + +VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSets( + VkDevice device, + uint32_t descriptorWriteCount, + const VkWriteDescriptorSet* pDescriptorWrites, + uint32_t descriptorCopyCount, + const VkCopyDescriptorSet* pDescriptorCopies); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateFramebuffer( + VkDevice device, + const VkFramebufferCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkFramebuffer* pFramebuffer); + +VKAPI_ATTR void VKAPI_CALL vkDestroyFramebuffer( + VkDevice device, + VkFramebuffer framebuffer, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass( + VkDevice device, + const VkRenderPassCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkRenderPass* pRenderPass); + +VKAPI_ATTR void VKAPI_CALL vkDestroyRenderPass( + VkDevice device, + VkRenderPass renderPass, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR void VKAPI_CALL vkGetRenderAreaGranularity( + VkDevice device, + VkRenderPass renderPass, + VkExtent2D* pGranularity); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool( + VkDevice device, + const VkCommandPoolCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkCommandPool* pCommandPool); + +VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool( + VkDevice device, + VkCommandPool commandPool, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool( + VkDevice device, + VkCommandPool commandPool, + VkCommandPoolResetFlags flags); + +VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers( + VkDevice device, + const VkCommandBufferAllocateInfo* pAllocateInfo, + VkCommandBuffer* pCommandBuffers); + +VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers( + VkDevice device, + VkCommandPool commandPool, + uint32_t commandBufferCount, + const VkCommandBuffer* pCommandBuffers); + +VKAPI_ATTR VkResult VKAPI_CALL vkBeginCommandBuffer( + VkCommandBuffer commandBuffer, + const VkCommandBufferBeginInfo* pBeginInfo); + +VKAPI_ATTR VkResult VKAPI_CALL vkEndCommandBuffer( + VkCommandBuffer commandBuffer); + +VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandBuffer( + VkCommandBuffer commandBuffer, + VkCommandBufferResetFlags flags); + +VKAPI_ATTR void VKAPI_CALL vkCmdBindPipeline( + VkCommandBuffer commandBuffer, + VkPipelineBindPoint pipelineBindPoint, + VkPipeline pipeline); + +VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport( + VkCommandBuffer commandBuffer, + uint32_t firstViewport, + uint32_t viewportCount, + const VkViewport* pViewports); + +VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor( + VkCommandBuffer commandBuffer, + uint32_t firstScissor, + uint32_t scissorCount, + const VkRect2D* pScissors); + +VKAPI_ATTR void VKAPI_CALL vkCmdSetLineWidth( + VkCommandBuffer commandBuffer, + float lineWidth); + +VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBias( + VkCommandBuffer commandBuffer, + float depthBiasConstantFactor, + float depthBiasClamp, + float depthBiasSlopeFactor); + +VKAPI_ATTR void VKAPI_CALL vkCmdSetBlendConstants( + VkCommandBuffer commandBuffer, + const float blendConstants[4]); + +VKAPI_ATTR void VKAPI_CALL vkCmdSetDepthBounds( + VkCommandBuffer commandBuffer, + float minDepthBounds, + float maxDepthBounds); + +VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilCompareMask( + VkCommandBuffer commandBuffer, + VkStencilFaceFlags faceMask, + uint32_t compareMask); + +VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilWriteMask( + VkCommandBuffer commandBuffer, + VkStencilFaceFlags faceMask, + uint32_t writeMask); + +VKAPI_ATTR void VKAPI_CALL vkCmdSetStencilReference( + VkCommandBuffer commandBuffer, + VkStencilFaceFlags faceMask, + uint32_t reference); + +VKAPI_ATTR void VKAPI_CALL vkCmdBindDescriptorSets( + VkCommandBuffer commandBuffer, + VkPipelineBindPoint pipelineBindPoint, + VkPipelineLayout layout, + uint32_t firstSet, + uint32_t descriptorSetCount, + const VkDescriptorSet* pDescriptorSets, + uint32_t dynamicOffsetCount, + const uint32_t* pDynamicOffsets); + +VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer( + VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkIndexType indexType); + +VKAPI_ATTR void VKAPI_CALL vkCmdBindVertexBuffers( + VkCommandBuffer commandBuffer, + uint32_t firstBinding, + uint32_t bindingCount, + const VkBuffer* pBuffers, + const VkDeviceSize* pOffsets); + +VKAPI_ATTR void VKAPI_CALL vkCmdDraw( + VkCommandBuffer commandBuffer, + uint32_t vertexCount, + uint32_t instanceCount, + uint32_t firstVertex, + uint32_t firstInstance); + +VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexed( + VkCommandBuffer commandBuffer, + uint32_t indexCount, + uint32_t instanceCount, + uint32_t firstIndex, + int32_t vertexOffset, + uint32_t firstInstance); + +VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirect( + VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + uint32_t drawCount, + uint32_t stride); + +VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirect( + VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + uint32_t drawCount, + uint32_t stride); + +VKAPI_ATTR void VKAPI_CALL vkCmdDispatch( + VkCommandBuffer commandBuffer, + uint32_t groupCountX, + uint32_t groupCountY, + uint32_t groupCountZ); + +VKAPI_ATTR void VKAPI_CALL vkCmdDispatchIndirect( + VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset); + +VKAPI_ATTR void VKAPI_CALL vkCmdCopyBuffer( + VkCommandBuffer commandBuffer, + VkBuffer srcBuffer, + VkBuffer dstBuffer, + uint32_t regionCount, + const VkBufferCopy* pRegions); + +VKAPI_ATTR void VKAPI_CALL vkCmdCopyImage( + VkCommandBuffer commandBuffer, + VkImage srcImage, + VkImageLayout srcImageLayout, + VkImage dstImage, + VkImageLayout dstImageLayout, + uint32_t regionCount, + const VkImageCopy* pRegions); + +VKAPI_ATTR void VKAPI_CALL vkCmdBlitImage( + VkCommandBuffer commandBuffer, + VkImage srcImage, + VkImageLayout srcImageLayout, + VkImage dstImage, + VkImageLayout dstImageLayout, + uint32_t regionCount, + const VkImageBlit* pRegions, + VkFilter filter); + +VKAPI_ATTR void VKAPI_CALL vkCmdCopyBufferToImage( + VkCommandBuffer commandBuffer, + VkBuffer srcBuffer, + VkImage dstImage, + VkImageLayout dstImageLayout, + uint32_t regionCount, + const VkBufferImageCopy* pRegions); + +VKAPI_ATTR void VKAPI_CALL vkCmdCopyImageToBuffer( + VkCommandBuffer commandBuffer, + VkImage srcImage, + VkImageLayout srcImageLayout, + VkBuffer dstBuffer, + uint32_t regionCount, + const VkBufferImageCopy* pRegions); + +VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer( + VkCommandBuffer commandBuffer, + VkBuffer dstBuffer, + VkDeviceSize dstOffset, + VkDeviceSize dataSize, + const void* pData); + +VKAPI_ATTR void VKAPI_CALL vkCmdFillBuffer( + VkCommandBuffer commandBuffer, + VkBuffer dstBuffer, + VkDeviceSize dstOffset, + VkDeviceSize size, + uint32_t data); + +VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage( + VkCommandBuffer commandBuffer, + VkImage image, + VkImageLayout imageLayout, + const VkClearColorValue* pColor, + uint32_t rangeCount, + const VkImageSubresourceRange* pRanges); + +VKAPI_ATTR void VKAPI_CALL vkCmdClearDepthStencilImage( + VkCommandBuffer commandBuffer, + VkImage image, + VkImageLayout imageLayout, + const VkClearDepthStencilValue* pDepthStencil, + uint32_t rangeCount, + const VkImageSubresourceRange* pRanges); + +VKAPI_ATTR void VKAPI_CALL vkCmdClearAttachments( + VkCommandBuffer commandBuffer, + uint32_t attachmentCount, + const VkClearAttachment* pAttachments, + uint32_t rectCount, + const VkClearRect* pRects); + +VKAPI_ATTR void VKAPI_CALL vkCmdResolveImage( + VkCommandBuffer commandBuffer, + VkImage srcImage, + VkImageLayout srcImageLayout, + VkImage dstImage, + VkImageLayout dstImageLayout, + uint32_t regionCount, + const VkImageResolve* pRegions); + +VKAPI_ATTR void VKAPI_CALL vkCmdSetEvent( + VkCommandBuffer commandBuffer, + VkEvent event, + VkPipelineStageFlags stageMask); + +VKAPI_ATTR void VKAPI_CALL vkCmdResetEvent( + VkCommandBuffer commandBuffer, + VkEvent event, + VkPipelineStageFlags stageMask); + +VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents( + VkCommandBuffer commandBuffer, + uint32_t eventCount, + const VkEvent* pEvents, + VkPipelineStageFlags srcStageMask, + VkPipelineStageFlags dstStageMask, + uint32_t memoryBarrierCount, + const VkMemoryBarrier* pMemoryBarriers, + uint32_t bufferMemoryBarrierCount, + const VkBufferMemoryBarrier* pBufferMemoryBarriers, + uint32_t imageMemoryBarrierCount, + const VkImageMemoryBarrier* pImageMemoryBarriers); + +VKAPI_ATTR void VKAPI_CALL vkCmdPipelineBarrier( + VkCommandBuffer commandBuffer, + VkPipelineStageFlags srcStageMask, + VkPipelineStageFlags dstStageMask, + VkDependencyFlags dependencyFlags, + uint32_t memoryBarrierCount, + const VkMemoryBarrier* pMemoryBarriers, + uint32_t bufferMemoryBarrierCount, + const VkBufferMemoryBarrier* pBufferMemoryBarriers, + uint32_t imageMemoryBarrierCount, + const VkImageMemoryBarrier* pImageMemoryBarriers); + +VKAPI_ATTR void VKAPI_CALL vkCmdBeginQuery( + VkCommandBuffer commandBuffer, + VkQueryPool queryPool, + uint32_t query, + VkQueryControlFlags flags); + +VKAPI_ATTR void VKAPI_CALL vkCmdEndQuery( + VkCommandBuffer commandBuffer, + VkQueryPool queryPool, + uint32_t query); + +VKAPI_ATTR void VKAPI_CALL vkCmdResetQueryPool( + VkCommandBuffer commandBuffer, + VkQueryPool queryPool, + uint32_t firstQuery, + uint32_t queryCount); + +VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp( + VkCommandBuffer commandBuffer, + VkPipelineStageFlagBits pipelineStage, + VkQueryPool queryPool, + uint32_t query); + +VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults( + VkCommandBuffer commandBuffer, + VkQueryPool queryPool, + uint32_t firstQuery, + uint32_t queryCount, + VkBuffer dstBuffer, + VkDeviceSize dstOffset, + VkDeviceSize stride, + VkQueryResultFlags flags); + +VKAPI_ATTR void VKAPI_CALL vkCmdPushConstants( + VkCommandBuffer commandBuffer, + VkPipelineLayout layout, + VkShaderStageFlags stageFlags, + uint32_t offset, + uint32_t size, + const void* pValues); + +VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass( + VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + VkSubpassContents contents); + +VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass( + VkCommandBuffer commandBuffer, + VkSubpassContents contents); + +VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass( + VkCommandBuffer commandBuffer); + +VKAPI_ATTR void VKAPI_CALL vkCmdExecuteCommands( + VkCommandBuffer commandBuffer, + uint32_t commandBufferCount, + const VkCommandBuffer* pCommandBuffers); +#endif + +#define VK_VERSION_1_1 1 +// Vulkan 1.1 version number +#define VK_API_VERSION_1_1 VK_MAKE_VERSION(1, 1, 0)// Patch version should always be set to 0 + + +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSamplerYcbcrConversion) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorUpdateTemplate) + +#define VK_MAX_DEVICE_GROUP_SIZE 32 +#define VK_LUID_SIZE 8 +#define VK_QUEUE_FAMILY_EXTERNAL (~0U-1) + + +typedef enum VkPointClippingBehavior { + VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES = 0, + VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY = 1, + VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR = VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES, + VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY_KHR = VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY, + VK_POINT_CLIPPING_BEHAVIOR_BEGIN_RANGE = VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES, + VK_POINT_CLIPPING_BEHAVIOR_END_RANGE = VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY, + VK_POINT_CLIPPING_BEHAVIOR_RANGE_SIZE = (VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY - VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES + 1), + VK_POINT_CLIPPING_BEHAVIOR_MAX_ENUM = 0x7FFFFFFF +} VkPointClippingBehavior; + +typedef enum VkTessellationDomainOrigin { + VK_TESSELLATION_DOMAIN_ORIGIN_UPPER_LEFT = 0, + VK_TESSELLATION_DOMAIN_ORIGIN_LOWER_LEFT = 1, + VK_TESSELLATION_DOMAIN_ORIGIN_UPPER_LEFT_KHR = VK_TESSELLATION_DOMAIN_ORIGIN_UPPER_LEFT, + VK_TESSELLATION_DOMAIN_ORIGIN_LOWER_LEFT_KHR = VK_TESSELLATION_DOMAIN_ORIGIN_LOWER_LEFT, + VK_TESSELLATION_DOMAIN_ORIGIN_BEGIN_RANGE = VK_TESSELLATION_DOMAIN_ORIGIN_UPPER_LEFT, + VK_TESSELLATION_DOMAIN_ORIGIN_END_RANGE = VK_TESSELLATION_DOMAIN_ORIGIN_LOWER_LEFT, + VK_TESSELLATION_DOMAIN_ORIGIN_RANGE_SIZE = (VK_TESSELLATION_DOMAIN_ORIGIN_LOWER_LEFT - VK_TESSELLATION_DOMAIN_ORIGIN_UPPER_LEFT + 1), + VK_TESSELLATION_DOMAIN_ORIGIN_MAX_ENUM = 0x7FFFFFFF +} VkTessellationDomainOrigin; + +typedef enum VkSamplerYcbcrModelConversion { + VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY = 0, + VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_IDENTITY = 1, + VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709 = 2, + VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_601 = 3, + VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_2020 = 4, + VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY_KHR = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY, + VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_IDENTITY_KHR = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_IDENTITY, + VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709_KHR = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709, + VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_601_KHR = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_601, + VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_2020_KHR = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_2020, + VK_SAMPLER_YCBCR_MODEL_CONVERSION_BEGIN_RANGE = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY, + VK_SAMPLER_YCBCR_MODEL_CONVERSION_END_RANGE = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_2020, + VK_SAMPLER_YCBCR_MODEL_CONVERSION_RANGE_SIZE = (VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_2020 - VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY + 1), + VK_SAMPLER_YCBCR_MODEL_CONVERSION_MAX_ENUM = 0x7FFFFFFF +} VkSamplerYcbcrModelConversion; + +typedef enum VkSamplerYcbcrRange { + VK_SAMPLER_YCBCR_RANGE_ITU_FULL = 0, + VK_SAMPLER_YCBCR_RANGE_ITU_NARROW = 1, + VK_SAMPLER_YCBCR_RANGE_ITU_FULL_KHR = VK_SAMPLER_YCBCR_RANGE_ITU_FULL, + VK_SAMPLER_YCBCR_RANGE_ITU_NARROW_KHR = VK_SAMPLER_YCBCR_RANGE_ITU_NARROW, + VK_SAMPLER_YCBCR_RANGE_BEGIN_RANGE = VK_SAMPLER_YCBCR_RANGE_ITU_FULL, + VK_SAMPLER_YCBCR_RANGE_END_RANGE = VK_SAMPLER_YCBCR_RANGE_ITU_NARROW, + VK_SAMPLER_YCBCR_RANGE_RANGE_SIZE = (VK_SAMPLER_YCBCR_RANGE_ITU_NARROW - VK_SAMPLER_YCBCR_RANGE_ITU_FULL + 1), + VK_SAMPLER_YCBCR_RANGE_MAX_ENUM = 0x7FFFFFFF +} VkSamplerYcbcrRange; + +typedef enum VkChromaLocation { + VK_CHROMA_LOCATION_COSITED_EVEN = 0, + VK_CHROMA_LOCATION_MIDPOINT = 1, + VK_CHROMA_LOCATION_COSITED_EVEN_KHR = VK_CHROMA_LOCATION_COSITED_EVEN, + VK_CHROMA_LOCATION_MIDPOINT_KHR = VK_CHROMA_LOCATION_MIDPOINT, + VK_CHROMA_LOCATION_BEGIN_RANGE = VK_CHROMA_LOCATION_COSITED_EVEN, + VK_CHROMA_LOCATION_END_RANGE = VK_CHROMA_LOCATION_MIDPOINT, + VK_CHROMA_LOCATION_RANGE_SIZE = (VK_CHROMA_LOCATION_MIDPOINT - VK_CHROMA_LOCATION_COSITED_EVEN + 1), + VK_CHROMA_LOCATION_MAX_ENUM = 0x7FFFFFFF +} VkChromaLocation; + +typedef enum VkDescriptorUpdateTemplateType { + VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET = 0, + VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR = 1, + VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET, + VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_BEGIN_RANGE = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET, + VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_END_RANGE = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET, + VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_RANGE_SIZE = (VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET - VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET + 1), + VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_MAX_ENUM = 0x7FFFFFFF +} VkDescriptorUpdateTemplateType; + + +typedef enum VkSubgroupFeatureFlagBits { + VK_SUBGROUP_FEATURE_BASIC_BIT = 0x00000001, + VK_SUBGROUP_FEATURE_VOTE_BIT = 0x00000002, + VK_SUBGROUP_FEATURE_ARITHMETIC_BIT = 0x00000004, + VK_SUBGROUP_FEATURE_BALLOT_BIT = 0x00000008, + VK_SUBGROUP_FEATURE_SHUFFLE_BIT = 0x00000010, + VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT = 0x00000020, + VK_SUBGROUP_FEATURE_CLUSTERED_BIT = 0x00000040, + VK_SUBGROUP_FEATURE_QUAD_BIT = 0x00000080, + VK_SUBGROUP_FEATURE_PARTITIONED_BIT_NV = 0x00000100, + VK_SUBGROUP_FEATURE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkSubgroupFeatureFlagBits; +typedef VkFlags VkSubgroupFeatureFlags; + +typedef enum VkPeerMemoryFeatureFlagBits { + VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT = 0x00000001, + VK_PEER_MEMORY_FEATURE_COPY_DST_BIT = 0x00000002, + VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT = 0x00000004, + VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT = 0x00000008, + VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT_KHR = VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT, + VK_PEER_MEMORY_FEATURE_COPY_DST_BIT_KHR = VK_PEER_MEMORY_FEATURE_COPY_DST_BIT, + VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT_KHR = VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT, + VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT_KHR = VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT, + VK_PEER_MEMORY_FEATURE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkPeerMemoryFeatureFlagBits; +typedef VkFlags VkPeerMemoryFeatureFlags; + +typedef enum VkMemoryAllocateFlagBits { + VK_MEMORY_ALLOCATE_DEVICE_MASK_BIT = 0x00000001, + VK_MEMORY_ALLOCATE_DEVICE_MASK_BIT_KHR = VK_MEMORY_ALLOCATE_DEVICE_MASK_BIT, + VK_MEMORY_ALLOCATE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkMemoryAllocateFlagBits; +typedef VkFlags VkMemoryAllocateFlags; +typedef VkFlags VkCommandPoolTrimFlags; +typedef VkFlags VkDescriptorUpdateTemplateCreateFlags; + +typedef enum VkExternalMemoryHandleTypeFlagBits { + VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT = 0x00000001, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT = 0x00000002, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT = 0x00000004, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT = 0x00000008, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_KMT_BIT = 0x00000010, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP_BIT = 0x00000020, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE_BIT = 0x00000040, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT = 0x00000200, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID = 0x00000400, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT = 0x00000080, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_MAPPED_FOREIGN_MEMORY_BIT_EXT = 0x00000100, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_KMT_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_KMT_BIT, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP_BIT, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE_BIT_KHR = VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE_BIT, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkExternalMemoryHandleTypeFlagBits; +typedef VkFlags VkExternalMemoryHandleTypeFlags; + +typedef enum VkExternalMemoryFeatureFlagBits { + VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT = 0x00000001, + VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT = 0x00000002, + VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT = 0x00000004, + VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT_KHR = VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT, + VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHR = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT, + VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHR = VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT, + VK_EXTERNAL_MEMORY_FEATURE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkExternalMemoryFeatureFlagBits; +typedef VkFlags VkExternalMemoryFeatureFlags; + +typedef enum VkExternalFenceHandleTypeFlagBits { + VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT = 0x00000001, + VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT = 0x00000002, + VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT = 0x00000004, + VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT = 0x00000008, + VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT, + VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT, + VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT, + VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR = VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT, + VK_EXTERNAL_FENCE_HANDLE_TYPE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkExternalFenceHandleTypeFlagBits; +typedef VkFlags VkExternalFenceHandleTypeFlags; + +typedef enum VkExternalFenceFeatureFlagBits { + VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT = 0x00000001, + VK_EXTERNAL_FENCE_FEATURE_IMPORTABLE_BIT = 0x00000002, + VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR = VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT, + VK_EXTERNAL_FENCE_FEATURE_IMPORTABLE_BIT_KHR = VK_EXTERNAL_FENCE_FEATURE_IMPORTABLE_BIT, + VK_EXTERNAL_FENCE_FEATURE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkExternalFenceFeatureFlagBits; +typedef VkFlags VkExternalFenceFeatureFlags; + +typedef enum VkFenceImportFlagBits { + VK_FENCE_IMPORT_TEMPORARY_BIT = 0x00000001, + VK_FENCE_IMPORT_TEMPORARY_BIT_KHR = VK_FENCE_IMPORT_TEMPORARY_BIT, + VK_FENCE_IMPORT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkFenceImportFlagBits; +typedef VkFlags VkFenceImportFlags; + +typedef enum VkSemaphoreImportFlagBits { + VK_SEMAPHORE_IMPORT_TEMPORARY_BIT = 0x00000001, + VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT, + VK_SEMAPHORE_IMPORT_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkSemaphoreImportFlagBits; +typedef VkFlags VkSemaphoreImportFlags; + +typedef enum VkExternalSemaphoreHandleTypeFlagBits { + VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT = 0x00000001, + VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT = 0x00000002, + VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT = 0x00000004, + VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT = 0x00000008, + VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT = 0x00000010, + VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT, + VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT, + VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT, + VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT_KHR = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT, + VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT, + VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkExternalSemaphoreHandleTypeFlagBits; +typedef VkFlags VkExternalSemaphoreHandleTypeFlags; + +typedef enum VkExternalSemaphoreFeatureFlagBits { + VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT = 0x00000001, + VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT = 0x00000002, + VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR = VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT, + VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR = VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT, + VK_EXTERNAL_SEMAPHORE_FEATURE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF +} VkExternalSemaphoreFeatureFlagBits; +typedef VkFlags VkExternalSemaphoreFeatureFlags; + +typedef struct VkPhysicalDeviceSubgroupProperties { + VkStructureType sType; + void* pNext; + uint32_t subgroupSize; + VkShaderStageFlags supportedStages; + VkSubgroupFeatureFlags supportedOperations; + VkBool32 quadOperationsInAllStages; +} VkPhysicalDeviceSubgroupProperties; + +typedef struct VkBindBufferMemoryInfo { + VkStructureType sType; + const void* pNext; + VkBuffer buffer; + VkDeviceMemory memory; + VkDeviceSize memoryOffset; +} VkBindBufferMemoryInfo; + +typedef struct VkBindImageMemoryInfo { + VkStructureType sType; + const void* pNext; + VkImage image; + VkDeviceMemory memory; + VkDeviceSize memoryOffset; +} VkBindImageMemoryInfo; + +typedef struct VkPhysicalDevice16BitStorageFeatures { + VkStructureType sType; + void* pNext; + VkBool32 storageBuffer16BitAccess; + VkBool32 uniformAndStorageBuffer16BitAccess; + VkBool32 storagePushConstant16; + VkBool32 storageInputOutput16; +} VkPhysicalDevice16BitStorageFeatures; + +typedef struct VkMemoryDedicatedRequirements { + VkStructureType sType; + void* pNext; + VkBool32 prefersDedicatedAllocation; + VkBool32 requiresDedicatedAllocation; +} VkMemoryDedicatedRequirements; + +typedef struct VkMemoryDedicatedAllocateInfo { + VkStructureType sType; + const void* pNext; + VkImage image; + VkBuffer buffer; +} VkMemoryDedicatedAllocateInfo; + +typedef struct VkMemoryAllocateFlagsInfo { + VkStructureType sType; + const void* pNext; + VkMemoryAllocateFlags flags; + uint32_t deviceMask; +} VkMemoryAllocateFlagsInfo; + +typedef struct VkDeviceGroupRenderPassBeginInfo { + VkStructureType sType; + const void* pNext; + uint32_t deviceMask; + uint32_t deviceRenderAreaCount; + const VkRect2D* pDeviceRenderAreas; +} VkDeviceGroupRenderPassBeginInfo; + +typedef struct VkDeviceGroupCommandBufferBeginInfo { + VkStructureType sType; + const void* pNext; + uint32_t deviceMask; +} VkDeviceGroupCommandBufferBeginInfo; + +typedef struct VkDeviceGroupSubmitInfo { + VkStructureType sType; + const void* pNext; + uint32_t waitSemaphoreCount; + const uint32_t* pWaitSemaphoreDeviceIndices; + uint32_t commandBufferCount; + const uint32_t* pCommandBufferDeviceMasks; + uint32_t signalSemaphoreCount; + const uint32_t* pSignalSemaphoreDeviceIndices; +} VkDeviceGroupSubmitInfo; + +typedef struct VkDeviceGroupBindSparseInfo { + VkStructureType sType; + const void* pNext; + uint32_t resourceDeviceIndex; + uint32_t memoryDeviceIndex; +} VkDeviceGroupBindSparseInfo; + +typedef struct VkBindBufferMemoryDeviceGroupInfo { + VkStructureType sType; + const void* pNext; + uint32_t deviceIndexCount; + const uint32_t* pDeviceIndices; +} VkBindBufferMemoryDeviceGroupInfo; + +typedef struct VkBindImageMemoryDeviceGroupInfo { + VkStructureType sType; + const void* pNext; + uint32_t deviceIndexCount; + const uint32_t* pDeviceIndices; + uint32_t splitInstanceBindRegionCount; + const VkRect2D* pSplitInstanceBindRegions; +} VkBindImageMemoryDeviceGroupInfo; + +typedef struct VkPhysicalDeviceGroupProperties { + VkStructureType sType; + void* pNext; + uint32_t physicalDeviceCount; + VkPhysicalDevice physicalDevices[VK_MAX_DEVICE_GROUP_SIZE]; + VkBool32 subsetAllocation; +} VkPhysicalDeviceGroupProperties; + +typedef struct VkDeviceGroupDeviceCreateInfo { + VkStructureType sType; + const void* pNext; + uint32_t physicalDeviceCount; + const VkPhysicalDevice* pPhysicalDevices; +} VkDeviceGroupDeviceCreateInfo; + +typedef struct VkBufferMemoryRequirementsInfo2 { + VkStructureType sType; + const void* pNext; + VkBuffer buffer; +} VkBufferMemoryRequirementsInfo2; + +typedef struct VkImageMemoryRequirementsInfo2 { + VkStructureType sType; + const void* pNext; + VkImage image; +} VkImageMemoryRequirementsInfo2; + +typedef struct VkImageSparseMemoryRequirementsInfo2 { + VkStructureType sType; + const void* pNext; + VkImage image; +} VkImageSparseMemoryRequirementsInfo2; + +typedef struct VkMemoryRequirements2 { + VkStructureType sType; + void* pNext; + VkMemoryRequirements memoryRequirements; +} VkMemoryRequirements2; + +typedef struct VkSparseImageMemoryRequirements2 { + VkStructureType sType; + void* pNext; + VkSparseImageMemoryRequirements memoryRequirements; +} VkSparseImageMemoryRequirements2; + +typedef struct VkPhysicalDeviceFeatures2 { + VkStructureType sType; + void* pNext; + VkPhysicalDeviceFeatures features; +} VkPhysicalDeviceFeatures2; + +typedef struct VkPhysicalDeviceProperties2 { + VkStructureType sType; + void* pNext; + VkPhysicalDeviceProperties properties; +} VkPhysicalDeviceProperties2; + +typedef struct VkFormatProperties2 { + VkStructureType sType; + void* pNext; + VkFormatProperties formatProperties; +} VkFormatProperties2; + +typedef struct VkImageFormatProperties2 { + VkStructureType sType; + void* pNext; + VkImageFormatProperties imageFormatProperties; +} VkImageFormatProperties2; + +typedef struct VkPhysicalDeviceImageFormatInfo2 { + VkStructureType sType; + const void* pNext; + VkFormat format; + VkImageType type; + VkImageTiling tiling; + VkImageUsageFlags usage; + VkImageCreateFlags flags; +} VkPhysicalDeviceImageFormatInfo2; + +typedef struct VkQueueFamilyProperties2 { + VkStructureType sType; + void* pNext; + VkQueueFamilyProperties queueFamilyProperties; +} VkQueueFamilyProperties2; + +typedef struct VkPhysicalDeviceMemoryProperties2 { + VkStructureType sType; + void* pNext; + VkPhysicalDeviceMemoryProperties memoryProperties; +} VkPhysicalDeviceMemoryProperties2; + +typedef struct VkSparseImageFormatProperties2 { + VkStructureType sType; + void* pNext; + VkSparseImageFormatProperties properties; +} VkSparseImageFormatProperties2; + +typedef struct VkPhysicalDeviceSparseImageFormatInfo2 { + VkStructureType sType; + const void* pNext; + VkFormat format; + VkImageType type; + VkSampleCountFlagBits samples; + VkImageUsageFlags usage; + VkImageTiling tiling; +} VkPhysicalDeviceSparseImageFormatInfo2; + +typedef struct VkPhysicalDevicePointClippingProperties { + VkStructureType sType; + void* pNext; + VkPointClippingBehavior pointClippingBehavior; +} VkPhysicalDevicePointClippingProperties; + +typedef struct VkInputAttachmentAspectReference { + uint32_t subpass; + uint32_t inputAttachmentIndex; + VkImageAspectFlags aspectMask; +} VkInputAttachmentAspectReference; + +typedef struct VkRenderPassInputAttachmentAspectCreateInfo { + VkStructureType sType; + const void* pNext; + uint32_t aspectReferenceCount; + const VkInputAttachmentAspectReference* pAspectReferences; +} VkRenderPassInputAttachmentAspectCreateInfo; + +typedef struct VkImageViewUsageCreateInfo { + VkStructureType sType; + const void* pNext; + VkImageUsageFlags usage; +} VkImageViewUsageCreateInfo; + +typedef struct VkPipelineTessellationDomainOriginStateCreateInfo { + VkStructureType sType; + const void* pNext; + VkTessellationDomainOrigin domainOrigin; +} VkPipelineTessellationDomainOriginStateCreateInfo; + +typedef struct VkRenderPassMultiviewCreateInfo { + VkStructureType sType; + const void* pNext; + uint32_t subpassCount; + const uint32_t* pViewMasks; + uint32_t dependencyCount; + const int32_t* pViewOffsets; + uint32_t correlationMaskCount; + const uint32_t* pCorrelationMasks; +} VkRenderPassMultiviewCreateInfo; + +typedef struct VkPhysicalDeviceMultiviewFeatures { + VkStructureType sType; + void* pNext; + VkBool32 multiview; + VkBool32 multiviewGeometryShader; + VkBool32 multiviewTessellationShader; +} VkPhysicalDeviceMultiviewFeatures; + +typedef struct VkPhysicalDeviceMultiviewProperties { + VkStructureType sType; + void* pNext; + uint32_t maxMultiviewViewCount; + uint32_t maxMultiviewInstanceIndex; +} VkPhysicalDeviceMultiviewProperties; + +typedef struct VkPhysicalDeviceVariablePointerFeatures { + VkStructureType sType; + void* pNext; + VkBool32 variablePointersStorageBuffer; + VkBool32 variablePointers; +} VkPhysicalDeviceVariablePointerFeatures; + +typedef struct VkPhysicalDeviceProtectedMemoryFeatures { + VkStructureType sType; + void* pNext; + VkBool32 protectedMemory; +} VkPhysicalDeviceProtectedMemoryFeatures; + +typedef struct VkPhysicalDeviceProtectedMemoryProperties { + VkStructureType sType; + void* pNext; + VkBool32 protectedNoFault; +} VkPhysicalDeviceProtectedMemoryProperties; + +typedef struct VkDeviceQueueInfo2 { + VkStructureType sType; + const void* pNext; + VkDeviceQueueCreateFlags flags; + uint32_t queueFamilyIndex; + uint32_t queueIndex; +} VkDeviceQueueInfo2; + +typedef struct VkProtectedSubmitInfo { + VkStructureType sType; + const void* pNext; + VkBool32 protectedSubmit; +} VkProtectedSubmitInfo; + +typedef struct VkSamplerYcbcrConversionCreateInfo { + VkStructureType sType; + const void* pNext; + VkFormat format; + VkSamplerYcbcrModelConversion ycbcrModel; + VkSamplerYcbcrRange ycbcrRange; + VkComponentMapping components; + VkChromaLocation xChromaOffset; + VkChromaLocation yChromaOffset; + VkFilter chromaFilter; + VkBool32 forceExplicitReconstruction; +} VkSamplerYcbcrConversionCreateInfo; + +typedef struct VkSamplerYcbcrConversionInfo { + VkStructureType sType; + const void* pNext; + VkSamplerYcbcrConversion conversion; +} VkSamplerYcbcrConversionInfo; + +typedef struct VkBindImagePlaneMemoryInfo { + VkStructureType sType; + const void* pNext; + VkImageAspectFlagBits planeAspect; +} VkBindImagePlaneMemoryInfo; + +typedef struct VkImagePlaneMemoryRequirementsInfo { + VkStructureType sType; + const void* pNext; + VkImageAspectFlagBits planeAspect; +} VkImagePlaneMemoryRequirementsInfo; + +typedef struct VkPhysicalDeviceSamplerYcbcrConversionFeatures { + VkStructureType sType; + void* pNext; + VkBool32 samplerYcbcrConversion; +} VkPhysicalDeviceSamplerYcbcrConversionFeatures; + +typedef struct VkSamplerYcbcrConversionImageFormatProperties { + VkStructureType sType; + void* pNext; + uint32_t combinedImageSamplerDescriptorCount; +} VkSamplerYcbcrConversionImageFormatProperties; + +typedef struct VkDescriptorUpdateTemplateEntry { + uint32_t dstBinding; + uint32_t dstArrayElement; + uint32_t descriptorCount; + VkDescriptorType descriptorType; + size_t offset; + size_t stride; +} VkDescriptorUpdateTemplateEntry; + +typedef struct VkDescriptorUpdateTemplateCreateInfo { + VkStructureType sType; + void* pNext; + VkDescriptorUpdateTemplateCreateFlags flags; + uint32_t descriptorUpdateEntryCount; + const VkDescriptorUpdateTemplateEntry* pDescriptorUpdateEntries; + VkDescriptorUpdateTemplateType templateType; + VkDescriptorSetLayout descriptorSetLayout; + VkPipelineBindPoint pipelineBindPoint; + VkPipelineLayout pipelineLayout; + uint32_t set; +} VkDescriptorUpdateTemplateCreateInfo; + +typedef struct VkExternalMemoryProperties { + VkExternalMemoryFeatureFlags externalMemoryFeatures; + VkExternalMemoryHandleTypeFlags exportFromImportedHandleTypes; + VkExternalMemoryHandleTypeFlags compatibleHandleTypes; +} VkExternalMemoryProperties; + +typedef struct VkPhysicalDeviceExternalImageFormatInfo { + VkStructureType sType; + const void* pNext; + VkExternalMemoryHandleTypeFlagBits handleType; +} VkPhysicalDeviceExternalImageFormatInfo; + +typedef struct VkExternalImageFormatProperties { + VkStructureType sType; + void* pNext; + VkExternalMemoryProperties externalMemoryProperties; +} VkExternalImageFormatProperties; + +typedef struct VkPhysicalDeviceExternalBufferInfo { + VkStructureType sType; + const void* pNext; + VkBufferCreateFlags flags; + VkBufferUsageFlags usage; + VkExternalMemoryHandleTypeFlagBits handleType; +} VkPhysicalDeviceExternalBufferInfo; + +typedef struct VkExternalBufferProperties { + VkStructureType sType; + void* pNext; + VkExternalMemoryProperties externalMemoryProperties; +} VkExternalBufferProperties; + +typedef struct VkPhysicalDeviceIDProperties { + VkStructureType sType; + void* pNext; + uint8_t deviceUUID[VK_UUID_SIZE]; + uint8_t driverUUID[VK_UUID_SIZE]; + uint8_t deviceLUID[VK_LUID_SIZE]; + uint32_t deviceNodeMask; + VkBool32 deviceLUIDValid; +} VkPhysicalDeviceIDProperties; + +typedef struct VkExternalMemoryImageCreateInfo { + VkStructureType sType; + const void* pNext; + VkExternalMemoryHandleTypeFlags handleTypes; +} VkExternalMemoryImageCreateInfo; + +typedef struct VkExternalMemoryBufferCreateInfo { + VkStructureType sType; + const void* pNext; + VkExternalMemoryHandleTypeFlags handleTypes; +} VkExternalMemoryBufferCreateInfo; + +typedef struct VkExportMemoryAllocateInfo { + VkStructureType sType; + const void* pNext; + VkExternalMemoryHandleTypeFlags handleTypes; +} VkExportMemoryAllocateInfo; + +typedef struct VkPhysicalDeviceExternalFenceInfo { + VkStructureType sType; + const void* pNext; + VkExternalFenceHandleTypeFlagBits handleType; +} VkPhysicalDeviceExternalFenceInfo; + +typedef struct VkExternalFenceProperties { + VkStructureType sType; + void* pNext; + VkExternalFenceHandleTypeFlags exportFromImportedHandleTypes; + VkExternalFenceHandleTypeFlags compatibleHandleTypes; + VkExternalFenceFeatureFlags externalFenceFeatures; +} VkExternalFenceProperties; + +typedef struct VkExportFenceCreateInfo { + VkStructureType sType; + const void* pNext; + VkExternalFenceHandleTypeFlags handleTypes; +} VkExportFenceCreateInfo; + +typedef struct VkExportSemaphoreCreateInfo { + VkStructureType sType; + const void* pNext; + VkExternalSemaphoreHandleTypeFlags handleTypes; +} VkExportSemaphoreCreateInfo; + +typedef struct VkPhysicalDeviceExternalSemaphoreInfo { + VkStructureType sType; + const void* pNext; + VkExternalSemaphoreHandleTypeFlagBits handleType; +} VkPhysicalDeviceExternalSemaphoreInfo; + +typedef struct VkExternalSemaphoreProperties { + VkStructureType sType; + void* pNext; + VkExternalSemaphoreHandleTypeFlags exportFromImportedHandleTypes; + VkExternalSemaphoreHandleTypeFlags compatibleHandleTypes; + VkExternalSemaphoreFeatureFlags externalSemaphoreFeatures; +} VkExternalSemaphoreProperties; + +typedef struct VkPhysicalDeviceMaintenance3Properties { + VkStructureType sType; + void* pNext; + uint32_t maxPerSetDescriptors; + VkDeviceSize maxMemoryAllocationSize; +} VkPhysicalDeviceMaintenance3Properties; + +typedef struct VkDescriptorSetLayoutSupport { + VkStructureType sType; + void* pNext; + VkBool32 supported; +} VkDescriptorSetLayoutSupport; + +typedef struct VkPhysicalDeviceShaderDrawParameterFeatures { + VkStructureType sType; + void* pNext; + VkBool32 shaderDrawParameters; +} VkPhysicalDeviceShaderDrawParameterFeatures; + + +typedef VkResult (VKAPI_PTR *PFN_vkEnumerateInstanceVersion)(uint32_t* pApiVersion); +typedef VkResult (VKAPI_PTR *PFN_vkBindBufferMemory2)(VkDevice device, uint32_t bindInfoCount, const VkBindBufferMemoryInfo* pBindInfos); +typedef VkResult (VKAPI_PTR *PFN_vkBindImageMemory2)(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo* pBindInfos); +typedef void (VKAPI_PTR *PFN_vkGetDeviceGroupPeerMemoryFeatures)(VkDevice device, uint32_t heapIndex, uint32_t localDeviceIndex, uint32_t remoteDeviceIndex, VkPeerMemoryFeatureFlags* pPeerMemoryFeatures); +typedef void (VKAPI_PTR *PFN_vkCmdSetDeviceMask)(VkCommandBuffer commandBuffer, uint32_t deviceMask); +typedef void (VKAPI_PTR *PFN_vkCmdDispatchBase)(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ); +typedef VkResult (VKAPI_PTR *PFN_vkEnumeratePhysicalDeviceGroups)(VkInstance instance, uint32_t* pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties); +typedef void (VKAPI_PTR *PFN_vkGetImageMemoryRequirements2)(VkDevice device, const VkImageMemoryRequirementsInfo2* pInfo, VkMemoryRequirements2* pMemoryRequirements); +typedef void (VKAPI_PTR *PFN_vkGetBufferMemoryRequirements2)(VkDevice device, const VkBufferMemoryRequirementsInfo2* pInfo, VkMemoryRequirements2* pMemoryRequirements); +typedef void (VKAPI_PTR *PFN_vkGetImageSparseMemoryRequirements2)(VkDevice device, const VkImageSparseMemoryRequirementsInfo2* pInfo, uint32_t* pSparseMemoryRequirementCount, VkSparseImageMemoryRequirements2* pSparseMemoryRequirements); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceFeatures2)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures2* pFeatures); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceProperties2)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties2* pProperties); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceFormatProperties2)(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties2* pFormatProperties); +typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceImageFormatProperties2)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo, VkImageFormatProperties2* pImageFormatProperties); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceQueueFamilyProperties2)(VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties2* pQueueFamilyProperties); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceMemoryProperties2)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties2* pMemoryProperties); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceSparseImageFormatProperties2)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo, uint32_t* pPropertyCount, VkSparseImageFormatProperties2* pProperties); +typedef void (VKAPI_PTR *PFN_vkTrimCommandPool)(VkDevice device, VkCommandPool commandPool, VkCommandPoolTrimFlags flags); +typedef void (VKAPI_PTR *PFN_vkGetDeviceQueue2)(VkDevice device, const VkDeviceQueueInfo2* pQueueInfo, VkQueue* pQueue); +typedef VkResult (VKAPI_PTR *PFN_vkCreateSamplerYcbcrConversion)(VkDevice device, const VkSamplerYcbcrConversionCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSamplerYcbcrConversion* pYcbcrConversion); +typedef void (VKAPI_PTR *PFN_vkDestroySamplerYcbcrConversion)(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkCreateDescriptorUpdateTemplate)(VkDevice device, const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate); +typedef void (VKAPI_PTR *PFN_vkDestroyDescriptorUpdateTemplate)(VkDevice device, VkDescriptorUpdateTemplate descriptorUpdateTemplate, const VkAllocationCallbacks* pAllocator); +typedef void (VKAPI_PTR *PFN_vkUpdateDescriptorSetWithTemplate)(VkDevice device, VkDescriptorSet descriptorSet, VkDescriptorUpdateTemplate descriptorUpdateTemplate, const void* pData); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceExternalBufferProperties)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, VkExternalBufferProperties* pExternalBufferProperties); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceExternalFenceProperties)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo, VkExternalFenceProperties* pExternalFenceProperties); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceExternalSemaphoreProperties)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo, VkExternalSemaphoreProperties* pExternalSemaphoreProperties); +typedef void (VKAPI_PTR *PFN_vkGetDescriptorSetLayoutSupport)(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayoutSupport* pSupport); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceVersion( + uint32_t* pApiVersion); + +VKAPI_ATTR VkResult VKAPI_CALL vkBindBufferMemory2( + VkDevice device, + uint32_t bindInfoCount, + const VkBindBufferMemoryInfo* pBindInfos); + +VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory2( + VkDevice device, + uint32_t bindInfoCount, + const VkBindImageMemoryInfo* pBindInfos); + +VKAPI_ATTR void VKAPI_CALL vkGetDeviceGroupPeerMemoryFeatures( + VkDevice device, + uint32_t heapIndex, + uint32_t localDeviceIndex, + uint32_t remoteDeviceIndex, + VkPeerMemoryFeatureFlags* pPeerMemoryFeatures); + +VKAPI_ATTR void VKAPI_CALL vkCmdSetDeviceMask( + VkCommandBuffer commandBuffer, + uint32_t deviceMask); + +VKAPI_ATTR void VKAPI_CALL vkCmdDispatchBase( + VkCommandBuffer commandBuffer, + uint32_t baseGroupX, + uint32_t baseGroupY, + uint32_t baseGroupZ, + uint32_t groupCountX, + uint32_t groupCountY, + uint32_t groupCountZ); + +VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDeviceGroups( + VkInstance instance, + uint32_t* pPhysicalDeviceGroupCount, + VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties); + +VKAPI_ATTR void VKAPI_CALL vkGetImageMemoryRequirements2( + VkDevice device, + const VkImageMemoryRequirementsInfo2* pInfo, + VkMemoryRequirements2* pMemoryRequirements); + +VKAPI_ATTR void VKAPI_CALL vkGetBufferMemoryRequirements2( + VkDevice device, + const VkBufferMemoryRequirementsInfo2* pInfo, + VkMemoryRequirements2* pMemoryRequirements); + +VKAPI_ATTR void VKAPI_CALL vkGetImageSparseMemoryRequirements2( + VkDevice device, + const VkImageSparseMemoryRequirementsInfo2* pInfo, + uint32_t* pSparseMemoryRequirementCount, + VkSparseImageMemoryRequirements2* pSparseMemoryRequirements); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures2( + VkPhysicalDevice physicalDevice, + VkPhysicalDeviceFeatures2* pFeatures); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties2( + VkPhysicalDevice physicalDevice, + VkPhysicalDeviceProperties2* pProperties); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFormatProperties2( + VkPhysicalDevice physicalDevice, + VkFormat format, + VkFormatProperties2* pFormatProperties); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceImageFormatProperties2( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo, + VkImageFormatProperties2* pImageFormatProperties); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceQueueFamilyProperties2( + VkPhysicalDevice physicalDevice, + uint32_t* pQueueFamilyPropertyCount, + VkQueueFamilyProperties2* pQueueFamilyProperties); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties2( + VkPhysicalDevice physicalDevice, + VkPhysicalDeviceMemoryProperties2* pMemoryProperties); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceSparseImageFormatProperties2( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo, + uint32_t* pPropertyCount, + VkSparseImageFormatProperties2* pProperties); + +VKAPI_ATTR void VKAPI_CALL vkTrimCommandPool( + VkDevice device, + VkCommandPool commandPool, + VkCommandPoolTrimFlags flags); + +VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue2( + VkDevice device, + const VkDeviceQueueInfo2* pQueueInfo, + VkQueue* pQueue); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateSamplerYcbcrConversion( + VkDevice device, + const VkSamplerYcbcrConversionCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkSamplerYcbcrConversion* pYcbcrConversion); + +VKAPI_ATTR void VKAPI_CALL vkDestroySamplerYcbcrConversion( + VkDevice device, + VkSamplerYcbcrConversion ycbcrConversion, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorUpdateTemplate( + VkDevice device, + const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate); + +VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorUpdateTemplate( + VkDevice device, + VkDescriptorUpdateTemplate descriptorUpdateTemplate, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSetWithTemplate( + VkDevice device, + VkDescriptorSet descriptorSet, + VkDescriptorUpdateTemplate descriptorUpdateTemplate, + const void* pData); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalBufferProperties( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, + VkExternalBufferProperties* pExternalBufferProperties); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalFenceProperties( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo, + VkExternalFenceProperties* pExternalFenceProperties); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalSemaphoreProperties( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo, + VkExternalSemaphoreProperties* pExternalSemaphoreProperties); + +VKAPI_ATTR void VKAPI_CALL vkGetDescriptorSetLayoutSupport( + VkDevice device, + const VkDescriptorSetLayoutCreateInfo* pCreateInfo, + VkDescriptorSetLayoutSupport* pSupport); +#endif + +#define VK_KHR_surface 1 +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSurfaceKHR) + +#define VK_KHR_SURFACE_SPEC_VERSION 25 +#define VK_KHR_SURFACE_EXTENSION_NAME "VK_KHR_surface" + + +typedef enum VkColorSpaceKHR { + VK_COLOR_SPACE_SRGB_NONLINEAR_KHR = 0, + VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT = 1000104001, + VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT = 1000104002, + VK_COLOR_SPACE_DCI_P3_LINEAR_EXT = 1000104003, + VK_COLOR_SPACE_DCI_P3_NONLINEAR_EXT = 1000104004, + VK_COLOR_SPACE_BT709_LINEAR_EXT = 1000104005, + VK_COLOR_SPACE_BT709_NONLINEAR_EXT = 1000104006, + VK_COLOR_SPACE_BT2020_LINEAR_EXT = 1000104007, + VK_COLOR_SPACE_HDR10_ST2084_EXT = 1000104008, + VK_COLOR_SPACE_DOLBYVISION_EXT = 1000104009, + VK_COLOR_SPACE_HDR10_HLG_EXT = 1000104010, + VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT = 1000104011, + VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT = 1000104012, + VK_COLOR_SPACE_PASS_THROUGH_EXT = 1000104013, + VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT = 1000104014, + VK_COLORSPACE_SRGB_NONLINEAR_KHR = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, + VK_COLOR_SPACE_BEGIN_RANGE_KHR = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, + VK_COLOR_SPACE_END_RANGE_KHR = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, + VK_COLOR_SPACE_RANGE_SIZE_KHR = (VK_COLOR_SPACE_SRGB_NONLINEAR_KHR - VK_COLOR_SPACE_SRGB_NONLINEAR_KHR + 1), + VK_COLOR_SPACE_MAX_ENUM_KHR = 0x7FFFFFFF +} VkColorSpaceKHR; + +typedef enum VkPresentModeKHR { + VK_PRESENT_MODE_IMMEDIATE_KHR = 0, + VK_PRESENT_MODE_MAILBOX_KHR = 1, + VK_PRESENT_MODE_FIFO_KHR = 2, + VK_PRESENT_MODE_FIFO_RELAXED_KHR = 3, + VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR = 1000111000, + VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR = 1000111001, + VK_PRESENT_MODE_BEGIN_RANGE_KHR = VK_PRESENT_MODE_IMMEDIATE_KHR, + VK_PRESENT_MODE_END_RANGE_KHR = VK_PRESENT_MODE_FIFO_RELAXED_KHR, + VK_PRESENT_MODE_RANGE_SIZE_KHR = (VK_PRESENT_MODE_FIFO_RELAXED_KHR - VK_PRESENT_MODE_IMMEDIATE_KHR + 1), + VK_PRESENT_MODE_MAX_ENUM_KHR = 0x7FFFFFFF +} VkPresentModeKHR; + + +typedef enum VkSurfaceTransformFlagBitsKHR { + VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR = 0x00000001, + VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR = 0x00000002, + VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR = 0x00000004, + VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR = 0x00000008, + VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR = 0x00000010, + VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR = 0x00000020, + VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR = 0x00000040, + VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR = 0x00000080, + VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR = 0x00000100, + VK_SURFACE_TRANSFORM_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF +} VkSurfaceTransformFlagBitsKHR; +typedef VkFlags VkSurfaceTransformFlagsKHR; + +typedef enum VkCompositeAlphaFlagBitsKHR { + VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR = 0x00000001, + VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR = 0x00000002, + VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR = 0x00000004, + VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR = 0x00000008, + VK_COMPOSITE_ALPHA_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF +} VkCompositeAlphaFlagBitsKHR; +typedef VkFlags VkCompositeAlphaFlagsKHR; + +typedef struct VkSurfaceCapabilitiesKHR { + uint32_t minImageCount; + uint32_t maxImageCount; + VkExtent2D currentExtent; + VkExtent2D minImageExtent; + VkExtent2D maxImageExtent; + uint32_t maxImageArrayLayers; + VkSurfaceTransformFlagsKHR supportedTransforms; + VkSurfaceTransformFlagBitsKHR currentTransform; + VkCompositeAlphaFlagsKHR supportedCompositeAlpha; + VkImageUsageFlags supportedUsageFlags; +} VkSurfaceCapabilitiesKHR; + +typedef struct VkSurfaceFormatKHR { + VkFormat format; + VkColorSpaceKHR colorSpace; +} VkSurfaceFormatKHR; + + +typedef void (VKAPI_PTR *PFN_vkDestroySurfaceKHR)(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, VkSurfaceKHR surface, VkBool32* pSupported); +typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR* pSurfaceCapabilities); +typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceFormatsKHR)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pSurfaceFormatCount, VkSurfaceFormatKHR* pSurfaceFormats); +typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfacePresentModesKHR)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pPresentModeCount, VkPresentModeKHR* pPresentModes); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR( + VkInstance instance, + VkSurfaceKHR surface, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR( + VkPhysicalDevice physicalDevice, + uint32_t queueFamilyIndex, + VkSurfaceKHR surface, + VkBool32* pSupported); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR( + VkPhysicalDevice physicalDevice, + VkSurfaceKHR surface, + VkSurfaceCapabilitiesKHR* pSurfaceCapabilities); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKHR( + VkPhysicalDevice physicalDevice, + VkSurfaceKHR surface, + uint32_t* pSurfaceFormatCount, + VkSurfaceFormatKHR* pSurfaceFormats); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentModesKHR( + VkPhysicalDevice physicalDevice, + VkSurfaceKHR surface, + uint32_t* pPresentModeCount, + VkPresentModeKHR* pPresentModes); +#endif + +#define VK_KHR_swapchain 1 +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSwapchainKHR) + +#define VK_KHR_SWAPCHAIN_SPEC_VERSION 70 +#define VK_KHR_SWAPCHAIN_EXTENSION_NAME "VK_KHR_swapchain" + + +typedef enum VkSwapchainCreateFlagBitsKHR { + VK_SWAPCHAIN_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHR = 0x00000001, + VK_SWAPCHAIN_CREATE_PROTECTED_BIT_KHR = 0x00000002, + VK_SWAPCHAIN_CREATE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF +} VkSwapchainCreateFlagBitsKHR; +typedef VkFlags VkSwapchainCreateFlagsKHR; + +typedef enum VkDeviceGroupPresentModeFlagBitsKHR { + VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR = 0x00000001, + VK_DEVICE_GROUP_PRESENT_MODE_REMOTE_BIT_KHR = 0x00000002, + VK_DEVICE_GROUP_PRESENT_MODE_SUM_BIT_KHR = 0x00000004, + VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_MULTI_DEVICE_BIT_KHR = 0x00000008, + VK_DEVICE_GROUP_PRESENT_MODE_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF +} VkDeviceGroupPresentModeFlagBitsKHR; +typedef VkFlags VkDeviceGroupPresentModeFlagsKHR; + +typedef struct VkSwapchainCreateInfoKHR { + VkStructureType sType; + const void* pNext; + VkSwapchainCreateFlagsKHR flags; + VkSurfaceKHR surface; + uint32_t minImageCount; + VkFormat imageFormat; + VkColorSpaceKHR imageColorSpace; + VkExtent2D imageExtent; + uint32_t imageArrayLayers; + VkImageUsageFlags imageUsage; + VkSharingMode imageSharingMode; + uint32_t queueFamilyIndexCount; + const uint32_t* pQueueFamilyIndices; + VkSurfaceTransformFlagBitsKHR preTransform; + VkCompositeAlphaFlagBitsKHR compositeAlpha; + VkPresentModeKHR presentMode; + VkBool32 clipped; + VkSwapchainKHR oldSwapchain; +} VkSwapchainCreateInfoKHR; + +typedef struct VkPresentInfoKHR { + VkStructureType sType; + const void* pNext; + uint32_t waitSemaphoreCount; + const VkSemaphore* pWaitSemaphores; + uint32_t swapchainCount; + const VkSwapchainKHR* pSwapchains; + const uint32_t* pImageIndices; + VkResult* pResults; +} VkPresentInfoKHR; + +typedef struct VkImageSwapchainCreateInfoKHR { + VkStructureType sType; + const void* pNext; + VkSwapchainKHR swapchain; +} VkImageSwapchainCreateInfoKHR; + +typedef struct VkBindImageMemorySwapchainInfoKHR { + VkStructureType sType; + const void* pNext; + VkSwapchainKHR swapchain; + uint32_t imageIndex; +} VkBindImageMemorySwapchainInfoKHR; + +typedef struct VkAcquireNextImageInfoKHR { + VkStructureType sType; + const void* pNext; + VkSwapchainKHR swapchain; + uint64_t timeout; + VkSemaphore semaphore; + VkFence fence; + uint32_t deviceMask; +} VkAcquireNextImageInfoKHR; + +typedef struct VkDeviceGroupPresentCapabilitiesKHR { + VkStructureType sType; + const void* pNext; + uint32_t presentMask[VK_MAX_DEVICE_GROUP_SIZE]; + VkDeviceGroupPresentModeFlagsKHR modes; +} VkDeviceGroupPresentCapabilitiesKHR; + +typedef struct VkDeviceGroupPresentInfoKHR { + VkStructureType sType; + const void* pNext; + uint32_t swapchainCount; + const uint32_t* pDeviceMasks; + VkDeviceGroupPresentModeFlagBitsKHR mode; +} VkDeviceGroupPresentInfoKHR; + +typedef struct VkDeviceGroupSwapchainCreateInfoKHR { + VkStructureType sType; + const void* pNext; + VkDeviceGroupPresentModeFlagsKHR modes; +} VkDeviceGroupSwapchainCreateInfoKHR; + + +typedef VkResult (VKAPI_PTR *PFN_vkCreateSwapchainKHR)(VkDevice device, const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchain); +typedef void (VKAPI_PTR *PFN_vkDestroySwapchainKHR)(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainImagesKHR)(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pSwapchainImageCount, VkImage* pSwapchainImages); +typedef VkResult (VKAPI_PTR *PFN_vkAcquireNextImageKHR)(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t* pImageIndex); +typedef VkResult (VKAPI_PTR *PFN_vkQueuePresentKHR)(VkQueue queue, const VkPresentInfoKHR* pPresentInfo); +typedef VkResult (VKAPI_PTR *PFN_vkGetDeviceGroupPresentCapabilitiesKHR)(VkDevice device, VkDeviceGroupPresentCapabilitiesKHR* pDeviceGroupPresentCapabilities); +typedef VkResult (VKAPI_PTR *PFN_vkGetDeviceGroupSurfacePresentModesKHR)(VkDevice device, VkSurfaceKHR surface, VkDeviceGroupPresentModeFlagsKHR* pModes); +typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDevicePresentRectanglesKHR)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t* pRectCount, VkRect2D* pRects); +typedef VkResult (VKAPI_PTR *PFN_vkAcquireNextImage2KHR)(VkDevice device, const VkAcquireNextImageInfoKHR* pAcquireInfo, uint32_t* pImageIndex); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR( + VkDevice device, + const VkSwapchainCreateInfoKHR* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkSwapchainKHR* pSwapchain); + +VKAPI_ATTR void VKAPI_CALL vkDestroySwapchainKHR( + VkDevice device, + VkSwapchainKHR swapchain, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainImagesKHR( + VkDevice device, + VkSwapchainKHR swapchain, + uint32_t* pSwapchainImageCount, + VkImage* pSwapchainImages); + +VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR( + VkDevice device, + VkSwapchainKHR swapchain, + uint64_t timeout, + VkSemaphore semaphore, + VkFence fence, + uint32_t* pImageIndex); + +VKAPI_ATTR VkResult VKAPI_CALL vkQueuePresentKHR( + VkQueue queue, + const VkPresentInfoKHR* pPresentInfo); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupPresentCapabilitiesKHR( + VkDevice device, + VkDeviceGroupPresentCapabilitiesKHR* pDeviceGroupPresentCapabilities); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetDeviceGroupSurfacePresentModesKHR( + VkDevice device, + VkSurfaceKHR surface, + VkDeviceGroupPresentModeFlagsKHR* pModes); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDevicePresentRectanglesKHR( + VkPhysicalDevice physicalDevice, + VkSurfaceKHR surface, + uint32_t* pRectCount, + VkRect2D* pRects); + +VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImage2KHR( + VkDevice device, + const VkAcquireNextImageInfoKHR* pAcquireInfo, + uint32_t* pImageIndex); +#endif + +#define VK_KHR_display 1 +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDisplayKHR) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDisplayModeKHR) + +#define VK_KHR_DISPLAY_SPEC_VERSION 21 +#define VK_KHR_DISPLAY_EXTENSION_NAME "VK_KHR_display" + + +typedef enum VkDisplayPlaneAlphaFlagBitsKHR { + VK_DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR = 0x00000001, + VK_DISPLAY_PLANE_ALPHA_GLOBAL_BIT_KHR = 0x00000002, + VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_BIT_KHR = 0x00000004, + VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_PREMULTIPLIED_BIT_KHR = 0x00000008, + VK_DISPLAY_PLANE_ALPHA_FLAG_BITS_MAX_ENUM_KHR = 0x7FFFFFFF +} VkDisplayPlaneAlphaFlagBitsKHR; +typedef VkFlags VkDisplayPlaneAlphaFlagsKHR; +typedef VkFlags VkDisplayModeCreateFlagsKHR; +typedef VkFlags VkDisplaySurfaceCreateFlagsKHR; + +typedef struct VkDisplayPropertiesKHR { + VkDisplayKHR display; + const char* displayName; + VkExtent2D physicalDimensions; + VkExtent2D physicalResolution; + VkSurfaceTransformFlagsKHR supportedTransforms; + VkBool32 planeReorderPossible; + VkBool32 persistentContent; +} VkDisplayPropertiesKHR; + +typedef struct VkDisplayModeParametersKHR { + VkExtent2D visibleRegion; + uint32_t refreshRate; +} VkDisplayModeParametersKHR; + +typedef struct VkDisplayModePropertiesKHR { + VkDisplayModeKHR displayMode; + VkDisplayModeParametersKHR parameters; +} VkDisplayModePropertiesKHR; + +typedef struct VkDisplayModeCreateInfoKHR { + VkStructureType sType; + const void* pNext; + VkDisplayModeCreateFlagsKHR flags; + VkDisplayModeParametersKHR parameters; +} VkDisplayModeCreateInfoKHR; + +typedef struct VkDisplayPlaneCapabilitiesKHR { + VkDisplayPlaneAlphaFlagsKHR supportedAlpha; + VkOffset2D minSrcPosition; + VkOffset2D maxSrcPosition; + VkExtent2D minSrcExtent; + VkExtent2D maxSrcExtent; + VkOffset2D minDstPosition; + VkOffset2D maxDstPosition; + VkExtent2D minDstExtent; + VkExtent2D maxDstExtent; +} VkDisplayPlaneCapabilitiesKHR; + +typedef struct VkDisplayPlanePropertiesKHR { + VkDisplayKHR currentDisplay; + uint32_t currentStackIndex; +} VkDisplayPlanePropertiesKHR; + +typedef struct VkDisplaySurfaceCreateInfoKHR { + VkStructureType sType; + const void* pNext; + VkDisplaySurfaceCreateFlagsKHR flags; + VkDisplayModeKHR displayMode; + uint32_t planeIndex; + uint32_t planeStackIndex; + VkSurfaceTransformFlagBitsKHR transform; + float globalAlpha; + VkDisplayPlaneAlphaFlagBitsKHR alphaMode; + VkExtent2D imageExtent; +} VkDisplaySurfaceCreateInfoKHR; + + +typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceDisplayPropertiesKHR)(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayPropertiesKHR* pProperties); +typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR)(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayPlanePropertiesKHR* pProperties); +typedef VkResult (VKAPI_PTR *PFN_vkGetDisplayPlaneSupportedDisplaysKHR)(VkPhysicalDevice physicalDevice, uint32_t planeIndex, uint32_t* pDisplayCount, VkDisplayKHR* pDisplays); +typedef VkResult (VKAPI_PTR *PFN_vkGetDisplayModePropertiesKHR)(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t* pPropertyCount, VkDisplayModePropertiesKHR* pProperties); +typedef VkResult (VKAPI_PTR *PFN_vkCreateDisplayModeKHR)(VkPhysicalDevice physicalDevice, VkDisplayKHR display, const VkDisplayModeCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDisplayModeKHR* pMode); +typedef VkResult (VKAPI_PTR *PFN_vkGetDisplayPlaneCapabilitiesKHR)(VkPhysicalDevice physicalDevice, VkDisplayModeKHR mode, uint32_t planeIndex, VkDisplayPlaneCapabilitiesKHR* pCapabilities); +typedef VkResult (VKAPI_PTR *PFN_vkCreateDisplayPlaneSurfaceKHR)(VkInstance instance, const VkDisplaySurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPropertiesKHR( + VkPhysicalDevice physicalDevice, + uint32_t* pPropertyCount, + VkDisplayPropertiesKHR* pProperties); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPlanePropertiesKHR( + VkPhysicalDevice physicalDevice, + uint32_t* pPropertyCount, + VkDisplayPlanePropertiesKHR* pProperties); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneSupportedDisplaysKHR( + VkPhysicalDevice physicalDevice, + uint32_t planeIndex, + uint32_t* pDisplayCount, + VkDisplayKHR* pDisplays); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayModePropertiesKHR( + VkPhysicalDevice physicalDevice, + VkDisplayKHR display, + uint32_t* pPropertyCount, + VkDisplayModePropertiesKHR* pProperties); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayModeKHR( + VkPhysicalDevice physicalDevice, + VkDisplayKHR display, + const VkDisplayModeCreateInfoKHR* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkDisplayModeKHR* pMode); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneCapabilitiesKHR( + VkPhysicalDevice physicalDevice, + VkDisplayModeKHR mode, + uint32_t planeIndex, + VkDisplayPlaneCapabilitiesKHR* pCapabilities); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateDisplayPlaneSurfaceKHR( + VkInstance instance, + const VkDisplaySurfaceCreateInfoKHR* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkSurfaceKHR* pSurface); +#endif + +#define VK_KHR_display_swapchain 1 +#define VK_KHR_DISPLAY_SWAPCHAIN_SPEC_VERSION 9 +#define VK_KHR_DISPLAY_SWAPCHAIN_EXTENSION_NAME "VK_KHR_display_swapchain" + +typedef struct VkDisplayPresentInfoKHR { + VkStructureType sType; + const void* pNext; + VkRect2D srcRect; + VkRect2D dstRect; + VkBool32 persistent; +} VkDisplayPresentInfoKHR; + + +typedef VkResult (VKAPI_PTR *PFN_vkCreateSharedSwapchainsKHR)(VkDevice device, uint32_t swapchainCount, const VkSwapchainCreateInfoKHR* pCreateInfos, const VkAllocationCallbacks* pAllocator, VkSwapchainKHR* pSwapchains); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkCreateSharedSwapchainsKHR( + VkDevice device, + uint32_t swapchainCount, + const VkSwapchainCreateInfoKHR* pCreateInfos, + const VkAllocationCallbacks* pAllocator, + VkSwapchainKHR* pSwapchains); +#endif + +#define VK_KHR_sampler_mirror_clamp_to_edge 1 +#define VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_SPEC_VERSION 1 +#define VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME "VK_KHR_sampler_mirror_clamp_to_edge" + + +#define VK_KHR_multiview 1 +#define VK_KHR_MULTIVIEW_SPEC_VERSION 1 +#define VK_KHR_MULTIVIEW_EXTENSION_NAME "VK_KHR_multiview" + +typedef VkRenderPassMultiviewCreateInfo VkRenderPassMultiviewCreateInfoKHR; + +typedef VkPhysicalDeviceMultiviewFeatures VkPhysicalDeviceMultiviewFeaturesKHR; + +typedef VkPhysicalDeviceMultiviewProperties VkPhysicalDeviceMultiviewPropertiesKHR; + + + +#define VK_KHR_get_physical_device_properties2 1 +#define VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_SPEC_VERSION 1 +#define VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME "VK_KHR_get_physical_device_properties2" + +typedef VkPhysicalDeviceFeatures2 VkPhysicalDeviceFeatures2KHR; + +typedef VkPhysicalDeviceProperties2 VkPhysicalDeviceProperties2KHR; + +typedef VkFormatProperties2 VkFormatProperties2KHR; + +typedef VkImageFormatProperties2 VkImageFormatProperties2KHR; + +typedef VkPhysicalDeviceImageFormatInfo2 VkPhysicalDeviceImageFormatInfo2KHR; + +typedef VkQueueFamilyProperties2 VkQueueFamilyProperties2KHR; + +typedef VkPhysicalDeviceMemoryProperties2 VkPhysicalDeviceMemoryProperties2KHR; + +typedef VkSparseImageFormatProperties2 VkSparseImageFormatProperties2KHR; + +typedef VkPhysicalDeviceSparseImageFormatInfo2 VkPhysicalDeviceSparseImageFormatInfo2KHR; + + +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceFeatures2KHR)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures2* pFeatures); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceProperties2KHR)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties2* pProperties); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceFormatProperties2KHR)(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties2* pFormatProperties); +typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceImageFormatProperties2KHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo, VkImageFormatProperties2* pImageFormatProperties); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceQueueFamilyProperties2KHR)(VkPhysicalDevice physicalDevice, uint32_t* pQueueFamilyPropertyCount, VkQueueFamilyProperties2* pQueueFamilyProperties); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceMemoryProperties2KHR)(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties2* pMemoryProperties); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceSparseImageFormatProperties2KHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo, uint32_t* pPropertyCount, VkSparseImageFormatProperties2* pProperties); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures2KHR( + VkPhysicalDevice physicalDevice, + VkPhysicalDeviceFeatures2* pFeatures); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties2KHR( + VkPhysicalDevice physicalDevice, + VkPhysicalDeviceProperties2* pProperties); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFormatProperties2KHR( + VkPhysicalDevice physicalDevice, + VkFormat format, + VkFormatProperties2* pFormatProperties); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceImageFormatProperties2KHR( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo, + VkImageFormatProperties2* pImageFormatProperties); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceQueueFamilyProperties2KHR( + VkPhysicalDevice physicalDevice, + uint32_t* pQueueFamilyPropertyCount, + VkQueueFamilyProperties2* pQueueFamilyProperties); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties2KHR( + VkPhysicalDevice physicalDevice, + VkPhysicalDeviceMemoryProperties2* pMemoryProperties); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceSparseImageFormatProperties2KHR( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceSparseImageFormatInfo2* pFormatInfo, + uint32_t* pPropertyCount, + VkSparseImageFormatProperties2* pProperties); +#endif + +#define VK_KHR_device_group 1 +#define VK_KHR_DEVICE_GROUP_SPEC_VERSION 3 +#define VK_KHR_DEVICE_GROUP_EXTENSION_NAME "VK_KHR_device_group" + +typedef VkPeerMemoryFeatureFlags VkPeerMemoryFeatureFlagsKHR; + +typedef VkPeerMemoryFeatureFlagBits VkPeerMemoryFeatureFlagBitsKHR; + +typedef VkMemoryAllocateFlags VkMemoryAllocateFlagsKHR; + +typedef VkMemoryAllocateFlagBits VkMemoryAllocateFlagBitsKHR; + + +typedef VkMemoryAllocateFlagsInfo VkMemoryAllocateFlagsInfoKHR; + +typedef VkDeviceGroupRenderPassBeginInfo VkDeviceGroupRenderPassBeginInfoKHR; + +typedef VkDeviceGroupCommandBufferBeginInfo VkDeviceGroupCommandBufferBeginInfoKHR; + +typedef VkDeviceGroupSubmitInfo VkDeviceGroupSubmitInfoKHR; + +typedef VkDeviceGroupBindSparseInfo VkDeviceGroupBindSparseInfoKHR; + +typedef VkBindBufferMemoryDeviceGroupInfo VkBindBufferMemoryDeviceGroupInfoKHR; + +typedef VkBindImageMemoryDeviceGroupInfo VkBindImageMemoryDeviceGroupInfoKHR; + + +typedef void (VKAPI_PTR *PFN_vkGetDeviceGroupPeerMemoryFeaturesKHR)(VkDevice device, uint32_t heapIndex, uint32_t localDeviceIndex, uint32_t remoteDeviceIndex, VkPeerMemoryFeatureFlags* pPeerMemoryFeatures); +typedef void (VKAPI_PTR *PFN_vkCmdSetDeviceMaskKHR)(VkCommandBuffer commandBuffer, uint32_t deviceMask); +typedef void (VKAPI_PTR *PFN_vkCmdDispatchBaseKHR)(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkGetDeviceGroupPeerMemoryFeaturesKHR( + VkDevice device, + uint32_t heapIndex, + uint32_t localDeviceIndex, + uint32_t remoteDeviceIndex, + VkPeerMemoryFeatureFlags* pPeerMemoryFeatures); + +VKAPI_ATTR void VKAPI_CALL vkCmdSetDeviceMaskKHR( + VkCommandBuffer commandBuffer, + uint32_t deviceMask); + +VKAPI_ATTR void VKAPI_CALL vkCmdDispatchBaseKHR( + VkCommandBuffer commandBuffer, + uint32_t baseGroupX, + uint32_t baseGroupY, + uint32_t baseGroupZ, + uint32_t groupCountX, + uint32_t groupCountY, + uint32_t groupCountZ); +#endif + +#define VK_KHR_shader_draw_parameters 1 +#define VK_KHR_SHADER_DRAW_PARAMETERS_SPEC_VERSION 1 +#define VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME "VK_KHR_shader_draw_parameters" + + +#define VK_KHR_maintenance1 1 +#define VK_KHR_MAINTENANCE1_SPEC_VERSION 2 +#define VK_KHR_MAINTENANCE1_EXTENSION_NAME "VK_KHR_maintenance1" + +typedef VkCommandPoolTrimFlags VkCommandPoolTrimFlagsKHR; + + +typedef void (VKAPI_PTR *PFN_vkTrimCommandPoolKHR)(VkDevice device, VkCommandPool commandPool, VkCommandPoolTrimFlags flags); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkTrimCommandPoolKHR( + VkDevice device, + VkCommandPool commandPool, + VkCommandPoolTrimFlags flags); +#endif + +#define VK_KHR_device_group_creation 1 +#define VK_KHR_DEVICE_GROUP_CREATION_SPEC_VERSION 1 +#define VK_KHR_DEVICE_GROUP_CREATION_EXTENSION_NAME "VK_KHR_device_group_creation" +#define VK_MAX_DEVICE_GROUP_SIZE_KHR VK_MAX_DEVICE_GROUP_SIZE + +typedef VkPhysicalDeviceGroupProperties VkPhysicalDeviceGroupPropertiesKHR; + +typedef VkDeviceGroupDeviceCreateInfo VkDeviceGroupDeviceCreateInfoKHR; + + +typedef VkResult (VKAPI_PTR *PFN_vkEnumeratePhysicalDeviceGroupsKHR)(VkInstance instance, uint32_t* pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDeviceGroupsKHR( + VkInstance instance, + uint32_t* pPhysicalDeviceGroupCount, + VkPhysicalDeviceGroupProperties* pPhysicalDeviceGroupProperties); +#endif + +#define VK_KHR_external_memory_capabilities 1 +#define VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_SPEC_VERSION 1 +#define VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME "VK_KHR_external_memory_capabilities" +#define VK_LUID_SIZE_KHR VK_LUID_SIZE + +typedef VkExternalMemoryHandleTypeFlags VkExternalMemoryHandleTypeFlagsKHR; + +typedef VkExternalMemoryHandleTypeFlagBits VkExternalMemoryHandleTypeFlagBitsKHR; + +typedef VkExternalMemoryFeatureFlags VkExternalMemoryFeatureFlagsKHR; + +typedef VkExternalMemoryFeatureFlagBits VkExternalMemoryFeatureFlagBitsKHR; + + +typedef VkExternalMemoryProperties VkExternalMemoryPropertiesKHR; + +typedef VkPhysicalDeviceExternalImageFormatInfo VkPhysicalDeviceExternalImageFormatInfoKHR; + +typedef VkExternalImageFormatProperties VkExternalImageFormatPropertiesKHR; + +typedef VkPhysicalDeviceExternalBufferInfo VkPhysicalDeviceExternalBufferInfoKHR; + +typedef VkExternalBufferProperties VkExternalBufferPropertiesKHR; + +typedef VkPhysicalDeviceIDProperties VkPhysicalDeviceIDPropertiesKHR; + + +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceExternalBufferPropertiesKHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, VkExternalBufferProperties* pExternalBufferProperties); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalBufferPropertiesKHR( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, + VkExternalBufferProperties* pExternalBufferProperties); +#endif + +#define VK_KHR_external_memory 1 +#define VK_KHR_EXTERNAL_MEMORY_SPEC_VERSION 1 +#define VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME "VK_KHR_external_memory" +#define VK_QUEUE_FAMILY_EXTERNAL_KHR VK_QUEUE_FAMILY_EXTERNAL + +typedef VkExternalMemoryImageCreateInfo VkExternalMemoryImageCreateInfoKHR; + +typedef VkExternalMemoryBufferCreateInfo VkExternalMemoryBufferCreateInfoKHR; + +typedef VkExportMemoryAllocateInfo VkExportMemoryAllocateInfoKHR; + + + +#define VK_KHR_external_memory_fd 1 +#define VK_KHR_EXTERNAL_MEMORY_FD_SPEC_VERSION 1 +#define VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME "VK_KHR_external_memory_fd" + +typedef struct VkImportMemoryFdInfoKHR { + VkStructureType sType; + const void* pNext; + VkExternalMemoryHandleTypeFlagBits handleType; + int fd; +} VkImportMemoryFdInfoKHR; + +typedef struct VkMemoryFdPropertiesKHR { + VkStructureType sType; + void* pNext; + uint32_t memoryTypeBits; +} VkMemoryFdPropertiesKHR; + +typedef struct VkMemoryGetFdInfoKHR { + VkStructureType sType; + const void* pNext; + VkDeviceMemory memory; + VkExternalMemoryHandleTypeFlagBits handleType; +} VkMemoryGetFdInfoKHR; + + +typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryFdKHR)(VkDevice device, const VkMemoryGetFdInfoKHR* pGetFdInfo, int* pFd); +typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryFdPropertiesKHR)(VkDevice device, VkExternalMemoryHandleTypeFlagBits handleType, int fd, VkMemoryFdPropertiesKHR* pMemoryFdProperties); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryFdKHR( + VkDevice device, + const VkMemoryGetFdInfoKHR* pGetFdInfo, + int* pFd); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryFdPropertiesKHR( + VkDevice device, + VkExternalMemoryHandleTypeFlagBits handleType, + int fd, + VkMemoryFdPropertiesKHR* pMemoryFdProperties); +#endif + +#define VK_KHR_external_semaphore_capabilities 1 +#define VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_SPEC_VERSION 1 +#define VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME "VK_KHR_external_semaphore_capabilities" + +typedef VkExternalSemaphoreHandleTypeFlags VkExternalSemaphoreHandleTypeFlagsKHR; + +typedef VkExternalSemaphoreHandleTypeFlagBits VkExternalSemaphoreHandleTypeFlagBitsKHR; + +typedef VkExternalSemaphoreFeatureFlags VkExternalSemaphoreFeatureFlagsKHR; + +typedef VkExternalSemaphoreFeatureFlagBits VkExternalSemaphoreFeatureFlagBitsKHR; + + +typedef VkPhysicalDeviceExternalSemaphoreInfo VkPhysicalDeviceExternalSemaphoreInfoKHR; + +typedef VkExternalSemaphoreProperties VkExternalSemaphorePropertiesKHR; + + +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo, VkExternalSemaphoreProperties* pExternalSemaphoreProperties); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalSemaphorePropertiesKHR( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo, + VkExternalSemaphoreProperties* pExternalSemaphoreProperties); +#endif + +#define VK_KHR_external_semaphore 1 +#define VK_KHR_EXTERNAL_SEMAPHORE_SPEC_VERSION 1 +#define VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME "VK_KHR_external_semaphore" + +typedef VkSemaphoreImportFlags VkSemaphoreImportFlagsKHR; + +typedef VkSemaphoreImportFlagBits VkSemaphoreImportFlagBitsKHR; + + +typedef VkExportSemaphoreCreateInfo VkExportSemaphoreCreateInfoKHR; + + + +#define VK_KHR_external_semaphore_fd 1 +#define VK_KHR_EXTERNAL_SEMAPHORE_FD_SPEC_VERSION 1 +#define VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME "VK_KHR_external_semaphore_fd" + +typedef struct VkImportSemaphoreFdInfoKHR { + VkStructureType sType; + const void* pNext; + VkSemaphore semaphore; + VkSemaphoreImportFlags flags; + VkExternalSemaphoreHandleTypeFlagBits handleType; + int fd; +} VkImportSemaphoreFdInfoKHR; + +typedef struct VkSemaphoreGetFdInfoKHR { + VkStructureType sType; + const void* pNext; + VkSemaphore semaphore; + VkExternalSemaphoreHandleTypeFlagBits handleType; +} VkSemaphoreGetFdInfoKHR; + + +typedef VkResult (VKAPI_PTR *PFN_vkImportSemaphoreFdKHR)(VkDevice device, const VkImportSemaphoreFdInfoKHR* pImportSemaphoreFdInfo); +typedef VkResult (VKAPI_PTR *PFN_vkGetSemaphoreFdKHR)(VkDevice device, const VkSemaphoreGetFdInfoKHR* pGetFdInfo, int* pFd); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkImportSemaphoreFdKHR( + VkDevice device, + const VkImportSemaphoreFdInfoKHR* pImportSemaphoreFdInfo); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetSemaphoreFdKHR( + VkDevice device, + const VkSemaphoreGetFdInfoKHR* pGetFdInfo, + int* pFd); +#endif + +#define VK_KHR_push_descriptor 1 +#define VK_KHR_PUSH_DESCRIPTOR_SPEC_VERSION 2 +#define VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME "VK_KHR_push_descriptor" + +typedef struct VkPhysicalDevicePushDescriptorPropertiesKHR { + VkStructureType sType; + void* pNext; + uint32_t maxPushDescriptors; +} VkPhysicalDevicePushDescriptorPropertiesKHR; + + +typedef void (VKAPI_PTR *PFN_vkCmdPushDescriptorSetKHR)(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t set, uint32_t descriptorWriteCount, const VkWriteDescriptorSet* pDescriptorWrites); +typedef void (VKAPI_PTR *PFN_vkCmdPushDescriptorSetWithTemplateKHR)(VkCommandBuffer commandBuffer, VkDescriptorUpdateTemplate descriptorUpdateTemplate, VkPipelineLayout layout, uint32_t set, const void* pData); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkCmdPushDescriptorSetKHR( + VkCommandBuffer commandBuffer, + VkPipelineBindPoint pipelineBindPoint, + VkPipelineLayout layout, + uint32_t set, + uint32_t descriptorWriteCount, + const VkWriteDescriptorSet* pDescriptorWrites); + +VKAPI_ATTR void VKAPI_CALL vkCmdPushDescriptorSetWithTemplateKHR( + VkCommandBuffer commandBuffer, + VkDescriptorUpdateTemplate descriptorUpdateTemplate, + VkPipelineLayout layout, + uint32_t set, + const void* pData); +#endif + +#define VK_KHR_16bit_storage 1 +#define VK_KHR_16BIT_STORAGE_SPEC_VERSION 1 +#define VK_KHR_16BIT_STORAGE_EXTENSION_NAME "VK_KHR_16bit_storage" + +typedef VkPhysicalDevice16BitStorageFeatures VkPhysicalDevice16BitStorageFeaturesKHR; + + + +#define VK_KHR_incremental_present 1 +#define VK_KHR_INCREMENTAL_PRESENT_SPEC_VERSION 1 +#define VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME "VK_KHR_incremental_present" + +typedef struct VkRectLayerKHR { + VkOffset2D offset; + VkExtent2D extent; + uint32_t layer; +} VkRectLayerKHR; + +typedef struct VkPresentRegionKHR { + uint32_t rectangleCount; + const VkRectLayerKHR* pRectangles; +} VkPresentRegionKHR; + +typedef struct VkPresentRegionsKHR { + VkStructureType sType; + const void* pNext; + uint32_t swapchainCount; + const VkPresentRegionKHR* pRegions; +} VkPresentRegionsKHR; + + + +#define VK_KHR_descriptor_update_template 1 +typedef VkDescriptorUpdateTemplate VkDescriptorUpdateTemplateKHR; + + +#define VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_SPEC_VERSION 1 +#define VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME "VK_KHR_descriptor_update_template" + +typedef VkDescriptorUpdateTemplateType VkDescriptorUpdateTemplateTypeKHR; + + +typedef VkDescriptorUpdateTemplateCreateFlags VkDescriptorUpdateTemplateCreateFlagsKHR; + + +typedef VkDescriptorUpdateTemplateEntry VkDescriptorUpdateTemplateEntryKHR; + +typedef VkDescriptorUpdateTemplateCreateInfo VkDescriptorUpdateTemplateCreateInfoKHR; + + +typedef VkResult (VKAPI_PTR *PFN_vkCreateDescriptorUpdateTemplateKHR)(VkDevice device, const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate); +typedef void (VKAPI_PTR *PFN_vkDestroyDescriptorUpdateTemplateKHR)(VkDevice device, VkDescriptorUpdateTemplate descriptorUpdateTemplate, const VkAllocationCallbacks* pAllocator); +typedef void (VKAPI_PTR *PFN_vkUpdateDescriptorSetWithTemplateKHR)(VkDevice device, VkDescriptorSet descriptorSet, VkDescriptorUpdateTemplate descriptorUpdateTemplate, const void* pData); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkCreateDescriptorUpdateTemplateKHR( + VkDevice device, + const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate); + +VKAPI_ATTR void VKAPI_CALL vkDestroyDescriptorUpdateTemplateKHR( + VkDevice device, + VkDescriptorUpdateTemplate descriptorUpdateTemplate, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSetWithTemplateKHR( + VkDevice device, + VkDescriptorSet descriptorSet, + VkDescriptorUpdateTemplate descriptorUpdateTemplate, + const void* pData); +#endif + +#define VK_KHR_create_renderpass2 1 +#define VK_KHR_CREATE_RENDERPASS_2_SPEC_VERSION 1 +#define VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME "VK_KHR_create_renderpass2" + +typedef struct VkAttachmentDescription2KHR { + VkStructureType sType; + const void* pNext; + VkAttachmentDescriptionFlags flags; + VkFormat format; + VkSampleCountFlagBits samples; + VkAttachmentLoadOp loadOp; + VkAttachmentStoreOp storeOp; + VkAttachmentLoadOp stencilLoadOp; + VkAttachmentStoreOp stencilStoreOp; + VkImageLayout initialLayout; + VkImageLayout finalLayout; +} VkAttachmentDescription2KHR; + +typedef struct VkAttachmentReference2KHR { + VkStructureType sType; + const void* pNext; + uint32_t attachment; + VkImageLayout layout; + VkImageAspectFlags aspectMask; +} VkAttachmentReference2KHR; + +typedef struct VkSubpassDescription2KHR { + VkStructureType sType; + const void* pNext; + VkSubpassDescriptionFlags flags; + VkPipelineBindPoint pipelineBindPoint; + uint32_t viewMask; + uint32_t inputAttachmentCount; + const VkAttachmentReference2KHR* pInputAttachments; + uint32_t colorAttachmentCount; + const VkAttachmentReference2KHR* pColorAttachments; + const VkAttachmentReference2KHR* pResolveAttachments; + const VkAttachmentReference2KHR* pDepthStencilAttachment; + uint32_t preserveAttachmentCount; + const uint32_t* pPreserveAttachments; +} VkSubpassDescription2KHR; + +typedef struct VkSubpassDependency2KHR { + VkStructureType sType; + const void* pNext; + uint32_t srcSubpass; + uint32_t dstSubpass; + VkPipelineStageFlags srcStageMask; + VkPipelineStageFlags dstStageMask; + VkAccessFlags srcAccessMask; + VkAccessFlags dstAccessMask; + VkDependencyFlags dependencyFlags; + int32_t viewOffset; +} VkSubpassDependency2KHR; + +typedef struct VkRenderPassCreateInfo2KHR { + VkStructureType sType; + const void* pNext; + VkRenderPassCreateFlags flags; + uint32_t attachmentCount; + const VkAttachmentDescription2KHR* pAttachments; + uint32_t subpassCount; + const VkSubpassDescription2KHR* pSubpasses; + uint32_t dependencyCount; + const VkSubpassDependency2KHR* pDependencies; + uint32_t correlatedViewMaskCount; + const uint32_t* pCorrelatedViewMasks; +} VkRenderPassCreateInfo2KHR; + +typedef struct VkSubpassBeginInfoKHR { + VkStructureType sType; + const void* pNext; + VkSubpassContents contents; +} VkSubpassBeginInfoKHR; + +typedef struct VkSubpassEndInfoKHR { + VkStructureType sType; + const void* pNext; +} VkSubpassEndInfoKHR; + + +typedef VkResult (VKAPI_PTR *PFN_vkCreateRenderPass2KHR)(VkDevice device, const VkRenderPassCreateInfo2KHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkRenderPass* pRenderPass); +typedef void (VKAPI_PTR *PFN_vkCmdBeginRenderPass2KHR)(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, const VkSubpassBeginInfoKHR* pSubpassBeginInfo); +typedef void (VKAPI_PTR *PFN_vkCmdNextSubpass2KHR)(VkCommandBuffer commandBuffer, const VkSubpassBeginInfoKHR* pSubpassBeginInfo, const VkSubpassEndInfoKHR* pSubpassEndInfo); +typedef void (VKAPI_PTR *PFN_vkCmdEndRenderPass2KHR)(VkCommandBuffer commandBuffer, const VkSubpassEndInfoKHR* pSubpassEndInfo); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass2KHR( + VkDevice device, + const VkRenderPassCreateInfo2KHR* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkRenderPass* pRenderPass); + +VKAPI_ATTR void VKAPI_CALL vkCmdBeginRenderPass2KHR( + VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + const VkSubpassBeginInfoKHR* pSubpassBeginInfo); + +VKAPI_ATTR void VKAPI_CALL vkCmdNextSubpass2KHR( + VkCommandBuffer commandBuffer, + const VkSubpassBeginInfoKHR* pSubpassBeginInfo, + const VkSubpassEndInfoKHR* pSubpassEndInfo); + +VKAPI_ATTR void VKAPI_CALL vkCmdEndRenderPass2KHR( + VkCommandBuffer commandBuffer, + const VkSubpassEndInfoKHR* pSubpassEndInfo); +#endif + +#define VK_KHR_shared_presentable_image 1 +#define VK_KHR_SHARED_PRESENTABLE_IMAGE_SPEC_VERSION 1 +#define VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME "VK_KHR_shared_presentable_image" + +typedef struct VkSharedPresentSurfaceCapabilitiesKHR { + VkStructureType sType; + void* pNext; + VkImageUsageFlags sharedPresentSupportedUsageFlags; +} VkSharedPresentSurfaceCapabilitiesKHR; + + +typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainStatusKHR)(VkDevice device, VkSwapchainKHR swapchain); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainStatusKHR( + VkDevice device, + VkSwapchainKHR swapchain); +#endif + +#define VK_KHR_external_fence_capabilities 1 +#define VK_KHR_EXTERNAL_FENCE_CAPABILITIES_SPEC_VERSION 1 +#define VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME "VK_KHR_external_fence_capabilities" + +typedef VkExternalFenceHandleTypeFlags VkExternalFenceHandleTypeFlagsKHR; + +typedef VkExternalFenceHandleTypeFlagBits VkExternalFenceHandleTypeFlagBitsKHR; + +typedef VkExternalFenceFeatureFlags VkExternalFenceFeatureFlagsKHR; + +typedef VkExternalFenceFeatureFlagBits VkExternalFenceFeatureFlagBitsKHR; + + +typedef VkPhysicalDeviceExternalFenceInfo VkPhysicalDeviceExternalFenceInfoKHR; + +typedef VkExternalFenceProperties VkExternalFencePropertiesKHR; + + +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceExternalFencePropertiesKHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo, VkExternalFenceProperties* pExternalFenceProperties); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceExternalFencePropertiesKHR( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo, + VkExternalFenceProperties* pExternalFenceProperties); +#endif + +#define VK_KHR_external_fence 1 +#define VK_KHR_EXTERNAL_FENCE_SPEC_VERSION 1 +#define VK_KHR_EXTERNAL_FENCE_EXTENSION_NAME "VK_KHR_external_fence" + +typedef VkFenceImportFlags VkFenceImportFlagsKHR; + +typedef VkFenceImportFlagBits VkFenceImportFlagBitsKHR; + + +typedef VkExportFenceCreateInfo VkExportFenceCreateInfoKHR; + + + +#define VK_KHR_external_fence_fd 1 +#define VK_KHR_EXTERNAL_FENCE_FD_SPEC_VERSION 1 +#define VK_KHR_EXTERNAL_FENCE_FD_EXTENSION_NAME "VK_KHR_external_fence_fd" + +typedef struct VkImportFenceFdInfoKHR { + VkStructureType sType; + const void* pNext; + VkFence fence; + VkFenceImportFlags flags; + VkExternalFenceHandleTypeFlagBits handleType; + int fd; +} VkImportFenceFdInfoKHR; + +typedef struct VkFenceGetFdInfoKHR { + VkStructureType sType; + const void* pNext; + VkFence fence; + VkExternalFenceHandleTypeFlagBits handleType; +} VkFenceGetFdInfoKHR; + + +typedef VkResult (VKAPI_PTR *PFN_vkImportFenceFdKHR)(VkDevice device, const VkImportFenceFdInfoKHR* pImportFenceFdInfo); +typedef VkResult (VKAPI_PTR *PFN_vkGetFenceFdKHR)(VkDevice device, const VkFenceGetFdInfoKHR* pGetFdInfo, int* pFd); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkImportFenceFdKHR( + VkDevice device, + const VkImportFenceFdInfoKHR* pImportFenceFdInfo); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetFenceFdKHR( + VkDevice device, + const VkFenceGetFdInfoKHR* pGetFdInfo, + int* pFd); +#endif + +#define VK_KHR_maintenance2 1 +#define VK_KHR_MAINTENANCE2_SPEC_VERSION 1 +#define VK_KHR_MAINTENANCE2_EXTENSION_NAME "VK_KHR_maintenance2" + +typedef VkPointClippingBehavior VkPointClippingBehaviorKHR; + +typedef VkTessellationDomainOrigin VkTessellationDomainOriginKHR; + + +typedef VkPhysicalDevicePointClippingProperties VkPhysicalDevicePointClippingPropertiesKHR; + +typedef VkRenderPassInputAttachmentAspectCreateInfo VkRenderPassInputAttachmentAspectCreateInfoKHR; + +typedef VkInputAttachmentAspectReference VkInputAttachmentAspectReferenceKHR; + +typedef VkImageViewUsageCreateInfo VkImageViewUsageCreateInfoKHR; + +typedef VkPipelineTessellationDomainOriginStateCreateInfo VkPipelineTessellationDomainOriginStateCreateInfoKHR; + + + +#define VK_KHR_get_surface_capabilities2 1 +#define VK_KHR_GET_SURFACE_CAPABILITIES_2_SPEC_VERSION 1 +#define VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME "VK_KHR_get_surface_capabilities2" + +typedef struct VkPhysicalDeviceSurfaceInfo2KHR { + VkStructureType sType; + const void* pNext; + VkSurfaceKHR surface; +} VkPhysicalDeviceSurfaceInfo2KHR; + +typedef struct VkSurfaceCapabilities2KHR { + VkStructureType sType; + void* pNext; + VkSurfaceCapabilitiesKHR surfaceCapabilities; +} VkSurfaceCapabilities2KHR; + +typedef struct VkSurfaceFormat2KHR { + VkStructureType sType; + void* pNext; + VkSurfaceFormatKHR surfaceFormat; +} VkSurfaceFormat2KHR; + + +typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, VkSurfaceCapabilities2KHR* pSurfaceCapabilities); +typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceFormats2KHR)(VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, uint32_t* pSurfaceFormatCount, VkSurfaceFormat2KHR* pSurfaceFormats); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilities2KHR( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, + VkSurfaceCapabilities2KHR* pSurfaceCapabilities); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormats2KHR( + VkPhysicalDevice physicalDevice, + const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo, + uint32_t* pSurfaceFormatCount, + VkSurfaceFormat2KHR* pSurfaceFormats); +#endif + +#define VK_KHR_variable_pointers 1 +#define VK_KHR_VARIABLE_POINTERS_SPEC_VERSION 1 +#define VK_KHR_VARIABLE_POINTERS_EXTENSION_NAME "VK_KHR_variable_pointers" + +typedef VkPhysicalDeviceVariablePointerFeatures VkPhysicalDeviceVariablePointerFeaturesKHR; + + + +#define VK_KHR_get_display_properties2 1 +#define VK_KHR_GET_DISPLAY_PROPERTIES_2_SPEC_VERSION 1 +#define VK_KHR_GET_DISPLAY_PROPERTIES_2_EXTENSION_NAME "VK_KHR_get_display_properties2" + +typedef struct VkDisplayProperties2KHR { + VkStructureType sType; + void* pNext; + VkDisplayPropertiesKHR displayProperties; +} VkDisplayProperties2KHR; + +typedef struct VkDisplayPlaneProperties2KHR { + VkStructureType sType; + void* pNext; + VkDisplayPlanePropertiesKHR displayPlaneProperties; +} VkDisplayPlaneProperties2KHR; + +typedef struct VkDisplayModeProperties2KHR { + VkStructureType sType; + void* pNext; + VkDisplayModePropertiesKHR displayModeProperties; +} VkDisplayModeProperties2KHR; + +typedef struct VkDisplayPlaneInfo2KHR { + VkStructureType sType; + const void* pNext; + VkDisplayModeKHR mode; + uint32_t planeIndex; +} VkDisplayPlaneInfo2KHR; + +typedef struct VkDisplayPlaneCapabilities2KHR { + VkStructureType sType; + void* pNext; + VkDisplayPlaneCapabilitiesKHR capabilities; +} VkDisplayPlaneCapabilities2KHR; + + +typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceDisplayProperties2KHR)(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayProperties2KHR* pProperties); +typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceDisplayPlaneProperties2KHR)(VkPhysicalDevice physicalDevice, uint32_t* pPropertyCount, VkDisplayPlaneProperties2KHR* pProperties); +typedef VkResult (VKAPI_PTR *PFN_vkGetDisplayModeProperties2KHR)(VkPhysicalDevice physicalDevice, VkDisplayKHR display, uint32_t* pPropertyCount, VkDisplayModeProperties2KHR* pProperties); +typedef VkResult (VKAPI_PTR *PFN_vkGetDisplayPlaneCapabilities2KHR)(VkPhysicalDevice physicalDevice, const VkDisplayPlaneInfo2KHR* pDisplayPlaneInfo, VkDisplayPlaneCapabilities2KHR* pCapabilities); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayProperties2KHR( + VkPhysicalDevice physicalDevice, + uint32_t* pPropertyCount, + VkDisplayProperties2KHR* pProperties); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceDisplayPlaneProperties2KHR( + VkPhysicalDevice physicalDevice, + uint32_t* pPropertyCount, + VkDisplayPlaneProperties2KHR* pProperties); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayModeProperties2KHR( + VkPhysicalDevice physicalDevice, + VkDisplayKHR display, + uint32_t* pPropertyCount, + VkDisplayModeProperties2KHR* pProperties); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetDisplayPlaneCapabilities2KHR( + VkPhysicalDevice physicalDevice, + const VkDisplayPlaneInfo2KHR* pDisplayPlaneInfo, + VkDisplayPlaneCapabilities2KHR* pCapabilities); +#endif + +#define VK_KHR_dedicated_allocation 1 +#define VK_KHR_DEDICATED_ALLOCATION_SPEC_VERSION 3 +#define VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME "VK_KHR_dedicated_allocation" + +typedef VkMemoryDedicatedRequirements VkMemoryDedicatedRequirementsKHR; + +typedef VkMemoryDedicatedAllocateInfo VkMemoryDedicatedAllocateInfoKHR; + + + +#define VK_KHR_storage_buffer_storage_class 1 +#define VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_SPEC_VERSION 1 +#define VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_EXTENSION_NAME "VK_KHR_storage_buffer_storage_class" + + +#define VK_KHR_relaxed_block_layout 1 +#define VK_KHR_RELAXED_BLOCK_LAYOUT_SPEC_VERSION 1 +#define VK_KHR_RELAXED_BLOCK_LAYOUT_EXTENSION_NAME "VK_KHR_relaxed_block_layout" + + +#define VK_KHR_get_memory_requirements2 1 +#define VK_KHR_GET_MEMORY_REQUIREMENTS_2_SPEC_VERSION 1 +#define VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME "VK_KHR_get_memory_requirements2" + +typedef VkBufferMemoryRequirementsInfo2 VkBufferMemoryRequirementsInfo2KHR; + +typedef VkImageMemoryRequirementsInfo2 VkImageMemoryRequirementsInfo2KHR; + +typedef VkImageSparseMemoryRequirementsInfo2 VkImageSparseMemoryRequirementsInfo2KHR; + +typedef VkMemoryRequirements2 VkMemoryRequirements2KHR; + +typedef VkSparseImageMemoryRequirements2 VkSparseImageMemoryRequirements2KHR; + + +typedef void (VKAPI_PTR *PFN_vkGetImageMemoryRequirements2KHR)(VkDevice device, const VkImageMemoryRequirementsInfo2* pInfo, VkMemoryRequirements2* pMemoryRequirements); +typedef void (VKAPI_PTR *PFN_vkGetBufferMemoryRequirements2KHR)(VkDevice device, const VkBufferMemoryRequirementsInfo2* pInfo, VkMemoryRequirements2* pMemoryRequirements); +typedef void (VKAPI_PTR *PFN_vkGetImageSparseMemoryRequirements2KHR)(VkDevice device, const VkImageSparseMemoryRequirementsInfo2* pInfo, uint32_t* pSparseMemoryRequirementCount, VkSparseImageMemoryRequirements2* pSparseMemoryRequirements); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkGetImageMemoryRequirements2KHR( + VkDevice device, + const VkImageMemoryRequirementsInfo2* pInfo, + VkMemoryRequirements2* pMemoryRequirements); + +VKAPI_ATTR void VKAPI_CALL vkGetBufferMemoryRequirements2KHR( + VkDevice device, + const VkBufferMemoryRequirementsInfo2* pInfo, + VkMemoryRequirements2* pMemoryRequirements); + +VKAPI_ATTR void VKAPI_CALL vkGetImageSparseMemoryRequirements2KHR( + VkDevice device, + const VkImageSparseMemoryRequirementsInfo2* pInfo, + uint32_t* pSparseMemoryRequirementCount, + VkSparseImageMemoryRequirements2* pSparseMemoryRequirements); +#endif + +#define VK_KHR_image_format_list 1 +#define VK_KHR_IMAGE_FORMAT_LIST_SPEC_VERSION 1 +#define VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME "VK_KHR_image_format_list" + +typedef struct VkImageFormatListCreateInfoKHR { + VkStructureType sType; + const void* pNext; + uint32_t viewFormatCount; + const VkFormat* pViewFormats; +} VkImageFormatListCreateInfoKHR; + + + +#define VK_KHR_sampler_ycbcr_conversion 1 +typedef VkSamplerYcbcrConversion VkSamplerYcbcrConversionKHR; + + +#define VK_KHR_SAMPLER_YCBCR_CONVERSION_SPEC_VERSION 1 +#define VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME "VK_KHR_sampler_ycbcr_conversion" + +typedef VkSamplerYcbcrModelConversion VkSamplerYcbcrModelConversionKHR; + +typedef VkSamplerYcbcrRange VkSamplerYcbcrRangeKHR; + +typedef VkChromaLocation VkChromaLocationKHR; + + +typedef VkSamplerYcbcrConversionCreateInfo VkSamplerYcbcrConversionCreateInfoKHR; + +typedef VkSamplerYcbcrConversionInfo VkSamplerYcbcrConversionInfoKHR; + +typedef VkBindImagePlaneMemoryInfo VkBindImagePlaneMemoryInfoKHR; + +typedef VkImagePlaneMemoryRequirementsInfo VkImagePlaneMemoryRequirementsInfoKHR; + +typedef VkPhysicalDeviceSamplerYcbcrConversionFeatures VkPhysicalDeviceSamplerYcbcrConversionFeaturesKHR; + +typedef VkSamplerYcbcrConversionImageFormatProperties VkSamplerYcbcrConversionImageFormatPropertiesKHR; + + +typedef VkResult (VKAPI_PTR *PFN_vkCreateSamplerYcbcrConversionKHR)(VkDevice device, const VkSamplerYcbcrConversionCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSamplerYcbcrConversion* pYcbcrConversion); +typedef void (VKAPI_PTR *PFN_vkDestroySamplerYcbcrConversionKHR)(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion, const VkAllocationCallbacks* pAllocator); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkCreateSamplerYcbcrConversionKHR( + VkDevice device, + const VkSamplerYcbcrConversionCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkSamplerYcbcrConversion* pYcbcrConversion); + +VKAPI_ATTR void VKAPI_CALL vkDestroySamplerYcbcrConversionKHR( + VkDevice device, + VkSamplerYcbcrConversion ycbcrConversion, + const VkAllocationCallbacks* pAllocator); +#endif + +#define VK_KHR_bind_memory2 1 +#define VK_KHR_BIND_MEMORY_2_SPEC_VERSION 1 +#define VK_KHR_BIND_MEMORY_2_EXTENSION_NAME "VK_KHR_bind_memory2" + +typedef VkBindBufferMemoryInfo VkBindBufferMemoryInfoKHR; + +typedef VkBindImageMemoryInfo VkBindImageMemoryInfoKHR; + + +typedef VkResult (VKAPI_PTR *PFN_vkBindBufferMemory2KHR)(VkDevice device, uint32_t bindInfoCount, const VkBindBufferMemoryInfo* pBindInfos); +typedef VkResult (VKAPI_PTR *PFN_vkBindImageMemory2KHR)(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo* pBindInfos); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkBindBufferMemory2KHR( + VkDevice device, + uint32_t bindInfoCount, + const VkBindBufferMemoryInfo* pBindInfos); + +VKAPI_ATTR VkResult VKAPI_CALL vkBindImageMemory2KHR( + VkDevice device, + uint32_t bindInfoCount, + const VkBindImageMemoryInfo* pBindInfos); +#endif + +#define VK_KHR_maintenance3 1 +#define VK_KHR_MAINTENANCE3_SPEC_VERSION 1 +#define VK_KHR_MAINTENANCE3_EXTENSION_NAME "VK_KHR_maintenance3" + +typedef VkPhysicalDeviceMaintenance3Properties VkPhysicalDeviceMaintenance3PropertiesKHR; + +typedef VkDescriptorSetLayoutSupport VkDescriptorSetLayoutSupportKHR; + + +typedef void (VKAPI_PTR *PFN_vkGetDescriptorSetLayoutSupportKHR)(VkDevice device, const VkDescriptorSetLayoutCreateInfo* pCreateInfo, VkDescriptorSetLayoutSupport* pSupport); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkGetDescriptorSetLayoutSupportKHR( + VkDevice device, + const VkDescriptorSetLayoutCreateInfo* pCreateInfo, + VkDescriptorSetLayoutSupport* pSupport); +#endif + +#define VK_KHR_draw_indirect_count 1 +#define VK_KHR_DRAW_INDIRECT_COUNT_SPEC_VERSION 1 +#define VK_KHR_DRAW_INDIRECT_COUNT_EXTENSION_NAME "VK_KHR_draw_indirect_count" + +typedef void (VKAPI_PTR *PFN_vkCmdDrawIndirectCountKHR)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, uint32_t stride); +typedef void (VKAPI_PTR *PFN_vkCmdDrawIndexedIndirectCountKHR)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, uint32_t stride); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirectCountKHR( + VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkBuffer countBuffer, + VkDeviceSize countBufferOffset, + uint32_t maxDrawCount, + uint32_t stride); + +VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirectCountKHR( + VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkBuffer countBuffer, + VkDeviceSize countBufferOffset, + uint32_t maxDrawCount, + uint32_t stride); +#endif + +#define VK_KHR_8bit_storage 1 +#define VK_KHR_8BIT_STORAGE_SPEC_VERSION 1 +#define VK_KHR_8BIT_STORAGE_EXTENSION_NAME "VK_KHR_8bit_storage" + +typedef struct VkPhysicalDevice8BitStorageFeaturesKHR { + VkStructureType sType; + void* pNext; + VkBool32 storageBuffer8BitAccess; + VkBool32 uniformAndStorageBuffer8BitAccess; + VkBool32 storagePushConstant8; +} VkPhysicalDevice8BitStorageFeaturesKHR; + + + +#define VK_KHR_vulkan_memory_model 1 +#define VK_KHR_VULKAN_MEMORY_MODEL_SPEC_VERSION 2 +#define VK_KHR_VULKAN_MEMORY_MODEL_EXTENSION_NAME "VK_KHR_vulkan_memory_model" + +typedef struct VkPhysicalDeviceVulkanMemoryModelFeaturesKHR { + VkStructureType sType; + void* pNext; + VkBool32 vulkanMemoryModel; + VkBool32 vulkanMemoryModelDeviceScope; +} VkPhysicalDeviceVulkanMemoryModelFeaturesKHR; + + + +#define VK_EXT_debug_report 1 +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDebugReportCallbackEXT) + +#define VK_EXT_DEBUG_REPORT_SPEC_VERSION 9 +#define VK_EXT_DEBUG_REPORT_EXTENSION_NAME "VK_EXT_debug_report" + + +typedef enum VkDebugReportObjectTypeEXT { + VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT = 0, + VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT = 1, + VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT = 2, + VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT = 3, + VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT = 4, + VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT = 5, + VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT = 6, + VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT = 7, + VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT = 8, + VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT = 9, + VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT = 10, + VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT = 11, + VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT = 12, + VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT = 13, + VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT = 14, + VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT = 15, + VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT = 16, + VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT = 17, + VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT = 18, + VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT = 19, + VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT = 20, + VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT = 21, + VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT = 22, + VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT = 23, + VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT = 24, + VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT = 25, + VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT = 26, + VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT = 27, + VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT = 28, + VK_DEBUG_REPORT_OBJECT_TYPE_DISPLAY_KHR_EXT = 29, + VK_DEBUG_REPORT_OBJECT_TYPE_DISPLAY_MODE_KHR_EXT = 30, + VK_DEBUG_REPORT_OBJECT_TYPE_OBJECT_TABLE_NVX_EXT = 31, + VK_DEBUG_REPORT_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NVX_EXT = 32, + VK_DEBUG_REPORT_OBJECT_TYPE_VALIDATION_CACHE_EXT_EXT = 33, + VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION_EXT = 1000156000, + VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_EXT = 1000085000, + VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT = VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT, + VK_DEBUG_REPORT_OBJECT_TYPE_VALIDATION_CACHE_EXT = VK_DEBUG_REPORT_OBJECT_TYPE_VALIDATION_CACHE_EXT_EXT, + VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_KHR_EXT = VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_EXT, + VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION_KHR_EXT = VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION_EXT, + VK_DEBUG_REPORT_OBJECT_TYPE_BEGIN_RANGE_EXT = VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, + VK_DEBUG_REPORT_OBJECT_TYPE_END_RANGE_EXT = VK_DEBUG_REPORT_OBJECT_TYPE_VALIDATION_CACHE_EXT_EXT, + VK_DEBUG_REPORT_OBJECT_TYPE_RANGE_SIZE_EXT = (VK_DEBUG_REPORT_OBJECT_TYPE_VALIDATION_CACHE_EXT_EXT - VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT + 1), + VK_DEBUG_REPORT_OBJECT_TYPE_MAX_ENUM_EXT = 0x7FFFFFFF +} VkDebugReportObjectTypeEXT; + + +typedef enum VkDebugReportFlagBitsEXT { + VK_DEBUG_REPORT_INFORMATION_BIT_EXT = 0x00000001, + VK_DEBUG_REPORT_WARNING_BIT_EXT = 0x00000002, + VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT = 0x00000004, + VK_DEBUG_REPORT_ERROR_BIT_EXT = 0x00000008, + VK_DEBUG_REPORT_DEBUG_BIT_EXT = 0x00000010, + VK_DEBUG_REPORT_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF +} VkDebugReportFlagBitsEXT; +typedef VkFlags VkDebugReportFlagsEXT; + +typedef VkBool32 (VKAPI_PTR *PFN_vkDebugReportCallbackEXT)( + VkDebugReportFlagsEXT flags, + VkDebugReportObjectTypeEXT objectType, + uint64_t object, + size_t location, + int32_t messageCode, + const char* pLayerPrefix, + const char* pMessage, + void* pUserData); + +typedef struct VkDebugReportCallbackCreateInfoEXT { + VkStructureType sType; + const void* pNext; + VkDebugReportFlagsEXT flags; + PFN_vkDebugReportCallbackEXT pfnCallback; + void* pUserData; +} VkDebugReportCallbackCreateInfoEXT; + + +typedef VkResult (VKAPI_PTR *PFN_vkCreateDebugReportCallbackEXT)(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback); +typedef void (VKAPI_PTR *PFN_vkDestroyDebugReportCallbackEXT)(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks* pAllocator); +typedef void (VKAPI_PTR *PFN_vkDebugReportMessageEXT)(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object, size_t location, int32_t messageCode, const char* pLayerPrefix, const char* pMessage); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT( + VkInstance instance, + const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkDebugReportCallbackEXT* pCallback); + +VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT( + VkInstance instance, + VkDebugReportCallbackEXT callback, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT( + VkInstance instance, + VkDebugReportFlagsEXT flags, + VkDebugReportObjectTypeEXT objectType, + uint64_t object, + size_t location, + int32_t messageCode, + const char* pLayerPrefix, + const char* pMessage); +#endif + +#define VK_NV_glsl_shader 1 +#define VK_NV_GLSL_SHADER_SPEC_VERSION 1 +#define VK_NV_GLSL_SHADER_EXTENSION_NAME "VK_NV_glsl_shader" + + +#define VK_EXT_depth_range_unrestricted 1 +#define VK_EXT_DEPTH_RANGE_UNRESTRICTED_SPEC_VERSION 1 +#define VK_EXT_DEPTH_RANGE_UNRESTRICTED_EXTENSION_NAME "VK_EXT_depth_range_unrestricted" + + +#define VK_IMG_filter_cubic 1 +#define VK_IMG_FILTER_CUBIC_SPEC_VERSION 1 +#define VK_IMG_FILTER_CUBIC_EXTENSION_NAME "VK_IMG_filter_cubic" + + +#define VK_AMD_rasterization_order 1 +#define VK_AMD_RASTERIZATION_ORDER_SPEC_VERSION 1 +#define VK_AMD_RASTERIZATION_ORDER_EXTENSION_NAME "VK_AMD_rasterization_order" + + +typedef enum VkRasterizationOrderAMD { + VK_RASTERIZATION_ORDER_STRICT_AMD = 0, + VK_RASTERIZATION_ORDER_RELAXED_AMD = 1, + VK_RASTERIZATION_ORDER_BEGIN_RANGE_AMD = VK_RASTERIZATION_ORDER_STRICT_AMD, + VK_RASTERIZATION_ORDER_END_RANGE_AMD = VK_RASTERIZATION_ORDER_RELAXED_AMD, + VK_RASTERIZATION_ORDER_RANGE_SIZE_AMD = (VK_RASTERIZATION_ORDER_RELAXED_AMD - VK_RASTERIZATION_ORDER_STRICT_AMD + 1), + VK_RASTERIZATION_ORDER_MAX_ENUM_AMD = 0x7FFFFFFF +} VkRasterizationOrderAMD; + +typedef struct VkPipelineRasterizationStateRasterizationOrderAMD { + VkStructureType sType; + const void* pNext; + VkRasterizationOrderAMD rasterizationOrder; +} VkPipelineRasterizationStateRasterizationOrderAMD; + + + +#define VK_AMD_shader_trinary_minmax 1 +#define VK_AMD_SHADER_TRINARY_MINMAX_SPEC_VERSION 1 +#define VK_AMD_SHADER_TRINARY_MINMAX_EXTENSION_NAME "VK_AMD_shader_trinary_minmax" + + +#define VK_AMD_shader_explicit_vertex_parameter 1 +#define VK_AMD_SHADER_EXPLICIT_VERTEX_PARAMETER_SPEC_VERSION 1 +#define VK_AMD_SHADER_EXPLICIT_VERTEX_PARAMETER_EXTENSION_NAME "VK_AMD_shader_explicit_vertex_parameter" + + +#define VK_EXT_debug_marker 1 +#define VK_EXT_DEBUG_MARKER_SPEC_VERSION 4 +#define VK_EXT_DEBUG_MARKER_EXTENSION_NAME "VK_EXT_debug_marker" + +typedef struct VkDebugMarkerObjectNameInfoEXT { + VkStructureType sType; + const void* pNext; + VkDebugReportObjectTypeEXT objectType; + uint64_t object; + const char* pObjectName; +} VkDebugMarkerObjectNameInfoEXT; + +typedef struct VkDebugMarkerObjectTagInfoEXT { + VkStructureType sType; + const void* pNext; + VkDebugReportObjectTypeEXT objectType; + uint64_t object; + uint64_t tagName; + size_t tagSize; + const void* pTag; +} VkDebugMarkerObjectTagInfoEXT; + +typedef struct VkDebugMarkerMarkerInfoEXT { + VkStructureType sType; + const void* pNext; + const char* pMarkerName; + float color[4]; +} VkDebugMarkerMarkerInfoEXT; + + +typedef VkResult (VKAPI_PTR *PFN_vkDebugMarkerSetObjectTagEXT)(VkDevice device, const VkDebugMarkerObjectTagInfoEXT* pTagInfo); +typedef VkResult (VKAPI_PTR *PFN_vkDebugMarkerSetObjectNameEXT)(VkDevice device, const VkDebugMarkerObjectNameInfoEXT* pNameInfo); +typedef void (VKAPI_PTR *PFN_vkCmdDebugMarkerBeginEXT)(VkCommandBuffer commandBuffer, const VkDebugMarkerMarkerInfoEXT* pMarkerInfo); +typedef void (VKAPI_PTR *PFN_vkCmdDebugMarkerEndEXT)(VkCommandBuffer commandBuffer); +typedef void (VKAPI_PTR *PFN_vkCmdDebugMarkerInsertEXT)(VkCommandBuffer commandBuffer, const VkDebugMarkerMarkerInfoEXT* pMarkerInfo); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkDebugMarkerSetObjectTagEXT( + VkDevice device, + const VkDebugMarkerObjectTagInfoEXT* pTagInfo); + +VKAPI_ATTR VkResult VKAPI_CALL vkDebugMarkerSetObjectNameEXT( + VkDevice device, + const VkDebugMarkerObjectNameInfoEXT* pNameInfo); + +VKAPI_ATTR void VKAPI_CALL vkCmdDebugMarkerBeginEXT( + VkCommandBuffer commandBuffer, + const VkDebugMarkerMarkerInfoEXT* pMarkerInfo); + +VKAPI_ATTR void VKAPI_CALL vkCmdDebugMarkerEndEXT( + VkCommandBuffer commandBuffer); + +VKAPI_ATTR void VKAPI_CALL vkCmdDebugMarkerInsertEXT( + VkCommandBuffer commandBuffer, + const VkDebugMarkerMarkerInfoEXT* pMarkerInfo); +#endif + +#define VK_AMD_gcn_shader 1 +#define VK_AMD_GCN_SHADER_SPEC_VERSION 1 +#define VK_AMD_GCN_SHADER_EXTENSION_NAME "VK_AMD_gcn_shader" + + +#define VK_NV_dedicated_allocation 1 +#define VK_NV_DEDICATED_ALLOCATION_SPEC_VERSION 1 +#define VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME "VK_NV_dedicated_allocation" + +typedef struct VkDedicatedAllocationImageCreateInfoNV { + VkStructureType sType; + const void* pNext; + VkBool32 dedicatedAllocation; +} VkDedicatedAllocationImageCreateInfoNV; + +typedef struct VkDedicatedAllocationBufferCreateInfoNV { + VkStructureType sType; + const void* pNext; + VkBool32 dedicatedAllocation; +} VkDedicatedAllocationBufferCreateInfoNV; + +typedef struct VkDedicatedAllocationMemoryAllocateInfoNV { + VkStructureType sType; + const void* pNext; + VkImage image; + VkBuffer buffer; +} VkDedicatedAllocationMemoryAllocateInfoNV; + + + +#define VK_AMD_draw_indirect_count 1 +#define VK_AMD_DRAW_INDIRECT_COUNT_SPEC_VERSION 1 +#define VK_AMD_DRAW_INDIRECT_COUNT_EXTENSION_NAME "VK_AMD_draw_indirect_count" + +typedef void (VKAPI_PTR *PFN_vkCmdDrawIndirectCountAMD)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, uint32_t stride); +typedef void (VKAPI_PTR *PFN_vkCmdDrawIndexedIndirectCountAMD)(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount, uint32_t stride); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirectCountAMD( + VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkBuffer countBuffer, + VkDeviceSize countBufferOffset, + uint32_t maxDrawCount, + uint32_t stride); + +VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirectCountAMD( + VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkBuffer countBuffer, + VkDeviceSize countBufferOffset, + uint32_t maxDrawCount, + uint32_t stride); +#endif + +#define VK_AMD_negative_viewport_height 1 +#define VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_SPEC_VERSION 1 +#define VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME "VK_AMD_negative_viewport_height" + + +#define VK_AMD_gpu_shader_half_float 1 +#define VK_AMD_GPU_SHADER_HALF_FLOAT_SPEC_VERSION 1 +#define VK_AMD_GPU_SHADER_HALF_FLOAT_EXTENSION_NAME "VK_AMD_gpu_shader_half_float" + + +#define VK_AMD_shader_ballot 1 +#define VK_AMD_SHADER_BALLOT_SPEC_VERSION 1 +#define VK_AMD_SHADER_BALLOT_EXTENSION_NAME "VK_AMD_shader_ballot" + + +#define VK_AMD_texture_gather_bias_lod 1 +#define VK_AMD_TEXTURE_GATHER_BIAS_LOD_SPEC_VERSION 1 +#define VK_AMD_TEXTURE_GATHER_BIAS_LOD_EXTENSION_NAME "VK_AMD_texture_gather_bias_lod" + +typedef struct VkTextureLODGatherFormatPropertiesAMD { + VkStructureType sType; + void* pNext; + VkBool32 supportsTextureGatherLODBiasAMD; +} VkTextureLODGatherFormatPropertiesAMD; + + + +#define VK_AMD_shader_info 1 +#define VK_AMD_SHADER_INFO_SPEC_VERSION 1 +#define VK_AMD_SHADER_INFO_EXTENSION_NAME "VK_AMD_shader_info" + + +typedef enum VkShaderInfoTypeAMD { + VK_SHADER_INFO_TYPE_STATISTICS_AMD = 0, + VK_SHADER_INFO_TYPE_BINARY_AMD = 1, + VK_SHADER_INFO_TYPE_DISASSEMBLY_AMD = 2, + VK_SHADER_INFO_TYPE_BEGIN_RANGE_AMD = VK_SHADER_INFO_TYPE_STATISTICS_AMD, + VK_SHADER_INFO_TYPE_END_RANGE_AMD = VK_SHADER_INFO_TYPE_DISASSEMBLY_AMD, + VK_SHADER_INFO_TYPE_RANGE_SIZE_AMD = (VK_SHADER_INFO_TYPE_DISASSEMBLY_AMD - VK_SHADER_INFO_TYPE_STATISTICS_AMD + 1), + VK_SHADER_INFO_TYPE_MAX_ENUM_AMD = 0x7FFFFFFF +} VkShaderInfoTypeAMD; + +typedef struct VkShaderResourceUsageAMD { + uint32_t numUsedVgprs; + uint32_t numUsedSgprs; + uint32_t ldsSizePerLocalWorkGroup; + size_t ldsUsageSizeInBytes; + size_t scratchMemUsageInBytes; +} VkShaderResourceUsageAMD; + +typedef struct VkShaderStatisticsInfoAMD { + VkShaderStageFlags shaderStageMask; + VkShaderResourceUsageAMD resourceUsage; + uint32_t numPhysicalVgprs; + uint32_t numPhysicalSgprs; + uint32_t numAvailableVgprs; + uint32_t numAvailableSgprs; + uint32_t computeWorkGroupSize[3]; +} VkShaderStatisticsInfoAMD; + + +typedef VkResult (VKAPI_PTR *PFN_vkGetShaderInfoAMD)(VkDevice device, VkPipeline pipeline, VkShaderStageFlagBits shaderStage, VkShaderInfoTypeAMD infoType, size_t* pInfoSize, void* pInfo); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkGetShaderInfoAMD( + VkDevice device, + VkPipeline pipeline, + VkShaderStageFlagBits shaderStage, + VkShaderInfoTypeAMD infoType, + size_t* pInfoSize, + void* pInfo); +#endif + +#define VK_AMD_shader_image_load_store_lod 1 +#define VK_AMD_SHADER_IMAGE_LOAD_STORE_LOD_SPEC_VERSION 1 +#define VK_AMD_SHADER_IMAGE_LOAD_STORE_LOD_EXTENSION_NAME "VK_AMD_shader_image_load_store_lod" + + +#define VK_IMG_format_pvrtc 1 +#define VK_IMG_FORMAT_PVRTC_SPEC_VERSION 1 +#define VK_IMG_FORMAT_PVRTC_EXTENSION_NAME "VK_IMG_format_pvrtc" + + +#define VK_NV_external_memory_capabilities 1 +#define VK_NV_EXTERNAL_MEMORY_CAPABILITIES_SPEC_VERSION 1 +#define VK_NV_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME "VK_NV_external_memory_capabilities" + + +typedef enum VkExternalMemoryHandleTypeFlagBitsNV { + VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_NV = 0x00000001, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_NV = 0x00000002, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_IMAGE_BIT_NV = 0x00000004, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_IMAGE_KMT_BIT_NV = 0x00000008, + VK_EXTERNAL_MEMORY_HANDLE_TYPE_FLAG_BITS_MAX_ENUM_NV = 0x7FFFFFFF +} VkExternalMemoryHandleTypeFlagBitsNV; +typedef VkFlags VkExternalMemoryHandleTypeFlagsNV; + +typedef enum VkExternalMemoryFeatureFlagBitsNV { + VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT_NV = 0x00000001, + VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_NV = 0x00000002, + VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_NV = 0x00000004, + VK_EXTERNAL_MEMORY_FEATURE_FLAG_BITS_MAX_ENUM_NV = 0x7FFFFFFF +} VkExternalMemoryFeatureFlagBitsNV; +typedef VkFlags VkExternalMemoryFeatureFlagsNV; + +typedef struct VkExternalImageFormatPropertiesNV { + VkImageFormatProperties imageFormatProperties; + VkExternalMemoryFeatureFlagsNV externalMemoryFeatures; + VkExternalMemoryHandleTypeFlagsNV exportFromImportedHandleTypes; + VkExternalMemoryHandleTypeFlagsNV compatibleHandleTypes; +} VkExternalImageFormatPropertiesNV; + + +typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceExternalImageFormatPropertiesNV)(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkExternalMemoryHandleTypeFlagsNV externalHandleType, VkExternalImageFormatPropertiesNV* pExternalImageFormatProperties); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceExternalImageFormatPropertiesNV( + VkPhysicalDevice physicalDevice, + VkFormat format, + VkImageType type, + VkImageTiling tiling, + VkImageUsageFlags usage, + VkImageCreateFlags flags, + VkExternalMemoryHandleTypeFlagsNV externalHandleType, + VkExternalImageFormatPropertiesNV* pExternalImageFormatProperties); +#endif + +#define VK_NV_external_memory 1 +#define VK_NV_EXTERNAL_MEMORY_SPEC_VERSION 1 +#define VK_NV_EXTERNAL_MEMORY_EXTENSION_NAME "VK_NV_external_memory" + +typedef struct VkExternalMemoryImageCreateInfoNV { + VkStructureType sType; + const void* pNext; + VkExternalMemoryHandleTypeFlagsNV handleTypes; +} VkExternalMemoryImageCreateInfoNV; + +typedef struct VkExportMemoryAllocateInfoNV { + VkStructureType sType; + const void* pNext; + VkExternalMemoryHandleTypeFlagsNV handleTypes; +} VkExportMemoryAllocateInfoNV; + + + +#define VK_EXT_validation_flags 1 +#define VK_EXT_VALIDATION_FLAGS_SPEC_VERSION 1 +#define VK_EXT_VALIDATION_FLAGS_EXTENSION_NAME "VK_EXT_validation_flags" + + +typedef enum VkValidationCheckEXT { + VK_VALIDATION_CHECK_ALL_EXT = 0, + VK_VALIDATION_CHECK_SHADERS_EXT = 1, + VK_VALIDATION_CHECK_BEGIN_RANGE_EXT = VK_VALIDATION_CHECK_ALL_EXT, + VK_VALIDATION_CHECK_END_RANGE_EXT = VK_VALIDATION_CHECK_SHADERS_EXT, + VK_VALIDATION_CHECK_RANGE_SIZE_EXT = (VK_VALIDATION_CHECK_SHADERS_EXT - VK_VALIDATION_CHECK_ALL_EXT + 1), + VK_VALIDATION_CHECK_MAX_ENUM_EXT = 0x7FFFFFFF +} VkValidationCheckEXT; + +typedef struct VkValidationFlagsEXT { + VkStructureType sType; + const void* pNext; + uint32_t disabledValidationCheckCount; + const VkValidationCheckEXT* pDisabledValidationChecks; +} VkValidationFlagsEXT; + + + +#define VK_EXT_shader_subgroup_ballot 1 +#define VK_EXT_SHADER_SUBGROUP_BALLOT_SPEC_VERSION 1 +#define VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME "VK_EXT_shader_subgroup_ballot" + + +#define VK_EXT_shader_subgroup_vote 1 +#define VK_EXT_SHADER_SUBGROUP_VOTE_SPEC_VERSION 1 +#define VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME "VK_EXT_shader_subgroup_vote" + + +#define VK_EXT_astc_decode_mode 1 +#define VK_EXT_ASTC_DECODE_MODE_SPEC_VERSION 1 +#define VK_EXT_ASTC_DECODE_MODE_EXTENSION_NAME "VK_EXT_astc_decode_mode" + +typedef struct VkImageViewASTCDecodeModeEXT { + VkStructureType sType; + const void* pNext; + VkFormat decodeMode; +} VkImageViewASTCDecodeModeEXT; + +typedef struct VkPhysicalDeviceASTCDecodeFeaturesEXT { + VkStructureType sType; + void* pNext; + VkBool32 decodeModeSharedExponent; +} VkPhysicalDeviceASTCDecodeFeaturesEXT; + + + +#define VK_EXT_conditional_rendering 1 +#define VK_EXT_CONDITIONAL_RENDERING_SPEC_VERSION 1 +#define VK_EXT_CONDITIONAL_RENDERING_EXTENSION_NAME "VK_EXT_conditional_rendering" + + +typedef enum VkConditionalRenderingFlagBitsEXT { + VK_CONDITIONAL_RENDERING_INVERTED_BIT_EXT = 0x00000001, + VK_CONDITIONAL_RENDERING_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF +} VkConditionalRenderingFlagBitsEXT; +typedef VkFlags VkConditionalRenderingFlagsEXT; + +typedef struct VkConditionalRenderingBeginInfoEXT { + VkStructureType sType; + const void* pNext; + VkBuffer buffer; + VkDeviceSize offset; + VkConditionalRenderingFlagsEXT flags; +} VkConditionalRenderingBeginInfoEXT; + +typedef struct VkPhysicalDeviceConditionalRenderingFeaturesEXT { + VkStructureType sType; + void* pNext; + VkBool32 conditionalRendering; + VkBool32 inheritedConditionalRendering; +} VkPhysicalDeviceConditionalRenderingFeaturesEXT; + +typedef struct VkCommandBufferInheritanceConditionalRenderingInfoEXT { + VkStructureType sType; + const void* pNext; + VkBool32 conditionalRenderingEnable; +} VkCommandBufferInheritanceConditionalRenderingInfoEXT; + + +typedef void (VKAPI_PTR *PFN_vkCmdBeginConditionalRenderingEXT)(VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT* pConditionalRenderingBegin); +typedef void (VKAPI_PTR *PFN_vkCmdEndConditionalRenderingEXT)(VkCommandBuffer commandBuffer); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkCmdBeginConditionalRenderingEXT( + VkCommandBuffer commandBuffer, + const VkConditionalRenderingBeginInfoEXT* pConditionalRenderingBegin); + +VKAPI_ATTR void VKAPI_CALL vkCmdEndConditionalRenderingEXT( + VkCommandBuffer commandBuffer); +#endif + +#define VK_NVX_device_generated_commands 1 +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkObjectTableNVX) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkIndirectCommandsLayoutNVX) + +#define VK_NVX_DEVICE_GENERATED_COMMANDS_SPEC_VERSION 3 +#define VK_NVX_DEVICE_GENERATED_COMMANDS_EXTENSION_NAME "VK_NVX_device_generated_commands" + + +typedef enum VkIndirectCommandsTokenTypeNVX { + VK_INDIRECT_COMMANDS_TOKEN_TYPE_PIPELINE_NVX = 0, + VK_INDIRECT_COMMANDS_TOKEN_TYPE_DESCRIPTOR_SET_NVX = 1, + VK_INDIRECT_COMMANDS_TOKEN_TYPE_INDEX_BUFFER_NVX = 2, + VK_INDIRECT_COMMANDS_TOKEN_TYPE_VERTEX_BUFFER_NVX = 3, + VK_INDIRECT_COMMANDS_TOKEN_TYPE_PUSH_CONSTANT_NVX = 4, + VK_INDIRECT_COMMANDS_TOKEN_TYPE_DRAW_INDEXED_NVX = 5, + VK_INDIRECT_COMMANDS_TOKEN_TYPE_DRAW_NVX = 6, + VK_INDIRECT_COMMANDS_TOKEN_TYPE_DISPATCH_NVX = 7, + VK_INDIRECT_COMMANDS_TOKEN_TYPE_BEGIN_RANGE_NVX = VK_INDIRECT_COMMANDS_TOKEN_TYPE_PIPELINE_NVX, + VK_INDIRECT_COMMANDS_TOKEN_TYPE_END_RANGE_NVX = VK_INDIRECT_COMMANDS_TOKEN_TYPE_DISPATCH_NVX, + VK_INDIRECT_COMMANDS_TOKEN_TYPE_RANGE_SIZE_NVX = (VK_INDIRECT_COMMANDS_TOKEN_TYPE_DISPATCH_NVX - VK_INDIRECT_COMMANDS_TOKEN_TYPE_PIPELINE_NVX + 1), + VK_INDIRECT_COMMANDS_TOKEN_TYPE_MAX_ENUM_NVX = 0x7FFFFFFF +} VkIndirectCommandsTokenTypeNVX; + +typedef enum VkObjectEntryTypeNVX { + VK_OBJECT_ENTRY_TYPE_DESCRIPTOR_SET_NVX = 0, + VK_OBJECT_ENTRY_TYPE_PIPELINE_NVX = 1, + VK_OBJECT_ENTRY_TYPE_INDEX_BUFFER_NVX = 2, + VK_OBJECT_ENTRY_TYPE_VERTEX_BUFFER_NVX = 3, + VK_OBJECT_ENTRY_TYPE_PUSH_CONSTANT_NVX = 4, + VK_OBJECT_ENTRY_TYPE_BEGIN_RANGE_NVX = VK_OBJECT_ENTRY_TYPE_DESCRIPTOR_SET_NVX, + VK_OBJECT_ENTRY_TYPE_END_RANGE_NVX = VK_OBJECT_ENTRY_TYPE_PUSH_CONSTANT_NVX, + VK_OBJECT_ENTRY_TYPE_RANGE_SIZE_NVX = (VK_OBJECT_ENTRY_TYPE_PUSH_CONSTANT_NVX - VK_OBJECT_ENTRY_TYPE_DESCRIPTOR_SET_NVX + 1), + VK_OBJECT_ENTRY_TYPE_MAX_ENUM_NVX = 0x7FFFFFFF +} VkObjectEntryTypeNVX; + + +typedef enum VkIndirectCommandsLayoutUsageFlagBitsNVX { + VK_INDIRECT_COMMANDS_LAYOUT_USAGE_UNORDERED_SEQUENCES_BIT_NVX = 0x00000001, + VK_INDIRECT_COMMANDS_LAYOUT_USAGE_SPARSE_SEQUENCES_BIT_NVX = 0x00000002, + VK_INDIRECT_COMMANDS_LAYOUT_USAGE_EMPTY_EXECUTIONS_BIT_NVX = 0x00000004, + VK_INDIRECT_COMMANDS_LAYOUT_USAGE_INDEXED_SEQUENCES_BIT_NVX = 0x00000008, + VK_INDIRECT_COMMANDS_LAYOUT_USAGE_FLAG_BITS_MAX_ENUM_NVX = 0x7FFFFFFF +} VkIndirectCommandsLayoutUsageFlagBitsNVX; +typedef VkFlags VkIndirectCommandsLayoutUsageFlagsNVX; + +typedef enum VkObjectEntryUsageFlagBitsNVX { + VK_OBJECT_ENTRY_USAGE_GRAPHICS_BIT_NVX = 0x00000001, + VK_OBJECT_ENTRY_USAGE_COMPUTE_BIT_NVX = 0x00000002, + VK_OBJECT_ENTRY_USAGE_FLAG_BITS_MAX_ENUM_NVX = 0x7FFFFFFF +} VkObjectEntryUsageFlagBitsNVX; +typedef VkFlags VkObjectEntryUsageFlagsNVX; + +typedef struct VkDeviceGeneratedCommandsFeaturesNVX { + VkStructureType sType; + const void* pNext; + VkBool32 computeBindingPointSupport; +} VkDeviceGeneratedCommandsFeaturesNVX; + +typedef struct VkDeviceGeneratedCommandsLimitsNVX { + VkStructureType sType; + const void* pNext; + uint32_t maxIndirectCommandsLayoutTokenCount; + uint32_t maxObjectEntryCounts; + uint32_t minSequenceCountBufferOffsetAlignment; + uint32_t minSequenceIndexBufferOffsetAlignment; + uint32_t minCommandsTokenBufferOffsetAlignment; +} VkDeviceGeneratedCommandsLimitsNVX; + +typedef struct VkIndirectCommandsTokenNVX { + VkIndirectCommandsTokenTypeNVX tokenType; + VkBuffer buffer; + VkDeviceSize offset; +} VkIndirectCommandsTokenNVX; + +typedef struct VkIndirectCommandsLayoutTokenNVX { + VkIndirectCommandsTokenTypeNVX tokenType; + uint32_t bindingUnit; + uint32_t dynamicCount; + uint32_t divisor; +} VkIndirectCommandsLayoutTokenNVX; + +typedef struct VkIndirectCommandsLayoutCreateInfoNVX { + VkStructureType sType; + const void* pNext; + VkPipelineBindPoint pipelineBindPoint; + VkIndirectCommandsLayoutUsageFlagsNVX flags; + uint32_t tokenCount; + const VkIndirectCommandsLayoutTokenNVX* pTokens; +} VkIndirectCommandsLayoutCreateInfoNVX; + +typedef struct VkCmdProcessCommandsInfoNVX { + VkStructureType sType; + const void* pNext; + VkObjectTableNVX objectTable; + VkIndirectCommandsLayoutNVX indirectCommandsLayout; + uint32_t indirectCommandsTokenCount; + const VkIndirectCommandsTokenNVX* pIndirectCommandsTokens; + uint32_t maxSequencesCount; + VkCommandBuffer targetCommandBuffer; + VkBuffer sequencesCountBuffer; + VkDeviceSize sequencesCountOffset; + VkBuffer sequencesIndexBuffer; + VkDeviceSize sequencesIndexOffset; +} VkCmdProcessCommandsInfoNVX; + +typedef struct VkCmdReserveSpaceForCommandsInfoNVX { + VkStructureType sType; + const void* pNext; + VkObjectTableNVX objectTable; + VkIndirectCommandsLayoutNVX indirectCommandsLayout; + uint32_t maxSequencesCount; +} VkCmdReserveSpaceForCommandsInfoNVX; + +typedef struct VkObjectTableCreateInfoNVX { + VkStructureType sType; + const void* pNext; + uint32_t objectCount; + const VkObjectEntryTypeNVX* pObjectEntryTypes; + const uint32_t* pObjectEntryCounts; + const VkObjectEntryUsageFlagsNVX* pObjectEntryUsageFlags; + uint32_t maxUniformBuffersPerDescriptor; + uint32_t maxStorageBuffersPerDescriptor; + uint32_t maxStorageImagesPerDescriptor; + uint32_t maxSampledImagesPerDescriptor; + uint32_t maxPipelineLayouts; +} VkObjectTableCreateInfoNVX; + +typedef struct VkObjectTableEntryNVX { + VkObjectEntryTypeNVX type; + VkObjectEntryUsageFlagsNVX flags; +} VkObjectTableEntryNVX; + +typedef struct VkObjectTablePipelineEntryNVX { + VkObjectEntryTypeNVX type; + VkObjectEntryUsageFlagsNVX flags; + VkPipeline pipeline; +} VkObjectTablePipelineEntryNVX; + +typedef struct VkObjectTableDescriptorSetEntryNVX { + VkObjectEntryTypeNVX type; + VkObjectEntryUsageFlagsNVX flags; + VkPipelineLayout pipelineLayout; + VkDescriptorSet descriptorSet; +} VkObjectTableDescriptorSetEntryNVX; + +typedef struct VkObjectTableVertexBufferEntryNVX { + VkObjectEntryTypeNVX type; + VkObjectEntryUsageFlagsNVX flags; + VkBuffer buffer; +} VkObjectTableVertexBufferEntryNVX; + +typedef struct VkObjectTableIndexBufferEntryNVX { + VkObjectEntryTypeNVX type; + VkObjectEntryUsageFlagsNVX flags; + VkBuffer buffer; + VkIndexType indexType; +} VkObjectTableIndexBufferEntryNVX; + +typedef struct VkObjectTablePushConstantEntryNVX { + VkObjectEntryTypeNVX type; + VkObjectEntryUsageFlagsNVX flags; + VkPipelineLayout pipelineLayout; + VkShaderStageFlags stageFlags; +} VkObjectTablePushConstantEntryNVX; + + +typedef void (VKAPI_PTR *PFN_vkCmdProcessCommandsNVX)(VkCommandBuffer commandBuffer, const VkCmdProcessCommandsInfoNVX* pProcessCommandsInfo); +typedef void (VKAPI_PTR *PFN_vkCmdReserveSpaceForCommandsNVX)(VkCommandBuffer commandBuffer, const VkCmdReserveSpaceForCommandsInfoNVX* pReserveSpaceInfo); +typedef VkResult (VKAPI_PTR *PFN_vkCreateIndirectCommandsLayoutNVX)(VkDevice device, const VkIndirectCommandsLayoutCreateInfoNVX* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkIndirectCommandsLayoutNVX* pIndirectCommandsLayout); +typedef void (VKAPI_PTR *PFN_vkDestroyIndirectCommandsLayoutNVX)(VkDevice device, VkIndirectCommandsLayoutNVX indirectCommandsLayout, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkCreateObjectTableNVX)(VkDevice device, const VkObjectTableCreateInfoNVX* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkObjectTableNVX* pObjectTable); +typedef void (VKAPI_PTR *PFN_vkDestroyObjectTableNVX)(VkDevice device, VkObjectTableNVX objectTable, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkRegisterObjectsNVX)(VkDevice device, VkObjectTableNVX objectTable, uint32_t objectCount, const VkObjectTableEntryNVX* const* ppObjectTableEntries, const uint32_t* pObjectIndices); +typedef VkResult (VKAPI_PTR *PFN_vkUnregisterObjectsNVX)(VkDevice device, VkObjectTableNVX objectTable, uint32_t objectCount, const VkObjectEntryTypeNVX* pObjectEntryTypes, const uint32_t* pObjectIndices); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceGeneratedCommandsPropertiesNVX)(VkPhysicalDevice physicalDevice, VkDeviceGeneratedCommandsFeaturesNVX* pFeatures, VkDeviceGeneratedCommandsLimitsNVX* pLimits); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkCmdProcessCommandsNVX( + VkCommandBuffer commandBuffer, + const VkCmdProcessCommandsInfoNVX* pProcessCommandsInfo); + +VKAPI_ATTR void VKAPI_CALL vkCmdReserveSpaceForCommandsNVX( + VkCommandBuffer commandBuffer, + const VkCmdReserveSpaceForCommandsInfoNVX* pReserveSpaceInfo); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateIndirectCommandsLayoutNVX( + VkDevice device, + const VkIndirectCommandsLayoutCreateInfoNVX* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkIndirectCommandsLayoutNVX* pIndirectCommandsLayout); + +VKAPI_ATTR void VKAPI_CALL vkDestroyIndirectCommandsLayoutNVX( + VkDevice device, + VkIndirectCommandsLayoutNVX indirectCommandsLayout, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateObjectTableNVX( + VkDevice device, + const VkObjectTableCreateInfoNVX* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkObjectTableNVX* pObjectTable); + +VKAPI_ATTR void VKAPI_CALL vkDestroyObjectTableNVX( + VkDevice device, + VkObjectTableNVX objectTable, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkRegisterObjectsNVX( + VkDevice device, + VkObjectTableNVX objectTable, + uint32_t objectCount, + const VkObjectTableEntryNVX* const* ppObjectTableEntries, + const uint32_t* pObjectIndices); + +VKAPI_ATTR VkResult VKAPI_CALL vkUnregisterObjectsNVX( + VkDevice device, + VkObjectTableNVX objectTable, + uint32_t objectCount, + const VkObjectEntryTypeNVX* pObjectEntryTypes, + const uint32_t* pObjectIndices); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceGeneratedCommandsPropertiesNVX( + VkPhysicalDevice physicalDevice, + VkDeviceGeneratedCommandsFeaturesNVX* pFeatures, + VkDeviceGeneratedCommandsLimitsNVX* pLimits); +#endif + +#define VK_NV_clip_space_w_scaling 1 +#define VK_NV_CLIP_SPACE_W_SCALING_SPEC_VERSION 1 +#define VK_NV_CLIP_SPACE_W_SCALING_EXTENSION_NAME "VK_NV_clip_space_w_scaling" + +typedef struct VkViewportWScalingNV { + float xcoeff; + float ycoeff; +} VkViewportWScalingNV; + +typedef struct VkPipelineViewportWScalingStateCreateInfoNV { + VkStructureType sType; + const void* pNext; + VkBool32 viewportWScalingEnable; + uint32_t viewportCount; + const VkViewportWScalingNV* pViewportWScalings; +} VkPipelineViewportWScalingStateCreateInfoNV; + + +typedef void (VKAPI_PTR *PFN_vkCmdSetViewportWScalingNV)(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount, const VkViewportWScalingNV* pViewportWScalings); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkCmdSetViewportWScalingNV( + VkCommandBuffer commandBuffer, + uint32_t firstViewport, + uint32_t viewportCount, + const VkViewportWScalingNV* pViewportWScalings); +#endif + +#define VK_EXT_direct_mode_display 1 +#define VK_EXT_DIRECT_MODE_DISPLAY_SPEC_VERSION 1 +#define VK_EXT_DIRECT_MODE_DISPLAY_EXTENSION_NAME "VK_EXT_direct_mode_display" + +typedef VkResult (VKAPI_PTR *PFN_vkReleaseDisplayEXT)(VkPhysicalDevice physicalDevice, VkDisplayKHR display); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkReleaseDisplayEXT( + VkPhysicalDevice physicalDevice, + VkDisplayKHR display); +#endif + +#define VK_EXT_display_surface_counter 1 +#define VK_EXT_DISPLAY_SURFACE_COUNTER_SPEC_VERSION 1 +#define VK_EXT_DISPLAY_SURFACE_COUNTER_EXTENSION_NAME "VK_EXT_display_surface_counter" + + +typedef enum VkSurfaceCounterFlagBitsEXT { + VK_SURFACE_COUNTER_VBLANK_EXT = 0x00000001, + VK_SURFACE_COUNTER_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF +} VkSurfaceCounterFlagBitsEXT; +typedef VkFlags VkSurfaceCounterFlagsEXT; + +typedef struct VkSurfaceCapabilities2EXT { + VkStructureType sType; + void* pNext; + uint32_t minImageCount; + uint32_t maxImageCount; + VkExtent2D currentExtent; + VkExtent2D minImageExtent; + VkExtent2D maxImageExtent; + uint32_t maxImageArrayLayers; + VkSurfaceTransformFlagsKHR supportedTransforms; + VkSurfaceTransformFlagBitsKHR currentTransform; + VkCompositeAlphaFlagsKHR supportedCompositeAlpha; + VkImageUsageFlags supportedUsageFlags; + VkSurfaceCounterFlagsEXT supportedSurfaceCounters; +} VkSurfaceCapabilities2EXT; + + +typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceSurfaceCapabilities2EXT)(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, VkSurfaceCapabilities2EXT* pSurfaceCapabilities); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilities2EXT( + VkPhysicalDevice physicalDevice, + VkSurfaceKHR surface, + VkSurfaceCapabilities2EXT* pSurfaceCapabilities); +#endif + +#define VK_EXT_display_control 1 +#define VK_EXT_DISPLAY_CONTROL_SPEC_VERSION 1 +#define VK_EXT_DISPLAY_CONTROL_EXTENSION_NAME "VK_EXT_display_control" + + +typedef enum VkDisplayPowerStateEXT { + VK_DISPLAY_POWER_STATE_OFF_EXT = 0, + VK_DISPLAY_POWER_STATE_SUSPEND_EXT = 1, + VK_DISPLAY_POWER_STATE_ON_EXT = 2, + VK_DISPLAY_POWER_STATE_BEGIN_RANGE_EXT = VK_DISPLAY_POWER_STATE_OFF_EXT, + VK_DISPLAY_POWER_STATE_END_RANGE_EXT = VK_DISPLAY_POWER_STATE_ON_EXT, + VK_DISPLAY_POWER_STATE_RANGE_SIZE_EXT = (VK_DISPLAY_POWER_STATE_ON_EXT - VK_DISPLAY_POWER_STATE_OFF_EXT + 1), + VK_DISPLAY_POWER_STATE_MAX_ENUM_EXT = 0x7FFFFFFF +} VkDisplayPowerStateEXT; + +typedef enum VkDeviceEventTypeEXT { + VK_DEVICE_EVENT_TYPE_DISPLAY_HOTPLUG_EXT = 0, + VK_DEVICE_EVENT_TYPE_BEGIN_RANGE_EXT = VK_DEVICE_EVENT_TYPE_DISPLAY_HOTPLUG_EXT, + VK_DEVICE_EVENT_TYPE_END_RANGE_EXT = VK_DEVICE_EVENT_TYPE_DISPLAY_HOTPLUG_EXT, + VK_DEVICE_EVENT_TYPE_RANGE_SIZE_EXT = (VK_DEVICE_EVENT_TYPE_DISPLAY_HOTPLUG_EXT - VK_DEVICE_EVENT_TYPE_DISPLAY_HOTPLUG_EXT + 1), + VK_DEVICE_EVENT_TYPE_MAX_ENUM_EXT = 0x7FFFFFFF +} VkDeviceEventTypeEXT; + +typedef enum VkDisplayEventTypeEXT { + VK_DISPLAY_EVENT_TYPE_FIRST_PIXEL_OUT_EXT = 0, + VK_DISPLAY_EVENT_TYPE_BEGIN_RANGE_EXT = VK_DISPLAY_EVENT_TYPE_FIRST_PIXEL_OUT_EXT, + VK_DISPLAY_EVENT_TYPE_END_RANGE_EXT = VK_DISPLAY_EVENT_TYPE_FIRST_PIXEL_OUT_EXT, + VK_DISPLAY_EVENT_TYPE_RANGE_SIZE_EXT = (VK_DISPLAY_EVENT_TYPE_FIRST_PIXEL_OUT_EXT - VK_DISPLAY_EVENT_TYPE_FIRST_PIXEL_OUT_EXT + 1), + VK_DISPLAY_EVENT_TYPE_MAX_ENUM_EXT = 0x7FFFFFFF +} VkDisplayEventTypeEXT; + +typedef struct VkDisplayPowerInfoEXT { + VkStructureType sType; + const void* pNext; + VkDisplayPowerStateEXT powerState; +} VkDisplayPowerInfoEXT; + +typedef struct VkDeviceEventInfoEXT { + VkStructureType sType; + const void* pNext; + VkDeviceEventTypeEXT deviceEvent; +} VkDeviceEventInfoEXT; + +typedef struct VkDisplayEventInfoEXT { + VkStructureType sType; + const void* pNext; + VkDisplayEventTypeEXT displayEvent; +} VkDisplayEventInfoEXT; + +typedef struct VkSwapchainCounterCreateInfoEXT { + VkStructureType sType; + const void* pNext; + VkSurfaceCounterFlagsEXT surfaceCounters; +} VkSwapchainCounterCreateInfoEXT; + + +typedef VkResult (VKAPI_PTR *PFN_vkDisplayPowerControlEXT)(VkDevice device, VkDisplayKHR display, const VkDisplayPowerInfoEXT* pDisplayPowerInfo); +typedef VkResult (VKAPI_PTR *PFN_vkRegisterDeviceEventEXT)(VkDevice device, const VkDeviceEventInfoEXT* pDeviceEventInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence); +typedef VkResult (VKAPI_PTR *PFN_vkRegisterDisplayEventEXT)(VkDevice device, VkDisplayKHR display, const VkDisplayEventInfoEXT* pDisplayEventInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence); +typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainCounterEXT)(VkDevice device, VkSwapchainKHR swapchain, VkSurfaceCounterFlagBitsEXT counter, uint64_t* pCounterValue); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkDisplayPowerControlEXT( + VkDevice device, + VkDisplayKHR display, + const VkDisplayPowerInfoEXT* pDisplayPowerInfo); + +VKAPI_ATTR VkResult VKAPI_CALL vkRegisterDeviceEventEXT( + VkDevice device, + const VkDeviceEventInfoEXT* pDeviceEventInfo, + const VkAllocationCallbacks* pAllocator, + VkFence* pFence); + +VKAPI_ATTR VkResult VKAPI_CALL vkRegisterDisplayEventEXT( + VkDevice device, + VkDisplayKHR display, + const VkDisplayEventInfoEXT* pDisplayEventInfo, + const VkAllocationCallbacks* pAllocator, + VkFence* pFence); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainCounterEXT( + VkDevice device, + VkSwapchainKHR swapchain, + VkSurfaceCounterFlagBitsEXT counter, + uint64_t* pCounterValue); +#endif + +#define VK_GOOGLE_display_timing 1 +#define VK_GOOGLE_DISPLAY_TIMING_SPEC_VERSION 1 +#define VK_GOOGLE_DISPLAY_TIMING_EXTENSION_NAME "VK_GOOGLE_display_timing" + +typedef struct VkRefreshCycleDurationGOOGLE { + uint64_t refreshDuration; +} VkRefreshCycleDurationGOOGLE; + +typedef struct VkPastPresentationTimingGOOGLE { + uint32_t presentID; + uint64_t desiredPresentTime; + uint64_t actualPresentTime; + uint64_t earliestPresentTime; + uint64_t presentMargin; +} VkPastPresentationTimingGOOGLE; + +typedef struct VkPresentTimeGOOGLE { + uint32_t presentID; + uint64_t desiredPresentTime; +} VkPresentTimeGOOGLE; + +typedef struct VkPresentTimesInfoGOOGLE { + VkStructureType sType; + const void* pNext; + uint32_t swapchainCount; + const VkPresentTimeGOOGLE* pTimes; +} VkPresentTimesInfoGOOGLE; + + +typedef VkResult (VKAPI_PTR *PFN_vkGetRefreshCycleDurationGOOGLE)(VkDevice device, VkSwapchainKHR swapchain, VkRefreshCycleDurationGOOGLE* pDisplayTimingProperties); +typedef VkResult (VKAPI_PTR *PFN_vkGetPastPresentationTimingGOOGLE)(VkDevice device, VkSwapchainKHR swapchain, uint32_t* pPresentationTimingCount, VkPastPresentationTimingGOOGLE* pPresentationTimings); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkGetRefreshCycleDurationGOOGLE( + VkDevice device, + VkSwapchainKHR swapchain, + VkRefreshCycleDurationGOOGLE* pDisplayTimingProperties); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetPastPresentationTimingGOOGLE( + VkDevice device, + VkSwapchainKHR swapchain, + uint32_t* pPresentationTimingCount, + VkPastPresentationTimingGOOGLE* pPresentationTimings); +#endif + +#define VK_NV_sample_mask_override_coverage 1 +#define VK_NV_SAMPLE_MASK_OVERRIDE_COVERAGE_SPEC_VERSION 1 +#define VK_NV_SAMPLE_MASK_OVERRIDE_COVERAGE_EXTENSION_NAME "VK_NV_sample_mask_override_coverage" + + +#define VK_NV_geometry_shader_passthrough 1 +#define VK_NV_GEOMETRY_SHADER_PASSTHROUGH_SPEC_VERSION 1 +#define VK_NV_GEOMETRY_SHADER_PASSTHROUGH_EXTENSION_NAME "VK_NV_geometry_shader_passthrough" + + +#define VK_NV_viewport_array2 1 +#define VK_NV_VIEWPORT_ARRAY2_SPEC_VERSION 1 +#define VK_NV_VIEWPORT_ARRAY2_EXTENSION_NAME "VK_NV_viewport_array2" + + +#define VK_NVX_multiview_per_view_attributes 1 +#define VK_NVX_MULTIVIEW_PER_VIEW_ATTRIBUTES_SPEC_VERSION 1 +#define VK_NVX_MULTIVIEW_PER_VIEW_ATTRIBUTES_EXTENSION_NAME "VK_NVX_multiview_per_view_attributes" + +typedef struct VkPhysicalDeviceMultiviewPerViewAttributesPropertiesNVX { + VkStructureType sType; + void* pNext; + VkBool32 perViewPositionAllComponents; +} VkPhysicalDeviceMultiviewPerViewAttributesPropertiesNVX; + + + +#define VK_NV_viewport_swizzle 1 +#define VK_NV_VIEWPORT_SWIZZLE_SPEC_VERSION 1 +#define VK_NV_VIEWPORT_SWIZZLE_EXTENSION_NAME "VK_NV_viewport_swizzle" + + +typedef enum VkViewportCoordinateSwizzleNV { + VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_X_NV = 0, + VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_X_NV = 1, + VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_Y_NV = 2, + VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_Y_NV = 3, + VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_Z_NV = 4, + VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_Z_NV = 5, + VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_W_NV = 6, + VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_W_NV = 7, + VK_VIEWPORT_COORDINATE_SWIZZLE_BEGIN_RANGE_NV = VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_X_NV, + VK_VIEWPORT_COORDINATE_SWIZZLE_END_RANGE_NV = VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_W_NV, + VK_VIEWPORT_COORDINATE_SWIZZLE_RANGE_SIZE_NV = (VK_VIEWPORT_COORDINATE_SWIZZLE_NEGATIVE_W_NV - VK_VIEWPORT_COORDINATE_SWIZZLE_POSITIVE_X_NV + 1), + VK_VIEWPORT_COORDINATE_SWIZZLE_MAX_ENUM_NV = 0x7FFFFFFF +} VkViewportCoordinateSwizzleNV; + +typedef VkFlags VkPipelineViewportSwizzleStateCreateFlagsNV; + +typedef struct VkViewportSwizzleNV { + VkViewportCoordinateSwizzleNV x; + VkViewportCoordinateSwizzleNV y; + VkViewportCoordinateSwizzleNV z; + VkViewportCoordinateSwizzleNV w; +} VkViewportSwizzleNV; + +typedef struct VkPipelineViewportSwizzleStateCreateInfoNV { + VkStructureType sType; + const void* pNext; + VkPipelineViewportSwizzleStateCreateFlagsNV flags; + uint32_t viewportCount; + const VkViewportSwizzleNV* pViewportSwizzles; +} VkPipelineViewportSwizzleStateCreateInfoNV; + + + +#define VK_EXT_discard_rectangles 1 +#define VK_EXT_DISCARD_RECTANGLES_SPEC_VERSION 1 +#define VK_EXT_DISCARD_RECTANGLES_EXTENSION_NAME "VK_EXT_discard_rectangles" + + +typedef enum VkDiscardRectangleModeEXT { + VK_DISCARD_RECTANGLE_MODE_INCLUSIVE_EXT = 0, + VK_DISCARD_RECTANGLE_MODE_EXCLUSIVE_EXT = 1, + VK_DISCARD_RECTANGLE_MODE_BEGIN_RANGE_EXT = VK_DISCARD_RECTANGLE_MODE_INCLUSIVE_EXT, + VK_DISCARD_RECTANGLE_MODE_END_RANGE_EXT = VK_DISCARD_RECTANGLE_MODE_EXCLUSIVE_EXT, + VK_DISCARD_RECTANGLE_MODE_RANGE_SIZE_EXT = (VK_DISCARD_RECTANGLE_MODE_EXCLUSIVE_EXT - VK_DISCARD_RECTANGLE_MODE_INCLUSIVE_EXT + 1), + VK_DISCARD_RECTANGLE_MODE_MAX_ENUM_EXT = 0x7FFFFFFF +} VkDiscardRectangleModeEXT; + +typedef VkFlags VkPipelineDiscardRectangleStateCreateFlagsEXT; + +typedef struct VkPhysicalDeviceDiscardRectanglePropertiesEXT { + VkStructureType sType; + void* pNext; + uint32_t maxDiscardRectangles; +} VkPhysicalDeviceDiscardRectanglePropertiesEXT; + +typedef struct VkPipelineDiscardRectangleStateCreateInfoEXT { + VkStructureType sType; + const void* pNext; + VkPipelineDiscardRectangleStateCreateFlagsEXT flags; + VkDiscardRectangleModeEXT discardRectangleMode; + uint32_t discardRectangleCount; + const VkRect2D* pDiscardRectangles; +} VkPipelineDiscardRectangleStateCreateInfoEXT; + + +typedef void (VKAPI_PTR *PFN_vkCmdSetDiscardRectangleEXT)(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle, uint32_t discardRectangleCount, const VkRect2D* pDiscardRectangles); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkCmdSetDiscardRectangleEXT( + VkCommandBuffer commandBuffer, + uint32_t firstDiscardRectangle, + uint32_t discardRectangleCount, + const VkRect2D* pDiscardRectangles); +#endif + +#define VK_EXT_conservative_rasterization 1 +#define VK_EXT_CONSERVATIVE_RASTERIZATION_SPEC_VERSION 1 +#define VK_EXT_CONSERVATIVE_RASTERIZATION_EXTENSION_NAME "VK_EXT_conservative_rasterization" + + +typedef enum VkConservativeRasterizationModeEXT { + VK_CONSERVATIVE_RASTERIZATION_MODE_DISABLED_EXT = 0, + VK_CONSERVATIVE_RASTERIZATION_MODE_OVERESTIMATE_EXT = 1, + VK_CONSERVATIVE_RASTERIZATION_MODE_UNDERESTIMATE_EXT = 2, + VK_CONSERVATIVE_RASTERIZATION_MODE_BEGIN_RANGE_EXT = VK_CONSERVATIVE_RASTERIZATION_MODE_DISABLED_EXT, + VK_CONSERVATIVE_RASTERIZATION_MODE_END_RANGE_EXT = VK_CONSERVATIVE_RASTERIZATION_MODE_UNDERESTIMATE_EXT, + VK_CONSERVATIVE_RASTERIZATION_MODE_RANGE_SIZE_EXT = (VK_CONSERVATIVE_RASTERIZATION_MODE_UNDERESTIMATE_EXT - VK_CONSERVATIVE_RASTERIZATION_MODE_DISABLED_EXT + 1), + VK_CONSERVATIVE_RASTERIZATION_MODE_MAX_ENUM_EXT = 0x7FFFFFFF +} VkConservativeRasterizationModeEXT; + +typedef VkFlags VkPipelineRasterizationConservativeStateCreateFlagsEXT; + +typedef struct VkPhysicalDeviceConservativeRasterizationPropertiesEXT { + VkStructureType sType; + void* pNext; + float primitiveOverestimationSize; + float maxExtraPrimitiveOverestimationSize; + float extraPrimitiveOverestimationSizeGranularity; + VkBool32 primitiveUnderestimation; + VkBool32 conservativePointAndLineRasterization; + VkBool32 degenerateTrianglesRasterized; + VkBool32 degenerateLinesRasterized; + VkBool32 fullyCoveredFragmentShaderInputVariable; + VkBool32 conservativeRasterizationPostDepthCoverage; +} VkPhysicalDeviceConservativeRasterizationPropertiesEXT; + +typedef struct VkPipelineRasterizationConservativeStateCreateInfoEXT { + VkStructureType sType; + const void* pNext; + VkPipelineRasterizationConservativeStateCreateFlagsEXT flags; + VkConservativeRasterizationModeEXT conservativeRasterizationMode; + float extraPrimitiveOverestimationSize; +} VkPipelineRasterizationConservativeStateCreateInfoEXT; + + + +#define VK_EXT_swapchain_colorspace 1 +#define VK_EXT_SWAPCHAIN_COLOR_SPACE_SPEC_VERSION 3 +#define VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME "VK_EXT_swapchain_colorspace" + + +#define VK_EXT_hdr_metadata 1 +#define VK_EXT_HDR_METADATA_SPEC_VERSION 1 +#define VK_EXT_HDR_METADATA_EXTENSION_NAME "VK_EXT_hdr_metadata" + +typedef struct VkXYColorEXT { + float x; + float y; +} VkXYColorEXT; + +typedef struct VkHdrMetadataEXT { + VkStructureType sType; + const void* pNext; + VkXYColorEXT displayPrimaryRed; + VkXYColorEXT displayPrimaryGreen; + VkXYColorEXT displayPrimaryBlue; + VkXYColorEXT whitePoint; + float maxLuminance; + float minLuminance; + float maxContentLightLevel; + float maxFrameAverageLightLevel; +} VkHdrMetadataEXT; + + +typedef void (VKAPI_PTR *PFN_vkSetHdrMetadataEXT)(VkDevice device, uint32_t swapchainCount, const VkSwapchainKHR* pSwapchains, const VkHdrMetadataEXT* pMetadata); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkSetHdrMetadataEXT( + VkDevice device, + uint32_t swapchainCount, + const VkSwapchainKHR* pSwapchains, + const VkHdrMetadataEXT* pMetadata); +#endif + +#define VK_EXT_external_memory_dma_buf 1 +#define VK_EXT_EXTERNAL_MEMORY_DMA_BUF_SPEC_VERSION 1 +#define VK_EXT_EXTERNAL_MEMORY_DMA_BUF_EXTENSION_NAME "VK_EXT_external_memory_dma_buf" + + +#define VK_EXT_queue_family_foreign 1 +#define VK_EXT_QUEUE_FAMILY_FOREIGN_SPEC_VERSION 1 +#define VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME "VK_EXT_queue_family_foreign" +#define VK_QUEUE_FAMILY_FOREIGN_EXT (~0U-2) + + +#define VK_EXT_debug_utils 1 +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDebugUtilsMessengerEXT) + +#define VK_EXT_DEBUG_UTILS_SPEC_VERSION 1 +#define VK_EXT_DEBUG_UTILS_EXTENSION_NAME "VK_EXT_debug_utils" + +typedef VkFlags VkDebugUtilsMessengerCallbackDataFlagsEXT; +typedef VkFlags VkDebugUtilsMessengerCreateFlagsEXT; + +typedef enum VkDebugUtilsMessageSeverityFlagBitsEXT { + VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT = 0x00000001, + VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT = 0x00000010, + VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT = 0x00000100, + VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT = 0x00001000, + VK_DEBUG_UTILS_MESSAGE_SEVERITY_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF +} VkDebugUtilsMessageSeverityFlagBitsEXT; +typedef VkFlags VkDebugUtilsMessageSeverityFlagsEXT; + +typedef enum VkDebugUtilsMessageTypeFlagBitsEXT { + VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT = 0x00000001, + VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT = 0x00000002, + VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT = 0x00000004, + VK_DEBUG_UTILS_MESSAGE_TYPE_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF +} VkDebugUtilsMessageTypeFlagBitsEXT; +typedef VkFlags VkDebugUtilsMessageTypeFlagsEXT; + +typedef struct VkDebugUtilsObjectNameInfoEXT { + VkStructureType sType; + const void* pNext; + VkObjectType objectType; + uint64_t objectHandle; + const char* pObjectName; +} VkDebugUtilsObjectNameInfoEXT; + +typedef struct VkDebugUtilsObjectTagInfoEXT { + VkStructureType sType; + const void* pNext; + VkObjectType objectType; + uint64_t objectHandle; + uint64_t tagName; + size_t tagSize; + const void* pTag; +} VkDebugUtilsObjectTagInfoEXT; + +typedef struct VkDebugUtilsLabelEXT { + VkStructureType sType; + const void* pNext; + const char* pLabelName; + float color[4]; +} VkDebugUtilsLabelEXT; + +typedef struct VkDebugUtilsMessengerCallbackDataEXT { + VkStructureType sType; + const void* pNext; + VkDebugUtilsMessengerCallbackDataFlagsEXT flags; + const char* pMessageIdName; + int32_t messageIdNumber; + const char* pMessage; + uint32_t queueLabelCount; + VkDebugUtilsLabelEXT* pQueueLabels; + uint32_t cmdBufLabelCount; + VkDebugUtilsLabelEXT* pCmdBufLabels; + uint32_t objectCount; + VkDebugUtilsObjectNameInfoEXT* pObjects; +} VkDebugUtilsMessengerCallbackDataEXT; + +typedef VkBool32 (VKAPI_PTR *PFN_vkDebugUtilsMessengerCallbackEXT)( + VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, + VkDebugUtilsMessageTypeFlagsEXT messageType, + const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, + void* pUserData); + +typedef struct VkDebugUtilsMessengerCreateInfoEXT { + VkStructureType sType; + const void* pNext; + VkDebugUtilsMessengerCreateFlagsEXT flags; + VkDebugUtilsMessageSeverityFlagsEXT messageSeverity; + VkDebugUtilsMessageTypeFlagsEXT messageType; + PFN_vkDebugUtilsMessengerCallbackEXT pfnUserCallback; + void* pUserData; +} VkDebugUtilsMessengerCreateInfoEXT; + + +typedef VkResult (VKAPI_PTR *PFN_vkSetDebugUtilsObjectNameEXT)(VkDevice device, const VkDebugUtilsObjectNameInfoEXT* pNameInfo); +typedef VkResult (VKAPI_PTR *PFN_vkSetDebugUtilsObjectTagEXT)(VkDevice device, const VkDebugUtilsObjectTagInfoEXT* pTagInfo); +typedef void (VKAPI_PTR *PFN_vkQueueBeginDebugUtilsLabelEXT)(VkQueue queue, const VkDebugUtilsLabelEXT* pLabelInfo); +typedef void (VKAPI_PTR *PFN_vkQueueEndDebugUtilsLabelEXT)(VkQueue queue); +typedef void (VKAPI_PTR *PFN_vkQueueInsertDebugUtilsLabelEXT)(VkQueue queue, const VkDebugUtilsLabelEXT* pLabelInfo); +typedef void (VKAPI_PTR *PFN_vkCmdBeginDebugUtilsLabelEXT)(VkCommandBuffer commandBuffer, const VkDebugUtilsLabelEXT* pLabelInfo); +typedef void (VKAPI_PTR *PFN_vkCmdEndDebugUtilsLabelEXT)(VkCommandBuffer commandBuffer); +typedef void (VKAPI_PTR *PFN_vkCmdInsertDebugUtilsLabelEXT)(VkCommandBuffer commandBuffer, const VkDebugUtilsLabelEXT* pLabelInfo); +typedef VkResult (VKAPI_PTR *PFN_vkCreateDebugUtilsMessengerEXT)(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pMessenger); +typedef void (VKAPI_PTR *PFN_vkDestroyDebugUtilsMessengerEXT)(VkInstance instance, VkDebugUtilsMessengerEXT messenger, const VkAllocationCallbacks* pAllocator); +typedef void (VKAPI_PTR *PFN_vkSubmitDebugUtilsMessageEXT)(VkInstance instance, VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkSetDebugUtilsObjectNameEXT( + VkDevice device, + const VkDebugUtilsObjectNameInfoEXT* pNameInfo); + +VKAPI_ATTR VkResult VKAPI_CALL vkSetDebugUtilsObjectTagEXT( + VkDevice device, + const VkDebugUtilsObjectTagInfoEXT* pTagInfo); + +VKAPI_ATTR void VKAPI_CALL vkQueueBeginDebugUtilsLabelEXT( + VkQueue queue, + const VkDebugUtilsLabelEXT* pLabelInfo); + +VKAPI_ATTR void VKAPI_CALL vkQueueEndDebugUtilsLabelEXT( + VkQueue queue); + +VKAPI_ATTR void VKAPI_CALL vkQueueInsertDebugUtilsLabelEXT( + VkQueue queue, + const VkDebugUtilsLabelEXT* pLabelInfo); + +VKAPI_ATTR void VKAPI_CALL vkCmdBeginDebugUtilsLabelEXT( + VkCommandBuffer commandBuffer, + const VkDebugUtilsLabelEXT* pLabelInfo); + +VKAPI_ATTR void VKAPI_CALL vkCmdEndDebugUtilsLabelEXT( + VkCommandBuffer commandBuffer); + +VKAPI_ATTR void VKAPI_CALL vkCmdInsertDebugUtilsLabelEXT( + VkCommandBuffer commandBuffer, + const VkDebugUtilsLabelEXT* pLabelInfo); + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT( + VkInstance instance, + const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkDebugUtilsMessengerEXT* pMessenger); + +VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT( + VkInstance instance, + VkDebugUtilsMessengerEXT messenger, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR void VKAPI_CALL vkSubmitDebugUtilsMessageEXT( + VkInstance instance, + VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, + VkDebugUtilsMessageTypeFlagsEXT messageTypes, + const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData); +#endif + +#define VK_EXT_sampler_filter_minmax 1 +#define VK_EXT_SAMPLER_FILTER_MINMAX_SPEC_VERSION 1 +#define VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME "VK_EXT_sampler_filter_minmax" + + +typedef enum VkSamplerReductionModeEXT { + VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT = 0, + VK_SAMPLER_REDUCTION_MODE_MIN_EXT = 1, + VK_SAMPLER_REDUCTION_MODE_MAX_EXT = 2, + VK_SAMPLER_REDUCTION_MODE_BEGIN_RANGE_EXT = VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT, + VK_SAMPLER_REDUCTION_MODE_END_RANGE_EXT = VK_SAMPLER_REDUCTION_MODE_MAX_EXT, + VK_SAMPLER_REDUCTION_MODE_RANGE_SIZE_EXT = (VK_SAMPLER_REDUCTION_MODE_MAX_EXT - VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT + 1), + VK_SAMPLER_REDUCTION_MODE_MAX_ENUM_EXT = 0x7FFFFFFF +} VkSamplerReductionModeEXT; + +typedef struct VkSamplerReductionModeCreateInfoEXT { + VkStructureType sType; + const void* pNext; + VkSamplerReductionModeEXT reductionMode; +} VkSamplerReductionModeCreateInfoEXT; + +typedef struct VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT { + VkStructureType sType; + void* pNext; + VkBool32 filterMinmaxSingleComponentFormats; + VkBool32 filterMinmaxImageComponentMapping; +} VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT; + + + +#define VK_AMD_gpu_shader_int16 1 +#define VK_AMD_GPU_SHADER_INT16_SPEC_VERSION 1 +#define VK_AMD_GPU_SHADER_INT16_EXTENSION_NAME "VK_AMD_gpu_shader_int16" + + +#define VK_AMD_mixed_attachment_samples 1 +#define VK_AMD_MIXED_ATTACHMENT_SAMPLES_SPEC_VERSION 1 +#define VK_AMD_MIXED_ATTACHMENT_SAMPLES_EXTENSION_NAME "VK_AMD_mixed_attachment_samples" + + +#define VK_AMD_shader_fragment_mask 1 +#define VK_AMD_SHADER_FRAGMENT_MASK_SPEC_VERSION 1 +#define VK_AMD_SHADER_FRAGMENT_MASK_EXTENSION_NAME "VK_AMD_shader_fragment_mask" + + +#define VK_EXT_inline_uniform_block 1 +#define VK_EXT_INLINE_UNIFORM_BLOCK_SPEC_VERSION 1 +#define VK_EXT_INLINE_UNIFORM_BLOCK_EXTENSION_NAME "VK_EXT_inline_uniform_block" + +typedef struct VkPhysicalDeviceInlineUniformBlockFeaturesEXT { + VkStructureType sType; + void* pNext; + VkBool32 inlineUniformBlock; + VkBool32 descriptorBindingInlineUniformBlockUpdateAfterBind; +} VkPhysicalDeviceInlineUniformBlockFeaturesEXT; + +typedef struct VkPhysicalDeviceInlineUniformBlockPropertiesEXT { + VkStructureType sType; + void* pNext; + uint32_t maxInlineUniformBlockSize; + uint32_t maxPerStageDescriptorInlineUniformBlocks; + uint32_t maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks; + uint32_t maxDescriptorSetInlineUniformBlocks; + uint32_t maxDescriptorSetUpdateAfterBindInlineUniformBlocks; +} VkPhysicalDeviceInlineUniformBlockPropertiesEXT; + +typedef struct VkWriteDescriptorSetInlineUniformBlockEXT { + VkStructureType sType; + const void* pNext; + uint32_t dataSize; + const void* pData; +} VkWriteDescriptorSetInlineUniformBlockEXT; + +typedef struct VkDescriptorPoolInlineUniformBlockCreateInfoEXT { + VkStructureType sType; + const void* pNext; + uint32_t maxInlineUniformBlockBindings; +} VkDescriptorPoolInlineUniformBlockCreateInfoEXT; + + + +#define VK_EXT_shader_stencil_export 1 +#define VK_EXT_SHADER_STENCIL_EXPORT_SPEC_VERSION 1 +#define VK_EXT_SHADER_STENCIL_EXPORT_EXTENSION_NAME "VK_EXT_shader_stencil_export" + + +#define VK_EXT_sample_locations 1 +#define VK_EXT_SAMPLE_LOCATIONS_SPEC_VERSION 1 +#define VK_EXT_SAMPLE_LOCATIONS_EXTENSION_NAME "VK_EXT_sample_locations" + +typedef struct VkSampleLocationEXT { + float x; + float y; +} VkSampleLocationEXT; + +typedef struct VkSampleLocationsInfoEXT { + VkStructureType sType; + const void* pNext; + VkSampleCountFlagBits sampleLocationsPerPixel; + VkExtent2D sampleLocationGridSize; + uint32_t sampleLocationsCount; + const VkSampleLocationEXT* pSampleLocations; +} VkSampleLocationsInfoEXT; + +typedef struct VkAttachmentSampleLocationsEXT { + uint32_t attachmentIndex; + VkSampleLocationsInfoEXT sampleLocationsInfo; +} VkAttachmentSampleLocationsEXT; + +typedef struct VkSubpassSampleLocationsEXT { + uint32_t subpassIndex; + VkSampleLocationsInfoEXT sampleLocationsInfo; +} VkSubpassSampleLocationsEXT; + +typedef struct VkRenderPassSampleLocationsBeginInfoEXT { + VkStructureType sType; + const void* pNext; + uint32_t attachmentInitialSampleLocationsCount; + const VkAttachmentSampleLocationsEXT* pAttachmentInitialSampleLocations; + uint32_t postSubpassSampleLocationsCount; + const VkSubpassSampleLocationsEXT* pPostSubpassSampleLocations; +} VkRenderPassSampleLocationsBeginInfoEXT; + +typedef struct VkPipelineSampleLocationsStateCreateInfoEXT { + VkStructureType sType; + const void* pNext; + VkBool32 sampleLocationsEnable; + VkSampleLocationsInfoEXT sampleLocationsInfo; +} VkPipelineSampleLocationsStateCreateInfoEXT; + +typedef struct VkPhysicalDeviceSampleLocationsPropertiesEXT { + VkStructureType sType; + void* pNext; + VkSampleCountFlags sampleLocationSampleCounts; + VkExtent2D maxSampleLocationGridSize; + float sampleLocationCoordinateRange[2]; + uint32_t sampleLocationSubPixelBits; + VkBool32 variableSampleLocations; +} VkPhysicalDeviceSampleLocationsPropertiesEXT; + +typedef struct VkMultisamplePropertiesEXT { + VkStructureType sType; + void* pNext; + VkExtent2D maxSampleLocationGridSize; +} VkMultisamplePropertiesEXT; + + +typedef void (VKAPI_PTR *PFN_vkCmdSetSampleLocationsEXT)(VkCommandBuffer commandBuffer, const VkSampleLocationsInfoEXT* pSampleLocationsInfo); +typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceMultisamplePropertiesEXT)(VkPhysicalDevice physicalDevice, VkSampleCountFlagBits samples, VkMultisamplePropertiesEXT* pMultisampleProperties); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkCmdSetSampleLocationsEXT( + VkCommandBuffer commandBuffer, + const VkSampleLocationsInfoEXT* pSampleLocationsInfo); + +VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMultisamplePropertiesEXT( + VkPhysicalDevice physicalDevice, + VkSampleCountFlagBits samples, + VkMultisamplePropertiesEXT* pMultisampleProperties); +#endif + +#define VK_EXT_blend_operation_advanced 1 +#define VK_EXT_BLEND_OPERATION_ADVANCED_SPEC_VERSION 2 +#define VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME "VK_EXT_blend_operation_advanced" + + +typedef enum VkBlendOverlapEXT { + VK_BLEND_OVERLAP_UNCORRELATED_EXT = 0, + VK_BLEND_OVERLAP_DISJOINT_EXT = 1, + VK_BLEND_OVERLAP_CONJOINT_EXT = 2, + VK_BLEND_OVERLAP_BEGIN_RANGE_EXT = VK_BLEND_OVERLAP_UNCORRELATED_EXT, + VK_BLEND_OVERLAP_END_RANGE_EXT = VK_BLEND_OVERLAP_CONJOINT_EXT, + VK_BLEND_OVERLAP_RANGE_SIZE_EXT = (VK_BLEND_OVERLAP_CONJOINT_EXT - VK_BLEND_OVERLAP_UNCORRELATED_EXT + 1), + VK_BLEND_OVERLAP_MAX_ENUM_EXT = 0x7FFFFFFF +} VkBlendOverlapEXT; + +typedef struct VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT { + VkStructureType sType; + void* pNext; + VkBool32 advancedBlendCoherentOperations; +} VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT; + +typedef struct VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT { + VkStructureType sType; + void* pNext; + uint32_t advancedBlendMaxColorAttachments; + VkBool32 advancedBlendIndependentBlend; + VkBool32 advancedBlendNonPremultipliedSrcColor; + VkBool32 advancedBlendNonPremultipliedDstColor; + VkBool32 advancedBlendCorrelatedOverlap; + VkBool32 advancedBlendAllOperations; +} VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT; + +typedef struct VkPipelineColorBlendAdvancedStateCreateInfoEXT { + VkStructureType sType; + const void* pNext; + VkBool32 srcPremultiplied; + VkBool32 dstPremultiplied; + VkBlendOverlapEXT blendOverlap; +} VkPipelineColorBlendAdvancedStateCreateInfoEXT; + + + +#define VK_NV_fragment_coverage_to_color 1 +#define VK_NV_FRAGMENT_COVERAGE_TO_COLOR_SPEC_VERSION 1 +#define VK_NV_FRAGMENT_COVERAGE_TO_COLOR_EXTENSION_NAME "VK_NV_fragment_coverage_to_color" + +typedef VkFlags VkPipelineCoverageToColorStateCreateFlagsNV; + +typedef struct VkPipelineCoverageToColorStateCreateInfoNV { + VkStructureType sType; + const void* pNext; + VkPipelineCoverageToColorStateCreateFlagsNV flags; + VkBool32 coverageToColorEnable; + uint32_t coverageToColorLocation; +} VkPipelineCoverageToColorStateCreateInfoNV; + + + +#define VK_NV_framebuffer_mixed_samples 1 +#define VK_NV_FRAMEBUFFER_MIXED_SAMPLES_SPEC_VERSION 1 +#define VK_NV_FRAMEBUFFER_MIXED_SAMPLES_EXTENSION_NAME "VK_NV_framebuffer_mixed_samples" + + +typedef enum VkCoverageModulationModeNV { + VK_COVERAGE_MODULATION_MODE_NONE_NV = 0, + VK_COVERAGE_MODULATION_MODE_RGB_NV = 1, + VK_COVERAGE_MODULATION_MODE_ALPHA_NV = 2, + VK_COVERAGE_MODULATION_MODE_RGBA_NV = 3, + VK_COVERAGE_MODULATION_MODE_BEGIN_RANGE_NV = VK_COVERAGE_MODULATION_MODE_NONE_NV, + VK_COVERAGE_MODULATION_MODE_END_RANGE_NV = VK_COVERAGE_MODULATION_MODE_RGBA_NV, + VK_COVERAGE_MODULATION_MODE_RANGE_SIZE_NV = (VK_COVERAGE_MODULATION_MODE_RGBA_NV - VK_COVERAGE_MODULATION_MODE_NONE_NV + 1), + VK_COVERAGE_MODULATION_MODE_MAX_ENUM_NV = 0x7FFFFFFF +} VkCoverageModulationModeNV; + +typedef VkFlags VkPipelineCoverageModulationStateCreateFlagsNV; + +typedef struct VkPipelineCoverageModulationStateCreateInfoNV { + VkStructureType sType; + const void* pNext; + VkPipelineCoverageModulationStateCreateFlagsNV flags; + VkCoverageModulationModeNV coverageModulationMode; + VkBool32 coverageModulationTableEnable; + uint32_t coverageModulationTableCount; + const float* pCoverageModulationTable; +} VkPipelineCoverageModulationStateCreateInfoNV; + + + +#define VK_NV_fill_rectangle 1 +#define VK_NV_FILL_RECTANGLE_SPEC_VERSION 1 +#define VK_NV_FILL_RECTANGLE_EXTENSION_NAME "VK_NV_fill_rectangle" + + +#define VK_EXT_post_depth_coverage 1 +#define VK_EXT_POST_DEPTH_COVERAGE_SPEC_VERSION 1 +#define VK_EXT_POST_DEPTH_COVERAGE_EXTENSION_NAME "VK_EXT_post_depth_coverage" + + +#define VK_EXT_validation_cache 1 +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkValidationCacheEXT) + +#define VK_EXT_VALIDATION_CACHE_SPEC_VERSION 1 +#define VK_EXT_VALIDATION_CACHE_EXTENSION_NAME "VK_EXT_validation_cache" + + +typedef enum VkValidationCacheHeaderVersionEXT { + VK_VALIDATION_CACHE_HEADER_VERSION_ONE_EXT = 1, + VK_VALIDATION_CACHE_HEADER_VERSION_BEGIN_RANGE_EXT = VK_VALIDATION_CACHE_HEADER_VERSION_ONE_EXT, + VK_VALIDATION_CACHE_HEADER_VERSION_END_RANGE_EXT = VK_VALIDATION_CACHE_HEADER_VERSION_ONE_EXT, + VK_VALIDATION_CACHE_HEADER_VERSION_RANGE_SIZE_EXT = (VK_VALIDATION_CACHE_HEADER_VERSION_ONE_EXT - VK_VALIDATION_CACHE_HEADER_VERSION_ONE_EXT + 1), + VK_VALIDATION_CACHE_HEADER_VERSION_MAX_ENUM_EXT = 0x7FFFFFFF +} VkValidationCacheHeaderVersionEXT; + +typedef VkFlags VkValidationCacheCreateFlagsEXT; + +typedef struct VkValidationCacheCreateInfoEXT { + VkStructureType sType; + const void* pNext; + VkValidationCacheCreateFlagsEXT flags; + size_t initialDataSize; + const void* pInitialData; +} VkValidationCacheCreateInfoEXT; + +typedef struct VkShaderModuleValidationCacheCreateInfoEXT { + VkStructureType sType; + const void* pNext; + VkValidationCacheEXT validationCache; +} VkShaderModuleValidationCacheCreateInfoEXT; + + +typedef VkResult (VKAPI_PTR *PFN_vkCreateValidationCacheEXT)(VkDevice device, const VkValidationCacheCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkValidationCacheEXT* pValidationCache); +typedef void (VKAPI_PTR *PFN_vkDestroyValidationCacheEXT)(VkDevice device, VkValidationCacheEXT validationCache, const VkAllocationCallbacks* pAllocator); +typedef VkResult (VKAPI_PTR *PFN_vkMergeValidationCachesEXT)(VkDevice device, VkValidationCacheEXT dstCache, uint32_t srcCacheCount, const VkValidationCacheEXT* pSrcCaches); +typedef VkResult (VKAPI_PTR *PFN_vkGetValidationCacheDataEXT)(VkDevice device, VkValidationCacheEXT validationCache, size_t* pDataSize, void* pData); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkCreateValidationCacheEXT( + VkDevice device, + const VkValidationCacheCreateInfoEXT* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkValidationCacheEXT* pValidationCache); + +VKAPI_ATTR void VKAPI_CALL vkDestroyValidationCacheEXT( + VkDevice device, + VkValidationCacheEXT validationCache, + const VkAllocationCallbacks* pAllocator); + +VKAPI_ATTR VkResult VKAPI_CALL vkMergeValidationCachesEXT( + VkDevice device, + VkValidationCacheEXT dstCache, + uint32_t srcCacheCount, + const VkValidationCacheEXT* pSrcCaches); + +VKAPI_ATTR VkResult VKAPI_CALL vkGetValidationCacheDataEXT( + VkDevice device, + VkValidationCacheEXT validationCache, + size_t* pDataSize, + void* pData); +#endif + +#define VK_EXT_descriptor_indexing 1 +#define VK_EXT_DESCRIPTOR_INDEXING_SPEC_VERSION 2 +#define VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME "VK_EXT_descriptor_indexing" + + +typedef enum VkDescriptorBindingFlagBitsEXT { + VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT = 0x00000001, + VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT = 0x00000002, + VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT = 0x00000004, + VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT = 0x00000008, + VK_DESCRIPTOR_BINDING_FLAG_BITS_MAX_ENUM_EXT = 0x7FFFFFFF +} VkDescriptorBindingFlagBitsEXT; +typedef VkFlags VkDescriptorBindingFlagsEXT; + +typedef struct VkDescriptorSetLayoutBindingFlagsCreateInfoEXT { + VkStructureType sType; + const void* pNext; + uint32_t bindingCount; + const VkDescriptorBindingFlagsEXT* pBindingFlags; +} VkDescriptorSetLayoutBindingFlagsCreateInfoEXT; + +typedef struct VkPhysicalDeviceDescriptorIndexingFeaturesEXT { + VkStructureType sType; + void* pNext; + VkBool32 shaderInputAttachmentArrayDynamicIndexing; + VkBool32 shaderUniformTexelBufferArrayDynamicIndexing; + VkBool32 shaderStorageTexelBufferArrayDynamicIndexing; + VkBool32 shaderUniformBufferArrayNonUniformIndexing; + VkBool32 shaderSampledImageArrayNonUniformIndexing; + VkBool32 shaderStorageBufferArrayNonUniformIndexing; + VkBool32 shaderStorageImageArrayNonUniformIndexing; + VkBool32 shaderInputAttachmentArrayNonUniformIndexing; + VkBool32 shaderUniformTexelBufferArrayNonUniformIndexing; + VkBool32 shaderStorageTexelBufferArrayNonUniformIndexing; + VkBool32 descriptorBindingUniformBufferUpdateAfterBind; + VkBool32 descriptorBindingSampledImageUpdateAfterBind; + VkBool32 descriptorBindingStorageImageUpdateAfterBind; + VkBool32 descriptorBindingStorageBufferUpdateAfterBind; + VkBool32 descriptorBindingUniformTexelBufferUpdateAfterBind; + VkBool32 descriptorBindingStorageTexelBufferUpdateAfterBind; + VkBool32 descriptorBindingUpdateUnusedWhilePending; + VkBool32 descriptorBindingPartiallyBound; + VkBool32 descriptorBindingVariableDescriptorCount; + VkBool32 runtimeDescriptorArray; +} VkPhysicalDeviceDescriptorIndexingFeaturesEXT; + +typedef struct VkPhysicalDeviceDescriptorIndexingPropertiesEXT { + VkStructureType sType; + void* pNext; + uint32_t maxUpdateAfterBindDescriptorsInAllPools; + VkBool32 shaderUniformBufferArrayNonUniformIndexingNative; + VkBool32 shaderSampledImageArrayNonUniformIndexingNative; + VkBool32 shaderStorageBufferArrayNonUniformIndexingNative; + VkBool32 shaderStorageImageArrayNonUniformIndexingNative; + VkBool32 shaderInputAttachmentArrayNonUniformIndexingNative; + VkBool32 robustBufferAccessUpdateAfterBind; + VkBool32 quadDivergentImplicitLod; + uint32_t maxPerStageDescriptorUpdateAfterBindSamplers; + uint32_t maxPerStageDescriptorUpdateAfterBindUniformBuffers; + uint32_t maxPerStageDescriptorUpdateAfterBindStorageBuffers; + uint32_t maxPerStageDescriptorUpdateAfterBindSampledImages; + uint32_t maxPerStageDescriptorUpdateAfterBindStorageImages; + uint32_t maxPerStageDescriptorUpdateAfterBindInputAttachments; + uint32_t maxPerStageUpdateAfterBindResources; + uint32_t maxDescriptorSetUpdateAfterBindSamplers; + uint32_t maxDescriptorSetUpdateAfterBindUniformBuffers; + uint32_t maxDescriptorSetUpdateAfterBindUniformBuffersDynamic; + uint32_t maxDescriptorSetUpdateAfterBindStorageBuffers; + uint32_t maxDescriptorSetUpdateAfterBindStorageBuffersDynamic; + uint32_t maxDescriptorSetUpdateAfterBindSampledImages; + uint32_t maxDescriptorSetUpdateAfterBindStorageImages; + uint32_t maxDescriptorSetUpdateAfterBindInputAttachments; +} VkPhysicalDeviceDescriptorIndexingPropertiesEXT; + +typedef struct VkDescriptorSetVariableDescriptorCountAllocateInfoEXT { + VkStructureType sType; + const void* pNext; + uint32_t descriptorSetCount; + const uint32_t* pDescriptorCounts; +} VkDescriptorSetVariableDescriptorCountAllocateInfoEXT; + +typedef struct VkDescriptorSetVariableDescriptorCountLayoutSupportEXT { + VkStructureType sType; + void* pNext; + uint32_t maxVariableDescriptorCount; +} VkDescriptorSetVariableDescriptorCountLayoutSupportEXT; + + + +#define VK_EXT_shader_viewport_index_layer 1 +#define VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_SPEC_VERSION 1 +#define VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME "VK_EXT_shader_viewport_index_layer" + + +#define VK_EXT_global_priority 1 +#define VK_EXT_GLOBAL_PRIORITY_SPEC_VERSION 2 +#define VK_EXT_GLOBAL_PRIORITY_EXTENSION_NAME "VK_EXT_global_priority" + + +typedef enum VkQueueGlobalPriorityEXT { + VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT = 128, + VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT = 256, + VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT = 512, + VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT = 1024, + VK_QUEUE_GLOBAL_PRIORITY_BEGIN_RANGE_EXT = VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT, + VK_QUEUE_GLOBAL_PRIORITY_END_RANGE_EXT = VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT, + VK_QUEUE_GLOBAL_PRIORITY_RANGE_SIZE_EXT = (VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT - VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT + 1), + VK_QUEUE_GLOBAL_PRIORITY_MAX_ENUM_EXT = 0x7FFFFFFF +} VkQueueGlobalPriorityEXT; + +typedef struct VkDeviceQueueGlobalPriorityCreateInfoEXT { + VkStructureType sType; + const void* pNext; + VkQueueGlobalPriorityEXT globalPriority; +} VkDeviceQueueGlobalPriorityCreateInfoEXT; + + + +#define VK_EXT_external_memory_host 1 +#define VK_EXT_EXTERNAL_MEMORY_HOST_SPEC_VERSION 1 +#define VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME "VK_EXT_external_memory_host" + +typedef struct VkImportMemoryHostPointerInfoEXT { + VkStructureType sType; + const void* pNext; + VkExternalMemoryHandleTypeFlagBits handleType; + void* pHostPointer; +} VkImportMemoryHostPointerInfoEXT; + +typedef struct VkMemoryHostPointerPropertiesEXT { + VkStructureType sType; + void* pNext; + uint32_t memoryTypeBits; +} VkMemoryHostPointerPropertiesEXT; + +typedef struct VkPhysicalDeviceExternalMemoryHostPropertiesEXT { + VkStructureType sType; + void* pNext; + VkDeviceSize minImportedHostPointerAlignment; +} VkPhysicalDeviceExternalMemoryHostPropertiesEXT; + + +typedef VkResult (VKAPI_PTR *PFN_vkGetMemoryHostPointerPropertiesEXT)(VkDevice device, VkExternalMemoryHandleTypeFlagBits handleType, const void* pHostPointer, VkMemoryHostPointerPropertiesEXT* pMemoryHostPointerProperties); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryHostPointerPropertiesEXT( + VkDevice device, + VkExternalMemoryHandleTypeFlagBits handleType, + const void* pHostPointer, + VkMemoryHostPointerPropertiesEXT* pMemoryHostPointerProperties); +#endif + +#define VK_AMD_buffer_marker 1 +#define VK_AMD_BUFFER_MARKER_SPEC_VERSION 1 +#define VK_AMD_BUFFER_MARKER_EXTENSION_NAME "VK_AMD_buffer_marker" + +typedef void (VKAPI_PTR *PFN_vkCmdWriteBufferMarkerAMD)(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkBuffer dstBuffer, VkDeviceSize dstOffset, uint32_t marker); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkCmdWriteBufferMarkerAMD( + VkCommandBuffer commandBuffer, + VkPipelineStageFlagBits pipelineStage, + VkBuffer dstBuffer, + VkDeviceSize dstOffset, + uint32_t marker); +#endif + +#define VK_AMD_shader_core_properties 1 +#define VK_AMD_SHADER_CORE_PROPERTIES_SPEC_VERSION 1 +#define VK_AMD_SHADER_CORE_PROPERTIES_EXTENSION_NAME "VK_AMD_shader_core_properties" + +typedef struct VkPhysicalDeviceShaderCorePropertiesAMD { + VkStructureType sType; + void* pNext; + uint32_t shaderEngineCount; + uint32_t shaderArraysPerEngineCount; + uint32_t computeUnitsPerShaderArray; + uint32_t simdPerComputeUnit; + uint32_t wavefrontsPerSimd; + uint32_t wavefrontSize; + uint32_t sgprsPerSimd; + uint32_t minSgprAllocation; + uint32_t maxSgprAllocation; + uint32_t sgprAllocationGranularity; + uint32_t vgprsPerSimd; + uint32_t minVgprAllocation; + uint32_t maxVgprAllocation; + uint32_t vgprAllocationGranularity; +} VkPhysicalDeviceShaderCorePropertiesAMD; + + + +#define VK_EXT_vertex_attribute_divisor 1 +#define VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_SPEC_VERSION 3 +#define VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME "VK_EXT_vertex_attribute_divisor" + +typedef struct VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT { + VkStructureType sType; + void* pNext; + uint32_t maxVertexAttribDivisor; +} VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT; + +typedef struct VkVertexInputBindingDivisorDescriptionEXT { + uint32_t binding; + uint32_t divisor; +} VkVertexInputBindingDivisorDescriptionEXT; + +typedef struct VkPipelineVertexInputDivisorStateCreateInfoEXT { + VkStructureType sType; + const void* pNext; + uint32_t vertexBindingDivisorCount; + const VkVertexInputBindingDivisorDescriptionEXT* pVertexBindingDivisors; +} VkPipelineVertexInputDivisorStateCreateInfoEXT; + +typedef struct VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT { + VkStructureType sType; + void* pNext; + VkBool32 vertexAttributeInstanceRateDivisor; + VkBool32 vertexAttributeInstanceRateZeroDivisor; +} VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT; + + + +#define VK_NV_shader_subgroup_partitioned 1 +#define VK_NV_SHADER_SUBGROUP_PARTITIONED_SPEC_VERSION 1 +#define VK_NV_SHADER_SUBGROUP_PARTITIONED_EXTENSION_NAME "VK_NV_shader_subgroup_partitioned" + + +#define VK_NV_device_diagnostic_checkpoints 1 +#define VK_NV_DEVICE_DIAGNOSTIC_CHECKPOINTS_SPEC_VERSION 2 +#define VK_NV_DEVICE_DIAGNOSTIC_CHECKPOINTS_EXTENSION_NAME "VK_NV_device_diagnostic_checkpoints" + +typedef struct VkQueueFamilyCheckpointPropertiesNV { + VkStructureType sType; + void* pNext; + VkPipelineStageFlags checkpointExecutionStageMask; +} VkQueueFamilyCheckpointPropertiesNV; + +typedef struct VkCheckpointDataNV { + VkStructureType sType; + void* pNext; + VkPipelineStageFlagBits stage; + void* pCheckpointMarker; +} VkCheckpointDataNV; + + +typedef void (VKAPI_PTR *PFN_vkCmdSetCheckpointNV)(VkCommandBuffer commandBuffer, const void* pCheckpointMarker); +typedef void (VKAPI_PTR *PFN_vkGetQueueCheckpointDataNV)(VkQueue queue, uint32_t* pCheckpointDataCount, VkCheckpointDataNV* pCheckpointData); + +#ifndef VK_NO_PROTOTYPES +VKAPI_ATTR void VKAPI_CALL vkCmdSetCheckpointNV( + VkCommandBuffer commandBuffer, + const void* pCheckpointMarker); + +VKAPI_ATTR void VKAPI_CALL vkGetQueueCheckpointDataNV( + VkQueue queue, + uint32_t* pCheckpointDataCount, + VkCheckpointDataNV* pCheckpointData); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/main/kotlin/vulkan/base/Vulkan Buffer.kt b/src/main/kotlin/vulkan/base/Vulkan Buffer.kt index a0c74c7..e0eb8af 100644 --- a/src/main/kotlin/vulkan/base/Vulkan Buffer.kt +++ b/src/main/kotlin/vulkan/base/Vulkan Buffer.kt @@ -10,13 +10,11 @@ package vulkan.base -import org.lwjgl.PointerBuffer import org.lwjgl.system.MemoryUtil.NULL -import org.lwjgl.system.MemoryUtil.memCallocPointer -import org.lwjgl.vulkan.VK10.VK_WHOLE_SIZE import org.lwjgl.vulkan.VkDescriptorBufferInfo import org.lwjgl.vulkan.VkDevice import vkk.* +import vulkan.VK_WHOLE_SIZE /** * @brief Encapsulates access to a Vulkan buffer backed up by device memory @@ -25,11 +23,11 @@ import vkk.* class Buffer { lateinit var device: VkDevice - var buffer: VkBuffer = NULL - var memory: VkDeviceMemory = NULL + var buffer = VkBuffer(NULL) + var memory = VkDeviceMemory(NULL) val descriptor: VkDescriptorBufferInfo = VkDescriptorBufferInfo.calloc() - var size: VkDeviceSize = 0 - var alignment: VkDeviceSize = 0 + var size = VkDeviceSize(0) + var alignment = VkDeviceSize(0) var mapped = NULL /** @brief Usage flags to be filled by external source at buffer creation (to query at some later point) */ @@ -45,11 +43,11 @@ class Buffer { * * @return VkResult of the buffer mapping call */ - fun map(size: VkDeviceSize = VK_WHOLE_SIZE, offset: VkDeviceSize = 0) { + fun map(size: VkDeviceSize = VK_WHOLE_SIZE, offset: VkDeviceSize = VkDeviceSize(0)) { mapped = device.mapMemory(memory, offset, size) } - fun mapping(size: VkDeviceSize = VK_WHOLE_SIZE, offset: VkDeviceSize = 0, block: (Long) -> Unit) { + fun mapping(size: VkDeviceSize = VK_WHOLE_SIZE, offset: VkDeviceSize = VkDeviceSize(0), block: (Long) -> Unit) { map(size, offset) block(mapped) unmap() @@ -74,7 +72,7 @@ class Buffer { * * @return VkResult of the bindBufferMemory call */ - fun bind(offset: VkDeviceSize = 0) = device.bindBufferMemory(buffer, memory, offset) + fun bind(offset: VkDeviceSize = VkDeviceSize(0)) = device.bindBufferMemory(buffer, memory, offset) /** * Setup the default descriptor for this buffer @@ -83,7 +81,7 @@ class Buffer { * @param offset (Optional) Byte offset from beginning * */ - fun setupDescriptor(size: VkDeviceSize = VK_WHOLE_SIZE, offset: VkDeviceSize = 0) { + fun setupDescriptor(size: VkDeviceSize = VK_WHOLE_SIZE, offset: VkDeviceSize = VkDeviceSize(0)) { descriptor.also { it.offset = offset it.buffer = buffer @@ -114,7 +112,7 @@ class Buffer { * * @return VkResult of the flush call */ - fun flush(size: VkDeviceSize = VK_WHOLE_SIZE, offset: VkDeviceSize = 0): VkResult { + fun flush(size: VkDeviceSize = VK_WHOLE_SIZE, offset: VkDeviceSize = VkDeviceSize(0)): VkResult { val mappedRange = vk.MappedMemoryRange { type = VkStructureType.MAPPED_MEMORY_RANGE this.memory = memory @@ -134,7 +132,7 @@ class Buffer { * * @return VkResult of the invalidate call */ - fun invalidate(size: VkDeviceSize = VK_WHOLE_SIZE, offset: VkDeviceSize = 0): VkResult { + fun invalidate(size: VkDeviceSize = VK_WHOLE_SIZE, offset: VkDeviceSize = VkDeviceSize(0)): VkResult { val mappedRange = vk.MappedMemoryRange { type = VkStructureType.MAPPED_MEMORY_RANGE this.memory = memory @@ -148,9 +146,9 @@ class Buffer { * Release all Vulkan resources held by this buffer */ fun destroy() { - if (buffer != NULL) - vk.destroyBuffer(device, buffer) - if (memory != NULL) - vk.freeMemory(device, memory) + if (buffer.L != NULL) + device destroyBuffer buffer + if (memory.L != NULL) + device freeMemory memory } } \ No newline at end of file diff --git a/src/main/kotlin/vulkan/base/Vulkan Texture.kt b/src/main/kotlin/vulkan/base/Vulkan Texture.kt index e3d2b49..12917da 100644 --- a/src/main/kotlin/vulkan/base/Vulkan Texture.kt +++ b/src/main/kotlin/vulkan/base/Vulkan Texture.kt @@ -22,17 +22,17 @@ import java.io.File open class Texture { lateinit var device: VulkanDevice - var image: VkImage = NULL + var image = VkImage (NULL) var imageLayout = VkImageLayout.UNDEFINED - var deviceMemory: VkDeviceMemory = NULL - var view: VkImageView = NULL + var deviceMemory = VkDeviceMemory (NULL) + var view = VkImageView (NULL) val size = Vec2i() var mipLevels = 0 var layerCount = 0 val descriptor = VkDescriptorImageInfo.calloc() /** @brief Optional sampler to use with this texture */ - var sampler: VkSampler = NULL + var sampler= VkSampler (NULL) /** @brief Update image descriptor from current sampler, view and image layout */ fun updateDescriptor() { @@ -48,7 +48,7 @@ open class Texture { device.logicalDevice!!.apply { destroyImageView(view) destroyImage(image) - if (sampler != NULL) + if (sampler.L != NULL) destroySampler(sampler) freeMemory(deviceMemory) } @@ -114,7 +114,7 @@ class Texture2D : Texture() { // Create a host-visible staging buffer that contains the raw image data val bufferCreateInfo = vk.BufferCreateInfo { - size = tex2D.size.L + size = VkDeviceSize(tex2D.size.L) // This buffer is used as a transfer source for the buffer copy usage = VkBufferUsage.TRANSFER_SRC_BIT.i sharingMode = VkSharingMode.EXCLUSIVE @@ -132,13 +132,13 @@ class Texture2D : Texture() { dev.bindBufferMemory(stagingBuffer, stagingMemory) // Copy texture data into staging buffer - dev.mappingMemory(stagingMemory, 0, memReqs.size, 0) { data -> + dev.mappingMemory(stagingMemory, VkDeviceSize(0), memReqs.size, 0) { data -> memCopy(memAddress(tex2D.data()), data, tex2D.size.L) } // Setup buffer copy regions for each mip level val bufferCopyRegions = vk.BufferImageCopy(mipLevels) - var offset = 0L + var offset = VkDeviceSize(0L) for (i in 0 until mipLevels) { @@ -266,7 +266,7 @@ class Texture2D : Texture() { val subResLayout = dev.getImageSubresourceLayout(mappableImage, subRes) // Map image memory - dev.mappingMemory(mappableMemory, 0, memReqs.size, 0) { data -> + dev.mappingMemory(mappableMemory, VkDeviceSize(0), memReqs.size, 0) { data -> // Copy image data into memory memCopy(memAddress(tex2D[subRes.mipLevel].data()!!), data, tex2D[subRes.mipLevel].size.L) } diff --git a/src/main/kotlin/vulkan/base/VulkanDebug.kt b/src/main/kotlin/vulkan/base/VulkanDebug.kt index 0ed7d68..d165d47 100644 --- a/src/main/kotlin/vulkan/base/VulkanDebug.kt +++ b/src/main/kotlin/vulkan/base/VulkanDebug.kt @@ -3,6 +3,7 @@ package vulkan.base import VkDebugReportCallbackFunc import glm_.vec4.Vec4 import org.lwjgl.system.MemoryUtil.NULL +import org.lwjgl.system.Pointer import org.lwjgl.vulkan.VkCommandBuffer import org.lwjgl.vulkan.VkDevice import org.lwjgl.vulkan.VkInstance @@ -16,7 +17,7 @@ object debug { /** Default validation layers */ val validationLayerNames = arrayListOf("VK_LAYER_LUNARG_standard_validation") - var msgCallback: VkDebugReportCallback = NULL + var msgCallback = VkDebugReportCallback(NULL) /** Default debug callback */ val messageCallback: VkDebugReportCallbackFunc = { flags, _, _, _, msgCode, layerPrefix, msg, _ -> @@ -72,7 +73,7 @@ object debug { /** Clear debug callback */ fun freeDebugCallback(instance: VkInstance) { - if (msgCallback != NULL) + if (msgCallback.L != NULL) instance destroyDebugReportCallbackEXT msgCallback } } @@ -89,6 +90,20 @@ object debugMarker { lateinit var device: VkDevice + /** Sets the debug name of an object + * All Objects in Vulkan are represented by their 64-bit handles which are passed into this function + * along with the object type */ + fun setObjectName(device: VkDevice, `object`: VkObject, objectType: VkDebugReportObjectType, name: String) { + setObjectName(device, `object`.L, objectType, name) + } + + /** Sets the debug name of an object + * All Objects in Vulkan are represented by their 64-bit handles which are passed into this function + * along with the object type */ + fun setObjectName(device: VkDevice, pointer: Pointer, objectType: VkDebugReportObjectType, name: String) { + setObjectName(device, pointer.adr, objectType, name) + } + /** Sets the debug name of an object * All Objects in Vulkan are represented by their 64-bit handles which are passed into this function * along with the object type */ @@ -159,11 +174,11 @@ object debugMarker { // TODO remove device? // Object specific naming functions fun setCommandBufferName(device: VkDevice, cmdBuffer: VkCommandBuffer, name: String) { - setObjectName(device, cmdBuffer.adr, VkDebugReportObjectType.COMMAND_BUFFER_EXT, name) + setObjectName(device, cmdBuffer, VkDebugReportObjectType.COMMAND_BUFFER_EXT, name) } fun setQueueName(device: VkDevice, queue: VkQueue, name: String) { - setObjectName(device, queue.adr, VkDebugReportObjectType.QUEUE_EXT, name) + setObjectName(device, queue, VkDebugReportObjectType.QUEUE_EXT, name) } fun setImageName(device: VkDevice, image: VkImage, name: String) { diff --git a/src/main/kotlin/vulkan/base/VulkanDevice.kt b/src/main/kotlin/vulkan/base/VulkanDevice.kt index 29d491d..178bbf9 100644 --- a/src/main/kotlin/vulkan/base/VulkanDevice.kt +++ b/src/main/kotlin/vulkan/base/VulkanDevice.kt @@ -1,19 +1,19 @@ package vulkan.base -import ab.appBuffer import glm_.L import glm_.i -import glm_.size -import org.lwjgl.system.MemoryUtil.* +import imgui.getValue +import imgui.setValue +import kool.adr +import kool.remSize +import org.lwjgl.system.MemoryUtil.NULL +import org.lwjgl.system.MemoryUtil.memCopy import org.lwjgl.vulkan.* import org.lwjgl.vulkan.EXTDebugMarker.VK_EXT_DEBUG_MARKER_EXTENSION_NAME import org.lwjgl.vulkan.KHRSwapchain.VK_KHR_SWAPCHAIN_EXTENSION_NAME import org.lwjgl.vulkan.VK10.* import vkk.* import vulkan.base.tools.DEFAULT_FENCE_TIMEOUT -import java.nio.ByteBuffer -import java.nio.FloatBuffer -import java.nio.IntBuffer import kotlin.reflect.KMutableProperty0 class VulkanDevice @@ -42,7 +42,7 @@ constructor( val supportedExtensions: ArrayList /** @brief Default command pool for the graphics queue family index */ - var commandPool: VkCommandPool = NULL + var commandPool = VkCommandPool(NULL) /** @brief Set to true when the debug marker extension is detected */ var enableDebugMarkers = false @@ -80,14 +80,15 @@ constructor( * @note Frees the logical device */ fun destroy() { - if (commandPool != NULL) vkDestroyCommandPool(logicalDevice!!, commandPool, null) - logicalDevice?.let { vkDestroyDevice(it, null) } + if (commandPool.L != NULL) + logicalDevice!! destroyCommandPool commandPool + logicalDevice?.destroy() } /** * Get the index of a memory type that has all the requested property bits set * - * @param typeBits Bitmask with bits set for each memory type supported by the resource to request for (from VkMemoryRequirements) + * @param typeBits_ Bitmask with bits set for each memory type supported by the resource to request for (from VkMemoryRequirements) * @param properties Bitmask of properties for the memory type to request * @param (Optional) memTypeFound Pointer to a bool that is set to true if a matching memory type has been found * @@ -95,8 +96,8 @@ constructor( * * @throw Throws an exception if memTypeFound is null and no memory type could be found that supports the requested properties */ - fun getMemoryType(typeBits: Int, properties: VkMemoryPropertyFlags, memTypeFound: KMutableProperty0? = null): Int { - var typeBits = typeBits + fun getMemoryType(typeBits_: Int, properties: VkMemoryPropertyFlags, memTypeFound: KMutableProperty0? = null): Int { + var typeBits = typeBits_ for (i in 0 until memoryProperties.memoryTypeCount) { if ((typeBits and 1) == 1 && (memoryProperties.memoryTypes[i].propertyFlags and properties) == properties) { if (memTypeFound?.get() == true) @@ -214,7 +215,7 @@ constructor( deviceExtensions += VK_KHR_SWAPCHAIN_EXTENSION_NAME val deviceCreateInfo = vk.DeviceCreateInfo { - this.queueCreateInfos = queueCreateInfos.toBuffer() + this.queueCreateInfos = queueCreateInfos.toBufferStack() this.enabledFeatures = enabledFeatures } @@ -229,7 +230,7 @@ constructor( val result = vk.createDevice(physicalDevice, deviceCreateInfo, ::logicalDevice) - if (result == VkResult.SUCCESS) + if (result == SUCCESS) // Create a default command pool for graphics command buffers commandPool = createCommandPool(queueFamilyIndices.graphics) @@ -245,14 +246,17 @@ constructor( * @param usageFlags Usage flag bitmask for the buffer (i.e. index, vertex, uniform buffer) * @param memoryPropertyFlags Memory properties for this buffer (i.e. device local, host visible, coherent) * @param size Size of the buffer in byes - * @param buffer Pointer to the buffer handle acquired by the function - * @param memory Pointer to the memory handle acquired by the function + * @param pBuffer Pointer to the buffer handle acquired by the function + * @param pMemory Pointer to the memory handle acquired by the function * @param data Pointer to the data that should be copied to the buffer after creation (optional, if not set, no data is copied over) * * @return VK_SUCCESS if buffer handle and memory have been created and (optionally passed) data has been copied */ fun createBuffer(usageFlags: VkBufferUsageFlags, memoryPropertyFlags: VkMemoryPropertyFlags, size: VkDeviceSize, - buffer: KMutableProperty0, memory: KMutableProperty0, data: Long = NULL) { + pBuffer: KMutableProperty0, pMemory: KMutableProperty0, data: Long = NULL) { + + var buffer by pBuffer + var memory by pMemory val dev = logicalDevice!! // Create the buffer handle @@ -261,21 +265,21 @@ constructor( this.size = size sharingMode = VkSharingMode.EXCLUSIVE } - dev.createBuffer(bufferCreateInfo, buffer) + buffer = dev createBuffer bufferCreateInfo // Create the memory backing up the buffer handle - val memReqs = dev getBufferMemoryRequirements buffer() + val memReqs = dev getBufferMemoryRequirements buffer val memAlloc = vk.MemoryAllocateInfo { allocationSize = memReqs.size // Find a memory type index that fits the properties of the buffer memoryTypeIndex = getMemoryType(memReqs.memoryTypeBits, memoryPropertyFlags) } - dev.allocateMemory(memAlloc, memory) + memory = dev allocateMemory memAlloc // If a pointer to the buffer data has been passed, map the buffer and copy over the data if (data != NULL) - dev.mappingMemory(memory(), 0, size) { mapped -> - memCopy(data, mapped, size) + dev.mappingMemory(pMemory(), VkDeviceSize(0), size) { mapped -> + memCopy(data, mapped, size.L) // If host coherency hasn't been requested, do a manual flush to make writes visible if (memoryPropertyFlags hasnt VkMemoryProperty.HOST_COHERENT_BIT) { // val mappedRange = vk.MappedMemoryRange{ @@ -288,22 +292,13 @@ constructor( } // Attach the memory to the buffer object - dev.bindBufferMemory(buffer(), memory()) - } - - fun createBuffer(usageFlags: VkBufferUsageFlags, memoryPropertyFlags: VkMemoryPropertyFlags, buffer: Buffer, bytes: ByteBuffer) { - createBuffer(usageFlags, memoryPropertyFlags, buffer, bytes.size.L, memAddress(bytes)) + dev.bindBufferMemory(pBuffer(), pMemory()) } - fun createBuffer(usageFlags: VkBufferUsageFlags, memoryPropertyFlags: VkMemoryPropertyFlags, buffer: Buffer, floats: FloatBuffer) { - createBuffer(usageFlags, memoryPropertyFlags, buffer, floats.size.L, memAddress(floats)) + fun createBuffer(usageFlags: VkBufferUsageFlags, memoryPropertyFlags: VkMemoryPropertyFlags, buffer: Buffer, bytes: java.nio.Buffer) { + createBuffer(usageFlags, memoryPropertyFlags, buffer, VkDeviceSize(bytes.remSize.L), bytes.adr) } - fun createBuffer(usageFlags: VkBufferUsageFlags, memoryPropertyFlags: VkMemoryPropertyFlags, buffer: Buffer, ints: IntBuffer) { - createBuffer(usageFlags, memoryPropertyFlags, buffer, ints.size.L, memAddress(ints)) - } - - /** * Create a buffer on the device * @@ -339,7 +334,7 @@ constructor( } // If a pointer to the buffer data has been passed, map the buffer and copy over the data if (data != NULL) - buffer.mapping { dst -> memCopy(data, dst, size) } + buffer.mapping { dst -> memCopy(data, dst, size.L) } // Initialize a default descriptor that covers the whole buffer size buffer.setupDescriptor() @@ -392,7 +387,7 @@ constructor( this.queueFamilyIndex = queueFamilyIndex flags = createFlags } - return getLong { vk.createCommandPool(logicalDevice!!, cmdPoolInfo, it).check() } + return logicalDevice!! createCommandPool cmdPoolInfo } @@ -429,14 +424,12 @@ constructor( */ fun flushCommandBuffer(commandBuffer: VkCommandBuffer, queue: VkQueue, free: Boolean = true) { - if (commandBuffer.adr == NULL) + if (commandBuffer.isInvalid()) return commandBuffer.end() - val submitInfo = vk.SubmitInfo { - commandBuffers = appBuffer pointerBufferOf commandBuffer - } + val submitInfo = vk.SubmitInfo { this.commandBuffer = commandBuffer } // Create fence to ensure that the command buffer has finished executing logicalDevice!!.withFence { fence -> // Submit to the queue diff --git a/src/main/kotlin/vulkan/base/VulkanExampleBase.kt b/src/main/kotlin/vulkan/base/VulkanExampleBase.kt index eb8cec1..b47cdae 100644 --- a/src/main/kotlin/vulkan/base/VulkanExampleBase.kt +++ b/src/main/kotlin/vulkan/base/VulkanExampleBase.kt @@ -1,28 +1,25 @@ package vulkan.base -import ab.appBuffer import glm_.detail.GLM_DEPTH_CLIP_SPACE import glm_.detail.GlmDepthClipSpace import glm_.f import glm_.i -import glm_.set import glm_.vec2.Vec2 import glm_.vec2.Vec2i import glm_.vec3.Vec3 import glm_.vec4.Vec4 import graphics.scenery.spirvcrossj.Loader import graphics.scenery.spirvcrossj.libspirvcrossj +import kool.stak import org.lwjgl.glfw.GLFW.* import org.lwjgl.system.MemoryUtil.NULL import org.lwjgl.vulkan.* import org.lwjgl.vulkan.EXTDebugReport.VK_EXT_DEBUG_REPORT_EXTENSION_NAME import org.lwjgl.vulkan.VK10.* import uno.buffer.intBufferOf -import uno.buffer.longBufferOf import uno.glfw.* import uno.glfw.windowHint.Api import vkk.* -import vkk.LongArrayList.resize import vulkan.ENABLE_VALIDATION import vulkan.base.initializers.commandBufferAllocateInfo import vulkan.base.tools.loadShader @@ -79,7 +76,7 @@ abstract class VulkanExampleBase { /** Depth buffer format (selected during Vulkan initialization) */ var depthFormat = VkFormat.UNDEFINED /** Command buffer pool */ - var cmdPool: VkCommandPool = NULL + var cmdPool = VkCommandPool(NULL) /** @brief Pipeline stages used to wait at for graphics queue submissions */ val submitPipelineStages = intBufferOf(VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i) /** Contains command buffers and semaphores to be presented to the queue */ @@ -87,31 +84,31 @@ abstract class VulkanExampleBase { /** Command buffers used for rendering */ lateinit var drawCmdBuffers: ArrayList /** Global render pass for frame buffer writes */ - var renderPass: VkRenderPass = NULL + var renderPass = VkRenderPass(NULL) /** List of available frame buffers (same as number of swap chain images) */ - val frameBuffers = ArrayList() + var frameBuffers = vkFramebufferArrayOf() /** Active frame buffer index */ var currentBuffer = 0 /** Descriptor set pool */ - var descriptorPool: VkDescriptorPool = NULL + var descriptorPool = VkDescriptorPool(NULL) /** List of shader modules created (stored for cleanup) */ val shaderModules = ArrayList() // Pipeline cache object - var pipelineCache: VkPipelineCache = NULL + var pipelineCache = VkPipelineCache(NULL) // Wraps the swap chain to present images (framebuffers) to the windowing system var swapChain = VulkanSwapChain() // Synchronization semaphores object semaphores { // Swap chain image presentation - var presentComplete: VkSemaphore = NULL + var presentComplete = VkSemaphore(NULL) // Command buffer submission and execution - var renderComplete: VkSemaphore = NULL + var renderComplete = VkSemaphore(NULL) // UI overlay submission and execution - var overlayComplete: VkSemaphore = NULL + var overlayComplete = VkSemaphore(NULL) } - var waitFences = VkFenceArray(0) + var waitFences = vkFenceArrayOf() var prepared = false val size = Vec2i(1280, 720) @@ -292,9 +289,9 @@ abstract class VulkanExampleBase { protected val depthStencil = DepthStencil() class DepthStencil { - var image: VkImage = NULL - var mem: VkDeviceMemory = NULL - var view: VkImageView = NULL + var image = VkImage(NULL) + var mem = VkDeviceMemory(NULL) + var view = VkImageView(NULL) } // struct { @@ -315,7 +312,7 @@ abstract class VulkanExampleBase { if (prepared) swapChain.cleanup() device.apply { - if (descriptorPool != NULL) + if (descriptorPool.L != NULL) destroyDescriptorPool(descriptorPool) destroyCommandBuffers() destroyRenderPass(renderPass) @@ -356,7 +353,7 @@ abstract class VulkanExampleBase { if (settings.validation) { /* The report flags determine what type of messages for the layers will be displayed For validating (debugging) an appplication the error and warning bits should suffice */ - val debugReportFlags = VkDebugReport.ERROR_BIT_EXT or VkDebugReport.WARNING_BIT_EXT or VkDebugReport.INFORMATION_BIT_EXT + val debugReportFlags = VkDebugReport.ERROR_BIT_EXT or VkDebugReport.WARNING_BIT_EXT// or VkDebugReport.INFORMATION_BIT_EXT // Additional flags include performance info, loader and layer debug messages, etc. debug.setupDebugging(instance, debugReportFlags, null) } @@ -459,12 +456,13 @@ abstract class VulkanExampleBase { /* Set up submit info structure Semaphores will stay the same during application lifetime Command buffer submission info is set by each example */ - submitInfo = cVkSubmitInfo { - waitDstStageMask = submitPipelineStages - waitSemaphoreCount = 1 - waitSemaphores = longBufferOf(semaphores.presentComplete) - signalSemaphores = longBufferOf(semaphores.renderComplete) - } + TODO() +// submitInfo = cVkSubmitInfo { +// waitDstStageMask = submitPipelineStages +// waitSemaphoreCount = 1 +// waitSemaphore = semaphores.presentComplete +// signalSemaphore = semaphores.renderComplete +// } } /** Create GLFW window */ @@ -472,7 +470,8 @@ abstract class VulkanExampleBase { with(glfw) { val fullscreen = false init() - if (!vulkanSupported) throw AssertionError("GLFW failed to find the Vulkan loader") + if (!vulkanSupported) + throw AssertionError("GLFW failed to find the Vulkan loader") windowHint { default() api = Api.None @@ -548,7 +547,7 @@ abstract class VulkanExampleBase { fun createSynchronizationPrimitives() { // Wait fences to sync command buffer access val fenceCreateInfo = vk.FenceCreateInfo(VK_FENCE_CREATE_SIGNALED_BIT) - waitFences = VkFenceArray(drawCmdBuffers.size) { device createFence fenceCreateInfo } + waitFences = initVkFenceArray(drawCmdBuffers.size) { device createFence fenceCreateInfo } } /** Creates a new (graphics) command pool object storing command buffers */ @@ -577,7 +576,7 @@ abstract class VulkanExampleBase { } val memAlloc = vk.MemoryAllocateInfo { - allocationSize = 0 + allocationSize = VkDeviceSize(0) memoryTypeIndex = 0 } @@ -599,7 +598,7 @@ abstract class VulkanExampleBase { memAlloc.allocationSize = memReqs.size memAlloc.memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) depthStencil.mem = device allocateMemory memAlloc - VK_CHECK_RESULT(vkBindImageMemory(device, depthStencil.image, depthStencil.mem, 0)) + device.bindImageMemory(depthStencil.image, depthStencil.mem) depthStencilView.image = depthStencil.image depthStencil.view = device createImageView depthStencilView @@ -607,9 +606,9 @@ abstract class VulkanExampleBase { /** Create framebuffers for all requested swap chain images * Can be overriden in derived class to setup a custom framebuffer (e.g. for MSAA) */ - open fun setupFrameBuffer() { + open fun setupFrameBuffer() = stak { - val attachments = appBuffer.longBuffer(2) + val attachments = it.vkImageViewBufferBig(2) // Depth/Stencil attachment is the same for all frame buffers attachments[1] = depthStencil.view @@ -625,10 +624,9 @@ abstract class VulkanExampleBase { } // Create frame buffers for every swap chain image - frameBuffers resize swapChain.imageCount - for (i in frameBuffers.indices) { + frameBuffers = initVkFramebufferArray(swapChain.imageCount) { i -> attachments[0] = swapChain.buffers[i].view - frameBuffers[i] = device createFramebuffer frameBufferCreateInfo + device createFramebuffer frameBufferCreateInfo } } @@ -722,7 +720,7 @@ abstract class VulkanExampleBase { fun setupSwapChain() = swapChain.create(size, settings.vsync) /** Check if command buffers are valid (!= NULL) */ - fun checkCommandBuffers() = drawCmdBuffers.all { it.adr != NULL } + fun checkCommandBuffers() = drawCmdBuffers.all { it.isValid() } /** Create command buffers for drawing commands */ fun createCommandBuffers() { @@ -763,7 +761,7 @@ abstract class VulkanExampleBase { commandBuffer.end() val submitInfo = vk.SubmitInfo { - commandBuffers = appBuffer.pointerBufferOf(commandBuffer) + this.commandBuffer = commandBuffer } queue submit submitInfo @@ -775,7 +773,7 @@ abstract class VulkanExampleBase { /** Create a cache pool for rendering pipelines */ fun createPipelineCache() { - pipelineCache = device createPipelineCache vk.PipelineCacheCreateInfo {} + pipelineCache = device createPipelineCache vk.PipelineCacheCreateInfo() } /** Prepare commonly used Vulkan functions */ @@ -838,7 +836,7 @@ abstract class VulkanExampleBase { } } name = "main" // todo : make param - assert(module != NULL) + assert(module.L != NULL) if (add) shaderModules += module } @@ -865,7 +863,7 @@ abstract class VulkanExampleBase { } // Flush device to make sure all resources can be freed - if (device.adr != NULL) + if (device.isValid()) device.waitIdle() } @@ -950,7 +948,7 @@ abstract class VulkanExampleBase { // Acquire the next image from the swap chain val err = swapChain.acquireNextImage(semaphores.presentComplete, ::currentBuffer) // Recreate the swapchain if it's no longer compatible with the surface (OUT_OF_DATE) or no longer optimal for presentation (SUBOPTIMAL) - if (err == VkResult.ERROR_OUT_OF_DATE_KHR || err == VkResult.SUBOPTIMAL_KHR) + if (err == ERROR_OUT_OF_DATE_KHR || err == SUBOPTIMAL_KHR) windowResize(window.size) else err.check() @@ -989,7 +987,15 @@ abstract class VulkanExampleBase { // submitInfo.pSignalSemaphores = &semaphores.renderComplete } - swapChain.queuePresent(queue, currentBuffer, if (submitOverlay) semaphores.overlayComplete else semaphores.renderComplete) + val res = swapChain.queuePresent(queue, currentBuffer, if (submitOverlay) semaphores.overlayComplete else semaphores.renderComplete) + + if (res != SUCCESS && res != SUBOPTIMAL_KHR) + if (res == ERROR_OUT_OF_DATE_KHR) { + // Swap chain is no longer compatible with the surface and needs to be recreated + windowResize(window.size) + return + } else + res.check() queue.waitIdle() } @@ -1002,8 +1008,6 @@ abstract class VulkanExampleBase { /** Called if the window is resized and some resources have to be recreated */ fun windowResize(newSize: Vec2i) { - appBuffer.reset() - if (!prepared) return prepared = false @@ -1015,11 +1019,13 @@ abstract class VulkanExampleBase { setupSwapChain() // Recreate the frame buffers - vkDestroyImageView(device, depthStencil.view, null) - vkDestroyImage(device, depthStencil.image, null) - vkFreeMemory(device, depthStencil.mem, null) + device.apply { + destroyImageView(depthStencil.view) + destroyImage(depthStencil.image) + freeMemory(depthStencil.mem) + } setupDepthStencil() - frameBuffers.forEach { vkDestroyFramebuffer(device, it, null) } + frameBuffers.forEach(device::destroyFramebuffer) setupFrameBuffer() // Command buffers need to be recreated as they may store @@ -1028,7 +1034,7 @@ abstract class VulkanExampleBase { createCommandBuffers() buildCommandBuffers() - vkDeviceWaitIdle(device) + device.waitIdle() if (settings.overlay) uiOverlay!!.resize(size, frameBuffers) diff --git a/src/main/kotlin/vulkan/base/VulkanModel.kt b/src/main/kotlin/vulkan/base/VulkanModel.kt index 873c303..7a6cf38 100644 --- a/src/main/kotlin/vulkan/base/VulkanModel.kt +++ b/src/main/kotlin/vulkan/base/VulkanModel.kt @@ -13,12 +13,12 @@ import assimp.Importer import assimp.or import glm_.BYTES import glm_.L -import glm_.buffer.free import glm_.max import glm_.min import glm_.vec2.Vec2 import glm_.vec3.Vec3 import glm_.vec4.Vec4 +import kool.free import org.lwjgl.system.MemoryUtil.NULL import org.lwjgl.vulkan.VkDevice import org.lwjgl.vulkan.VkQueue @@ -92,9 +92,9 @@ class Model { val dev = device!! vk.destroyBuffer(dev, vertices.buffer) vk.freeMemory(dev, vertices.memory) - if (indices.buffer != NULL) { - vk.destroyBuffer(dev, indices.buffer) - vk.freeMemory(dev, indices.memory) + if (indices.buffer.L != NULL) { + dev destroyBuffer indices.buffer + dev freeMemory indices.memory } if (::vertexBuffer.isInitialized) vertexBuffer.free() @@ -250,14 +250,14 @@ class Model { VkBufferUsage.VERTEX_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT, VkMemoryProperty.DEVICE_LOCAL_BIT.i, this.vertices, - vBufferSize.L) + VkDeviceSize(vBufferSize.L)) // Index buffer device.createBuffer( VkBufferUsage.INDEX_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT, VkMemoryProperty.DEVICE_LOCAL_BIT.i, this.indices, - iBufferSize.L) + VkDeviceSize(iBufferSize.L)) // Copy from staging buffers val copyCmd = device.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) diff --git a/src/main/kotlin/vulkan/base/VulkanSwapChain.kt b/src/main/kotlin/vulkan/base/VulkanSwapChain.kt index bb4c613..29eedb4 100644 --- a/src/main/kotlin/vulkan/base/VulkanSwapChain.kt +++ b/src/main/kotlin/vulkan/base/VulkanSwapChain.kt @@ -1,19 +1,18 @@ package vulkan.base -import ab.appBuffer import gli_.has import glm_.vec2.Vec2i import org.lwjgl.system.MemoryUtil.NULL import org.lwjgl.vulkan.KHRSurface.VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR -import org.lwjgl.vulkan.KHRSurface.vkDestroySurfaceKHR -import org.lwjgl.vulkan.KHRSwapchain.vkDestroySwapchainKHR -import org.lwjgl.vulkan.VK10.vkDestroyImageView +import org.lwjgl.vulkan.KHRSwapchain.vkQueuePresentKHR import org.lwjgl.vulkan.VkDevice import org.lwjgl.vulkan.VkInstance import org.lwjgl.vulkan.VkPhysicalDevice import org.lwjgl.vulkan.VkQueue import uno.glfw.GlfwWindow import vkk.* +import vulkan.UINT32_MAX +import vulkan.UINT64_MAX import kotlin.reflect.KMutableProperty0 class VulkanSwapChain { @@ -21,7 +20,7 @@ class VulkanSwapChain { lateinit var instance: VkInstance lateinit var device: VkDevice lateinit var physicalDevice: VkPhysicalDevice - var surface: VkSurfaceKHR = NULL + var surface = VkSurface(NULL) // // Function pointers // PFN_vkGetPhysicalDeviceSurfaceSupportKHR fpGetPhysicalDeviceSurfaceSupportKHR; // PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR fpGetPhysicalDeviceSurfaceCapabilitiesKHR; @@ -36,10 +35,10 @@ class VulkanSwapChain { var colorFormat = VkFormat.UNDEFINED var colorSpace = VkColorSpace.SRGB_NONLINEAR_KHR /** @brief Handle to the current swap chain, required for recreation */ - var swapChain: VkSwapchainKHR = NULL + var swapChain = VkSwapchainKHR(NULL) var imageCount = 0 - lateinit var images: VkImageArray - val buffers = ArrayList() + var images = vkImageArrayOf() + var buffers = arrayOf() /** @brief Queue family index of the detected graphics and presenting device queue */ var queueNodeIndex = UINT32_MAX @@ -219,7 +218,7 @@ class VulkanSwapChain { /* If an existing swap chain is re-created, destroy the old swap chain This also cleans up all the presentable images */ - if (oldSwapchain != NULL) { + if (oldSwapchain.L != NULL) { for (i in 0 until imageCount) device destroyImageView buffers[i].view device destroySwapchainKHR oldSwapchain @@ -230,8 +229,9 @@ class VulkanSwapChain { imageCount = images.size // Get the swap chain buffers containing the image and imageview - buffers resize images.size - for (i in images.indices) { + buffers = Array(images.size) { i -> + + val buffer = SwapChainBuffer() val colorAttachmentView = vk.ImageViewCreateInfo { format = colorFormat @@ -247,12 +247,12 @@ class VulkanSwapChain { flags = 0 images[i].also { - buffers[i].image = it - image(it) // TODO BUG + buffer.image = it + image(it.L) // TODO BUG } } - - buffers[i].view = device createImageView colorAttachmentView + buffer.view = device createImageView colorAttachmentView + buffer } } @@ -266,11 +266,25 @@ class VulkanSwapChain { * * @return VkResult of the image acquisition */ - fun acquireNextImage(presentCompleteSemaphore: VkSemaphore, imageIndex: KMutableProperty0): VkResult { + infix fun acquireNextImage(presentCompleteSemaphore: VkSemaphore): Int = // By setting timeout to UINT64_MAX we will always wait until the next image has been acquired or an actual error is thrown // With that we don't have to handle VK_NOT_READY - return vk.acquireNextImageKHR(device, swapChain, UINT64_MAX, presentCompleteSemaphore, NULL, imageIndex) - } + device.acquireNextImageKHR(swapChain, UINT64_MAX, presentCompleteSemaphore) + + /** + * Acquires the next image in the swap chain + * + * @param presentCompleteSemaphore (Optional) Semaphore that is signaled when the image is ready for use + * @param imageIndex Pointer to the image index that will be increased if the next image could be acquired + * + * @note The function will always wait until the next image has been acquired by setting timeout to UINT64_MAX + * + * @return VkResult of the image acquisition + */ + fun acquireNextImage(presentCompleteSemaphore: VkSemaphore, imageIndex: KMutableProperty0): VkResult = + // By setting timeout to UINT64_MAX we will always wait until the next image has been acquired or an actual error is thrown + // With that we don't have to handle VK_NOT_READY + vk.acquireNextImageKHR(device, swapChain, UINT64_MAX, presentCompleteSemaphore, VkFence(NULL), imageIndex) /** * Queue an image for presentation @@ -281,16 +295,16 @@ class VulkanSwapChain { * * @return VkResult of the queue presentation */ - fun queuePresent(queue: VkQueue, imageIndex: Int, waitSemaphore: VkSemaphore = NULL) { + fun queuePresent(queue: VkQueue, imageIndex: Int, waitSemaphore: VkSemaphore = VkSemaphore(NULL)): VkResult { val presentInfo = vk.PresentInfoKHR { swapchainCount = 1 - swapchains = appBuffer.longBufferOf(swapChain) - imageIndices = appBuffer.intBufferOf(imageIndex) + swapchain = swapChain + this.imageIndex = imageIndex // Check if a wait semaphore has been specified to wait for before presenting the image - if (waitSemaphore != NULL) - waitSemaphores = appBuffer.longBufferOf(waitSemaphore) + if (waitSemaphore.L != NULL) + this.waitSemaphore = waitSemaphore } - queue presentKHR presentInfo + return VkResult(vkQueuePresentKHR(queue, presentInfo)) // queue presentKHR presentInfo } @@ -298,15 +312,16 @@ class VulkanSwapChain { * Destroy and free Vulkan resources used for the swapchain */ fun cleanup() { - if (swapChain != NULL) + + if (swapChain.L != NULL) for (i in 0 until imageCount) - vkDestroyImageView(device, buffers[i].view, null) - if (surface != NULL) { - vkDestroySwapchainKHR(device, swapChain, null) - vkDestroySurfaceKHR(instance, surface, null) + device destroyImageView buffers[i].view + if (surface.L != NULL) { + device destroySwapchainKHR swapChain + instance destroySurfaceKHR surface } - surface = NULL - swapChain = NULL + surface = VkSurface(NULL) + swapChain = VkSwapchainKHR(NULL) } inline infix fun ArrayList.resize(newSize: Int) { @@ -320,6 +335,6 @@ class VulkanSwapChain { } class SwapChainBuffer { - var image: VkImage = NULL - var view: VkImageView = NULL + var image = VkImage(NULL) + var view = VkImageView(NULL) } \ No newline at end of file diff --git a/src/main/kotlin/vulkan/base/VulkanTools.kt b/src/main/kotlin/vulkan/base/VulkanTools.kt index ebe5785..9b9fac1 100644 --- a/src/main/kotlin/vulkan/base/VulkanTools.kt +++ b/src/main/kotlin/vulkan/base/VulkanTools.kt @@ -1,6 +1,7 @@ package vulkan.base import org.lwjgl.system.MemoryUtil +import org.lwjgl.system.MemoryUtil.NULL import org.lwjgl.vulkan.VkCommandBuffer import org.lwjgl.vulkan.VkDevice import org.lwjgl.vulkan.VkImageSubresourceRange @@ -220,7 +221,7 @@ object tools { val file = File(filename) - var shaderModule = MemoryUtil.NULL + var shaderModule = VkShaderModule(NULL) if (file.exists() && file.canRead()) { diff --git a/src/main/kotlin/vulkan/base/VulkanUIOverlay.kt b/src/main/kotlin/vulkan/base/VulkanUIOverlay.kt index fbfcfa0..48be4d6 100644 --- a/src/main/kotlin/vulkan/base/VulkanUIOverlay.kt +++ b/src/main/kotlin/vulkan/base/VulkanUIOverlay.kt @@ -3,6 +3,7 @@ package vulkan.base import glm_.vec2.Vec2i import org.lwjgl.vulkan.VkQueue import vkk.VkFramebuffer +import vkk.VkFramebufferArray class UIOverlayCreateInfo { @@ -85,7 +86,7 @@ class UIOverlay { // // void update(); - fun resize(size: Vec2i, framebuffers: ArrayList) { + fun resize(size: Vec2i, framebuffers: VkFramebufferArray) { // ImGuiIO& io = ImGui::GetIO(); // io.DisplaySize = ImVec2((float)(width), (float)(height)); diff --git a/src/main/kotlin/vulkan/basics/01a Triangle Verbose.kt b/src/main/kotlin/vulkan/basics/01a Triangle Verbose.kt index 6815074..cf9ec3b 100644 --- a/src/main/kotlin/vulkan/basics/01a Triangle Verbose.kt +++ b/src/main/kotlin/vulkan/basics/01a Triangle Verbose.kt @@ -1,11 +1,12 @@ package vulkan.basics import glm_.* -import glm_.buffer.bufferBig -import glm_.buffer.free import glm_.func.rad import glm_.mat4x4.Mat4 import glm_.vec3.Vec3 +import kool.bufferBig +import kool.cap +import kool.free import org.lwjgl.system.MemoryUtil import org.lwjgl.system.MemoryUtil.NULL import org.lwjgl.vulkan.* @@ -15,9 +16,8 @@ import uno.buffer.floatBufferOf import uno.buffer.intBufferOf import uno.buffer.toBuffer import uno.glfw.glfw -import uno.kotlin.buffers.capacity import vkk.* -import vkk.LongArrayList.resize +import vulkan.UINT64_MAX import vulkan.USE_STAGING import vulkan.assetPath import vulkan.base.VulkanExampleBase @@ -56,22 +56,22 @@ private class TriangleVerbose : VulkanExampleBase() { /** Vertex buffer and attributes */ object vertices { /** Handle to the device memory for this buffer */ - var memory: VkDeviceMemory = NULL + var memory: Long = NULL /** Handle to the Vulkan buffer object that the memory is bound to */ - var buffer: VkBuffer = NULL + var buffer: Long = NULL } /** Index buffer */ object indices { - var memory: VkDeviceMemory = NULL - var buffer: VkBuffer = NULL + var memory: Long = NULL + var buffer: Long = NULL var count = 0 } /** Uniform buffer block object */ object uniformBufferVS { - var memory: VkDeviceMemory = NULL - var buffer: VkBuffer = NULL + var memory: Long = NULL + var buffer: Long = NULL lateinit var descriptor: VkDescriptorBufferInfo.Buffer } @@ -107,7 +107,7 @@ private class TriangleVerbose : VulkanExampleBase() { * It defines interface (without binding any actual data) between the shader stages used by the pipeline and the * shader resources * A pipeline layout can be shared among multiple pipelines as long as their interfaces match */ - var pipelineLayout: VkPipelineLayout = NULL + var pipelineLayout: Long = NULL /** Pipelines (often called "pipeline state objects") are used to bake all states that affect a pipeline * While in OpenGL every state can be changed at (almost) any time, Vulkan requires to layout the graphics @@ -116,16 +116,16 @@ private class TriangleVerbose : VulkanExampleBase() { * this not discussed here) * Even though this adds a new dimension of planing ahead, it's a great opportunity for performance optimizations * by the driver */ - var pipeline: VkPipeline = NULL + var pipeline: Long = NULL /** The descriptor set layout describes the shader binding layout (without actually referencing descriptor) * Like the pipeline layout it's pretty much a blueprint and can be used with different descriptor sets as long as * their layout matches */ - var descriptorSetLayout: VkDescriptorSetLayout = NULL + var descriptorSetLayout: Long = NULL /** The descriptor set stores the resources bound to the binding points in a shader * It connects the binding points of the different shaders with the buffers and images used for those bindings */ - var descriptorSet: VkDescriptorSet = NULL + var descriptorSet: Long = NULL /* Synchronization primitives @@ -134,8 +134,8 @@ private class TriangleVerbose : VulkanExampleBase() { /** Semaphores * Used to coordinate operations within the graphics queue and ensure correct command ordering */ - var presentCompleteSemaphore: VkSemaphore = NULL - var renderCompleteSemaphore: VkSemaphore = NULL + var presentCompleteSemaphore: Long = NULL + var renderCompleteSemaphore: Long = NULL /** Fences * Used to check the completion of queue operations (e.g. command buffer execution) */ @@ -168,7 +168,7 @@ private class TriangleVerbose : VulkanExampleBase() { vkDestroySemaphore(device, renderCompleteSemaphore, null) for (fence in waitFences) - vkDestroyFence(device, fence, null) + vkDestroyFence(device, fence.L, null) super.destroy() } @@ -179,8 +179,8 @@ private class TriangleVerbose : VulkanExampleBase() { * This is necessary as implementations can offer an arbitrary number of memory types with different * memory properties. * You can check http://vulkan.gpuinfo.org/ for details on different memory configurations */ - fun getMemoryTypeIndex(typeBits: Int, properties: VkMemoryPropertyFlags): Int { - var typeBits = typeBits + fun getMemoryTypeIndex(typeBits_: Int, properties: Int): Int { + var typeBits = typeBits_ // Iterate over all memory types available for the device used in this example for (i in 0 until deviceMemoryProperties.memoryTypeCount()) { if ((typeBits and 1) == 1 && (deviceMemoryProperties.memoryTypes(i).propertyFlags() and properties) == properties) @@ -214,9 +214,10 @@ private class TriangleVerbose : VulkanExampleBase() { // Create in signaled state so we don't wait on first render of each command buffer .flags(VK_FENCE_CREATE_SIGNALED_BIT) val pFence = MemoryUtil.memAllocLong(1) + waitFences = vkFenceArrayBig(drawCmdBuffers.size) for (i in drawCmdBuffers.indices) { VK_CHECK_RESULT(vkCreateFence(device, fenceCreateInfo, null, pFence)) - waitFences += pFence[0] + waitFences[i] = VkFence(pFence[0]) } semaphoreCreateInfo.free() @@ -233,7 +234,7 @@ private class TriangleVerbose : VulkanExampleBase() { val cmdBufAllocateInfo = VkCommandBufferAllocateInfo.calloc() .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO) .pNext(NULL) - .commandPool(cmdPool) + .commandPool(cmdPool.L) .level(VK_COMMAND_BUFFER_LEVEL_PRIMARY) .commandBufferCount(1) val pCmdBuffer = MemoryUtil.memAllocPointer(1) @@ -259,7 +260,7 @@ private class TriangleVerbose : VulkanExampleBase() { * Uses a fence to ensure command buffer has finished executing before deleting it */ fun flushCommandBuffer(commandBuffer: VkCommandBuffer) { - assert(commandBuffer.adr != NULL) + assert(commandBuffer.address() != NULL) VK_CHECK_RESULT(vkEndCommandBuffer(commandBuffer)) @@ -277,7 +278,7 @@ private class TriangleVerbose : VulkanExampleBase() { .flags(0) val pFence = MemoryUtil.memAllocLong(1) VK_CHECK_RESULT(vkCreateFence(device, fenceCreateInfo, null, pFence)) - val fence: VkFence = pFence[0] + val fence = pFence[0] // Submit to the queue VK_CHECK_RESULT(vkQueueSubmit(queue, submitInfo, fence)) @@ -285,8 +286,9 @@ private class TriangleVerbose : VulkanExampleBase() { VK_CHECK_RESULT(vkWaitForFences(device, fence, true, DEFAULT_FENCE_TIMEOUT)) vkDestroyFence(device, fence, null) - vkFreeCommandBuffers(device, cmdPool, commandBuffer) + vkFreeCommandBuffers(device, cmdPool.L, commandBuffer) + fenceCreateInfo.free() pCommandBuffer.free() pFence.free() } @@ -303,19 +305,19 @@ private class TriangleVerbose : VulkanExampleBase() { // Set clear values for all framebuffer attachments with loadOp set to clear // We use two attachments (color and depth) that are cleared at the start of the subpass and as such we need to set clear values for both val clearValues = VkClearValue.calloc(2) - clearValues[0].color + clearValues[0].color() .float32(0, 0f) .float32(1, 0f) .float32(2, 0.2f) .float32(3, 1f) - clearValues[1].depthStencil + clearValues[1].depthStencil() .depth(1f) .stencil(0) val renderPassBeginInfo = VkRenderPassBeginInfo.calloc() .sType(VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO) .pNext(NULL) - .renderPass(renderPass) + .renderPass(renderPass.L) renderPassBeginInfo.renderArea().apply { offset() .x(0) @@ -329,7 +331,7 @@ private class TriangleVerbose : VulkanExampleBase() { for (i in drawCmdBuffers.indices) { // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) + renderPassBeginInfo.framebuffer(frameBuffers[i].L) VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], cmdBufInfo)) @@ -366,7 +368,7 @@ private class TriangleVerbose : VulkanExampleBase() { vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline) // Bind triangle vertex buffer (contains position and colors) - val offset: VkDeviceSize = 0 + val offset = 0L val pBuffer = MemoryUtil.memAllocLong(1) pBuffer[0] = vertices.buffer val pOffset = MemoryUtil.memAllocLong(1) @@ -399,11 +401,11 @@ private class TriangleVerbose : VulkanExampleBase() { fun draw() { // Get next image in the swap chain (back/front buffer) - swapChain.acquireNextImage(presentCompleteSemaphore, ::currentBuffer).check() + currentBuffer = swapChain acquireNextImage VkSemaphore(presentCompleteSemaphore) // Use a fence to wait until the command buffer has finished execution before using it again - VK_CHECK_RESULT(vkWaitForFences(device, waitFences[currentBuffer], true, UINT64_MAX)) - VK_CHECK_RESULT(vkResetFences(device, waitFences[currentBuffer])) + VK_CHECK_RESULT(vkWaitForFences(device, waitFences[currentBuffer].L, true, UINT64_MAX)) + VK_CHECK_RESULT(vkResetFences(device, waitFences[currentBuffer].L)) // Pipeline stage at which the queue submission will wait (via pWaitSemaphores) val waitStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT @@ -431,13 +433,13 @@ private class TriangleVerbose : VulkanExampleBase() { .pCommandBuffers(pCommandBuffer) // Submit to the graphics queue passing a wait fence - queue.submit(submitInfo, waitFences[currentBuffer]) + VK_CHECK_RESULT(vkQueueSubmit(queue, submitInfo, waitFences[currentBuffer].L)) /* Present the current buffer to the swap chain Pass the semaphore signaled by the command buffer submission from the submit info as the wait semaphore for swap chain presentation This ensures that the image is not presented to the windowing system until all commands have been submitted */ - swapChain.queuePresent(queue, currentBuffer, renderCompleteSemaphore) + swapChain.queuePresent(queue, currentBuffer, VkSemaphore(renderCompleteSemaphore)) pWaitStageMask.free() pWaitSemaphore.free() @@ -466,7 +468,7 @@ private class TriangleVerbose : VulkanExampleBase() { // Setup indices val indexBuffer = intBufferOf(0, 1, 2) - indices.count = indexBuffer.capacity + indices.count = indexBuffer.cap val indexBufferSize = indexBuffer.size.L val memAlloc = VkMemoryAllocateInfo.calloc() @@ -491,8 +493,8 @@ private class TriangleVerbose : VulkanExampleBase() { - Use the device local buffers for rendering */ class StagingBuffer { - var memory: VkDeviceMemory = NULL - var buffer: VkBuffer = NULL + var memory = NULL + var buffer = NULL } val stagingBuffers = object { @@ -679,7 +681,7 @@ private class TriangleVerbose : VulkanExampleBase() { val pDescriptorPool = MemoryUtil.memAllocLong(1) VK_CHECK_RESULT(vkCreateDescriptorPool(device, descriptorPoolInfo, null, pDescriptorPool)) - descriptorPool = pDescriptorPool[0] + descriptorPool = VkDescriptorPool(pDescriptorPool[0]) typeCounts.free() descriptorPoolInfo.free() @@ -731,7 +733,7 @@ private class TriangleVerbose : VulkanExampleBase() { pDescriptorSetLayour[0] = descriptorSetLayout val allocInfo = VkDescriptorSetAllocateInfo.calloc() .sType(VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO) - .descriptorPool(descriptorPool) + .descriptorPool(descriptorPool.L) .pSetLayouts(pDescriptorSetLayour) val pDescriptorSet = MemoryUtil.memAllocLong(1) @@ -778,20 +780,20 @@ private class TriangleVerbose : VulkanExampleBase() { .initialLayout(VK_IMAGE_LAYOUT_UNDEFINED) val pImage = MemoryUtil.memAllocLong(1) VK_CHECK_RESULT(vkCreateImage(device, image, null, pImage)) - depthStencil.image = pImage[0] + depthStencil.image = VkImage(pImage[0]) // Allocate memory for the image (device local) and bind it to our image val memAlloc = VkMemoryAllocateInfo.calloc() .sType(VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO) .pNext(NULL) val memReqs = VkMemoryRequirements.calloc() - vkGetImageMemoryRequirements(device, depthStencil.image, memReqs) + vkGetImageMemoryRequirements(device, depthStencil.image.L, memReqs) memAlloc.allocationSize(memReqs.size()) memAlloc.memoryTypeIndex(getMemoryTypeIndex(memReqs.memoryTypeBits(), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) val pMemory = MemoryUtil.memAllocLong(1) VK_CHECK_RESULT(vkAllocateMemory(device, memAlloc, null, pMemory)) - depthStencil.mem = pMemory[0] - VK_CHECK_RESULT(vkBindImageMemory(device, depthStencil.image, depthStencil.mem, 0)) + depthStencil.mem = VkDeviceMemory(pMemory[0]) + VK_CHECK_RESULT(vkBindImageMemory(device, depthStencil.image.L, depthStencil.mem.L, 0)) /* Create a view for the depth stencil image Images aren't directly accessed in Vulkan, but rather through views described by a subresource range @@ -807,10 +809,10 @@ private class TriangleVerbose : VulkanExampleBase() { .levelCount(1) .baseArrayLayer(0) .layerCount(1) - depthStencilView.image(depthStencil.image) + depthStencilView.image(depthStencil.image.L) val pImageView = MemoryUtil.memAllocLong(1) VK_CHECK_RESULT(vkCreateImageView(device, depthStencilView, null, pImageView)) - depthStencil.view = pImageView[0] + depthStencil.view = VkImageView(pImageView[0]) image.free() pImage.free() @@ -825,17 +827,16 @@ private class TriangleVerbose : VulkanExampleBase() { * Note: Override of virtual function in the base class and called from within VulkanExampleBase::prepare */ override fun setupFrameBuffer() { // Create a frame buffer for every image in the swapchain - frameBuffers resize swapChain.imageCount - for (i in frameBuffers.indices) { + frameBuffers = initVkFramebufferArray(swapChain.imageCount) { i -> val attachments = MemoryUtil.memAllocLong(2) - attachments[0] = swapChain.buffers[i].view // Color attachment is the view of the swapchain image - attachments[1] = depthStencil.view // Depth/Stencil attachment is the same for all frame buffers + attachments[0] = swapChain.buffers[i].view.L // Color attachment is the view of the swapchain image + attachments[1] = depthStencil.view.L // Depth/Stencil attachment is the same for all frame buffers val frameBufferCreateInfo = VkFramebufferCreateInfo.calloc() .sType(VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO) .pNext(NULL) // All frame buffers use the same renderpass setup - .renderPass(renderPass) + .renderPass(renderPass.L) .pAttachments(attachments) .width(size.x) .height(size.y) @@ -843,9 +844,9 @@ private class TriangleVerbose : VulkanExampleBase() { // Create the framebuffer val pFramebuffer = MemoryUtil.memAllocLong(1) VK_CHECK_RESULT(vkCreateFramebuffer(device, frameBufferCreateInfo, null, pFramebuffer)) - frameBuffers[i] = pFramebuffer[0] - - pFramebuffer.free() + VkFramebuffer(pFramebuffer[0]).also { + pFramebuffer.free() + } } } @@ -946,7 +947,7 @@ private class TriangleVerbose : VulkanExampleBase() { val pRenderPass = MemoryUtil.memAllocLong(1) VK_CHECK_RESULT(vkCreateRenderPass(device, renderPassInfo, null, pRenderPass)) - renderPass = pRenderPass[0] + renderPass = VkRenderPass(pRenderPass[0]) attachments.free() colorReference.free() @@ -960,7 +961,7 @@ private class TriangleVerbose : VulkanExampleBase() { /** Vulkan loads it's shaders from an immediate binary representation called SPIR-V * Shaders are compiled offline from e.g. GLSL using the reference glslang compiler * This function loads such a shader from a binary file and returns a shader module structure */ - fun loadSPIRVShader(filename: String): VkShaderModule { + fun loadSPIRVShader(filename: String): Long { var shaderCode: ByteBuffer? = null @@ -1007,7 +1008,7 @@ private class TriangleVerbose : VulkanExampleBase() { // The layout used for this pipeline (can be shared among multiple pipelines using the same layout) .layout(pipelineLayout) // Renderpass this pipeline is attached to - .renderPass(renderPass) + .renderPass(renderPass.L) /* Construct the different states making up the pipeline @@ -1138,7 +1139,7 @@ private class TriangleVerbose : VulkanExampleBase() { .module(loadSPIRVShader("$assetPath/shaders/triangle/triangle.vert.spv")) // Main entry point for the shader .pName(pName) - assert(shaderStages[0].module() != NULL) + assert(shaderStages[0].module.L != NULL) // Fragment shader shaderStages[1] @@ -1150,7 +1151,7 @@ private class TriangleVerbose : VulkanExampleBase() { .module(loadSPIRVShader("$assetPath/shaders/triangle/triangle.frag.spv")) // Main entry point for the shader .pName(pName) - assert(shaderStages[1].module() != NULL) + assert(shaderStages[1].module.L != NULL) // Set pipeline shader stage info pipelineCreateInfo @@ -1163,17 +1164,17 @@ private class TriangleVerbose : VulkanExampleBase() { .pMultisampleState(multisampleState) .pViewportState(viewportState) .pDepthStencilState(depthStencilState) - .renderPass(renderPass) + .renderPass(renderPass.L) .pDynamicState(dynamicState) // Create rendering pipeline using the specified states val pPipeline = MemoryUtil.memAllocLong(1) - VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, pipelineCreateInfo, null, pPipeline)) + VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache.L, pipelineCreateInfo, null, pPipeline)) pipeline = pPipeline[0] // Shader modules are no longer needed once the graphics pipeline has been created - vkDestroyShaderModule(device, shaderStages[0].module, null) - vkDestroyShaderModule(device, shaderStages[1].module, null) + vkDestroyShaderModule(device, shaderStages[0].module.L, null) + vkDestroyShaderModule(device, shaderStages[1].module.L, null) pipelineCreateInfo.free() inputAssemblyState.free() diff --git a/src/main/kotlin/vulkan/basics/01b Triangle.kt b/src/main/kotlin/vulkan/basics/01b Triangle.kt index b26c935..5b38824 100644 --- a/src/main/kotlin/vulkan/basics/01b Triangle.kt +++ b/src/main/kotlin/vulkan/basics/01b Triangle.kt @@ -1,933 +1,936 @@ -package vulkan.basics - -import ab.appBuffer -import glm_.L -import glm_.buffer.adr -import glm_.func.rad -import glm_.glm -import glm_.mat4x4.Mat4 -import glm_.size -import glm_.vec3.Vec3 -import org.lwjgl.system.MemoryUtil.NULL -import org.lwjgl.system.MemoryUtil.memCopy -import org.lwjgl.vulkan.VK10.VK_SUBPASS_EXTERNAL -import org.lwjgl.vulkan.VkCommandBuffer -import org.lwjgl.vulkan.VkDescriptorBufferInfo -import org.lwjgl.vulkan.VkDevice -import uno.glfw.glfw -import uno.kotlin.buffers.capacity -import vkk.* -import vkk.LongArrayList.resize -import vulkan.USE_STAGING -import vulkan.assetPath -import vulkan.base.VulkanExampleBase -import vulkan.base.tools.DEFAULT_FENCE_TIMEOUT - - -fun main(args: Array) { - Triangle().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - -private class Triangle : VulkanExampleBase() { - - init { - zoom = -2.5f - title = "Vulkan Example - Basic indexed triangle" - // Values not set here are initialized in the base class constructor - } - - /** Vertex layout used in this example */ - object Vertex { - // float position [3]; -// float color [3]; - val size = Vec3.size * 2 - val offsetPosition = 0 - val offsetColor = Vec3.size - } - - /** Vertex buffer and attributes */ - object vertices { - /** Handle to the device memory for this buffer */ - var memory: VkDeviceMemory = NULL - /** Handle to the Vulkan buffer object that the memory is bound to */ - var buffer: VkBuffer = NULL - } - - /** Index buffer */ - object indices { - var memory: VkDeviceMemory = NULL - var buffer: VkBuffer = NULL - var count = 0 - } - - /** Uniform buffer block object */ - object uniformBufferVS { - var memory: VkDeviceMemory = NULL - var buffer: VkBuffer = NULL - lateinit var descriptor: VkDescriptorBufferInfo - } - - /* - For simplicity we use the same uniform block layout as in the shader: - - layout(set = 0, binding = 0) uniform UBO { - mat4 projectionMatrix; - mat4 modelMatrix; - mat4 viewMatrix; - } ubo; - - This way we can just memcopy the ubo data to the ubo - Note: You should use data types that align with the GPU in order to avoid manual padding (vec4, mat4) */ - object uboVS : Bufferizable() { - - var projectionMatrix = Mat4() - @Order(1) - var modelMatrix = Mat4() - var viewMatrix = Mat4() - } - - /** The pipeline layout is used by a pipline to access the descriptor sets - * It defines interface (without binding any actual data) between the shader stages used by the pipeline and the - * shader resources - * A pipeline layout can be shared among multiple pipelines as long as their interfaces match */ - var pipelineLayout: VkPipelineLayout = NULL - - /** Pipelines (often called "pipeline state objects") are used to bake all states that affect a pipeline - * While in OpenGL every state can be changed at (almost) any time, Vulkan requires to layout the graphics - * (and compute) pipeline states upfront - * So for each combination of non-dynamic pipeline states you need a new pipeline (there are a few exceptions to - * this not discussed here) - * Even though this adds a new dimension of planing ahead, it's a great opportunity for performance optimizations - * by the driver */ - var pipeline: VkPipeline = NULL - - /** The descriptor set layout describes the shader binding layout (without actually referencing descriptor) - * Like the pipeline layout it's pretty much a blueprint and can be used with different descriptor sets as long as - * their layout matches */ - var descriptorSetLayout: VkDescriptorSetLayout = NULL - - /** The descriptor set stores the resources bound to the binding points in a shader - * It connects the binding points of the different shaders with the buffers and images used for those bindings */ - var descriptorSet: VkDescriptorSet = NULL - - - /* Synchronization primitives - Synchronization is an important concept of Vulkan that OpenGL mostly hid away. - Getting this right is crucial to using Vulkan. */ - - /** Semaphores - * Used to coordinate operations within the graphics queue and ensure correct command ordering */ - var presentCompleteSemaphore: VkSemaphore = NULL - var renderCompleteSemaphore: VkSemaphore = NULL - - /** Fences - * Used to check the completion of queue operations (e.g. command buffer execution) */ -// val waitFences = ArrayList() - - override fun destroy() { // TODO add to verbose - - window.destroy() - window.onWindowClosed() - glfw.terminate() - - /* Clean up used Vulkan resources - Note: Inherited destructor cleans up resources stored in base class */ - device.apply { - - destroyPipeline(pipeline) - - destroyPipelineLayout(pipelineLayout) - destroyDescriptorSetLayout(descriptorSetLayout) - - destroyBuffer(vertices.buffer) - freeMemory(vertices.memory) - - destroyBuffer(indices.buffer) - freeMemory(indices.memory) - - destroyBuffer(uniformBufferVS.buffer) - freeMemory(uniformBufferVS.memory) - - destroySemaphores(presentCompleteSemaphore, renderCompleteSemaphore) - - destroyFences(waitFences) - } - super.destroy() - } - - /** This function is used to request a device memory type that supports all the property flags we request - * (e.g. device local, host visibile) - * Upon success it will return the index of the memory type that fits our requestes memory properties - * This is necessary as implementations can offer an arbitrary number of memory types with different - * memory properties. - * You can check http://vulkan.gpuinfo.org/ for details on different memory configurations */ - fun getMemoryTypeIndex(typeBits: Int, properties: VkMemoryPropertyFlags): Int { - var typeBits = typeBits - // Iterate over all memory types available for the device used in this example - for (i in 0 until deviceMemoryProperties.memoryTypeCount) { - if ((typeBits and 1) == 1 && (deviceMemoryProperties.memoryTypes[i].propertyFlags and properties) == properties) - return i - typeBits = typeBits ushr 1 - } - throw Error("Could not find a suitable memory type!") - } - - /** Create the Vulkan synchronization primitives used in this example */ - fun prepareSynchronizationPrimitives() { - // Semaphores (Used for correct command ordering) - val semaphoreCreateInfo = vk.SemaphoreCreateInfo() - - // Semaphore used to ensures that image presentation is complete before starting to submit again - presentCompleteSemaphore = device createSemaphore semaphoreCreateInfo - - // Semaphore used to ensures that all commands submitted have been finished before submitting the image to the queue - renderCompleteSemaphore = device createSemaphore semaphoreCreateInfo - - // Fences (Used to check draw command buffer completion) - val fenceCreateInfo = vk.FenceCreateInfo( - // Create in signaled state so we don't wait on first render of each command buffer - VkFenceCreate.SIGNALED_BIT.i) - for (i in drawCmdBuffers.indices) - waitFences += device createFence fenceCreateInfo - } - - /** Get a new command buffer from the command pool - * If begin is true, the command buffer is also started so we can start adding commands */ - fun getCommandBuffer(begin: Boolean): VkCommandBuffer { - - val cmdBufAllocateInfo = vk.CommandBufferAllocateInfo(cmdPool, VkCommandBufferLevel.PRIMARY, 1) - - val cmdBuffer = device allocateCommandBuffer cmdBufAllocateInfo - - // If requested, also start the new command buffer - if (begin) - cmdBuffer begin vk.CommandBufferBeginInfo() - - return cmdBuffer - } - - /** End the command buffer and submit it to the queue - * Uses a fence to ensure command buffer has finished executing before deleting it */ - fun flushCommandBuffer(commandBuffer: VkCommandBuffer) { - - assert(commandBuffer.adr != NULL) - - commandBuffer.end() - - val submitInfo = vk.SubmitInfo { this.commandBuffer = commandBuffer } - - // Create fence to ensure that the command buffer has finished executing - val fenceCreateInfo = vk.FenceCreateInfo() - val fence = device createFence fenceCreateInfo - - // Submit to the queue - queue.submit(submitInfo, fence) - // Wait for the fence to signal that command buffer has finished executing - device.waitForFence(fence, true, DEFAULT_FENCE_TIMEOUT) - - device destroyFence fence - device.freeCommandBuffer(cmdPool, commandBuffer) - } - - /** Build separate command buffers for every framebuffer image - * Unlike in OpenGL all rendering commands are recorded once into command buffers that are then resubmitted to the queue - * This allows to generate work upfront and from multiple threads, one of the biggest advantages of Vulkan */ - override fun buildCommandBuffers() { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - /* Set clear values for all framebuffer attachments with loadOp set to clear - We use two attachments (color and depth) that are cleared at the start of the subpass and - as such we need to set clear values for both */ - val clearValues = vk.ClearValue(2).also { - it[0].color(0f, 0f, 0.2f, 1f) - it[1].depthStencil(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@Triangle.renderPass - renderArea.apply { - offset(0) - extent(size) - } - this.clearValues = clearValues - } - - for (i in drawCmdBuffers.indices) { - // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) // TODO =, BUG - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - /* Start the first sub pass specified in our default render pass setup by the base class - This will clear the color and depth attachment */ - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - // Update dynamic viewport state - setViewport(size) - - // Update dynamic scissor state - setScissor(size) - - // Bind descriptor sets describing shader binding points - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) - - /* Bind the rendering pipeline - The pipeline (state object) contains all states of the rendering pipeline, binding it will set all - the states specified at pipeline creation time */ - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipeline) - - // Bind triangle vertex buffer (contains position and colors) - bindVertexBuffers(0, vertices.buffer) - - // Bind triangle index buffer - bindIndexBuffer(indices.buffer, 0, VkIndexType.UINT32) - // Draw indexed triangle - drawIndexed(indices.count, 1, 0, 0, 1) - - endRenderPass() - - /* Ending the render pass will add an implicit barrier transitioning the frame buffer color attachment to - VK_IMAGE_LAYOUT_PRESENT_SRC_KHR for presenting it to the windowing system */ - - end() - } - } - } - - fun draw() { - // Get next image in the swap chain (back/front buffer) - swapChain.acquireNextImage(presentCompleteSemaphore, ::currentBuffer).check() - - // Use a fence to wait until the command buffer has finished execution before using it again - device.waitForFence(waitFences[currentBuffer], true, UINT64_MAX) - device resetFence waitFences[currentBuffer] - - // Pipeline stage at which the queue submission will wait (via pWaitSemaphores) - val waitStageMask = appBuffer.intBufferOf(VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i) - // The submit info structure specifices a command buffer queue submission batch - val submitInfo = vk.SubmitInfo { - // Pointer to the list of pipeline stages that the semaphore waits will occur at - waitDstStageMask = waitStageMask - // Semaphore(s) to wait upon before the submitted command buffer starts executing - waitSemaphore = presentCompleteSemaphore - // One wait semaphore - waitSemaphoreCount = 1 - // Semaphore(s) to be signaled when command buffers have completed - signalSemaphore = renderCompleteSemaphore - // One signal semaphore + Command buffers(s) to execute in this batch (submission) - commandBuffer = drawCmdBuffers[currentBuffer] - } - - // Submit to the graphics queue passing a wait fence - queue.submit(submitInfo, waitFences[currentBuffer]) - - /* Present the current buffer to the swap chain - Pass the semaphore signaled by the command buffer submission from the submit info as the wait semaphore - for swap chain presentation - This ensures that the image is not presented to the windowing system until all commands have been submitted */ - swapChain.queuePresent(queue, currentBuffer, renderCompleteSemaphore) - } - - /** Prepare vertex and index buffers for an indexed triangle - * Also uploads them to device local memory using staging and initializes vertex input and attribute binding - * to match the vertex shader */ - fun prepareVertices() { - /* A note on memory management in Vulkan in general: - This is a very complex topic and while it's fine for an example application to to small individual memory - allocations that is not what should be done a real-world application, where you should allocate large - chunks of memory at once instead. */ - - // Setup vertices - val vertexBuffer = appBuffer.floatBufferOf( - // position color - +1f, +1f, +0f, 1f, 0f, 0f, - -1f, +1f, +0f, 0f, 1f, 0f, - +0f, -1f, +0f, 0f, 0f, 1f) - - val vertexBufferSize = vertexBuffer.size.L - - // Setup indices - val indexBuffer = appBuffer.intBufferOf(0, 1, 2) - indices.count = indexBuffer.capacity - val indexBufferSize = indexBuffer.size.L - - val memoryPropertiesFlags = VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT - - if (USE_STAGING) { - - /* Static data like vertex and index buffer should be stored on the device memory for optimal (and fastest) - access by the GPU - - To achieve this we use so-called "staging buffers" : - - Create a buffer that's visible to the host (and can be mapped) - - Copy the data to this buffer - - Create another buffer that's local on the device (VRAM) with the same size - - Copy the data from the host to the device using a command buffer - - Delete the host visible (staging) buffer - - Use the device local buffers for rendering */ - - class StagingBuffer { - var memory: VkDeviceMemory = NULL - var buffer: VkBuffer = NULL - } - - val stagingBuffers = object { - val vertices = StagingBuffer() - val indices = StagingBuffer() - } - - // Vertex buffer - val vertexBufferInfo = vk.BufferCreateInfo { - size = vertexBufferSize - // Buffer is used as the copy source - usage = VkBufferUsage.TRANSFER_SRC_BIT.i - } - // Create a host-visible buffer to copy the vertex data to (staging buffer) - stagingBuffers.vertices.buffer = device createBuffer vertexBufferInfo - val memReqs = device getBufferMemoryRequirements stagingBuffers.vertices.buffer - val memAlloc = vk.MemoryAllocateInfo { - allocationSize = memReqs.size - // Request a host visible memory type that can be used to copy our data do - // Also request it to be coherent, so that writes are visible to the GPU right after unmapping the buffer - memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, memoryPropertiesFlags) - } - stagingBuffers.vertices.memory = device allocateMemory memAlloc - // Map and copy - device.mappingMemory(stagingBuffers.vertices.memory, 0, memAlloc.allocationSize) { data -> - memCopy(vertexBuffer.adr, data, vertexBufferSize) - } - device.bindBufferMemory(stagingBuffers.vertices.buffer, stagingBuffers.vertices.memory) - - // Create a device local buffer to which the (host local) vertex data will be copied and which will be used for rendering - vertexBufferInfo.usage = VkBufferUsage.VERTEX_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT - vertices.buffer = device createBuffer vertexBufferInfo - device.getBufferMemoryRequirements(vertices.buffer, memReqs) - memAlloc.allocationSize = memReqs.size - memAlloc.memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT.i) - vertices.memory = device allocateMemory memAlloc - device.bindBufferMemory(vertices.buffer, vertices.memory) - - // Index buffer - val indexbufferInfo = vk.BufferCreateInfo { - size = indexBufferSize - usage = VkBufferUsage.TRANSFER_SRC_BIT.i - } - // Copy index data to a buffer visible to the host (staging buffer) - stagingBuffers.indices.buffer = device createBuffer indexbufferInfo - device.getBufferMemoryRequirements(stagingBuffers.indices.buffer, memReqs) - memAlloc.allocationSize = memReqs.size - memAlloc.memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, memoryPropertiesFlags) - stagingBuffers.indices.memory = device allocateMemory memAlloc - device.mappingMemory(stagingBuffers.indices.memory, 0, indexBufferSize) { data -> - memCopy(indexBuffer.adr, data, indexBufferSize) - } - device.bindBufferMemory(stagingBuffers.indices.buffer, stagingBuffers.indices.memory) - - // Create destination buffer with device only visibility - indexbufferInfo.usage = VkBufferUsage.INDEX_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT - indices.buffer = device createBuffer indexbufferInfo - device.getBufferMemoryRequirements(indices.buffer, memReqs) - memAlloc.allocationSize = memReqs.size - memAlloc.memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT.i) - indices.memory = device allocateMemory memAlloc - device.bindBufferMemory(indices.buffer, indices.memory) - - /* Buffer copies have to be submitted to a queue, so we need a command buffer for them - Note: Some devices offer a dedicated transfer queue (with only the transfer bit set) that may be faster - when doing lots of copies */ - val copyCmd = getCommandBuffer(true) - - // Put buffer region copies into command buffer - val copyRegion = vk.BufferCopy() - - // Vertex buffer - copyRegion.size = vertexBufferSize - copyCmd.copyBuffer(stagingBuffers.vertices.buffer, vertices.buffer, copyRegion) - // Index buffer - copyRegion.size = indexBufferSize - copyCmd.copyBuffer(stagingBuffers.indices.buffer, indices.buffer, copyRegion) - - - // Flushing the command buffer will also submit it to the queue and uses a fence to ensure that all commands have been executed before returning - flushCommandBuffer(copyCmd) - - // Destroy staging buffers - // Note: Staging buffer must not be deleted before the copies have been submitted and executed - device.apply { - destroyBuffer(stagingBuffers.vertices.buffer) - freeMemory(stagingBuffers.vertices.memory) - destroyBuffer(stagingBuffers.indices.buffer) - freeMemory(stagingBuffers.indices.memory) - } - - } else { - - /* Don't use staging - Create host-visible buffers only and use these for rendering. This is not advised and will usually - result in lower rendering performance */ - - // Vertex buffer - val vertexBufferInfo = vk.BufferCreateInfo { - size = vertexBufferSize - usage = VkBufferUsage.VERTEX_BUFFER_BIT.i - } - - // Copy vertex data to a buffer visible to the host - vertices.buffer = device createBuffer vertexBufferInfo - val memReqs = device getBufferMemoryRequirements vertices.buffer - val memAlloc = vk.MemoryAllocateInfo { - allocationSize = memReqs.size - // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT is host visible memory, and VK_MEMORY_PROPERTY_HOST_COHERENT_BIT makes sure writes are directly visible - memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, memoryPropertiesFlags) - } - vertices.memory = device allocateMemory memAlloc - device.mappingMemory(vertices.memory, 0, memAlloc.allocationSize) { data -> - memCopy(vertexBuffer.adr, data, vertexBufferSize) - } - device.bindBufferMemory(vertices.buffer, vertices.memory) - - // Index buffer - val indexbufferInfo = vk.BufferCreateInfo { - size = indexBufferSize - usage = VkBufferUsage.INDEX_BUFFER_BIT.i - } - - // Copy index data to a buffer visible to the host - indices.buffer = device createBuffer indexbufferInfo - device.getBufferMemoryRequirements(indices.buffer, memReqs) - memAlloc.allocationSize = memReqs.size - memAlloc.memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, memoryPropertiesFlags) - indices.memory = device allocateMemory memAlloc - device.mappingMemory(indices.memory, 0, indexBufferSize) { data -> - memCopy(indexBuffer.adr, data, indexBufferSize) - } - device.bindBufferMemory(indices.buffer, indices.memory) - } - } - - fun setupDescriptorPool() { - // We need to tell the API the number of max. requested descriptors per type - // This example only uses one descriptor type (uniform buffer) and only requests one descriptor of this type - val typeCounts = vk.DescriptorPoolSize(VkDescriptorType.UNIFORM_BUFFER, 1) - - // For additional types you need to add new entries in the type count list - // E.g. for two combined image samplers : - // typeCounts[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - // typeCounts[1].descriptorCount = 2; - - // Create the global descriptor pool - // All descriptors used in this example are allocated from this pool - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(typeCounts, - // Set the max. number of descriptor sets that can be requested from this pool (requesting beyond this limit will result in an error) - maxSets = 1) - - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - /* Setup layout of descriptors used in this example - Basically connects the different shader stages to descriptors for binding uniform buffers, image samplers, etc. - So every shader binding should map to one descriptor set layout binding */ - - // Binding 0: Uniform buffer (Vertex shader) - val layoutBinding = vk.DescriptorSetLayoutBinding { - descriptorType = VkDescriptorType.UNIFORM_BUFFER - descriptorCount = 1 - stageFlags = VkShaderStage.VERTEX_BIT.i - } - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(layoutBinding) - - descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - // Create the pipeline layout that is used to generate the rendering pipelines that are based on this descriptor set layout - // In a more complex scenario you would have different pipeline layouts for different descriptor set layouts that could be reused - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) - - pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - } - - fun setupDescriptorSet() { - // Allocate a new descriptor set from the global descriptor pool - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) - - descriptorSet = device allocateDescriptorSets allocInfo - - /* Update the descriptor set determining the shader binding points - For every binding point used in a shader there needs to be one descriptor set matching that binding point */ - - val writeDescriptorSet = vk.WriteDescriptorSet(descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBufferVS.descriptor) - - device updateDescriptorSets writeDescriptorSet - } - - /** Create the depth (and stencil) buffer attachments used by our framebuffers - * Note: Override of virtual function in the base class and called from within VulkanExampleBase::prepare */ - override fun setupDepthStencil() { - // Create an optimal image used as the depth stencil attachment - val image = vk.ImageCreateInfo { - imageType = VkImageType.`2D` - format = depthFormat - // Use example's height and width - extent.set(size.x, size.y, 1) - mipLevels = 1 - arrayLayers = 1 - samples = VkSampleCount.`1_BIT` - tiling = VkImageTiling.OPTIMAL - usage = VkImageUsage.DEPTH_STENCIL_ATTACHMENT_BIT or VkImageUsage.TRANSFER_SRC_BIT - initialLayout = VkImageLayout.UNDEFINED - } - depthStencil.image = device createImage image - - // Allocate memory for the image (device local) and bind it to our image - val memAlloc = vk.MemoryAllocateInfo { - val memReqs = device getImageMemoryRequirements depthStencil.image - allocationSize = memReqs.size - memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT.i) - } - depthStencil.mem = device allocateMemory memAlloc - device.bindImageMemory(depthStencil.image, depthStencil.mem) - - /* Create a view for the depth stencil image - Images aren't directly accessed in Vulkan, but rather through views described by a subresource range - This allows for multiple views of one image with differing ranges (e.g. for different layers) */ - val depthStencilView = vk.ImageViewCreateInfo { - viewType = VkImageViewType.`2D` - format = depthFormat - subresourceRange.apply { - aspectMask = VkImageAspect.DEPTH_BIT or VkImageAspect.STENCIL_BIT - baseMipLevel = 0 - levelCount = 1 - baseArrayLayer = 0 - layerCount = 1 - } - this.image = depthStencil.image - } - depthStencil.view = device createImageView depthStencilView - } - - /** Create a frame buffer for each swap chain image - * Note: Override of virtual function in the base class and called from within VulkanExampleBase::prepare */ - override fun setupFrameBuffer() { - // Create a frame buffer for every image in the swapchain - frameBuffers resize swapChain.imageCount - for (i in frameBuffers.indices) { - val attachments = appBuffer.longBufferOf( - swapChain.buffers[i].view, // Color attachment is the view of the swapchain image - depthStencil.view) // Depth/Stencil attachment is the same for all frame buffers - - val (w, h) = size // TODO BUG - - val frameBufferCreateInfo = vk.FramebufferCreateInfo { - // All frame buffers use the same renderpass setup - renderPass = this@Triangle.renderPass - this.attachments = attachments - //it.size(size, 1) TODO BUG - width = w - height = h - layers = 1 - } - // Create the framebuffer - frameBuffers[i] = device createFramebuffer frameBufferCreateInfo - } - } - - /** Render pass setup - * Render passes are a new concept in Vulkan. They describe the attachments used during rendering and may contain - * multiple subpasses with attachment dependencies - * This allows the driver to know up-front what the rendering will look like and is a good opportunity to optimize - * especially on tile-based renderers (with multiple subpasses) - * Using sub pass dependencies also adds implicit layout transitions for the attachment used, so we don't need - * to add explicit image memory barriers to transform them - * Note: Override of virtual function in the base class and called from within VulkanExampleBase::prepare */ - override fun setupRenderPass() { - // This example will use a single render pass with one subpass - - // Descriptors for the attachments used by this renderpass - val attachments = vk.AttachmentDescription(2).also { - // Color attachment - it[0].apply { - format = swapChain.colorFormat // Use the color format selected by the swapchain - samples = VkSampleCount.`1_BIT` // We don't use multi sampling in this example - loadOp = VkAttachmentLoadOp.CLEAR // Clear this attachment at the start of the render pass - storeOp = VkAttachmentStoreOp.STORE // Keep it's contents after the render pass is finished (for displaying it) - stencilLoadOp = VkAttachmentLoadOp.DONT_CARE // We don't use stencil, so don't care for load - stencilStoreOp = VkAttachmentStoreOp.DONT_CARE // Same for store - initialLayout = VkImageLayout.UNDEFINED // Layout at render pass start. Initial doesn't matter, so we use undefined - finalLayout = VkImageLayout.PRESENT_SRC_KHR // Layout to which the attachment is transitioned when the render pass is finished - } - // As we want to present the color buffer to the swapchain, we transition to PRESENT_KHR - // Depth attachment - it[1].apply { - format = depthFormat // A proper depth format is selected in the example base - samples = VkSampleCount.`1_BIT` - loadOp = VkAttachmentLoadOp.CLEAR // Clear depth at start of first subpass - storeOp = VkAttachmentStoreOp.DONT_CARE // We don't need depth after render pass has finished (DONT_CARE may result in better performance) - stencilLoadOp = VkAttachmentLoadOp.DONT_CARE // No stencil - stencilStoreOp = VkAttachmentStoreOp.DONT_CARE // No Stencil - initialLayout = VkImageLayout.UNDEFINED // Layout at render pass start. Initial doesn't matter, so we use undefined - finalLayout = VkImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL // Transition to depth/stencil attachment - } - } - // Setup attachment references - val colorReference = vk.AttachmentReference(1) { - attachment = 0 // Attachment 0 is color - layout = VkImageLayout.COLOR_ATTACHMENT_OPTIMAL // Attachment layout used as color during the subpass - } - - val depthReference = vk.AttachmentReference { - attachment = 1 // Attachment 1 is color - layout = VkImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL // Attachment used as depth/stemcil used during the subpass - } - - // Setup a single subpass reference - val subpassDescription = vk.SubpassDescription { - pipelineBindPoint = VkPipelineBindPoint.GRAPHICS - colorAttachmentCount = 1 - colorAttachments = colorReference // Reference to the color attachment in slot 0 - depthStencilAttachment = depthReference // Reference to the depth attachment in slot 1 - inputAttachments = null // (Input attachments not used by this example) - preserveAttachments = null // (Preserve attachments not used by this example) - resolveAttachments = null // Resolve attachments are resolved at the end of a sub pass and can be used for e.g. multi sampling - } - - /* Setup subpass dependencies - These will add the implicit ttachment layout transitionss specified by the attachment descriptions - The actual usage layout is preserved through the layout specified in the attachment reference - Each subpass dependency will introduce a memory and execution dependency between the source and dest subpass described by - srcStageMask, dstStageMask, srcAccessMask, dstAccessMask (and dependencyFlags is set) - Note: VK_SUBPASS_EXTERNAL is a special constant that refers to all commands executed outside of the actual renderpass) */ - val dependencies = vk.SubpassDependency(2).also { - /* First dependency at the start of the renderpass - Does the transition from final to initial layout */ - it[0].apply { - srcSubpass = VK_SUBPASS_EXTERNAL // Producer of the dependency - dstSubpass = 0 // Consumer is our single subpass that will wait for the execution depdendency - srcStageMask = VkPipelineStage.BOTTOM_OF_PIPE_BIT.i - dstStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i - srcAccessMask = VkAccess.MEMORY_READ_BIT.i - dstAccessMask = VkAccess.COLOR_ATTACHMENT_READ_BIT or VkAccess.COLOR_ATTACHMENT_WRITE_BIT - dependencyFlags = VkDependency.BY_REGION_BIT.i - } - /* Second dependency at the end the renderpass - Does the transition from the initial to the final layout */ - it[1].apply { - srcSubpass = 0 // Producer of the dependency is our single subpass - dstSubpass = VK_SUBPASS_EXTERNAL // Consumer are all commands outside of the renderpass - srcStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i - dstStageMask = VkPipelineStage.BOTTOM_OF_PIPE_BIT.i - srcAccessMask = VkAccess.COLOR_ATTACHMENT_READ_BIT or VkAccess.COLOR_ATTACHMENT_WRITE_BIT - dstAccessMask = VkAccess.MEMORY_READ_BIT.i - dependencyFlags = VkDependency.BY_REGION_BIT.i - } - } - // Create the actual renderpass - val renderPassInfo = vk.RenderPassCreateInfo { - this.attachments = attachments // Descriptions of the attachments used by the render pass - subpass = subpassDescription // We only use one subpass in this example, Description of that subpass - this.dependencies = dependencies // Subpass dependencies used by the render pass - } - - renderPass = device createRenderPass renderPassInfo - } - - fun preparePipelines() { - /* Create the graphics pipeline used in this example - Vulkan uses the concept of rendering pipelines to encapsulate fixed states, replacing OpenGL's complex state machine - A pipeline is then stored and hashed on the GPU making pipeline changes very fast - Note: There are still a few dynamic states that are not directly part of the pipeline (but the info that they are used is) */ - - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo( - // The layout used for this pipeline (can be shared among multiple pipelines using the same layout) - pipelineLayout, - // Renderpass this pipeline is attached to - renderPass) - - /* Construct the different states making up the pipeline - - Input assembly state describes how primitives are assembled - This pipeline will assemble vertex data as a triangle lists (though we only use one triangle) */ - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST) - - // Rasterization state - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.COUNTER_CLOCKWISE) - - /* Color blend state describes how blend factors are calculated (if used) - We need one blend attachment state per color attachment (even if blending is not used */ - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - /* Viewport state sets the number of viewports and scissor used in this pipeline - Note: This is actually overriden by the dynamic states (see below) */ - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - /** Enable dynamic states - * Most states are baked into the pipeline, but there are still a few dynamic states that can be changed within a command buffer - * To be able to change these we need do specify which dynamic states will be changed using this pipeline. - * Their actual states are set later on in the command buffer. - * For this example we will set the viewport and scissor using dynamic states */ - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - /* Depth and stencil state containing depth and stencil compare and test operations - We only use depth tests and want depth tests and writes to be enabled and compare with less or equal */ - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) - - /* Multi sampling state - This example does not make use fo multi sampling (for anti-aliasing), the state must still be set and passed to the pipeline */ - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - /* Vertex input descriptions - Specifies the vertex input parameters for a pipeline - - Vertex input binding - This example uses a single vertex input binding at binding point 0 (see vkCmdBindVertexBuffers) */ - val vertexInputBinding = vk.VertexInputBindingDescription(0, Vertex.size, VkVertexInputRate.VERTEX) - - // Inpute attribute bindings describe shader attribute locations and memory layouts - val vertexInputAttributs = vk.VertexInputAttributeDescription(2).also { - /* These match the following shader layout (see triangle.vert): - layout (location = 0) in vec3 inPos; - layout (location = 1) in vec3 inColor; */ - it[0].apply { - // Attribute location 0: Position - binding = 0 - location = 0 - // Position attribute is three 32 bit signed (SFLOAT) floats (R32 G32 B32) - format = VkFormat.R32G32B32_SFLOAT - offset = Vertex.offsetPosition - } - it[1].apply { - // Attribute location 1: Color - binding = 0 - location = 1 - // Color attribute is three 32 bit signed (SFLOAT) floats (R32 G32 B32) - format = VkFormat.R32G32B32_SFLOAT - offset = Vertex.offsetColor - } - } - // Vertex input state used for pipeline creation - val vertexInputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertexInputBinding - vertexAttributeDescriptions = vertexInputAttributs - } - - // Shaders - val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { - // Vertex shader - it[0].loadShader("$assetPath/shaders/triangle/triangle.vert.spv", VkShaderStage.VERTEX_BIT, false) - // Fragment shader - it[1].loadShader("$assetPath/shaders/triangle/triangle.frag.spv", VkShaderStage.FRAGMENT_BIT, false) - } - // Set pipeline shader stage info - pipelineCreateInfo.also { - it.stages = shaderStages - // Assign the pipeline states to the pipeline creation info structure - it.vertexInputState = vertexInputState - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.renderPass = renderPass - it.dynamicState = dynamicState - it.tessellationState = null - } - // Create rendering pipeline using the specified states - pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - - // Shader modules are no longer needed once the graphics pipeline has been created, - // normally they will be destroyed in ::destroy, but we pass false at creation above to delete them now - device destroyShaderModules shaderStages - } - - fun prepareUniformBuffers() { - /* Prepare and initialize a uniform buffer block containing shader uniforms - Single uniforms like in OpenGL are no longer present in Vulkan. All Shader uniforms are passed - via uniform buffer blocks */ - - val bufferInfo = vk.BufferCreateInfo { - size = uboVS.size.L - // This buffer will be used as a uniform buffer - usage = VkBufferUsage.UNIFORM_BUFFER_BIT.i - } - - // Create a new buffer - uniformBufferVS.buffer = device createBuffer bufferInfo - // Get memory requirements including size, alignment and memory type - val memReqs = device getBufferMemoryRequirements uniformBufferVS.buffer - // Vertex shader uniform buffer block - val allocInfo = vk.MemoryAllocateInfo { - allocationSize = memReqs.size - /* Get the memory type index that supports host visibile memory access - Most implementations offer multiple memory types and selecting the correct one to allocate memory from is crucial - We also want the buffer to be host coherent so we don't have to flush (or sync after every update. - Note: This may affect performance so you might not want to do this in a real world application that updates - buffers on a regular base */ - memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT) - } - // Allocate memory for the uniform buffer - uniformBufferVS.memory = device allocateMemory allocInfo - // Bind memory to buffer - device.bindBufferMemory(uniformBufferVS.buffer, uniformBufferVS.memory) - - // Store information in the uniform's descriptor that is used by the descriptor set - uniformBufferVS.descriptor = vk.DescriptorBufferInfo { - buffer = uniformBufferVS.buffer - range = uboVS.size.L - } - updateUniformBuffers() - } - - fun updateUniformBuffers() { - - // Update matrices - uboVS.projectionMatrix = glm.perspective(60f.rad, size.aspect, 0.1f, 256f) - - uboVS.viewMatrix = glm.translate(Mat4(1f), 0f, 0f, zoom) - - uboVS.modelMatrix = Mat4(1f) - .rotate(rotation.x.rad, 1f, 0f, 0f) - .rotate(rotation.y.rad, 0f, 1f, 0f) - .rotate(rotation.z.rad, 0f, 0f, 1f) - - // Map uniform buffer and update it - device.mappingMemory(uniformBufferVS.memory, 0, uboVS.size.L, 0) { data -> - uboVS to data - }/* Unmap after data has been copied - Note: Since we requested a host coherent memory type for the uniform buffer, the write is instantly visible to the GPU */ - } - - override fun prepare() { - super.prepare() - prepareSynchronizationPrimitives() - prepareVertices() - prepareUniformBuffers() - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSet() - buildCommandBuffers() - - window.show() - - prepared = true - } - - override fun render() { - if (!prepared) return - draw() - } - - /** This function is called by the base example class each time the view is changed by user input */ - override fun viewChanged() = updateUniformBuffers() -} \ No newline at end of file +//package vulkan.basics +// +//import glm_.L +//import glm_.func.rad +//import glm_.glm +//import glm_.mat4x4.Mat4 +//import glm_.size +//import glm_.vec3.Vec3 +//import kool.adr +//import kool.stak +//import org.lwjgl.system.MemoryUtil.NULL +//import org.lwjgl.system.MemoryUtil.memCopy +//import org.lwjgl.vulkan.VK10.VK_SUBPASS_EXTERNAL +//import org.lwjgl.vulkan.VkCommandBuffer +//import org.lwjgl.vulkan.VkDescriptorBufferInfo +//import uno.glfw.glfw +//import uno.kotlin.buffers.capacity +//import vkk.* +//import vulkan.UINT64_MAX +//import vulkan.USE_STAGING +//import vulkan.assetPath +//import vulkan.base.VulkanExampleBase +//import vulkan.base.tools.DEFAULT_FENCE_TIMEOUT +// +// +//fun main(args: Array) { +// Triangle().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +//private class Triangle : VulkanExampleBase() { +// +// init { +// zoom = -2.5f +// title = "Vulkan Example - Basic indexed triangle" +// // Values not set here are initialized in the base class constructor +// } +// +// /** Vertex layout used in this example */ +// object Vertex { +// // float position [3]; +//// float color [3]; +// val size = Vec3.size * 2 +// val offsetPosition = 0 +// val offsetColor = Vec3.size +// } +// +// /** Vertex buffer and attributes */ +// object vertices { +// /** Handle to the device memory for this buffer */ +// var memory = VkDeviceMemory(NULL) +// /** Handle to the Vulkan buffer object that the memory is bound to */ +// var buffer = VkBuffer(NULL) +// } +// +// /** Index buffer */ +// object indices { +// var memory = VkDeviceMemory(NULL) +// var buffer = VkBuffer(NULL) +// var count = 0 +// } +// +// /** Uniform buffer block object */ +// object uniformBufferVS { +// var memory = VkDeviceMemory(NULL) +// var buffer = VkBuffer(NULL) +// lateinit var descriptor: VkDescriptorBufferInfo +// } +// +// /* +// For simplicity we use the same uniform block layout as in the shader: +// +// layout(set = 0, binding = 0) uniform UBO { +// mat4 projectionMatrix; +// mat4 modelMatrix; +// mat4 viewMatrix; +// } ubo; +// +// This way we can just memcopy the ubo data to the ubo +// Note: You should use data types that align with the GPU in order to avoid manual padding (vec4, mat4) */ +// object uboVS : Bufferizable() { +// +// var projectionMatrix = Mat4() +// @Order(1) +// var modelMatrix = Mat4() +// var viewMatrix = Mat4() +// } +// +// /** The pipeline layout is used by a pipline to access the descriptor sets +// * It defines interface (without binding any actual data) between the shader stages used by the pipeline and the +// * shader resources +// * A pipeline layout can be shared among multiple pipelines as long as their interfaces match */ +// var pipelineLayout = VkPipelineLayout(NULL) +// +// /** Pipelines (often called "pipeline state objects") are used to bake all states that affect a pipeline +// * While in OpenGL every state can be changed at (almost) any time, Vulkan requires to layout the graphics +// * (and compute) pipeline states upfront +// * So for each combination of non-dynamic pipeline states you need a new pipeline (there are a few exceptions to +// * this not discussed here) +// * Even though this adds a new dimension of planing ahead, it's a great opportunity for performance optimizations +// * by the driver */ +// var pipeline = VkPipeline(NULL) +// +// /** The descriptor set layout describes the shader binding layout (without actually referencing descriptor) +// * Like the pipeline layout it's pretty much a blueprint and can be used with different descriptor sets as long as +// * their layout matches */ +// var descriptorSetLayout = VkDescriptorSetLayout(NULL) +// +// /** The descriptor set stores the resources bound to the binding points in a shader +// * It connects the binding points of the different shaders with the buffers and images used for those bindings */ +// var descriptorSet = VkDescriptorSet(NULL) +// +// +// /* Synchronization primitives +// Synchronization is an important concept of Vulkan that OpenGL mostly hid away. +// Getting this right is crucial to using Vulkan. */ +// +// /** Semaphores +// * Used to coordinate operations within the graphics queue and ensure correct command ordering */ +// var presentCompleteSemaphore = VkSemaphore(NULL) +// var renderCompleteSemaphore = VkSemaphore(NULL) +// +// /** Fences +// * Used to check the completion of queue operations (e.g. command buffer execution) */ +//// val waitFences = ArrayList() +// +// override fun destroy() { // TODO add to verbose +// +// window.destroy() +// window.onWindowClosed() +// glfw.terminate() +// +// /* Clean up used Vulkan resources +// Note: Inherited destructor cleans up resources stored in base class */ +// device.apply { +// +// destroyPipeline(pipeline) +// +// destroyPipelineLayout(pipelineLayout) +// destroyDescriptorSetLayout(descriptorSetLayout) +// +// destroyBuffer(vertices.buffer) +// freeMemory(vertices.memory) +// +// destroyBuffer(indices.buffer) +// freeMemory(indices.memory) +// +// destroyBuffer(uniformBufferVS.buffer) +// freeMemory(uniformBufferVS.memory) +// +// destroySemaphores(presentCompleteSemaphore, renderCompleteSemaphore) +// +// destroyFences(waitFences) +// } +// super.destroy() +// } +// +// /** This function is used to request a device memory type that supports all the property flags we request +// * (e.g. device local, host visibile) +// * Upon success it will return the index of the memory type that fits our requestes memory properties +// * This is necessary as implementations can offer an arbitrary number of memory types with different +// * memory properties. +// * You can check http://vulkan.gpuinfo.org/ for details on different memory configurations */ +// fun getMemoryTypeIndex(typeBits_: Int, properties: VkMemoryPropertyFlags): Int { +// var typeBits = typeBits_ +// // Iterate over all memory types available for the device used in this example +// for (i in 0 until deviceMemoryProperties.memoryTypeCount) { +// if ((typeBits and 1) == 1 && (deviceMemoryProperties.memoryTypes[i].propertyFlags and properties) == properties) +// return i +// typeBits = typeBits ushr 1 +// } +// throw Error("Could not find a suitable memory type!") +// } +// +// /** Create the Vulkan synchronization primitives used in this example */ +// fun prepareSynchronizationPrimitives() { +// // Semaphores (Used for correct command ordering) +// val semaphoreCreateInfo = vk.SemaphoreCreateInfo() +// +// // Semaphore used to ensures that image presentation is complete before starting to submit again +// presentCompleteSemaphore = device createSemaphore semaphoreCreateInfo +// +// // Semaphore used to ensures that all commands submitted have been finished before submitting the image to the queue +// renderCompleteSemaphore = device createSemaphore semaphoreCreateInfo +// +// // Fences (Used to check draw command buffer completion) +// val fenceCreateInfo = vk.FenceCreateInfo( +// // Create in signaled state so we don't wait on first render of each command buffer +// VkFenceCreate.SIGNALED_BIT.i) +// waitFences = initVkFenceArray(drawCmdBuffers.size) { +// device createFence fenceCreateInfo +// } +// } +// +// /** Get a new command buffer from the command pool +// * If begin is true, the command buffer is also started so we can start adding commands */ +// fun getCommandBuffer(begin: Boolean): VkCommandBuffer { +// +// val cmdBufAllocateInfo = vk.CommandBufferAllocateInfo(cmdPool, VkCommandBufferLevel.PRIMARY, 1) +// +// val cmdBuffer = device allocateCommandBuffer cmdBufAllocateInfo +// +// // If requested, also start the new command buffer +// if (begin) +// cmdBuffer begin vk.CommandBufferBeginInfo() +// +// return cmdBuffer +// } +// +// /** End the command buffer and submit it to the queue +// * Uses a fence to ensure command buffer has finished executing before deleting it */ +// fun flushCommandBuffer(commandBuffer: VkCommandBuffer) { +// +// assert(commandBuffer.isValid()) +// +// commandBuffer.end() +// +// val submitInfo = vk.SubmitInfo { this.commandBuffer = commandBuffer } +// +// // Create fence to ensure that the command buffer has finished executing +// val fenceCreateInfo = vk.FenceCreateInfo() +// val fence = device createFence fenceCreateInfo +// +// // Submit to the queue +// queue.submit(submitInfo, fence) +// // Wait for the fence to signal that command buffer has finished executing +// device.waitForFence(fence, true, DEFAULT_FENCE_TIMEOUT) +// +// device destroyFence fence +// device.freeCommandBuffer(cmdPool, commandBuffer) +// } +// +// /** Build separate command buffers for every framebuffer image +// * Unlike in OpenGL all rendering commands are recorded once into command buffers that are then resubmitted to the queue +// * This allows to generate work upfront and from multiple threads, one of the biggest advantages of Vulkan */ +// override fun buildCommandBuffers() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// /* Set clear values for all framebuffer attachments with loadOp set to clear +// We use two attachments (color and depth) that are cleared at the start of the subpass and +// as such we need to set clear values for both */ +// val clearValues = vk.ClearValue(2).also { +// it[0].color(0f, 0f, 0.2f, 1f) +// it[1].depthStencil(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@Triangle.renderPass +// renderArea.apply { +// offset(0) +// extent(size) +// } +// this.clearValues = clearValues +// } +// +// for (i in drawCmdBuffers.indices) { +// // Set target frame buffer +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) // TODO = BUG +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// /* Start the first sub pass specified in our default render pass setup by the base class +// This will clear the color and depth attachment */ +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// // Update dynamic viewport state +// setViewport(size) +// +// // Update dynamic scissor state +// setScissor(size) +// +// // Bind descriptor sets describing shader binding points +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) +// +// /* Bind the rendering pipeline +// The pipeline (state object) contains all states of the rendering pipeline, binding it will set all +// the states specified at pipeline creation time */ +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipeline) +// +// // Bind triangle vertex buffer (contains position and colors) +// bindVertexBuffers(0, vertices.buffer) +// +// // Bind triangle index buffer +// bindIndexBuffer(indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// // Draw indexed triangle +// drawIndexed(indices.count, 1, 0, 0, 1) +// +// endRenderPass() +// +// /* Ending the render pass will add an implicit barrier transitioning the frame buffer color attachment to +// VK_IMAGE_LAYOUT_PRESENT_SRC_KHR for presenting it to the windowing system */ +// +// end() +// } +// } +// } +// +// fun draw() = stak { +// // Get next image in the swap chain (back/front buffer) +// swapChain.acquireNextImage(presentCompleteSemaphore, ::currentBuffer).check() +// +// // Use a fence to wait until the command buffer has finished execution before using it again +// device.waitForFence(waitFences[currentBuffer], true, UINT64_MAX) +// device resetFence waitFences[currentBuffer] +// +// // Pipeline stage at which the queue submission will wait (via pWaitSemaphores) +// val waitStageMask = it.ints(VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i) +// // The submit info structure specifices a command buffer queue submission batch +// val submitInfo = vk.SubmitInfo { +// // Pointer to the list of pipeline stages that the semaphore waits will occur at +// waitDstStageMask = waitStageMask +// // Semaphore(s) to wait upon before the submitted command buffer starts executing +// waitSemaphore = presentCompleteSemaphore +// // One wait semaphore +// waitSemaphoreCount = 1 +// // Semaphore(s) to be signaled when command buffers have completed +// signalSemaphore = renderCompleteSemaphore +// // One signal semaphore + Command buffers(s) to execute in this batch (submission) +// commandBuffer = drawCmdBuffers[currentBuffer] +// } +// +// // Submit to the graphics queue passing a wait fence +// queue.submit(submitInfo, waitFences[currentBuffer]) +// +// /* Present the current buffer to the swap chain +// Pass the semaphore signaled by the command buffer submission from the submit info as the wait semaphore +// for swap chain presentation +// This ensures that the image is not presented to the windowing system until all commands have been submitted */ +// swapChain.queuePresent(queue, currentBuffer, renderCompleteSemaphore) +// } +// +// /** Prepare vertex and index buffers for an indexed triangle +// * Also uploads them to device local memory using staging and initializes vertex input and attribute binding +// * to match the vertex shader */ +// fun prepareVertices() = stak { +// /* A note on memory management in Vulkan in general: +// This is a very complex topic and while it's fine for an example application to to small individual memory +// allocations that is not what should be done a real-world application, where you should allocate large +// chunks of memory at once instead. */ +// +// // Setup vertices +// val vertexBuffer = it.floats( +// // position color +// +1f, +1f, +0f, 1f, 0f, 0f, +// -1f, +1f, +0f, 0f, 1f, 0f, +// +0f, -1f, +0f, 0f, 0f, 1f) +// +// val vertexBufferSize = VkDeviceSize(vertexBuffer.size.L) +// +// // Setup indices +// val indexBuffer = it.ints(0, 1, 2) +// indices.count = indexBuffer.capacity +// val indexBufferSize = VkDeviceSize(indexBuffer.size.L) +// +// val memoryPropertiesFlags = VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT +// +// if (USE_STAGING) { +// +// /* Static data like vertex and index buffer should be stored on the device memory for optimal (and fastest) +// access by the GPU +// +// To achieve this we use so-called "staging buffers" : +// - Create a buffer that's visible to the host (and can be mapped) +// - Copy the data to this buffer +// - Create another buffer that's local on the device (VRAM) with the same size +// - Copy the data from the host to the device using a command buffer +// - Delete the host visible (staging) buffer +// - Use the device local buffers for rendering */ +// +// class StagingBuffer { +// var memory = VkDeviceMemory(NULL) +// var buffer = VkBuffer(NULL) +// } +// +// val stagingBuffers = object { +// val vertices = StagingBuffer() +// val indices = StagingBuffer() +// } +// +// // Vertex buffer +// val vertexBufferInfo = vk.BufferCreateInfo { +// size = vertexBufferSize +// // Buffer is used as the copy source +// usage = VkBufferUsage.TRANSFER_SRC_BIT.i +// } +// // Create a host-visible buffer to copy the vertex data to (staging buffer) +// stagingBuffers.vertices.buffer = device createBuffer vertexBufferInfo +// val memReqs = device getBufferMemoryRequirements stagingBuffers.vertices.buffer +// val memAlloc = vk.MemoryAllocateInfo { +// allocationSize = memReqs.size +// // Request a host visible memory type that can be used to copy our data do +// // Also request it to be coherent, so that writes are visible to the GPU right after unmapping the buffer +// memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, memoryPropertiesFlags) +// } +// stagingBuffers.vertices.memory = device allocateMemory memAlloc +// // Map and copy +// device.mappingMemory(stagingBuffers.vertices.memory, VkDeviceSize(0), memAlloc.allocationSize) { data -> +// memCopy(vertexBuffer.adr, data, vertexBufferSize) +// } +// device.bindBufferMemory(stagingBuffers.vertices.buffer, stagingBuffers.vertices.memory) +// +// // Create a device local buffer to which the (host local) vertex data will be copied and which will be used for rendering +// vertexBufferInfo.usage = VkBufferUsage.VERTEX_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT +// vertices.buffer = device createBuffer vertexBufferInfo +// device.getBufferMemoryRequirements(vertices.buffer, memReqs) +// memAlloc.allocationSize = memReqs.size +// memAlloc.memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT.i) +// vertices.memory = device allocateMemory memAlloc +// device.bindBufferMemory(vertices.buffer, vertices.memory) +// +// // Index buffer +// val indexbufferInfo = vk.BufferCreateInfo { +// size = indexBufferSize +// usage = VkBufferUsage.TRANSFER_SRC_BIT.i +// } +// // Copy index data to a buffer visible to the host (staging buffer) +// stagingBuffers.indices.buffer = device createBuffer indexbufferInfo +// device.getBufferMemoryRequirements(stagingBuffers.indices.buffer, memReqs) +// memAlloc.allocationSize = memReqs.size +// memAlloc.memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, memoryPropertiesFlags) +// stagingBuffers.indices.memory = device allocateMemory memAlloc +// device.mappingMemory(stagingBuffers.indices.memory, VkDeviceSize(0), indexBufferSize) { data -> +// memCopy(indexBuffer.adr, data, indexBufferSize) +// } +// device.bindBufferMemory(stagingBuffers.indices.buffer, stagingBuffers.indices.memory) +// +// // Create destination buffer with device only visibility +// indexbufferInfo.usage = VkBufferUsage.INDEX_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT +// indices.buffer = device createBuffer indexbufferInfo +// device.getBufferMemoryRequirements(indices.buffer, memReqs) +// memAlloc.allocationSize = memReqs.size +// memAlloc.memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT.i) +// indices.memory = device allocateMemory memAlloc +// device.bindBufferMemory(indices.buffer, indices.memory) +// +// /* Buffer copies have to be submitted to a queue, so we need a command buffer for them +// Note: Some devices offer a dedicated transfer queue (with only the transfer bit set) that may be faster +// when doing lots of copies */ +// val copyCmd = getCommandBuffer(true) +// +// // Put buffer region copies into command buffer +// val copyRegion = vk.BufferCopy() +// +// // Vertex buffer +// copyRegion.size = vertexBufferSize +// copyCmd.copyBuffer(stagingBuffers.vertices.buffer, vertices.buffer, copyRegion) +// // Index buffer +// copyRegion.size = indexBufferSize +// copyCmd.copyBuffer(stagingBuffers.indices.buffer, indices.buffer, copyRegion) +// +// +// // Flushing the command buffer will also submit it to the queue and uses a fence to ensure that all commands have been executed before returning +// flushCommandBuffer(copyCmd) +// +// // Destroy staging buffers +// // Note: Staging buffer must not be deleted before the copies have been submitted and executed +// device.apply { +// destroyBuffer(stagingBuffers.vertices.buffer) +// freeMemory(stagingBuffers.vertices.memory) +// destroyBuffer(stagingBuffers.indices.buffer) +// freeMemory(stagingBuffers.indices.memory) +// } +// +// Unit +// +// } else { +// +// /* Don't use staging +// Create host-visible buffers only and use these for rendering. This is not advised and will usually +// result in lower rendering performance */ +// +// // Vertex buffer +// val vertexBufferInfo = vk.BufferCreateInfo { +// size = vertexBufferSize +// usage = VkBufferUsage.VERTEX_BUFFER_BIT.i +// } +// +// // Copy vertex data to a buffer visible to the host +// vertices.buffer = device createBuffer vertexBufferInfo +// val memReqs = device getBufferMemoryRequirements vertices.buffer +// val memAlloc = vk.MemoryAllocateInfo { +// allocationSize = memReqs.size +// // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT is host visible memory, and VK_MEMORY_PROPERTY_HOST_COHERENT_BIT makes sure writes are directly visible +// memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, memoryPropertiesFlags) +// } +// vertices.memory = device allocateMemory memAlloc +// device.mappingMemory(vertices.memory, VkDeviceSize(0), memAlloc.allocationSize) { data -> +// memCopy(vertexBuffer.adr, data, vertexBufferSize) +// } +// device.bindBufferMemory(vertices.buffer, vertices.memory) +// +// // Index buffer +// val indexbufferInfo = vk.BufferCreateInfo { +// size = indexBufferSize +// usage = VkBufferUsage.INDEX_BUFFER_BIT.i +// } +// +// // Copy index data to a buffer visible to the host +// indices.buffer = device createBuffer indexbufferInfo +// device.getBufferMemoryRequirements(indices.buffer, memReqs) +// memAlloc.allocationSize = memReqs.size +// memAlloc.memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, memoryPropertiesFlags) +// indices.memory = device allocateMemory memAlloc +// device.mappingMemory(indices.memory, VkDeviceSize(0), indexBufferSize) { data -> +// memCopy(indexBuffer.adr, data, indexBufferSize) +// } +// device.bindBufferMemory(indices.buffer, indices.memory) +// } +// } +// +// fun setupDescriptorPool() { +// // We need to tell the API the number of max. requested descriptors per type +// // This example only uses one descriptor type (uniform buffer) and only requests one descriptor of this type +// val typeCounts = vk.DescriptorPoolSize(VkDescriptorType.UNIFORM_BUFFER, 1) +// +// // For additional types you need to add new entries in the type count list +// // E.g. for two combined image samplers : +// // typeCounts[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; +// // typeCounts[1].descriptorCount = 2; +// +// // Create the global descriptor pool +// // All descriptors used in this example are allocated from this pool +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(typeCounts, +// // Set the max. number of descriptor sets that can be requested from this pool (requesting beyond this limit will result in an error) +// maxSets = 1) +// +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// /* Setup layout of descriptors used in this example +// Basically connects the different shader stages to descriptors for binding uniform buffers, image samplers, etc. +// So every shader binding should map to one descriptor set layout binding */ +// +// // Binding 0: Uniform buffer (Vertex shader) +// val layoutBinding = vk.DescriptorSetLayoutBinding { +// descriptorType = VkDescriptorType.UNIFORM_BUFFER +// descriptorCount = 1 +// stageFlags = VkShaderStage.VERTEX_BIT.i +// } +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(layoutBinding) +// +// descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// // Create the pipeline layout that is used to generate the rendering pipelines that are based on this descriptor set layout +// // In a more complex scenario you would have different pipeline layouts for different descriptor set layouts that could be reused +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) +// +// pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// } +// +// fun setupDescriptorSet() { +// // Allocate a new descriptor set from the global descriptor pool +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) +// +// descriptorSet = device allocateDescriptorSets allocInfo +// +// /* Update the descriptor set determining the shader binding points +// For every binding point used in a shader there needs to be one descriptor set matching that binding point */ +// +// val writeDescriptorSet = vk.WriteDescriptorSet(descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBufferVS.descriptor) +// +// device updateDescriptorSets writeDescriptorSet +// } +// +// /** Create the depth (and stencil) buffer attachments used by our framebuffers +// * Note: Override of virtual function in the base class and called from within VulkanExampleBase::prepare */ +// override fun setupDepthStencil() { +// // Create an optimal image used as the depth stencil attachment +// val image = vk.ImageCreateInfo { +// imageType = VkImageType.`2D` +// format = depthFormat +// // Use example's height and width +// extent.set(size.x, size.y, 1) +// mipLevels = 1 +// arrayLayers = 1 +// samples = VkSampleCount.`1_BIT` +// tiling = VkImageTiling.OPTIMAL +// usage = VkImageUsage.DEPTH_STENCIL_ATTACHMENT_BIT or VkImageUsage.TRANSFER_SRC_BIT +// initialLayout = VkImageLayout.UNDEFINED +// } +// depthStencil.image = device createImage image +// +// // Allocate memory for the image (device local) and bind it to our image +// val memAlloc = vk.MemoryAllocateInfo { +// val memReqs = device getImageMemoryRequirements depthStencil.image +// allocationSize = memReqs.size +// memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT.i) +// } +// depthStencil.mem = device allocateMemory memAlloc +// device.bindImageMemory(depthStencil.image, depthStencil.mem) +// +// /* Create a view for the depth stencil image +// Images aren't directly accessed in Vulkan, but rather through views described by a subresource range +// This allows for multiple views of one image with differing ranges (e.g. for different layers) */ +// val depthStencilView = vk.ImageViewCreateInfo { +// viewType = VkImageViewType.`2D` +// format = depthFormat +// subresourceRange.apply { +// aspectMask = VkImageAspect.DEPTH_BIT or VkImageAspect.STENCIL_BIT +// baseMipLevel = 0 +// levelCount = 1 +// baseArrayLayer = 0 +// layerCount = 1 +// } +// this.image = depthStencil.image +// } +// depthStencil.view = device createImageView depthStencilView +// } +// +// /** Create a frame buffer for each swap chain image +// * Note: Override of virtual function in the base class and called from within VulkanExampleBase::prepare */ +// override fun setupFrameBuffer() { +// // Create a frame buffer for every image in the swapchain +// frameBuffers = initVkFramebufferArray(swapChain.imageCount) { i -> +// stak { +// val attachments = it.vkImageViewBufferOf( +// swapChain.buffers[i].view, // Color attachment is the view of the swapchain image +// depthStencil.view) // Depth/Stencil attachment is the same for all frame buffers +// +// val (w, h) = size // TODO BUG +// +// val frameBufferCreateInfo = vk.FramebufferCreateInfo { +// // All frame buffers use the same renderpass setup +// renderPass = this@Triangle.renderPass +// this.attachments = attachments +// //it.size(size, 1) TODO BUG +// width = w +// height = h +// layers = 1 +// } +// // Create the framebuffer +// device createFramebuffer frameBufferCreateInfo +// } +// } +// } +// +// /** Render pass setup +// * Render passes are a new concept in Vulkan. They describe the attachments used during rendering and may contain +// * multiple subpasses with attachment dependencies +// * This allows the driver to know up-front what the rendering will look like and is a good opportunity to optimize +// * especially on tile-based renderers (with multiple subpasses) +// * Using sub pass dependencies also adds implicit layout transitions for the attachment used, so we don't need +// * to add explicit image memory barriers to transform them +// * Note: Override of virtual function in the base class and called from within VulkanExampleBase::prepare */ +// override fun setupRenderPass() { +// // This example will use a single render pass with one subpass +// +// // Descriptors for the attachments used by this renderpass +// val attachments = vk.AttachmentDescription(2).also { +// // Color attachment +// it[0].apply { +// format = swapChain.colorFormat // Use the color format selected by the swapchain +// samples = VkSampleCount.`1_BIT` // We don't use multi sampling in this example +// loadOp = VkAttachmentLoadOp.CLEAR // Clear this attachment at the start of the render pass +// storeOp = VkAttachmentStoreOp.STORE // Keep it's contents after the render pass is finished (for displaying it) +// stencilLoadOp = VkAttachmentLoadOp.DONT_CARE // We don't use stencil, so don't care for load +// stencilStoreOp = VkAttachmentStoreOp.DONT_CARE // Same for store +// initialLayout = VkImageLayout.UNDEFINED // Layout at render pass start. Initial doesn't matter, so we use undefined +// finalLayout = VkImageLayout.PRESENT_SRC_KHR // Layout to which the attachment is transitioned when the render pass is finished +// } +// // As we want to present the color buffer to the swapchain, we transition to PRESENT_KHR +// // Depth attachment +// it[1].apply { +// format = depthFormat // A proper depth format is selected in the example base +// samples = VkSampleCount.`1_BIT` +// loadOp = VkAttachmentLoadOp.CLEAR // Clear depth at start of first subpass +// storeOp = VkAttachmentStoreOp.DONT_CARE // We don't need depth after render pass has finished (DONT_CARE may result in better performance) +// stencilLoadOp = VkAttachmentLoadOp.DONT_CARE // No stencil +// stencilStoreOp = VkAttachmentStoreOp.DONT_CARE // No Stencil +// initialLayout = VkImageLayout.UNDEFINED // Layout at render pass start. Initial doesn't matter, so we use undefined +// finalLayout = VkImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL // Transition to depth/stencil attachment +// } +// } +// // Setup attachment references +// val colorReference = vk.AttachmentReference(1) { +// attachment = 0 // Attachment 0 is color +// layout = VkImageLayout.COLOR_ATTACHMENT_OPTIMAL // Attachment layout used as color during the subpass +// } +// +// val depthReference = vk.AttachmentReference { +// attachment = 1 // Attachment 1 is color +// layout = VkImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL // Attachment used as depth/stemcil used during the subpass +// } +// +// // Setup a single subpass reference +// val subpassDescription = vk.SubpassDescription { +// pipelineBindPoint = VkPipelineBindPoint.GRAPHICS +// colorAttachmentCount = 1 +// colorAttachments = colorReference // Reference to the color attachment in slot 0 +// depthStencilAttachment = depthReference // Reference to the depth attachment in slot 1 +// inputAttachments = null // (Input attachments not used by this example) +// preserveAttachments = null // (Preserve attachments not used by this example) +// resolveAttachments = null // Resolve attachments are resolved at the end of a sub pass and can be used for e.g. multi sampling +// } +// +// /* Setup subpass dependencies +// These will add the implicit ttachment layout transitionss specified by the attachment descriptions +// The actual usage layout is preserved through the layout specified in the attachment reference +// Each subpass dependency will introduce a memory and execution dependency between the source and dest subpass described by +// srcStageMask, dstStageMask, srcAccessMask, dstAccessMask (and dependencyFlags is set) +// Note: VK_SUBPASS_EXTERNAL is a special constant that refers to all commands executed outside of the actual renderpass) */ +// val dependencies = vk.SubpassDependency(2).also { +// /* First dependency at the start of the renderpass +// Does the transition from final to initial layout */ +// it[0].apply { +// srcSubpass = VK_SUBPASS_EXTERNAL // Producer of the dependency +// dstSubpass = 0 // Consumer is our single subpass that will wait for the execution depdendency +// srcStageMask = VkPipelineStage.BOTTOM_OF_PIPE_BIT.i +// dstStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i +// srcAccessMask = VkAccess.MEMORY_READ_BIT.i +// dstAccessMask = VkAccess.COLOR_ATTACHMENT_READ_BIT or VkAccess.COLOR_ATTACHMENT_WRITE_BIT +// dependencyFlags = VkDependency.BY_REGION_BIT.i +// } +// /* Second dependency at the end the renderpass +// Does the transition from the initial to the final layout */ +// it[1].apply { +// srcSubpass = 0 // Producer of the dependency is our single subpass +// dstSubpass = VK_SUBPASS_EXTERNAL // Consumer are all commands outside of the renderpass +// srcStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i +// dstStageMask = VkPipelineStage.BOTTOM_OF_PIPE_BIT.i +// srcAccessMask = VkAccess.COLOR_ATTACHMENT_READ_BIT or VkAccess.COLOR_ATTACHMENT_WRITE_BIT +// dstAccessMask = VkAccess.MEMORY_READ_BIT.i +// dependencyFlags = VkDependency.BY_REGION_BIT.i +// } +// } +// // Create the actual renderpass +// val renderPassInfo = vk.RenderPassCreateInfo { +// this.attachments = attachments // Descriptions of the attachments used by the render pass +// subpass = subpassDescription // We only use one subpass in this example, Description of that subpass +// this.dependencies = dependencies // Subpass dependencies used by the render pass +// } +// +// renderPass = device createRenderPass renderPassInfo +// } +// +// fun preparePipelines() { +// /* Create the graphics pipeline used in this example +// Vulkan uses the concept of rendering pipelines to encapsulate fixed states, replacing OpenGL's complex state machine +// A pipeline is then stored and hashed on the GPU making pipeline changes very fast +// Note: There are still a few dynamic states that are not directly part of the pipeline (but the info that they are used is) */ +// +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo( +// // The layout used for this pipeline (can be shared among multiple pipelines using the same layout) +// pipelineLayout, +// // Renderpass this pipeline is attached to +// renderPass) +// +// /* Construct the different states making up the pipeline +// +// Input assembly state describes how primitives are assembled +// This pipeline will assemble vertex data as a triangle lists (though we only use one triangle) */ +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST) +// +// // Rasterization state +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.COUNTER_CLOCKWISE) +// +// /* Color blend state describes how blend factors are calculated (if used) +// We need one blend attachment state per color attachment (even if blending is not used */ +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// /* Viewport state sets the number of viewports and scissor used in this pipeline +// Note: This is actually overriden by the dynamic states (see below) */ +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// /** Enable dynamic states +// * Most states are baked into the pipeline, but there are still a few dynamic states that can be changed within a command buffer +// * To be able to change these we need do specify which dynamic states will be changed using this pipeline. +// * Their actual states are set later on in the command buffer. +// * For this example we will set the viewport and scissor using dynamic states */ +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// /* Depth and stencil state containing depth and stencil compare and test operations +// We only use depth tests and want depth tests and writes to be enabled and compare with less or equal */ +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) +// +// /* Multi sampling state +// This example does not make use fo multi sampling (for anti-aliasing), the state must still be set and passed to the pipeline */ +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// /* Vertex input descriptions +// Specifies the vertex input parameters for a pipeline +// +// Vertex input binding +// This example uses a single vertex input binding at binding point 0 (see vkCmdBindVertexBuffers) */ +// val vertexInputBinding = vk.VertexInputBindingDescription(0, Vertex.size, VkVertexInputRate.VERTEX) +// +// // Inpute attribute bindings describe shader attribute locations and memory layouts +// val vertexInputAttributs = vk.VertexInputAttributeDescription(2).also { +// /* These match the following shader layout (see triangle.vert): +// layout (location = 0) in vec3 inPos; +// layout (location = 1) in vec3 inColor; */ +// it[0].apply { +// // Attribute location 0: Position +// binding = 0 +// location = 0 +// // Position attribute is three 32 bit signed (SFLOAT) floats (R32 G32 B32) +// format = VkFormat.R32G32B32_SFLOAT +// offset = Vertex.offsetPosition +// } +// it[1].apply { +// // Attribute location 1: Color +// binding = 0 +// location = 1 +// // Color attribute is three 32 bit signed (SFLOAT) floats (R32 G32 B32) +// format = VkFormat.R32G32B32_SFLOAT +// offset = Vertex.offsetColor +// } +// } +// // Vertex input state used for pipeline creation +// val vertexInputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertexInputBinding +// vertexAttributeDescriptions = vertexInputAttributs +// } +// +// // Shaders +// val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { +// // Vertex shader +// it[0].loadShader("$assetPath/shaders/triangle/triangle.vert.spv", VkShaderStage.VERTEX_BIT, false) +// // Fragment shader +// it[1].loadShader("$assetPath/shaders/triangle/triangle.frag.spv", VkShaderStage.FRAGMENT_BIT, false) +// } +// // Set pipeline shader stage info +// pipelineCreateInfo.also { +// it.stages = shaderStages +// // Assign the pipeline states to the pipeline creation info structure +// it.vertexInputState = vertexInputState +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.renderPass = renderPass +// it.dynamicState = dynamicState +// it.tessellationState = null +// } +// // Create rendering pipeline using the specified states +// pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// +// // Shader modules are no longer needed once the graphics pipeline has been created, +// // normally they will be destroyed in ::destroy, but we pass false at creation above to delete them now +// device destroyShaderModules shaderStages +// } +// +// fun prepareUniformBuffers() { +// /* Prepare and initialize a uniform buffer block containing shader uniforms +// Single uniforms like in OpenGL are no longer present in Vulkan. All Shader uniforms are passed +// via uniform buffer blocks */ +// +// val bufferInfo = vk.BufferCreateInfo { +// size = VkDeviceSize(uboVS.size.L) +// // This buffer will be used as a uniform buffer +// usage = VkBufferUsage.UNIFORM_BUFFER_BIT.i +// } +// +// // Create a new buffer +// uniformBufferVS.buffer = device createBuffer bufferInfo +// // Get memory requirements including size, alignment and memory type +// val memReqs = device getBufferMemoryRequirements uniformBufferVS.buffer +// // Vertex shader uniform buffer block +// val allocInfo = vk.MemoryAllocateInfo { +// allocationSize = memReqs.size +// /* Get the memory type index that supports host visibile memory access +// Most implementations offer multiple memory types and selecting the correct one to allocate memory from is crucial +// We also want the buffer to be host coherent so we don't have to flush (or sync after every update. +// Note: This may affect performance so you might not want to do this in a real world application that updates +// buffers on a regular base */ +// memoryTypeIndex = getMemoryTypeIndex(memReqs.memoryTypeBits, VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT) +// } +// // Allocate memory for the uniform buffer +// uniformBufferVS.memory = device allocateMemory allocInfo +// // Bind memory to buffer +// device.bindBufferMemory(uniformBufferVS.buffer, uniformBufferVS.memory) +// +// // Store information in the uniform's descriptor that is used by the descriptor set +// uniformBufferVS.descriptor = vk.DescriptorBufferInfo { +// buffer = uniformBufferVS.buffer +// range = VkDeviceSize(uboVS.size.L) +// } +// updateUniformBuffers() +// } +// +// fun updateUniformBuffers() { +// +// // Update matrices +// uboVS.projectionMatrix = glm.perspective(60f.rad, size.aspect, 0.1f, 256f) +// +// uboVS.viewMatrix = glm.translate(Mat4(1f), 0f, 0f, zoom) +// +// uboVS.modelMatrix = Mat4(1f) +// .rotate(rotation.x.rad, 1f, 0f, 0f) +// .rotate(rotation.y.rad, 0f, 1f, 0f) +// .rotate(rotation.z.rad, 0f, 0f, 1f) +// +// // Map uniform buffer and update it +// device.mappingMemory(uniformBufferVS.memory, VkDeviceSize(0), VkDeviceSize(uboVS.size.L), 0) { data -> +// uboVS to data +// }/* Unmap after data has been copied +// Note: Since we requested a host coherent memory type for the uniform buffer, the write is instantly visible to the GPU */ +// } +// +// override fun prepare() { +// super.prepare() +// prepareSynchronizationPrimitives() +// prepareVertices() +// prepareUniformBuffers() +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSet() +// buildCommandBuffers() +// +// window.show() +// +// prepared = true +// } +// +// override fun render() { +// if (!prepared) return +// draw() +// } +// +// /** This function is called by the base example class each time the view is changed by user input */ +// override fun viewChanged() = updateUniformBuffers() +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/basics/02 Pipelines.kt b/src/main/kotlin/vulkan/basics/02 Pipelines.kt index 262eae7..b5287b0 100644 --- a/src/main/kotlin/vulkan/basics/02 Pipelines.kt +++ b/src/main/kotlin/vulkan/basics/02 Pipelines.kt @@ -1,379 +1,379 @@ -package vulkan.basics - -import glm_.L -import glm_.func.rad -import glm_.glm -import glm_.mat4x4.Mat4 -import glm_.vec2.Vec2 -import glm_.vec3.Vec3 -import glm_.vec4.Vec4 -import org.lwjgl.system.MemoryUtil.NULL -import vkk.* -import vulkan.VERTEX_BUFFER_BIND_ID -import vulkan.assetPath -import vulkan.base.* - -/* -* Vulkan Example - Using different pipelines in one single renderpass -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - - -fun main(args: Array) { - Pipelines().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - -private class Pipelines : VulkanExampleBase() { - - /** Vertex layout for the models */ - val vertexLayout = VertexLayout( - VertexComponent.POSITION, - VertexComponent.NORMAL, - VertexComponent.UV, - VertexComponent.COLOR) - - object models { - val cube = Model() - } - - val uniformBuffer = Buffer() - - /** Same uniform buffer layout as shader */ - object uboVS : Bufferizable() { - var projection = Mat4() - @Order(1) - var modelView = Mat4() - @Order(2) - val lightPos = Vec4(0f, 2f, 1f, 0f) - } - - var pipelineLayout: VkPipelineLayout = NULL - var descriptorSet: VkDescriptorSet = NULL - var descriptorSetLayout: VkDescriptorSetLayout = NULL - - object pipelines { - var phong: VkPipeline = NULL - var wireframe: VkPipeline = NULL - var toon: VkPipeline = NULL - } - - init { - zoom = -10.5f - rotation(-25f, 15f, 0f) - title = "Pipeline state objects" -// settings.overlay = true - } - - override fun destroy() { - // Clean up used Vulkan resources - // Note : Inherited destructor cleans up resources stored in base class - device.apply { - destroyPipeline(pipelines.phong) - if (deviceFeatures.fillModeNonSolid) - destroyPipeline(pipelines.wireframe) - destroyPipeline(pipelines.toon) - - destroyPipelineLayout(pipelineLayout) - destroyDescriptorSetLayout(descriptorSetLayout) - } - models.cube.destroy() - uniformBuffer.destroy() - - super.destroy() - } - - // Enable physical device features required for this example - override fun getEnabledFeatures() { - // Fill mode non solid is required for wireframe display - if (deviceFeatures.fillModeNonSolid) { - enabledFeatures.fillModeNonSolid = true - // Wide lines must be present for line width > 1.0f - if (deviceFeatures.wideLines) - enabledFeatures.wideLines = true - } - } - - override fun buildCommandBuffers() { - - val cmdBufInfo = vk.CommandBufferBeginInfo {} - - val clearValues = vk.ClearValue(2).also { - it[0].color(defaultClearColor) - it[1].depthStencil(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@Pipelines.renderPass - renderArea.apply { - offset.set(0, 0) - extent.set(size.x, size.y) - } - this.clearValues = clearValues - } - - for (i in drawCmdBuffers.indices) { - - // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - val viewport = vk.Viewport(size) - setViewport(viewport) - - setScissor(size) - - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) - - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.cube.vertices.buffer) - bindIndexBuffer(models.cube.indices.buffer, 0, VkIndexType.UINT32) - - // Left : Solid colored - viewport.width = size.x / 3f - setViewport(viewport) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.phong) - - drawIndexed(models.cube.indexCount, 1, 0, 0, 0) - - // Center : Toon - viewport.x = size.x / 3f - setViewport(viewport) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.toon) - // Line width > 1.0f only if wide lines feature is supported - if (deviceFeatures.wideLines) - setLineWidth(2f) - - drawIndexed(models.cube.indexCount, 1, 0, 0, 0) - - if (deviceFeatures.fillModeNonSolid) { - // Right : Wireframe - viewport.x = size.x / 3f + size.x / 3f - setViewport(viewport) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.wireframe) - drawIndexed(models.cube.indexCount, 1, 0, 0, 0) - } - - endRenderPass() - - end() - } - } - } - - fun loadAssets() { - models.cube.loadFromFile("$assetPath/models/treasure_smooth.dae", vertexLayout, 1f, vulkanDevice, queue) - } - - fun setupDescriptorPool() { - - val poolSize = vk.DescriptorPoolSize(VkDescriptorType.UNIFORM_BUFFER, 1) - - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSize, 2) - - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - - val setLayoutBinding = vk.DescriptorSetLayoutBinding(VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBinding) - - descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) - - pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - } - - fun setupDescriptorSet() { - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) - - descriptorSet = device allocateDescriptorSets allocInfo - - val writeDescriptorSet = vk.WriteDescriptorSet( - descriptorSet, - VkDescriptorType.UNIFORM_BUFFER, - 0, // Binding 0 : Vertex shader uniform buffer - uniformBuffer.descriptor) - - device updateDescriptorSets writeDescriptorSet - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo( - VkPrimitiveTopology.TRIANGLE_LIST, - 0, - false) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo( - VkPolygonMode.FILL, - VkCullMode.BACK_BIT.i, - VkFrontFace.CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR, VkDynamicState.LINE_WIDTH) - - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass) - - val shaderStages = vk.PipelineShaderStageCreateInfo(2) - - pipelineCreateInfo.let { - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - } - // Shared vertex bindings and attributes used by all pipelines - - // Binding description - val vertexInputBindings = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, vertexLayout.stride, VkVertexInputRate.VERTEX) - - // Attribute descriptions - val vertexInputAttributes = vk.VertexInputAttributeDescription( - VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, 0, // Location 0: Position - VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32_SFLOAT, Vec3.size, // Location 1: Color - VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32G32_SFLOAT, Vec3.size * 2, // Location 2 : Texture coordinates - VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2 + Vec2.size) // Location 3 : Normal - - val vertexInputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertexInputBindings - vertexAttributeDescriptions = vertexInputAttributes - } - pipelineCreateInfo.vertexInputState = vertexInputState - - /* Create the graphics pipeline state objects - - We are using this pipeline as the base for the other pipelines (derivatives) - Pipeline derivatives can be used for pipelines that share most of their state - Depending on the implementation this may result in better performance for pipeline switchting and faster creation time */ - pipelineCreateInfo.flags = VkPipelineCreate.ALLOW_DERIVATIVES_BIT.i - - // Textured pipeline - // Phong shading pipeline - shaderStages[0].loadShader("$assetPath/shaders/pipelines/phong.vert.spv", VkShaderStage.VERTEX_BIT) - shaderStages[1].loadShader("$assetPath/shaders/pipelines/phong.frag.spv", VkShaderStage.FRAGMENT_BIT) - pipelines.phong = device.createPipeline(pipelineCache, pipelineCreateInfo) - - // All pipelines created after the base pipeline will be derivatives - pipelineCreateInfo.flags = VkPipelineCreate.DERIVATIVE_BIT.i - // Base pipeline will be our first created pipeline - pipelineCreateInfo.basePipelineHandle = pipelines.phong - // It's only allowed to either use a handle or index for the base pipeline - // As we use the handle, we must set the index to -1 (see section 9.5 of the specification) - pipelineCreateInfo.basePipelineIndex = -1 - - // Toon shading pipeline - shaderStages[0].loadShader("$assetPath/shaders/pipelines/toon.vert.spv", VkShaderStage.VERTEX_BIT) - shaderStages[1].loadShader("$assetPath/shaders/pipelines/toon.frag.spv", VkShaderStage.FRAGMENT_BIT) - pipelines.toon = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - - // Pipeline for wire frame rendering - // Non solid rendering is not a mandatory Vulkan feature - if (deviceFeatures.fillModeNonSolid) { - rasterizationState.polygonMode = VkPolygonMode.LINE - shaderStages[0].loadShader("$assetPath/shaders/pipelines/wireframe.vert.spv", VkShaderStage.VERTEX_BIT) - shaderStages[1].loadShader("$assetPath/shaders/pipelines/wireframe.frag.spv", VkShaderStage.FRAGMENT_BIT) - pipelines.wireframe = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - } - - // Prepare and initialize uniform buffer containing shader uniforms - fun prepareUniformBuffers() { - // Create the vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBuffer, - uboVS.size.L) - - // Map persistent - uniformBuffer.map() - - updateUniformBuffers() - } - - fun updateUniformBuffers() { - - uboVS.projection = glm.perspective(60f.rad, (size.x / 3f) / size.y, 0.1f, 256f) - - val viewMatrix = glm.translate(Mat4(1f), Vec3(0f, 0f, zoom)) - - uboVS.modelView = viewMatrix translate cameraPos - uboVS.modelView - .rotateAssign(rotation.x.rad, 1f, 0f, 0f) - .rotateAssign(rotation.y.rad, 0f, 1f, 0f) - .rotateAssign(rotation.z.rad, 0f, 0f, 1f) - - uboVS to uniformBuffer.mapped - } - - fun draw() { - - super.prepareFrame() - - submitInfo.commandBuffer = drawCmdBuffers [currentBuffer] - queue submit submitInfo - - super.submitFrame() - } - - override fun prepare() { - super.prepare() - loadAssets() - prepareUniformBuffers() - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSet() - buildCommandBuffers() - prepared = true - window.show() - } - - override fun render() { - if (!prepared) - return - draw() - } - - override fun viewChanged() = updateUniformBuffers() - -// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) -// { -// if (!deviceFeatures.fillModeNonSolid) { -// if (overlay->header("Info")) { overlay -> -// text("Non solid fill modes not supported!") +//package vulkan.basics +// +//import glm_.L +//import glm_.func.rad +//import glm_.glm +//import glm_.mat4x4.Mat4 +//import glm_.vec2.Vec2 +//import glm_.vec3.Vec3 +//import glm_.vec4.Vec4 +//import org.lwjgl.system.MemoryUtil.NULL +//import vkk.* +//import vulkan.VERTEX_BUFFER_BIND_ID +//import vulkan.assetPath +//import vulkan.base.* +// +///* +//* Vulkan Example - Using different pipelines in one single renderpass +//* +//* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +// +//fun main(args: Array) { +// Pipelines().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +//private class Pipelines : VulkanExampleBase() { +// +// /** Vertex layout for the models */ +// val vertexLayout = VertexLayout( +// VertexComponent.POSITION, +// VertexComponent.NORMAL, +// VertexComponent.UV, +// VertexComponent.COLOR) +// +// object models { +// val cube = Model() +// } +// +// val uniformBuffer = Buffer() +// +// /** Same uniform buffer layout as shader */ +// object uboVS : Bufferizable() { +// var projection = Mat4() +// @Order(1) +// var modelView = Mat4() +// @Order(2) +// val lightPos = Vec4(0f, 2f, 1f, 0f) +// } +// +// var pipelineLayout = VkPipelineLayout(NULL) +// var descriptorSet = VkDescriptorSet(NULL) +// var descriptorSetLayout = VkDescriptorSetLayout(NULL) +// +// object pipelines { +// var phong = VkPipeline(NULL) +// var wireframe = VkPipeline(NULL) +// var toon = VkPipeline(NULL) +// } +// +// init { +// zoom = -10.5f +// rotation(-25f, 15f, 0f) +// title = "Pipeline state objects" +//// settings.overlay = true +// } +// +// override fun destroy() { +// // Clean up used Vulkan resources +// // Note : Inherited destructor cleans up resources stored in base class +// device.apply { +// destroyPipeline(pipelines.phong) +// if (deviceFeatures.fillModeNonSolid) +// destroyPipeline(pipelines.wireframe) +// destroyPipeline(pipelines.toon) +// +// destroyPipelineLayout(pipelineLayout) +// destroyDescriptorSetLayout(descriptorSetLayout) +// } +// models.cube.destroy() +// uniformBuffer.destroy() +// +// super.destroy() +// } +// +// // Enable physical device features required for this example +// override fun getEnabledFeatures() { +// // Fill mode non solid is required for wireframe display +// if (deviceFeatures.fillModeNonSolid) { +// enabledFeatures.fillModeNonSolid = true +// // Wide lines must be present for line width > 1.0f +// if (deviceFeatures.wideLines) +// enabledFeatures.wideLines = true +// } +// } +// +// override fun buildCommandBuffers() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo {} +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(defaultClearColor) +// it[1].depthStencil(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@Pipelines.renderPass +// renderArea.apply { +// offset.set(0, 0) +// extent.set(size.x, size.y) // } +// this.clearValues = clearValues // } +// +// for (i in drawCmdBuffers.indices) { +// +// // Set target frame buffer +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// val viewport = vk.Viewport(size) +// setViewport(viewport) +// +// setScissor(size) +// +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) +// +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.cube.vertices.buffer) +// bindIndexBuffer(models.cube.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// +// // Left : Solid colored +// viewport.width = size.x / 3f +// setViewport(viewport) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.phong) +// +// drawIndexed(models.cube.indexCount, 1, 0, 0, 0) +// +// // Center : Toon +// viewport.x = size.x / 3f +// setViewport(viewport) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.toon) +// // Line width > 1.0f only if wide lines feature is supported +// if (deviceFeatures.wideLines) +// setLineWidth(2f) +// +// drawIndexed(models.cube.indexCount, 1, 0, 0, 0) +// +// if (deviceFeatures.fillModeNonSolid) { +// // Right : Wireframe +// viewport.x = size.x / 3f + size.x / 3f +// setViewport(viewport) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.wireframe) +// drawIndexed(models.cube.indexCount, 1, 0, 0, 0) +// } +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// fun loadAssets() { +// models.cube.loadFromFile("$assetPath/models/treasure_smooth.dae", vertexLayout, 1f, vulkanDevice, queue) +// } +// +// fun setupDescriptorPool() { +// +// val poolSize = vk.DescriptorPoolSize(VkDescriptorType.UNIFORM_BUFFER, 1) +// +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSize, 2) +// +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// +// val setLayoutBinding = vk.DescriptorSetLayoutBinding(VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBinding) +// +// descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) +// +// pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// } +// +// fun setupDescriptorSet() { +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) +// +// descriptorSet = device allocateDescriptorSets allocInfo +// +// val writeDescriptorSet = vk.WriteDescriptorSet( +// descriptorSet, +// VkDescriptorType.UNIFORM_BUFFER, +// 0, // Binding 0 : Vertex shader uniform buffer +// uniformBuffer.descriptor) +// +// device updateDescriptorSets writeDescriptorSet +// } +// +// fun preparePipelines() { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo( +// VkPrimitiveTopology.TRIANGLE_LIST, +// 0, +// false) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo( +// VkPolygonMode.FILL, +// VkCullMode.BACK_BIT.i, +// VkFrontFace.CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR, VkDynamicState.LINE_WIDTH) +// +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass) +// +// val shaderStages = vk.PipelineShaderStageCreateInfo(2) +// +// pipelineCreateInfo.let { +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// } +// // Shared vertex bindings and attributes used by all pipelines +// +// // Binding description +// val vertexInputBindings = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, vertexLayout.stride, VkVertexInputRate.VERTEX) +// +// // Attribute descriptions +// val vertexInputAttributes = vk.VertexInputAttributeDescription( +// VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, 0, // Location 0: Position +// VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32_SFLOAT, Vec3.size, // Location 1: Color +// VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32G32_SFLOAT, Vec3.size * 2, // Location 2 : Texture coordinates +// VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2 + Vec2.size) // Location 3 : Normal +// +// val vertexInputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertexInputBindings +// vertexAttributeDescriptions = vertexInputAttributes +// } +// pipelineCreateInfo.vertexInputState = vertexInputState +// +// /* Create the graphics pipeline state objects +// +// We are using this pipeline as the base for the other pipelines (derivatives) +// Pipeline derivatives can be used for pipelines that share most of their state +// Depending on the implementation this may result in better performance for pipeline switchting and faster creation time */ +// pipelineCreateInfo.flags = VkPipelineCreate.ALLOW_DERIVATIVES_BIT.i +// +// // Textured pipeline +// // Phong shading pipeline +// shaderStages[0].loadShader("$assetPath/shaders/pipelines/phong.vert.spv", VkShaderStage.VERTEX_BIT) +// shaderStages[1].loadShader("$assetPath/shaders/pipelines/phong.frag.spv", VkShaderStage.FRAGMENT_BIT) +// pipelines.phong = device.createPipeline(pipelineCache, pipelineCreateInfo) +// +// // All pipelines created after the base pipeline will be derivatives +// pipelineCreateInfo.flags = VkPipelineCreate.DERIVATIVE_BIT.i +// // Base pipeline will be our first created pipeline +// pipelineCreateInfo.basePipelineHandle = pipelines.phong +// // It's only allowed to either use a handle or index for the base pipeline +// // As we use the handle, we must set the index to -1 (see section 9.5 of the specification) +// pipelineCreateInfo.basePipelineIndex = -1 +// +// // Toon shading pipeline +// shaderStages[0].loadShader("$assetPath/shaders/pipelines/toon.vert.spv", VkShaderStage.VERTEX_BIT) +// shaderStages[1].loadShader("$assetPath/shaders/pipelines/toon.frag.spv", VkShaderStage.FRAGMENT_BIT) +// pipelines.toon = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// +// // Pipeline for wire frame rendering +// // Non solid rendering is not a mandatory Vulkan feature +// if (deviceFeatures.fillModeNonSolid) { +// rasterizationState.polygonMode = VkPolygonMode.LINE +// shaderStages[0].loadShader("$assetPath/shaders/pipelines/wireframe.vert.spv", VkShaderStage.VERTEX_BIT) +// shaderStages[1].loadShader("$assetPath/shaders/pipelines/wireframe.frag.spv", VkShaderStage.FRAGMENT_BIT) +// pipelines.wireframe = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// } +// +// // Prepare and initialize uniform buffer containing shader uniforms +// fun prepareUniformBuffers() { +// // Create the vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBuffer, +// VkDeviceSize(uboVS.size.L)) +// +// // Map persistent +// uniformBuffer.map() +// +// updateUniformBuffers() +// } +// +// fun updateUniformBuffers() { +// +// uboVS.projection = glm.perspective(60f.rad, (size.x / 3f) / size.y, 0.1f, 256f) +// +// val viewMatrix = glm.translate(Mat4(1f), Vec3(0f, 0f, zoom)) +// +// uboVS.modelView = viewMatrix translate cameraPos +// uboVS.modelView +// .rotateAssign(rotation.x.rad, 1f, 0f, 0f) +// .rotateAssign(rotation.y.rad, 0f, 1f, 0f) +// .rotateAssign(rotation.z.rad, 0f, 0f, 1f) +// +// uboVS to uniformBuffer.mapped +// } +// +// fun draw() { +// +// super.prepareFrame() +// +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// queue submit submitInfo +// +// super.submitFrame() +// } +// +// override fun prepare() { +// super.prepare() +// loadAssets() +// prepareUniformBuffers() +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSet() +// buildCommandBuffers() +// prepared = true +// window.show() +// } +// +// override fun render() { +// if (!prepared) +// return +// draw() // } -} \ No newline at end of file +// +// override fun viewChanged() = updateUniformBuffers() +// +//// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) +//// { +//// if (!deviceFeatures.fillModeNonSolid) { +//// if (overlay->header("Info")) { overlay -> +//// text("Non solid fill modes not supported!") +//// } +//// } +//// } +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/basics/03 Descriptor Sets.kt b/src/main/kotlin/vulkan/basics/03 Descriptor Sets.kt index 4740b7b..e07bc43 100644 --- a/src/main/kotlin/vulkan/basics/03 Descriptor Sets.kt +++ b/src/main/kotlin/vulkan/basics/03 Descriptor Sets.kt @@ -1,402 +1,402 @@ -/* -* Vulkan Example - Using descriptor sets for passing data to shader stages -* -* Relevant code parts are marked with [POI] -* -* Copyright (C) 2018 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -package vulkan.basics - -import glm_.L -import glm_.func.rad -import glm_.glm -import glm_.mat4x4.Mat4 -import glm_.vec2.Vec2 -import glm_.vec3.Vec3 -import org.lwjgl.system.MemoryUtil.NULL -import vkk.* -import vulkan.assetPath -import vulkan.base.* - -fun main(args: Array) { - DescriptorSets().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - -private class DescriptorSets : VulkanExampleBase() { - - var animate = true - - val vertexLayout = VertexLayout( - VertexComponent.POSITION, - VertexComponent.NORMAL, - VertexComponent.UV, - VertexComponent.COLOR) - - class Cube { - - class Matrices : Bufferizable() { - var projection = Mat4() - var view = Mat4() - var model = Mat4() - - override var fieldOrder = arrayOf("projection", "view", "model") - } - - val matrices = Matrices() - var descriptorSet: VkDescriptorSet = NULL - val texture = Texture2D() - val uniformBuffer = Buffer() - val rotation = Vec3() - } - - val cubes = Array(2) { Cube() } - - object models { - val cube = Model() - } - - var pipeline: VkPipeline = NULL - var pipelineLayout: VkPipelineLayout = NULL - - var descriptorSetLayout: VkDescriptorSetLayout = NULL - - init { - title = "Using descriptor Sets" -// settings.overlay = true TODO - camera.type = Camera.CameraType.lookAt - camera.setPerspective(60f, size.aspect, 0.1f, 512f) - camera.setRotation(Vec3()) - camera.setTranslation(Vec3(0f, 0f, -5f)) - } - - override fun destroy() { - device.apply { - destroyPipeline(pipeline) - destroyPipelineLayout(pipelineLayout) - destroyDescriptorSetLayout(descriptorSetLayout) - } - models.cube.destroy() - for (cube in cubes) { - cube.uniformBuffer.destroy() - cube.texture.destroy() - } - super.destroy() - } - - override fun getEnabledFeatures() { - if (deviceFeatures.samplerAnisotropy) - enabledFeatures.samplerAnisotropy = true - } - - override fun buildCommandBuffers() { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(defaultClearColor) - it[1].depthStencil.set(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@DescriptorSets.renderPass - renderArea.offset.set(0, 0) - renderArea.extent.set(size.x, size.y) - this.clearValues = clearValues - } - for (i in drawCmdBuffers.indices) { - - renderPassBeginInfo.framebuffer(frameBuffers[i]) // TODO BUG - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipeline) - - setViewport(size) - setScissor(size) - - bindVertexBuffers(0, models.cube.vertices.buffer) - bindIndexBuffer(models.cube.indices.buffer, 0, VkIndexType.UINT32) - - // [POI] Render cubes with separate descriptor sets - for (cube in cubes) { - // Bind the cube's descriptor set. This tells the command buffer to use the uniform buffer and image set for this cube - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, cube.descriptorSet) - drawIndexed(models.cube.indexCount, 1, 0, 0, 0) - } - - endRenderPass() - - end() - } - } - } - - fun loadAssets() { - models.cube.loadFromFile("$assetPath/models/cube.dae", vertexLayout, 1f, vulkanDevice, queue) - cubes[0].texture.loadFromFile("$assetPath/textures/crate01_color_height_rgba.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) - cubes[1].texture.loadFromFile("$assetPath/textures/crate02_color_height_rgba.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) - } - - /** [POI] Set up descriptor sets and set layout */ - fun setupDescriptors() { - - /* - Descriptor set layout - - The layout describes the shader bindings and types used for a certain descriptor layout and as such - must match the shader bindings - - Shader bindings used in this example: - - VS: - layout (set = 0, binding = 0) uniform UBOMatrices ... - - FS : - layout (set = 0, binding = 1) uniform sampler2D ...; - */ - - val setLayoutBindings = vk.DescriptorSetLayoutBinding(2).also { - /* - Binding 0: Uniform buffers (used to pass matrices matrices) - */ - it[0].apply { - descriptorType = VkDescriptorType.UNIFORM_BUFFER - // Shader binding point - binding = 0 - // Accessible from the vertex shader only (flags can be combined to make it accessible to multiple shader stages) - stageFlags = VkShaderStage.VERTEX_BIT.i - // Binding contains one element (can be used for array bindings) - descriptorCount = 1 - } - /* - Binding 1: Combined image sampler (used to pass per object texture information) - */ - it[1].apply { - descriptorType = VkDescriptorType.COMBINED_IMAGE_SAMPLER - binding = 1 - // Accessible from the fragment shader only - stageFlags = VkShaderStage.FRAGMENT_BIT.i - descriptorCount = 1 - } - } - // Create the descriptor set layout - val descriptorLayoutCI = vk.DescriptorSetLayoutCreateInfo { bindings = setLayoutBindings } - descriptorSetLayout = device createDescriptorSetLayout descriptorLayoutCI - - /* - Descriptor pool - - Actual descriptors are allocated from a descriptor pool telling the driver what types and how many - descriptors this application will use - - An application can have multiple pools (e.g. for multiple threads) with any number of descriptor types - as long as device limits are not surpassed - - It's good practice to allocate pools with actually required descriptor types and counts - */ - - val descriptorPoolSizes = vk.DescriptorPoolSize(2).also { - // Uniform buffers : 1 for scene and 1 per object (scene and local matrices) - it[0].type = VkDescriptorType.UNIFORM_BUFFER - it[0].descriptorCount = 1 + cubes.size - - // Combined image samples : 1 per mesh texture - it[1].type = VkDescriptorType.COMBINED_IMAGE_SAMPLER - it[1].descriptorCount = cubes.size - } - // Create the global descriptor pool - val descriptorPoolCI = vk.DescriptorPoolCreateInfo { - poolSizes = descriptorPoolSizes - // Max. number of descriptor sets that can be allocted from this pool (one per object) - maxSets = descriptorPoolSizes.capacity() - } - descriptorPool = device createDescriptorPool descriptorPoolCI - - /* - Descriptor sets - - Using the shared descriptor set layout and the descriptor pool we will now allocate the descriptor sets. - - Descriptor sets contain the actual descriptor fo the objects (buffers, images) used at render time. - */ - - for (cube in cubes) { - - // Allocates an empty descriptor set without actual descriptors from the pool using the set layout - val allocateInfo = vk.DescriptorSetAllocateInfo { - descriptorPool = this@DescriptorSets.descriptorPool - descriptorSetCount = 1 - setLayout = descriptorSetLayout - } - cube.descriptorSet = device allocateDescriptorSets allocateInfo - - // Update the descriptor set with the actual descriptors matching shader bindings set in the layout - - val writeDescriptorSets = vk.WriteDescriptorSet(2).also { - /* - Binding 0: Object matrices Uniform buffer - */ - it[0].apply { - dstSet = cube.descriptorSet - dstBinding = 0 - descriptorType = VkDescriptorType.UNIFORM_BUFFER - bufferInfo_ = cube.uniformBuffer.descriptor - } - /* - Binding 1: Object texture - */ - it[1].apply { - dstSet = cube.descriptorSet - dstBinding = 1 - descriptorType = VkDescriptorType.COMBINED_IMAGE_SAMPLER - // Images use a different descriptor strucutre, so we use pImageInfo instead of pBufferInfo - imageInfo_ = cube.texture.descriptor - } - } - /* Execute the writes to update descriptors for this set - Note that it's also possible to gather all writes and only run updates once, even for multiple sets - This is possible because each VkWriteDescriptorSet also contains the destination set to be updated - For simplicity we will update once per set instead */ - device updateDescriptorSets writeDescriptorSets - } - } - - fun preparePipelines() { - /* - [POI] Create a pipeline layout used for our graphics pipeline - */ - val pipelineLayoutCI = vk.PipelineLayoutCreateInfo { - // The pipeline layout is based on the descriptor set layout we created above - setLayout = descriptorSetLayout - } - pipelineLayout = device createPipelineLayout pipelineLayoutCI - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - - val inputAssemblyStateCI = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) - val rasterizationStateCI = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.BACK_BIT.i, VkFrontFace.CLOCKWISE) - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - val colorBlendStateCI = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - val depthStencilStateCI = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) - val viewportStateCI = vk.PipelineViewportStateCreateInfo(1, 1, 0) - val multisampleStateCI = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - val dynamicStateCI = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - // Vertex bindings and attributes - val vertexInputBinding = vk.VertexInputBindingDescription(0, vertexLayout.stride, VkVertexInputRate.VERTEX) - - val vertexInputAttributes = vk.VertexInputAttributeDescription( - 0, 0, VkFormat.R32G32B32_SFLOAT, 0, // Location 0: Position - 0, 1, VkFormat.R32G32B32_SFLOAT, Vec3.size, // Location 1: Normal - 0, 2, VkFormat.R32G32_SFLOAT, Vec3.size * 2, // Location 2: UV - 0, 3, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2 + Vec2.size) // Location 3: Color - - val vertexInputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertexInputBinding - vertexAttributeDescriptions = vertexInputAttributes - } - val pipelineCreateInfoCI = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { - - it.vertexInputState = vertexInputState - it.inputAssemblyState = inputAssemblyStateCI - it.rasterizationState = rasterizationStateCI - it.colorBlendState = colorBlendStateCI - it.multisampleState = multisampleStateCI - it.viewportState = viewportStateCI - it.depthStencilState = depthStencilStateCI - it.dynamicState = dynamicStateCI - - it.stages = vk.PipelineShaderStageCreateInfo(2).also { - it[0].loadShader("$assetPath/shaders/descriptorsets/cube.vert.spv", VkShaderStage.VERTEX_BIT) - it[1].loadShader("$assetPath/shaders/descriptorsets/cube.frag.spv", VkShaderStage.FRAGMENT_BIT) - } - } - - pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfoCI) - } - - fun prepareUniformBuffers() { - // Vertex shader matrix uniform buffer block - for (cube in cubes) { - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - cube.uniformBuffer, - cube.matrices.size.L) - cube.uniformBuffer.map() - } - - updateUniformBuffers() - } - - fun updateUniformBuffers() { - - cubes[0].matrices.model = glm.translate(Mat4(1f), -2f, 0f, 0f) - cubes[1].matrices.model = glm.translate(Mat4(1f), 1.5f, 0.5f, 0f) - - for (cube in cubes) { - cube.matrices.apply { - projection put camera.matrices.perspective - view put camera.matrices.view - model - .rotateAssign(cube.rotation.x.rad, 1f, 0f, 0f) - .rotateAssign(cube.rotation.y.rad, 0f, 1f, 0f) - .rotateAssign(cube.rotation.z.rad, 0f, 0f, 1f) - } - cube.matrices to cube.uniformBuffer.mapped - } - } - - fun draw() { - super.prepareFrame() - submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] - queue submit submitInfo - super.submitFrame() - } - - override fun prepare() { - super.prepare() - loadAssets() - prepareUniformBuffers() - setupDescriptors() - preparePipelines() - buildCommandBuffers() - prepared = true - window.show() - } - - override fun render() { - if (!prepared) - return - draw() - if (animate) { - cubes[0].rotation.x += 2.5f * frameTimer - if (cubes[0].rotation.x > 360f) - cubes[0].rotation.x -= 360f - cubes[1].rotation.y += 2f * frameTimer - if (cubes[1].rotation.x > 360f) - cubes[1].rotation.x -= 360f - } - if (camera.updated || animate) - updateUniformBuffers() - } - -// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) -// { -// if (overlay->header("Settings")) { overlay -> -// checkBox("Animate", & animate) +///* +//* Vulkan Example - Using descriptor sets for passing data to shader stages +//* +//* Relevant code parts are marked with [POI] +//* +//* Copyright (C) 2018 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +//package vulkan.basics +// +//import glm_.L +//import glm_.func.rad +//import glm_.glm +//import glm_.mat4x4.Mat4 +//import glm_.vec2.Vec2 +//import glm_.vec3.Vec3 +//import org.lwjgl.system.MemoryUtil.NULL +//import vkk.* +//import vulkan.assetPath +//import vulkan.base.* +// +//fun main(args: Array) { +// DescriptorSets().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() // } +//} +// +//private class DescriptorSets : VulkanExampleBase() { +// +// var animate = true +// +// val vertexLayout = VertexLayout( +// VertexComponent.POSITION, +// VertexComponent.NORMAL, +// VertexComponent.UV, +// VertexComponent.COLOR) +// +// class Cube { +// +// class Matrices : Bufferizable() { +// var projection = Mat4() +// var view = Mat4() +// var model = Mat4() +// +// override var fieldOrder = arrayOf("projection", "view", "model") +// } +// +// val matrices = Matrices() +// var descriptorSet = VkDescriptorSet (NULL) +// val texture = Texture2D() +// val uniformBuffer = Buffer() +// val rotation = Vec3() // } -} \ No newline at end of file +// +// val cubes = Array(2) { Cube() } +// +// object models { +// val cube = Model() +// } +// +// var pipeline= VkPipeline (NULL) +// var pipelineLayout= VkPipelineLayout (NULL) +// +// var descriptorSetLayout= VkDescriptorSetLayout (NULL) +// +// init { +// title = "Using descriptor Sets" +//// settings.overlay = true TODO +// camera.type = Camera.CameraType.lookAt +// camera.setPerspective(60f, size.aspect, 0.1f, 512f) +// camera.setRotation(Vec3()) +// camera.setTranslation(Vec3(0f, 0f, -5f)) +// } +// +// override fun destroy() { +// device.apply { +// destroyPipeline(pipeline) +// destroyPipelineLayout(pipelineLayout) +// destroyDescriptorSetLayout(descriptorSetLayout) +// } +// models.cube.destroy() +// for (cube in cubes) { +// cube.uniformBuffer.destroy() +// cube.texture.destroy() +// } +// super.destroy() +// } +// +// override fun getEnabledFeatures() { +// if (deviceFeatures.samplerAnisotropy) +// enabledFeatures.samplerAnisotropy = true +// } +// +// override fun buildCommandBuffers() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(defaultClearColor) +// it[1].depthStencil.set(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@DescriptorSets.renderPass +// renderArea.offset.set(0, 0) +// renderArea.extent.set(size.x, size.y) +// this.clearValues = clearValues +// } +// for (i in drawCmdBuffers.indices) { +// +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) // TODO BUG +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipeline) +// +// setViewport(size) +// setScissor(size) +// +// bindVertexBuffers(0, models.cube.vertices.buffer) +// bindIndexBuffer(models.cube.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// +// // [POI] Render cubes with separate descriptor sets +// for (cube in cubes) { +// // Bind the cube's descriptor set. This tells the command buffer to use the uniform buffer and image set for this cube +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, cube.descriptorSet) +// drawIndexed(models.cube.indexCount, 1, 0, 0, 0) +// } +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// fun loadAssets() { +// models.cube.loadFromFile("$assetPath/models/cube.dae", vertexLayout, 1f, vulkanDevice, queue) +// cubes[0].texture.loadFromFile("$assetPath/textures/crate01_color_height_rgba.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) +// cubes[1].texture.loadFromFile("$assetPath/textures/crate02_color_height_rgba.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) +// } +// +// /** [POI] Set up descriptor sets and set layout */ +// fun setupDescriptors() { +// +// /* +// Descriptor set layout +// +// The layout describes the shader bindings and types used for a certain descriptor layout and as such +// must match the shader bindings +// +// Shader bindings used in this example: +// +// VS: +// layout (set = 0, binding = 0) uniform UBOMatrices ... +// +// FS : +// layout (set = 0, binding = 1) uniform sampler2D ...; +// */ +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding(2).also { +// /* +// Binding 0: Uniform buffers (used to pass matrices matrices) +// */ +// it[0].apply { +// descriptorType = VkDescriptorType.UNIFORM_BUFFER +// // Shader binding point +// binding = 0 +// // Accessible from the vertex shader only (flags can be combined to make it accessible to multiple shader stages) +// stageFlags = VkShaderStage.VERTEX_BIT.i +// // Binding contains one element (can be used for array bindings) +// descriptorCount = 1 +// } +// /* +// Binding 1: Combined image sampler (used to pass per object texture information) +// */ +// it[1].apply { +// descriptorType = VkDescriptorType.COMBINED_IMAGE_SAMPLER +// binding = 1 +// // Accessible from the fragment shader only +// stageFlags = VkShaderStage.FRAGMENT_BIT.i +// descriptorCount = 1 +// } +// } +// // Create the descriptor set layout +// val descriptorLayoutCI = vk.DescriptorSetLayoutCreateInfo { bindings = setLayoutBindings } +// descriptorSetLayout = device createDescriptorSetLayout descriptorLayoutCI +// +// /* +// Descriptor pool +// +// Actual descriptors are allocated from a descriptor pool telling the driver what types and how many +// descriptors this application will use +// +// An application can have multiple pools (e.g. for multiple threads) with any number of descriptor types +// as long as device limits are not surpassed +// +// It's good practice to allocate pools with actually required descriptor types and counts +// */ +// +// val descriptorPoolSizes = vk.DescriptorPoolSize(2).also { +// // Uniform buffers : 1 for scene and 1 per object (scene and local matrices) +// it[0].type = VkDescriptorType.UNIFORM_BUFFER +// it[0].descriptorCount = 1 + cubes.size +// +// // Combined image samples : 1 per mesh texture +// it[1].type = VkDescriptorType.COMBINED_IMAGE_SAMPLER +// it[1].descriptorCount = cubes.size +// } +// // Create the global descriptor pool +// val descriptorPoolCI = vk.DescriptorPoolCreateInfo { +// poolSizes = descriptorPoolSizes +// // Max. number of descriptor sets that can be allocted from this pool (one per object) +// maxSets = descriptorPoolSizes.capacity() +// } +// descriptorPool = device createDescriptorPool descriptorPoolCI +// +// /* +// Descriptor sets +// +// Using the shared descriptor set layout and the descriptor pool we will now allocate the descriptor sets. +// +// Descriptor sets contain the actual descriptor fo the objects (buffers, images) used at render time. +// */ +// +// for (cube in cubes) { +// +// // Allocates an empty descriptor set without actual descriptors from the pool using the set layout +// val allocateInfo = vk.DescriptorSetAllocateInfo { +// descriptorPool = this@DescriptorSets.descriptorPool +// descriptorSetCount = 1 +// setLayout = descriptorSetLayout +// } +// cube.descriptorSet = device allocateDescriptorSets allocateInfo +// +// // Update the descriptor set with the actual descriptors matching shader bindings set in the layout +// +// val writeDescriptorSets = vk.WriteDescriptorSet(2).also { +// /* +// Binding 0: Object matrices Uniform buffer +// */ +// it[0].apply { +// dstSet = cube.descriptorSet +// dstBinding = 0 +// descriptorType = VkDescriptorType.UNIFORM_BUFFER +// bufferInfo_ = cube.uniformBuffer.descriptor +// } +// /* +// Binding 1: Object texture +// */ +// it[1].apply { +// dstSet = cube.descriptorSet +// dstBinding = 1 +// descriptorType = VkDescriptorType.COMBINED_IMAGE_SAMPLER +// // Images use a different descriptor strucutre, so we use pImageInfo instead of pBufferInfo +// imageInfo_ = cube.texture.descriptor +// } +// } +// /* Execute the writes to update descriptors for this set +// Note that it's also possible to gather all writes and only run updates once, even for multiple sets +// This is possible because each VkWriteDescriptorSet also contains the destination set to be updated +// For simplicity we will update once per set instead */ +// device updateDescriptorSets writeDescriptorSets +// } +// } +// +// fun preparePipelines() { +// /* +// [POI] Create a pipeline layout used for our graphics pipeline +// */ +// val pipelineLayoutCI = vk.PipelineLayoutCreateInfo { +// // The pipeline layout is based on the descriptor set layout we created above +// setLayout = descriptorSetLayout +// } +// pipelineLayout = device createPipelineLayout pipelineLayoutCI +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// +// val inputAssemblyStateCI = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) +// val rasterizationStateCI = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.BACK_BIT.i, VkFrontFace.CLOCKWISE) +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// val colorBlendStateCI = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// val depthStencilStateCI = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) +// val viewportStateCI = vk.PipelineViewportStateCreateInfo(1, 1, 0) +// val multisampleStateCI = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// val dynamicStateCI = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// // Vertex bindings and attributes +// val vertexInputBinding = vk.VertexInputBindingDescription(0, vertexLayout.stride, VkVertexInputRate.VERTEX) +// +// val vertexInputAttributes = vk.VertexInputAttributeDescription( +// 0, 0, VkFormat.R32G32B32_SFLOAT, 0, // Location 0: Position +// 0, 1, VkFormat.R32G32B32_SFLOAT, Vec3.size, // Location 1: Normal +// 0, 2, VkFormat.R32G32_SFLOAT, Vec3.size * 2, // Location 2: UV +// 0, 3, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2 + Vec2.size) // Location 3: Color +// +// val vertexInputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertexInputBinding +// vertexAttributeDescriptions = vertexInputAttributes +// } +// val pipelineCreateInfoCI = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { +// +// it.vertexInputState = vertexInputState +// it.inputAssemblyState = inputAssemblyStateCI +// it.rasterizationState = rasterizationStateCI +// it.colorBlendState = colorBlendStateCI +// it.multisampleState = multisampleStateCI +// it.viewportState = viewportStateCI +// it.depthStencilState = depthStencilStateCI +// it.dynamicState = dynamicStateCI +// +// it.stages = vk.PipelineShaderStageCreateInfo(2).also { +// it[0].loadShader("$assetPath/shaders/descriptorsets/cube.vert.spv", VkShaderStage.VERTEX_BIT) +// it[1].loadShader("$assetPath/shaders/descriptorsets/cube.frag.spv", VkShaderStage.FRAGMENT_BIT) +// } +// } +// +// pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfoCI) +// } +// +// fun prepareUniformBuffers() { +// // Vertex shader matrix uniform buffer block +// for (cube in cubes) { +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// cube.uniformBuffer, +// VkDeviceSize(cube.matrices.size.L)) +// cube.uniformBuffer.map() +// } +// +// updateUniformBuffers() +// } +// +// fun updateUniformBuffers() { +// +// cubes[0].matrices.model = glm.translate(Mat4(1f), -2f, 0f, 0f) +// cubes[1].matrices.model = glm.translate(Mat4(1f), 1.5f, 0.5f, 0f) +// +// for (cube in cubes) { +// cube.matrices.apply { +// projection put camera.matrices.perspective +// view put camera.matrices.view +// model +// .rotateAssign(cube.rotation.x.rad, 1f, 0f, 0f) +// .rotateAssign(cube.rotation.y.rad, 0f, 1f, 0f) +// .rotateAssign(cube.rotation.z.rad, 0f, 0f, 1f) +// } +// cube.matrices to cube.uniformBuffer.mapped +// } +// } +// +// fun draw() { +// super.prepareFrame() +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// queue submit submitInfo +// super.submitFrame() +// } +// +// override fun prepare() { +// super.prepare() +// loadAssets() +// prepareUniformBuffers() +// setupDescriptors() +// preparePipelines() +// buildCommandBuffers() +// prepared = true +// window.show() +// } +// +// override fun render() { +// if (!prepared) +// return +// draw() +// if (animate) { +// cubes[0].rotation.x += 2.5f * frameTimer +// if (cubes[0].rotation.x > 360f) +// cubes[0].rotation.x -= 360f +// cubes[1].rotation.y += 2f * frameTimer +// if (cubes[1].rotation.x > 360f) +// cubes[1].rotation.x -= 360f +// } +// if (camera.updated || animate) +// updateUniformBuffers() +// } +// +//// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) +//// { +//// if (overlay->header("Settings")) { overlay -> +//// checkBox("Animate", & animate) +//// } +//// } +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/basics/04 Dynamic Uniform Buffers.kt b/src/main/kotlin/vulkan/basics/04 Dynamic Uniform Buffers.kt index bc47831..25123d4 100644 --- a/src/main/kotlin/vulkan/basics/04 Dynamic Uniform Buffers.kt +++ b/src/main/kotlin/vulkan/basics/04 Dynamic Uniform Buffers.kt @@ -1,451 +1,447 @@ -/* -* Vulkan Example - Dynamic uniform buffers -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -* -* Summary: -* Demonstrates the use of dynamic uniform buffers. -* -* Instead of using one uniform buffer per-object, this example allocates one big uniform buffer -* with respect to the alignment reported by the device via minUniformBufferOffsetAlignment that -* contains all matrices for the objects in the scene. -* -* The used descriptor type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC then allows to set a dynamic -* offset used to pass data from the single uniform buffer to the connected shader binding point. -*/ - -package vulkan.basics - -import ab.appBuffer -import glm_.L -import glm_.buffer.adr -import glm_.buffer.bufferBig -import glm_.buffer.free -import glm_.glm -import glm_.i -import glm_.mat4x4.Mat4 -import glm_.pow -import glm_.vec3.Vec3 -import glm_.vec3.operators.times -import org.lwjgl.system.MemoryUtil.NULL -import org.lwjgl.system.MemoryUtil.memCopy -import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo -import org.lwjgl.vulkan.VkVertexInputAttributeDescription -import org.lwjgl.vulkan.VkVertexInputBindingDescription -import uno.kotlin.buffers.capacity -import vkk.* -import vulkan.VERTEX_BUFFER_BIND_ID -import vulkan.assetPath -import vulkan.base.Buffer -import vulkan.base.Camera -import vulkan.base.VulkanExampleBase -import vulkan.base.initializers -import java.nio.ByteBuffer - -private const val OBJECT_INSTANCES = 125 - - -fun main(args: Array) { - DynamicUniformBuffers().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - -private class DynamicUniformBuffers : VulkanExampleBase() { - - /** Vertex layout for this example */ - object Vertex { - // float pos[3]; -// float color[3]; - val size = Vec3.size * 2 - val offsetPos = 0 - val offsetColor = Vec3.size - } - - object vertices { - lateinit var inputState: VkPipelineVertexInputStateCreateInfo - lateinit var bindingDescriptions: VkVertexInputBindingDescription - lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer - } - - val vertexBuffer = Buffer() - val indexBuffer = Buffer() - var indexCount = 0 - - object uniformBuffers { - val view = Buffer() - val dynamic = Buffer() - } - - object uboVS : Bufferizable() { - val projection = Mat4() - val view = Mat4() - } - - // Store random per-object rotations - val rotations = Array(OBJECT_INSTANCES) { Vec3() } - val rotationSpeeds = Array(OBJECT_INSTANCES) { Vec3() } - - /** One big uniform buffer that contains all matrices - * Note that we need to manually allocate the data to cope for GPU-specific uniform buffer offset alignments */ - object uboDataDynamic { - lateinit var model: ByteBuffer - var address = NULL - } - - var pipeline: VkPipeline = NULL - var pipelineLayout: VkPipelineLayout = NULL - var descriptorSet: VkDescriptorSet = NULL - var descriptorSetLayout: VkDescriptorSetLayout = NULL - - var animationTimer = 0f - - var dynamicAlignment = 0L - - init { - title = "Vulkan Example - Dynamic uniform buffers" - camera.type = Camera.CameraType.lookAt - camera.setPosition(Vec3(0f, 0f, -30f)) - camera.setRotation(Vec3(.0f)) - camera.setPerspective(60f, size.aspect, 0.1f, 256f) -// settings.overlay = true TODO - } - - override fun destroy() { - - uboDataDynamic.model.free() - - /* Clean up used Vulkan resources - Note : Inherited destructor cleans up resources stored in base class */ - device.apply { - destroyPipeline(pipeline) - - destroyPipelineLayout(pipelineLayout) - destroyDescriptorSetLayout(descriptorSetLayout) - } - - vertexBuffer.destroy() - indexBuffer.destroy() - - uniformBuffers.view.destroy() - uniformBuffers.dynamic.destroy() - - super.destroy() - } - - override fun buildCommandBuffers() { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(defaultClearColor) - it[1].depthStencil(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@DynamicUniformBuffers.renderPass - renderArea.apply { - offset(0) - extent(size) - } - this.clearValues = clearValues - } - - for (i in drawCmdBuffers.indices) { - - renderPassBeginInfo.framebuffer(frameBuffers[i]) - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - setViewport(size) - setScissor(size) - - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipeline) - - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, vertexBuffer.buffer) - bindIndexBuffer(indexBuffer.buffer, 0, VkIndexType.UINT32) - - // Render multiple objects using different model matrices by dynamically offsetting into one uniform buffer - repeat(OBJECT_INSTANCES) { - // One dynamic offset per dynamic descriptor to offset into the ubo containing all model matrices - val dynamicOffset = it * dynamicAlignment - // Bind the descriptor set for rendering a mesh using the dynamic offset - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet, dynamicOffset.i) - - drawIndexed(indexCount, 1, 0, 0, 0) - } - - endRenderPass() - - end() - } - } - } - - fun draw() { - - super.prepareFrame() - - // Command buffer to be submitted to the queue - submitInfo.commandBuffers = appBuffer.pointerBufferOf(drawCmdBuffers[currentBuffer]) - - // Submit to queue - queue submit submitInfo - - super.submitFrame() - } - - fun generateCube() { - // Setup vertices indices for a colored cube - val vertices = appBuffer.floatBufferOf( - -1f, -1f, +1f, 1f, 0f, 0f, - +1f, -1f, +1f, 0f, 1f, 0f, - +1f, +1f, +1f, 0f, 0f, 1f, - -1f, +1f, +1f, 0f, 0f, 0f, - -1f, -1f, -1f, 1f, 0f, 0f, - +1f, -1f, -1f, 0f, 1f, 0f, - +1f, +1f, -1f, 0f, 0f, 1f, - -1f, +1f, -1f, 0f, 0f, 0f) - - val indices = appBuffer.intBufferOf(0, 1, 2, 2, 3, 0, 1, 5, 6, 6, 2, 1, 7, 6, 5, 5, 4, 7, 4, 0, 3, 3, 7, 4, 4, 5, 1, 1, 0, 4, 3, 2, 6, 6, 7, 3) - - indexCount = indices.capacity - - // Create buffers - // For the sake of simplicity we won't stage the vertex data to the gpu memory - val flags = VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT - // Vertex buffer - vulkanDevice.createBuffer(VkBufferUsage.VERTEX_BUFFER_BIT.i, flags, vertexBuffer, vertices) - // Index buffer - vulkanDevice.createBuffer(VkBufferUsage.INDEX_BUFFER_BIT.i, flags, indexBuffer, indices) - } - - fun setupVertexDescriptions() { - // Binding description - vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, Vertex.size, VkVertexInputRate.VERTEX) - - // Attribute descriptions - vertices.attributeDescriptions = vk.VertexInputAttributeDescription( - // Location 0 : Position - VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, Vertex.offsetPos, - // Location 1 : Color - VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32_SFLOAT, Vertex.offsetColor) - - vertices.inputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertices.bindingDescriptions - vertexAttributeDescriptions = vertices.attributeDescriptions - } - } - - fun setupDescriptorPool() { - // Example uses one ubo and one image sampler - val poolSizes = vk.DescriptorPoolSize( - VkDescriptorType.UNIFORM_BUFFER, 1, - VkDescriptorType.UNIFORM_BUFFER_DYNAMIC, 1, - VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1) - - descriptorPool = device createDescriptorPool initializers.descriptorPoolCreateInfo(poolSizes, 2) - } - - fun setupDescriptorSetLayout() { - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, - VkDescriptorType.UNIFORM_BUFFER_DYNAMIC, VkShaderStage.VERTEX_BIT.i, 1, - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 2) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo { bindings = setLayoutBindings } - - descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo { setLayout = descriptorSetLayout } - - pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - } - - fun setupDescriptorSet() { - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) - - descriptorSet = device allocateDescriptorSets allocInfo - - val writeDescriptorSets = vk.WriteDescriptorSet( - // Binding 0 : Projection/View matrix uniform buffer - descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.view.descriptor, - // Binding 1 : Instance matrix as dynamic uniform buffer - descriptorSet, VkDescriptorType.UNIFORM_BUFFER_DYNAMIC, 1, uniformBuffers.dynamic.descriptor) - - device updateDescriptorSets writeDescriptorSets - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.COUNTER_CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(rasterizationSamples = VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - // Load shaders - val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { - it[0].loadShader("$assetPath/shaders/dynamicuniformbuffer/base.vert.spv", VkShaderStage.VERTEX_BIT) - it[1].loadShader("$assetPath/shaders/dynamicuniformbuffer/base.frag.spv", VkShaderStage.FRAGMENT_BIT) - } - - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { - it.vertexInputState = vertices.inputState - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - } - - pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - /** Prepare and initialize uniform buffer containing shader uniforms */ - fun prepareUniformBuffers() { - /* Allocate data for the dynamic uniform buffer object - We allocate this manually as the alignment of the offset differs between GPUs */ - - // Calculate required alignment based on minimum device offset alignment - val minUboAlignment = vulkanDevice.properties.limits.minUniformBufferOffsetAlignment - dynamicAlignment = Mat4.size.L - if (minUboAlignment > 0) - dynamicAlignment = (dynamicAlignment + minUboAlignment - 1) and (minUboAlignment - 1).inv() - - val bufferSize = OBJECT_INSTANCES * dynamicAlignment - - uboDataDynamic.model = bufferBig(bufferSize.i).apply { uboDataDynamic.address = adr } - - println("minUniformBufferOffsetAlignment = $minUboAlignment") - println("dynamicAlignment = $dynamicAlignment") - - // Vertex shader uniform buffer block - - // Static shared uniform buffer object with projection and view matrix - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBuffers.view, - uboVS.size.L) - - // Uniform buffer object with per-object matrices - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT.i, - uniformBuffers.dynamic, - bufferSize) - - // Map persistent - uniformBuffers.view.map() - uniformBuffers.dynamic.map() - - // Prepare per-object matrices with offsets and random rotations - repeat(OBJECT_INSTANCES) { - rotations[it] = Vec3 { glm.gaussRand(-1f, 1f) } * 2f * glm.PIf - rotationSpeeds[it] = Vec3 { glm.gaussRand(-1f, 1f) } - } - - updateUniformBuffers() - updateDynamicUniformBuffer(true) - } - - fun updateUniformBuffers() { - // Fixed ubo with projection and view matrices - uboVS.projection put camera.matrices.perspective - uboVS.view put camera.matrices.view - - uboVS to uniformBuffers.view.mapped - } - - fun updateDynamicUniformBuffer(force: Boolean = false) { - // Update at max. 60 fps - animationTimer += frameTimer - if (animationTimer <= 1f / 60f && !force) return - - // Dynamic ubo with per-object model matrices indexed by offsets in the command buffer - val dim = OBJECT_INSTANCES pow (1f / 3f) - val offset = Vec3(5f) - - for (x in 0 until dim) - for (y in 0 until dim) - for (z in 0 until dim) { - val index = x * dim * dim + y * dim + z - - // Update rotations - rotations[index] plusAssign animationTimer * rotationSpeeds[index] - - // Update matrices - val pos = -((dim * offset) / 2f) + offset / 2f - pos.x += x * offset.x - pos.y += y * offset.y - pos.z += z * offset.z - val modelMat = glm.translate(Mat4(1f), pos) - .rotateAssign(rotations[index].x, 1f, 1f, 0f) - .rotateAssign(rotations[index].y, 0f, 1f, 0f) - .rotateAssign(rotations[index].z, 0f, 0f, 1f) - // Aligned offset - modelMat.to(uboDataDynamic.model, index * dynamicAlignment.i) - } - - animationTimer = 0f - - memCopy(uboDataDynamic.address, uniformBuffers.dynamic.mapped, uniformBuffers.dynamic.size) - // Flush to make changes visible to the host - val memoryRange = vk.MappedMemoryRange { - memory = uniformBuffers.dynamic.memory - size = uniformBuffers.dynamic.size - } - device flushMappedMemoryRanges memoryRange - } - - override fun prepare() { - super.prepare() - generateCube() - setupVertexDescriptions() - prepareUniformBuffers() - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSet() - buildCommandBuffers() - prepared = true - window.show() - } - - override fun render() { - if (!prepared) - return - draw() - if (!paused) - updateDynamicUniformBuffer() - } - - override fun viewChanged() = updateUniformBuffers() -} \ No newline at end of file +///* +//* Vulkan Example - Dynamic uniform buffers +//* +//* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//* +//* Summary: +//* Demonstrates the use of dynamic uniform buffers. +//* +//* Instead of using one uniform buffer per-object, this example allocates one big uniform buffer +//* with respect to the alignment reported by the device via minUniformBufferOffsetAlignment that +//* contains all matrices for the objects in the scene. +//* +//* The used descriptor type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC then allows to set a dynamic +//* offset used to pass data from the single uniform buffer to the connected shader binding point. +//*/ +// +//package vulkan.basics +// +//import glm_.L +//import glm_.glm +//import glm_.i +//import glm_.mat4x4.Mat4 +//import glm_.pow +//import glm_.vec3.Vec3 +//import glm_.vec3.operators.times +//import kool.* +//import org.lwjgl.system.MemoryUtil.NULL +//import org.lwjgl.system.MemoryUtil.memCopy +//import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo +//import org.lwjgl.vulkan.VkVertexInputAttributeDescription +//import org.lwjgl.vulkan.VkVertexInputBindingDescription +//import vkk.* +//import vulkan.VERTEX_BUFFER_BIND_ID +//import vulkan.assetPath +//import vulkan.base.Buffer +//import vulkan.base.Camera +//import vulkan.base.VulkanExampleBase +//import vulkan.base.initializers +//import java.nio.ByteBuffer +// +//private const val OBJECT_INSTANCES = 125 +// +// +//fun main(args: Array) { +// DynamicUniformBuffers().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +//private class DynamicUniformBuffers : VulkanExampleBase() { +// +// /** Vertex layout for this example */ +// object Vertex { +// // float pos[3]; +//// float color[3]; +// val size = Vec3.size * 2 +// val offsetPos = 0 +// val offsetColor = Vec3.size +// } +// +// object vertices { +// lateinit var inputState: VkPipelineVertexInputStateCreateInfo +// lateinit var bindingDescriptions: VkVertexInputBindingDescription +// lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer +// } +// +// val vertexBuffer = Buffer() +// val indexBuffer = Buffer() +// var indexCount = 0 +// +// object uniformBuffers { +// val view = Buffer() +// val dynamic = Buffer() +// } +// +// object uboVS : Bufferizable() { +// val projection = Mat4() +// val view = Mat4() +// } +// +// // Store random per-object rotations +// val rotations = Array(OBJECT_INSTANCES) { Vec3() } +// val rotationSpeeds = Array(OBJECT_INSTANCES) { Vec3() } +// +// /** One big uniform buffer that contains all matrices +// * Note that we need to manually allocate the data to cope for GPU-specific uniform buffer offset alignments */ +// object uboDataDynamic { +// lateinit var model: ByteBuffer +// var address = NULL +// } +// +// var pipeline = VkPipeline(NULL) +// var pipelineLayout = VkPipelineLayout(NULL) +// var descriptorSet = VkDescriptorSet(NULL) +// var descriptorSetLayout = VkDescriptorSetLayout(NULL) +// +// var animationTimer = 0f +// +// var dynamicAlignment = 0L +// +// init { +// title = "Vulkan Example - Dynamic uniform buffers" +// camera.type = Camera.CameraType.lookAt +// camera.setPosition(Vec3(0f, 0f, -30f)) +// camera.setRotation(Vec3(.0f)) +// camera.setPerspective(60f, size.aspect, 0.1f, 256f) +//// settings.overlay = true TODO +// } +// +// override fun destroy() { +// +// uboDataDynamic.model.free() +// +// /* Clean up used Vulkan resources +// Note : Inherited destructor cleans up resources stored in base class */ +// device.apply { +// destroyPipeline(pipeline) +// +// destroyPipelineLayout(pipelineLayout) +// destroyDescriptorSetLayout(descriptorSetLayout) +// } +// +// vertexBuffer.destroy() +// indexBuffer.destroy() +// +// uniformBuffers.view.destroy() +// uniformBuffers.dynamic.destroy() +// +// super.destroy() +// } +// +// override fun buildCommandBuffers() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(defaultClearColor) +// it[1].depthStencil(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@DynamicUniformBuffers.renderPass +// renderArea.apply { +// offset(0) +// extent(size) +// } +// this.clearValues = clearValues +// } +// +// for (i in drawCmdBuffers.indices) { +// +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// setViewport(size) +// setScissor(size) +// +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipeline) +// +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, vertexBuffer.buffer) +// bindIndexBuffer(indexBuffer.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// +// // Render multiple objects using different model matrices by dynamically offsetting into one uniform buffer +// repeat(OBJECT_INSTANCES) { +// // One dynamic offset per dynamic descriptor to offset into the ubo containing all model matrices +// val dynamicOffset = it * dynamicAlignment +// // Bind the descriptor set for rendering a mesh using the dynamic offset +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet, dynamicOffset.i) +// +// drawIndexed(indexCount, 1, 0, 0, 0) +// } +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// fun draw() { +// +// super.prepareFrame() +// +// // Command buffer to be submitted to the queue +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// +// // Submit to queue +// queue submit submitInfo +// +// super.submitFrame() +// } +// +// fun generateCube() = stak { +// // Setup vertices indices for a colored cube +// val vertices = it.floats( +// -1f, -1f, +1f, 1f, 0f, 0f, +// +1f, -1f, +1f, 0f, 1f, 0f, +// +1f, +1f, +1f, 0f, 0f, 1f, +// -1f, +1f, +1f, 0f, 0f, 0f, +// -1f, -1f, -1f, 1f, 0f, 0f, +// +1f, -1f, -1f, 0f, 1f, 0f, +// +1f, +1f, -1f, 0f, 0f, 1f, +// -1f, +1f, -1f, 0f, 0f, 0f) +// +// val indices = it.ints(0, 1, 2, 2, 3, 0, 1, 5, 6, 6, 2, 1, 7, 6, 5, 5, 4, 7, 4, 0, 3, 3, 7, 4, 4, 5, 1, 1, 0, 4, 3, 2, 6, 6, 7, 3) +// +// indexCount = indices.cap +// +// // Create buffers +// // For the sake of simplicity we won't stage the vertex data to the gpu memory +// val flags = VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT +// // Vertex buffer +// vulkanDevice.createBuffer(VkBufferUsage.VERTEX_BUFFER_BIT.i, flags, vertexBuffer, vertices) +// // Index buffer +// vulkanDevice.createBuffer(VkBufferUsage.INDEX_BUFFER_BIT.i, flags, indexBuffer, indices) +// } +// +// fun setupVertexDescriptions() { +// // Binding description +// vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, Vertex.size, VkVertexInputRate.VERTEX) +// +// // Attribute descriptions +// vertices.attributeDescriptions = vk.VertexInputAttributeDescription( +// // Location 0 : Position +// VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, Vertex.offsetPos, +// // Location 1 : Color +// VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32_SFLOAT, Vertex.offsetColor) +// +// vertices.inputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertices.bindingDescriptions +// vertexAttributeDescriptions = vertices.attributeDescriptions +// } +// } +// +// fun setupDescriptorPool() { +// // Example uses one ubo and one image sampler +// val poolSizes = vk.DescriptorPoolSize( +// VkDescriptorType.UNIFORM_BUFFER, 1, +// VkDescriptorType.UNIFORM_BUFFER_DYNAMIC, 1, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1) +// +// descriptorPool = device createDescriptorPool initializers.descriptorPoolCreateInfo(poolSizes, 2) +// } +// +// fun setupDescriptorSetLayout() { +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, +// VkDescriptorType.UNIFORM_BUFFER_DYNAMIC, VkShaderStage.VERTEX_BIT.i, 1, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 2) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo { bindings = setLayoutBindings } +// +// descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo { setLayout = descriptorSetLayout } +// +// pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// } +// +// fun setupDescriptorSet() { +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) +// +// descriptorSet = device allocateDescriptorSets allocInfo +// +// val writeDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0 : Projection/View matrix uniform buffer +// descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.view.descriptor, +// // Binding 1 : Instance matrix as dynamic uniform buffer +// descriptorSet, VkDescriptorType.UNIFORM_BUFFER_DYNAMIC, 1, uniformBuffers.dynamic.descriptor) +// +// device updateDescriptorSets writeDescriptorSets +// } +// +// fun preparePipelines() { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.COUNTER_CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(rasterizationSamples = VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// // Load shaders +// val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { +// it[0].loadShader("$assetPath/shaders/dynamicuniformbuffer/base.vert.spv", VkShaderStage.VERTEX_BIT) +// it[1].loadShader("$assetPath/shaders/dynamicuniformbuffer/base.frag.spv", VkShaderStage.FRAGMENT_BIT) +// } +// +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { +// it.vertexInputState = vertices.inputState +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// } +// +// pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// +// /** Prepare and initialize uniform buffer containing shader uniforms */ +// fun prepareUniformBuffers() { +// /* Allocate data for the dynamic uniform buffer object +// We allocate this manually as the alignment of the offset differs between GPUs */ +// +// // Calculate required alignment based on minimum device offset alignment +// val minUboAlignment = vulkanDevice.properties.limits.minUniformBufferOffsetAlignment +// dynamicAlignment = Mat4.size.L +// if (minUboAlignment > 0) +// dynamicAlignment = (dynamicAlignment + minUboAlignment - 1) and (minUboAlignment - 1).inv() +// +// val bufferSize = VkDeviceSize(OBJECT_INSTANCES * dynamicAlignment) +// +// uboDataDynamic.model = bufferBig(bufferSize).apply { uboDataDynamic.address = adr } +// +// println("minUniformBufferOffsetAlignment = $minUboAlignment") +// println("dynamicAlignment = $dynamicAlignment") +// +// // Vertex shader uniform buffer block +// +// // Static shared uniform buffer object with projection and view matrix +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBuffers.view, +// VkDeviceSize(uboVS.size.L)) +// +// // Uniform buffer object with per-object matrices +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT.i, +// uniformBuffers.dynamic, +// bufferSize) +// +// // Map persistent +// uniformBuffers.view.map() +// uniformBuffers.dynamic.map() +// +// // Prepare per-object matrices with offsets and random rotations +// repeat(OBJECT_INSTANCES) { +// rotations[it] = Vec3 { glm.gaussRand(-1f, 1f) } * 2f * glm.PIf +// rotationSpeeds[it] = Vec3 { glm.gaussRand(-1f, 1f) } +// } +// +// updateUniformBuffers() +// updateDynamicUniformBuffer(true) +// } +// +// fun updateUniformBuffers() { +// // Fixed ubo with projection and view matrices +// uboVS.projection put camera.matrices.perspective +// uboVS.view put camera.matrices.view +// +// uboVS to uniformBuffers.view.mapped +// } +// +// fun updateDynamicUniformBuffer(force: Boolean = false) { +// // Update at max. 60 fps +// animationTimer += frameTimer +// if (animationTimer <= 1f / 60f && !force) return +// +// // Dynamic ubo with per-object model matrices indexed by offsets in the command buffer +// val dim = OBJECT_INSTANCES pow (1f / 3f) +// val offset = Vec3(5f) +// +// for (x in 0 until dim) +// for (y in 0 until dim) +// for (z in 0 until dim) { +// val index = x * dim * dim + y * dim + z +// +// // Update rotations +// rotations[index] plusAssign animationTimer * rotationSpeeds[index] +// +// // Update matrices +// val pos = -((dim * offset) / 2f) + offset / 2f +// pos.x += x * offset.x +// pos.y += y * offset.y +// pos.z += z * offset.z +// val modelMat = glm.translate(Mat4(1f), pos) +// .rotateAssign(rotations[index].x, 1f, 1f, 0f) +// .rotateAssign(rotations[index].y, 0f, 1f, 0f) +// .rotateAssign(rotations[index].z, 0f, 0f, 1f) +// // Aligned offset +// modelMat.to(uboDataDynamic.model, index * dynamicAlignment.i) +// } +// +// animationTimer = 0f +// +// memCopy(uboDataDynamic.address, uniformBuffers.dynamic.mapped, uniformBuffers.dynamic.size) +// // Flush to make changes visible to the host +// val memoryRange = vk.MappedMemoryRange { +// memory = uniformBuffers.dynamic.memory +// size = uniformBuffers.dynamic.size +// } +// device flushMappedMemoryRanges memoryRange +// } +// +// override fun prepare() { +// super.prepare() +// generateCube() +// setupVertexDescriptions() +// prepareUniformBuffers() +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSet() +// buildCommandBuffers() +// prepared = true +// window.show() +// } +// +// override fun render() { +// if (!prepared) +// return +// draw() +// if (!paused) +// updateDynamicUniformBuffer() +// } +// +// override fun viewChanged() = updateUniformBuffers() +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/basics/05 Push Constants.kt b/src/main/kotlin/vulkan/basics/05 Push Constants.kt index 3290919..73ff4b3 100644 --- a/src/main/kotlin/vulkan/basics/05 Push Constants.kt +++ b/src/main/kotlin/vulkan/basics/05 Push Constants.kt @@ -1,366 +1,366 @@ -/* -* Vulkan Example - Push constants example (small shader block accessed outside of uniforms for fast updates) -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -package vulkan.basics - -import glm_.L -import glm_.buffer.bufferBig -import glm_.func.rad -import glm_.glm -import glm_.mat4x4.Mat4 -import glm_.size -import glm_.vec2.Vec2 -import glm_.vec3.Vec3 -import glm_.vec4.Vec4 -import org.lwjgl.system.MemoryUtil.NULL -import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo -import org.lwjgl.vulkan.VkVertexInputAttributeDescription -import org.lwjgl.vulkan.VkVertexInputBindingDescription -import vkk.* -import vulkan.VERTEX_BUFFER_BIND_ID -import vulkan.assetPath -import vulkan.base.* -import kotlin.math.cos -import kotlin.math.sin - - -fun main(args: Array) { - PushConstants().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - - -private class PushConstants : VulkanExampleBase() { - - object vertices { - lateinit var inputState: VkPipelineVertexInputStateCreateInfo - lateinit var bindingDescriptions: VkVertexInputBindingDescription - lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer - } - - // Vertex layout for the models - val vertexLayout = VertexLayout( - VertexComponent.POSITION, - VertexComponent.NORMAL, - VertexComponent.UV, - VertexComponent.COLOR) - - object models { - val scene = Model() - } - - val uniformBuffer = Buffer() - - object uboVS: Bufferizable() { - - lateinit var projection: Mat4 - @Order(1) - lateinit var model: Mat4 - @Order(2) - val lightPos = Vec4(0f, 0, -2f, 1) - } - - object pipelines { - var solid: VkPipeline = NULL - } - - var pipelineLayout: VkPipelineLayout = NULL - var descriptorSet: VkDescriptorSet = NULL - var descriptorSetLayout: VkDescriptorSetLayout = NULL - - // This array holds the light positions and will be updated via a push constant - val pushConstants = bufferBig(Vec4.size * 6) - - init { - zoom = -30f - zoomSpeed = 2.5f - rotationSpeed = 0.5f - timerSpeed *= 0.5f - rotation(-32.5f, 45f, 0f) - title = "Push constants" -// settings.overlay = true - } - - override fun destroy() { - - device.apply { - // Clean up used Vulkan resources - // Note : Inherited destructor cleans up resources stored in base class - destroyPipeline(pipelines.solid) - - destroyPipelineLayout(pipelineLayout) - destroyDescriptorSetLayout(descriptorSetLayout) - } - models.scene.destroy() - - uniformBuffer.destroy() - - super.destroy() - } - - fun reBuildCommandBuffers() { - if (!checkCommandBuffers()) { - destroyCommandBuffers() - createCommandBuffers() - } - buildCommandBuffers() - } - - override fun buildCommandBuffers() { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(defaultClearColor) - it[1].depthStencil(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@PushConstants.renderPass - renderArea.apply { - offset(0) - extent(size) - } - this.clearValues = clearValues - } - for (i in drawCmdBuffers.indices) { - - // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - setViewport(size) - setScissor(size) - - // Update light positions - // w component = light radius scale - val r = 7.5f - val sinT = sin((timer * 360).rad) - val cosT = cos((timer * 360).rad) - val y = -4f - Vec4(r * 1.1 * sinT, y, r * 1.1 * cosT, 1f) to pushConstants - Vec4(-r * sinT, y, -r * cosT, 1f).to(pushConstants, Vec4.size) - Vec4(r * 0.85f * sinT, y, -sinT * 2.5f, 1.5f).to(pushConstants, Vec4.size * 2) - Vec4(0f, y, r * 1.25f * cosT, 1.5f).to(pushConstants, Vec4.size * 3) - Vec4(r * 2.25f * cosT, y, 0f, 1.25f).to(pushConstants, Vec4.size * 4) - Vec4(r * 2.5f * cosT, y, r * 2.5f * sinT, 1.25f).to(pushConstants, Vec4.size * 5) - - // Submit via push constant (rather than a UBO) - pushConstants( - pipelineLayout, - VkShaderStage.VERTEX_BIT.i, - 0, - pushConstants) - - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.solid) - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) - - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.scene.vertices.buffer) - bindIndexBuffer(models.scene.indices.buffer, 0, VkIndexType.UINT32) - - drawIndexed(models.scene.indexCount, 1, 0, 0, 0) - - endRenderPass() - - end() - } - } - } - - fun loadAssets() { - models.scene.loadFromFile("$assetPath/models/samplescene.dae", vertexLayout, 0.35f, vulkanDevice, queue) - } - - fun setupVertexDescriptions() { - // Binding description - vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, vertexLayout.stride, VkVertexInputRate.VERTEX) - - // Attribute descriptions - // Describes memory layout and shader positions - vertices.attributeDescriptions = vk.VertexInputAttributeDescription( - // Location 0 : Position - VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, 0, - // Location 1 : Normal - VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32_SFLOAT, Vec3.size, - // Location 2 : Texture coordinates - VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32G32_SFLOAT, Vec3.size * 2, - // Location 3 : Color - VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2 + Vec2.size) - - vertices.inputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertices.bindingDescriptions - vertexAttributeDescriptions = vertices.attributeDescriptions - } - } - - fun setupDescriptorPool() { - // Example uses one ubo - val poolSizes = vk.DescriptorPoolSize(VkDescriptorType.UNIFORM_BUFFER, 1) - - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) - - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - // Binding 0 : Vertex shader uniform buffer - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - - descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) - - /* Define push constant - Example uses six light positions as push constants - 6 * 4 * 4 = 96 bytes - Spec requires a minimum of 128 bytes, bigger values need to be checked against maxPushConstantsSize - But even at only 128 bytes, lots of stuff can fit inside push constants */ - val pushConstantRange = vk.PushConstantRange(VkShaderStage.VERTEX_BIT.i, pushConstants.size, 0) - - // Push constant ranges are part of the pipeline layout - pipelineLayoutCreateInfo.pushConstantRange = pushConstantRange - - pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - } - - fun setupDescriptorSet() { - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) - - descriptorSet = device allocateDescriptorSets allocInfo - - // Binding 0 : Vertex shader uniform buffer - val writeDescriptorSet = vk.WriteDescriptorSet(descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffer.descriptor) - - device updateDescriptorSets writeDescriptorSet - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.BACK_BIT.i, VkFrontFace.CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - // Solid rendering pipeline - // Load shaders - val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { - it[0].loadShader("$assetPath/shaders/pushconstants/lights.vert.spv", VkShaderStage.VERTEX_BIT) - it[1].loadShader("$assetPath/shaders/pushconstants/lights.frag.spv", VkShaderStage.FRAGMENT_BIT) - } - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { - it.vertexInputState = vertices.inputState - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - } - pipelines.solid = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - fun prepareUniformBuffers() { - // Vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBuffer, - uboVS.size.L) - - // Map persistent - uniformBuffer.map() - - updateUniformBuffers() - } - - fun updateUniformBuffers() { - // Vertex shader - var viewMatrix = Mat4(1f) - uboVS.projection = glm.perspective(60f.rad, size.aspect, 0.001f, 256f) - viewMatrix = glm.translate(viewMatrix, 0f, 2f, zoom) - - uboVS.model = viewMatrix * glm.translate(Mat4(1f), Vec3()) - .rotateAssign(rotation.x.rad, 1f, 0f, 0f) - .rotateAssign(rotation.y.rad, 0f, 1f, 0f) - .rotateAssign(rotation.z.rad, 0f, 0f, 1f) - - uboVS to uniformBuffer.mapped - } - - fun draw() { - - super.prepareFrame() - - // Command buffer to be sumitted to the queue - submitInfo.commandBuffer = drawCmdBuffers [currentBuffer] - - // Submit to queue - queue submit submitInfo - - super.submitFrame() - } - - override fun prepare() { - - super.prepare() - - // Check requested push constant size against hardware limit - // Specs require 128 bytes, so if the device complies our push constant buffer should always fit into memory - assert(pushConstants.size <= vulkanDevice.properties.limits.maxPushConstantsSize) - - loadAssets() - setupVertexDescriptions() - prepareUniformBuffers() - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSet() - buildCommandBuffers() - prepared = true - window.show() - } - - override fun render() - { - if (!prepared) - return - draw() - if (!paused) - reBuildCommandBuffers() - } - - override fun viewChanged() = updateUniformBuffers() -} \ No newline at end of file +///* +//* Vulkan Example - Push constants example (small shader block accessed outside of uniforms for fast updates) +//* +//* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +//package vulkan.basics +// +//import glm_.L +//import glm_.func.rad +//import glm_.glm +//import glm_.mat4x4.Mat4 +//import glm_.size +//import glm_.vec2.Vec2 +//import glm_.vec3.Vec3 +//import glm_.vec4.Vec4 +//import kool.bufferBig +//import org.lwjgl.system.MemoryUtil.NULL +//import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo +//import org.lwjgl.vulkan.VkVertexInputAttributeDescription +//import org.lwjgl.vulkan.VkVertexInputBindingDescription +//import vkk.* +//import vulkan.VERTEX_BUFFER_BIND_ID +//import vulkan.assetPath +//import vulkan.base.* +//import kotlin.math.cos +//import kotlin.math.sin +// +// +//fun main(args: Array) { +// PushConstants().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +// +//private class PushConstants : VulkanExampleBase() { +// +// object vertices { +// lateinit var inputState: VkPipelineVertexInputStateCreateInfo +// lateinit var bindingDescriptions: VkVertexInputBindingDescription +// lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer +// } +// +// // Vertex layout for the models +// val vertexLayout = VertexLayout( +// VertexComponent.POSITION, +// VertexComponent.NORMAL, +// VertexComponent.UV, +// VertexComponent.COLOR) +// +// object models { +// val scene = Model() +// } +// +// val uniformBuffer = Buffer() +// +// object uboVS: Bufferizable() { +// +// lateinit var projection: Mat4 +// @Order(1) +// lateinit var model: Mat4 +// @Order(2) +// val lightPos = Vec4(0f, 0, -2f, 1) +// } +// +// object pipelines { +// var solid = VkPipeline (NULL) +// } +// +// var pipelineLayout = VkPipelineLayout(NULL) +// var descriptorSet= VkDescriptorSet (NULL) +// var descriptorSetLayout= VkDescriptorSetLayout (NULL) +// +// // This array holds the light positions and will be updated via a push constant +// val pushConstants = bufferBig(Vec4.size * 6) +// +// init { +// zoom = -30f +// zoomSpeed = 2.5f +// rotationSpeed = 0.5f +// timerSpeed *= 0.5f +// rotation(-32.5f, 45f, 0f) +// title = "Push constants" +//// settings.overlay = true +// } +// +// override fun destroy() { +// +// device.apply { +// // Clean up used Vulkan resources +// // Note : Inherited destructor cleans up resources stored in base class +// destroyPipeline(pipelines.solid) +// +// destroyPipelineLayout(pipelineLayout) +// destroyDescriptorSetLayout(descriptorSetLayout) +// } +// models.scene.destroy() +// +// uniformBuffer.destroy() +// +// super.destroy() +// } +// +// fun reBuildCommandBuffers() { +// if (!checkCommandBuffers()) { +// destroyCommandBuffers() +// createCommandBuffers() +// } +// buildCommandBuffers() +// } +// +// override fun buildCommandBuffers() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(defaultClearColor) +// it[1].depthStencil(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@PushConstants.renderPass +// renderArea.apply { +// offset(0) +// extent(size) +// } +// this.clearValues = clearValues +// } +// for (i in drawCmdBuffers.indices) { +// +// // Set target frame buffer +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// setViewport(size) +// setScissor(size) +// +// // Update light positions +// // w component = light radius scale +// val r = 7.5f +// val sinT = sin((timer * 360).rad) +// val cosT = cos((timer * 360).rad) +// val y = -4f +// Vec4(r * 1.1 * sinT, y, r * 1.1 * cosT, 1f) to pushConstants +// Vec4(-r * sinT, y, -r * cosT, 1f).to(pushConstants, Vec4.size) +// Vec4(r * 0.85f * sinT, y, -sinT * 2.5f, 1.5f).to(pushConstants, Vec4.size * 2) +// Vec4(0f, y, r * 1.25f * cosT, 1.5f).to(pushConstants, Vec4.size * 3) +// Vec4(r * 2.25f * cosT, y, 0f, 1.25f).to(pushConstants, Vec4.size * 4) +// Vec4(r * 2.5f * cosT, y, r * 2.5f * sinT, 1.25f).to(pushConstants, Vec4.size * 5) +// +// // Submit via push constant (rather than a UBO) +// pushConstants( +// pipelineLayout, +// VkShaderStage.VERTEX_BIT.i, +// 0, +// pushConstants) +// +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.solid) +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) +// +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.scene.vertices.buffer) +// bindIndexBuffer(models.scene.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// +// drawIndexed(models.scene.indexCount, 1, 0, 0, 0) +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// fun loadAssets() { +// models.scene.loadFromFile("$assetPath/models/samplescene.dae", vertexLayout, 0.35f, vulkanDevice, queue) +// } +// +// fun setupVertexDescriptions() { +// // Binding description +// vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, vertexLayout.stride, VkVertexInputRate.VERTEX) +// +// // Attribute descriptions +// // Describes memory layout and shader positions +// vertices.attributeDescriptions = vk.VertexInputAttributeDescription( +// // Location 0 : Position +// VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, 0, +// // Location 1 : Normal +// VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32_SFLOAT, Vec3.size, +// // Location 2 : Texture coordinates +// VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32G32_SFLOAT, Vec3.size * 2, +// // Location 3 : Color +// VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2 + Vec2.size) +// +// vertices.inputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertices.bindingDescriptions +// vertexAttributeDescriptions = vertices.attributeDescriptions +// } +// } +// +// fun setupDescriptorPool() { +// // Example uses one ubo +// val poolSizes = vk.DescriptorPoolSize(VkDescriptorType.UNIFORM_BUFFER, 1) +// +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) +// +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// // Binding 0 : Vertex shader uniform buffer +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// +// descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) +// +// /* Define push constant +// Example uses six light positions as push constants +// 6 * 4 * 4 = 96 bytes +// Spec requires a minimum of 128 bytes, bigger values need to be checked against maxPushConstantsSize +// But even at only 128 bytes, lots of stuff can fit inside push constants */ +// val pushConstantRange = vk.PushConstantRange(VkShaderStage.VERTEX_BIT.i, pushConstants.size, 0) +// +// // Push constant ranges are part of the pipeline layout +// pipelineLayoutCreateInfo.pushConstantRange = pushConstantRange +// +// pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// } +// +// fun setupDescriptorSet() { +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) +// +// descriptorSet = device allocateDescriptorSets allocInfo +// +// // Binding 0 : Vertex shader uniform buffer +// val writeDescriptorSet = vk.WriteDescriptorSet(descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffer.descriptor) +// +// device updateDescriptorSets writeDescriptorSet +// } +// +// fun preparePipelines() { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.BACK_BIT.i, VkFrontFace.CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// // Solid rendering pipeline +// // Load shaders +// val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { +// it[0].loadShader("$assetPath/shaders/pushconstants/lights.vert.spv", VkShaderStage.VERTEX_BIT) +// it[1].loadShader("$assetPath/shaders/pushconstants/lights.frag.spv", VkShaderStage.FRAGMENT_BIT) +// } +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { +// it.vertexInputState = vertices.inputState +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// } +// pipelines.solid = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// +// fun prepareUniformBuffers() { +// // Vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBuffer, +// VkDeviceSize(uboVS.size.L)) +// +// // Map persistent +// uniformBuffer.map() +// +// updateUniformBuffers() +// } +// +// fun updateUniformBuffers() { +// // Vertex shader +// var viewMatrix = Mat4(1f) +// uboVS.projection = glm.perspective(60f.rad, size.aspect, 0.001f, 256f) +// viewMatrix = glm.translate(viewMatrix, 0f, 2f, zoom) +// +// uboVS.model = viewMatrix * glm.translate(Mat4(1f), Vec3()) +// .rotateAssign(rotation.x.rad, 1f, 0f, 0f) +// .rotateAssign(rotation.y.rad, 0f, 1f, 0f) +// .rotateAssign(rotation.z.rad, 0f, 0f, 1f) +// +// uboVS to uniformBuffer.mapped +// } +// +// fun draw() { +// +// super.prepareFrame() +// +// // Command buffer to be sumitted to the queue +// submitInfo.commandBuffer = drawCmdBuffers [currentBuffer] +// +// // Submit to queue +// queue submit submitInfo +// +// super.submitFrame() +// } +// +// override fun prepare() { +// +// super.prepare() +// +// // Check requested push constant size against hardware limit +// // Specs require 128 bytes, so if the device complies our push constant buffer should always fit into memory +// assert(pushConstants.size <= vulkanDevice.properties.limits.maxPushConstantsSize) +// +// loadAssets() +// setupVertexDescriptions() +// prepareUniformBuffers() +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSet() +// buildCommandBuffers() +// prepared = true +// window.show() +// } +// +// override fun render() +// { +// if (!prepared) +// return +// draw() +// if (!paused) +// reBuildCommandBuffers() +// } +// +// override fun viewChanged() = updateUniformBuffers() +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/basics/06 Specialization Constants.kt b/src/main/kotlin/vulkan/basics/06 Specialization Constants.kt index d5603ca..ba533e2 100644 --- a/src/main/kotlin/vulkan/basics/06 Specialization Constants.kt +++ b/src/main/kotlin/vulkan/basics/06 Specialization Constants.kt @@ -1,379 +1,379 @@ -/* -* Vulkan Example - Shader specialization constants -* -* For details see https://www.khronos.org/registry/vulkan/specs/misc/GL_KHR_vulkan_glsl.txt -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -package vulkan.basics - -import ab.appBuffer -import glm_.BYTES -import glm_.L -import glm_.mat4x4.Mat4 -import glm_.vec2.Vec2 -import glm_.vec3.Vec3 -import glm_.vec4.Vec4 -import org.lwjgl.system.MemoryUtil.NULL -import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo -import org.lwjgl.vulkan.VkVertexInputAttributeDescription -import org.lwjgl.vulkan.VkVertexInputBindingDescription -import vkk.* -import vulkan.VERTEX_BUFFER_BIND_ID -import vulkan.assetPath -import vulkan.base.* - - -fun main(args: Array) { - SpecializationConstants().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - - -class SpecializationConstants : VulkanExampleBase() { - - object vertices { - lateinit var inputState: VkPipelineVertexInputStateCreateInfo - lateinit var bindingDescriptions: VkVertexInputBindingDescription - lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer - } - - // Vertex layout for the models - val vertexLayout = VertexLayout( - VertexComponent.POSITION, - VertexComponent.NORMAL, - VertexComponent.UV, - VertexComponent.COLOR) - - object models { - val cube = Model() - } - - object textures { - val colormap = Texture2D() - } - - val uniformBuffer = Buffer() - - // Same uniform buffer layout as shader - object uboVS : Bufferizable() { - - lateinit var projection: Mat4 - @Order(1) - lateinit var modelView: Mat4 - @Order(2) - val lightPos = Vec4(0f, -2f, 1f, 0f) - } - - var pipelineLayout: VkPipelineLayout = NULL - var descriptorSet: VkDescriptorSet = NULL - var descriptorSetLayout: VkDescriptorSetLayout = NULL - - object pipelines { - var phong: VkPipeline = NULL - var toon: VkPipeline = NULL - var textured: VkPipeline = NULL - } - - init { - title = "Specialization constants" - camera.type = Camera.CameraType.lookAt - camera.setPerspective(60f, (size.x / 3f) / size.y, 0.1f, 512f) - camera.setRotation(Vec3(-40f, -90f, 0f)) - camera.setTranslation(Vec3(0f, 0f, -2f)) - settings.overlay = false // TODO - } - - override fun destroy() { - device.apply { - destroyPipeline(pipelines.phong) - destroyPipeline(pipelines.textured) - destroyPipeline(pipelines.toon) - - destroyPipelineLayout(pipelineLayout) - destroyDescriptorSetLayout(descriptorSetLayout) - } - models.cube.destroy() - textures.colormap.destroy() - uniformBuffer.destroy() - - super.destroy() - } - - override fun buildCommandBuffers() { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(defaultClearColor) - it[1].depthStencil(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@SpecializationConstants.renderPass - renderArea.apply { - offset(0) - extent(size) - } - this.clearValues = clearValues - } - for (i in drawCmdBuffers.indices) { - // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - val viewport = vk.Viewport(size) - setViewport(viewport) - setScissor(size) - - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) - - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.cube.vertices.buffer) - bindIndexBuffer(models.cube.indices.buffer, 0, VkIndexType.UINT32) - - // Left - viewport.width = size.x / 3f - setViewport(viewport) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.phong) - - drawIndexed(models.cube.indexCount, 1, 0, 0, 0) - - // Center - viewport.x = size.x / 3f - setViewport(viewport) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.toon) - drawIndexed(models.cube.indexCount, 1, 0, 0, 0) - - // Right - viewport.x = size.x / 3f + size.x / 3f - setViewport(viewport) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.textured) - drawIndexed(models.cube.indexCount, 1, 0, 0, 0) - - endRenderPass() - - end() - } - } - } - - fun loadAssets() { - models.cube.loadFromFile("$assetPath/models/color_teapot_spheres.dae", vertexLayout, 0.1f, vulkanDevice, queue) - textures.colormap.loadFromFile("$assetPath/textures/metalplate_nomips_rgba.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) - } - - fun setupVertexDescriptions() { - // Binding description - vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, vertexLayout.stride, VkVertexInputRate.VERTEX) - - // Attribute descriptions - vertices.attributeDescriptions = vk.VertexInputAttributeDescription( - // Location 0 : Position - VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, 0, - // Location 1 : Color - VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32_SFLOAT, Vec3.size, - // Location 3 : Texture coordinates - VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32G32_SFLOAT, Vec3.size * 2, - // Location 2 : Normal - VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2 + Vec2.size) - - vertices.inputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertices.bindingDescriptions - vertexAttributeDescriptions = vertices.attributeDescriptions - } - } - - fun setupDescriptorPool() { - - val poolSizes = vk.DescriptorPoolSize( - VkDescriptorType.UNIFORM_BUFFER, 1, - VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1) - - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 1) - - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - - descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) - - pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - } - - fun setupDescriptorSet() { - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) - - descriptorSet = device allocateDescriptorSets allocInfo - - val writeDescriptorSets = vk.WriteDescriptorSet( - descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffer.descriptor, - descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textures.colormap.descriptor) - - device updateDescriptorSets writeDescriptorSets - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR, VkDynamicState.LINE_WIDTH) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - val shaderStages = vk.PipelineShaderStageCreateInfo(2) - - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { - it.vertexInputState = vertices.inputState - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - } - // Prepare specialization data - - // Host data to take specialization constants from - val specializationData = appBuffer.buffer(Int.BYTES + Float.BYTES).apply { - putFloat(Int.BYTES, 0.5f) - } -// { -// // Sets the lighting model used in the fragment "uber" shader -// uint32_t lightingModel -// // Parameter for the toon shading part of the fragment shader -// float toonDesaturationFactor = 0.5f +///* +//* Vulkan Example - Shader specialization constants +//* +//* For details see https://www.khronos.org/registry/vulkan/specs/misc/GL_KHR_vulkan_glsl.txt +//* +//* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +//package vulkan.basics +// +//import glm_.BYTES +//import glm_.L +//import glm_.mat4x4.Mat4 +//import glm_.vec2.Vec2 +//import glm_.vec3.Vec3 +//import glm_.vec4.Vec4 +//import kool.stak +//import org.lwjgl.system.MemoryUtil.NULL +//import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo +//import org.lwjgl.vulkan.VkVertexInputAttributeDescription +//import org.lwjgl.vulkan.VkVertexInputBindingDescription +//import vkk.* +//import vulkan.VERTEX_BUFFER_BIND_ID +//import vulkan.assetPath +//import vulkan.base.* +// +// +//fun main(args: Array) { +// SpecializationConstants().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +// +//class SpecializationConstants : VulkanExampleBase() { +// +// object vertices { +// lateinit var inputState: VkPipelineVertexInputStateCreateInfo +// lateinit var bindingDescriptions: VkVertexInputBindingDescription +// lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer +// } +// +// // Vertex layout for the models +// val vertexLayout = VertexLayout( +// VertexComponent.POSITION, +// VertexComponent.NORMAL, +// VertexComponent.UV, +// VertexComponent.COLOR) +// +// object models { +// val cube = Model() +// } +// +// object textures { +// val colormap = Texture2D() +// } +// +// val uniformBuffer = Buffer() +// +// // Same uniform buffer layout as shader +// object uboVS : Bufferizable() { +// +// lateinit var projection: Mat4 +// @Order(1) +// lateinit var modelView: Mat4 +// @Order(2) +// val lightPos = Vec4(0f, -2f, 1f, 0f) +// } +// +// var pipelineLayout = VkPipelineLayout (NULL) +// var descriptorSet= VkDescriptorSet (NULL) +// var descriptorSetLayout= VkDescriptorSetLayout (NULL) +// +// object pipelines { +// var phong= VkPipeline (NULL) +// var toon= VkPipeline (NULL) +// var textured = VkPipeline(NULL) +// } +// +// init { +// title = "Specialization constants" +// camera.type = Camera.CameraType.lookAt +// camera.setPerspective(60f, (size.x / 3f) / size.y, 0.1f, 512f) +// camera.setRotation(Vec3(-40f, -90f, 0f)) +// camera.setTranslation(Vec3(0f, 0f, -2f)) +// settings.overlay = false // TODO +// } +// +// override fun destroy() { +// device.apply { +// destroyPipeline(pipelines.phong) +// destroyPipeline(pipelines.textured) +// destroyPipeline(pipelines.toon) +// +// destroyPipelineLayout(pipelineLayout) +// destroyDescriptorSetLayout(descriptorSetLayout) // } - - // Each shader constant of a shader stage corresponds to one map entry - val specializationMapEntries = vk.SpecializationMapEntry(2).also { - // Shader bindings based on specialization constants are marked by the new "constant_id" layout qualifier: - // layout (constant_id = 0) const int LIGHTING_MODEL = 0; - // layout (constant_id = 1) const float PARAM_TOON_DESATURATION = 0.0f; - - // Map entry for the lighting model to be used by the fragment shader - it[0].apply { - constantId = 0 - size = Int.BYTES.L - offset = 0 - } - // Map entry for the toon shader parameter - it[1].apply { - constantId = 1 - size = Float.BYTES.L - offset = Int.BYTES - } - } - // Prepare specialization info block for the shader stage - val specializationInfo = vk.SpecializationInfo { - mapEntries = specializationMapEntries - data = specializationData - } - // Create pipelines - // All pipelines will use the same "uber" shader and specialization constants to change branching and parameters of that shader - shaderStages[0].loadShader("$assetPath/shaders/specializationconstants/uber.vert.spv", VkShaderStage.VERTEX_BIT) - shaderStages[1].loadShader("$assetPath/shaders/specializationconstants/uber.frag.spv", VkShaderStage.FRAGMENT_BIT) - // Specialization info is assigned is part of the shader stage (modul) and must be set after creating the module and before creating the pipeline - shaderStages[1].specializationInfo = specializationInfo - - // Solid phong shading - specializationData.putInt(0, 0) - pipelines.phong = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - - // Phong and textured - specializationData.putInt(0, 1) - pipelines.toon = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - - // Textured discard - specializationData.putInt(0, 2) - pipelines.textured = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - // Prepare and initialize uniform buffer containing shader uniforms - fun prepareUniformBuffers() { - // Create the vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBuffer, - uboVS.size.L) - - // Map persistent - uniformBuffer.map() - - updateUniformBuffers() - } - - fun updateUniformBuffers() { - uboVS.projection = camera.matrices.perspective - uboVS.modelView = camera.matrices.view - - uboVS to uniformBuffer.mapped - } - - fun draw() { - - super.prepareFrame() - - submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] - queue submit submitInfo - - super.submitFrame() - } - - override fun prepare() { - super.prepare() - loadAssets() - setupVertexDescriptions() - prepareUniformBuffers() - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSet() - buildCommandBuffers() - prepared = true - window.show() - } - - override fun render() { - if (!prepared) - return - draw() - } - - override fun viewChanged() = updateUniformBuffers() -} \ No newline at end of file +// models.cube.destroy() +// textures.colormap.destroy() +// uniformBuffer.destroy() +// +// super.destroy() +// } +// +// override fun buildCommandBuffers() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(defaultClearColor) +// it[1].depthStencil(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@SpecializationConstants.renderPass +// renderArea.apply { +// offset(0) +// extent(size) +// } +// this.clearValues = clearValues +// } +// for (i in drawCmdBuffers.indices) { +// // Set target frame buffer +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// val viewport = vk.Viewport(size) +// setViewport(viewport) +// setScissor(size) +// +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) +// +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.cube.vertices.buffer) +// bindIndexBuffer(models.cube.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// +// // Left +// viewport.width = size.x / 3f +// setViewport(viewport) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.phong) +// +// drawIndexed(models.cube.indexCount, 1, 0, 0, 0) +// +// // Center +// viewport.x = size.x / 3f +// setViewport(viewport) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.toon) +// drawIndexed(models.cube.indexCount, 1, 0, 0, 0) +// +// // Right +// viewport.x = size.x / 3f + size.x / 3f +// setViewport(viewport) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.textured) +// drawIndexed(models.cube.indexCount, 1, 0, 0, 0) +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// fun loadAssets() { +// models.cube.loadFromFile("$assetPath/models/color_teapot_spheres.dae", vertexLayout, 0.1f, vulkanDevice, queue) +// textures.colormap.loadFromFile("$assetPath/textures/metalplate_nomips_rgba.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) +// } +// +// fun setupVertexDescriptions() { +// // Binding description +// vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, vertexLayout.stride, VkVertexInputRate.VERTEX) +// +// // Attribute descriptions +// vertices.attributeDescriptions = vk.VertexInputAttributeDescription( +// // Location 0 : Position +// VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, 0, +// // Location 1 : Color +// VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32_SFLOAT, Vec3.size, +// // Location 3 : Texture coordinates +// VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32G32_SFLOAT, Vec3.size * 2, +// // Location 2 : Normal +// VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2 + Vec2.size) +// +// vertices.inputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertices.bindingDescriptions +// vertexAttributeDescriptions = vertices.attributeDescriptions +// } +// } +// +// fun setupDescriptorPool() { +// +// val poolSizes = vk.DescriptorPoolSize( +// VkDescriptorType.UNIFORM_BUFFER, 1, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1) +// +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 1) +// +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// +// descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) +// +// pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// } +// +// fun setupDescriptorSet() { +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) +// +// descriptorSet = device allocateDescriptorSets allocInfo +// +// val writeDescriptorSets = vk.WriteDescriptorSet( +// descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffer.descriptor, +// descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textures.colormap.descriptor) +// +// device updateDescriptorSets writeDescriptorSets +// } +// +// fun preparePipelines() = stak { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR, VkDynamicState.LINE_WIDTH) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// val shaderStages = vk.PipelineShaderStageCreateInfo(2) +// +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { +// it.vertexInputState = vertices.inputState +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// } +// // Prepare specialization data +// +// // Host data to take specialization constants from +// val specializationData = it.malloc(Int.BYTES + Float.BYTES).apply { +// putFloat(Int.BYTES, 0.5f) +// } +//// { +//// // Sets the lighting model used in the fragment "uber" shader +//// uint32_t lightingModel +//// // Parameter for the toon shading part of the fragment shader +//// float toonDesaturationFactor = 0.5f +//// } +// +// // Each shader constant of a shader stage corresponds to one map entry +// val specializationMapEntries = vk.SpecializationMapEntry(2).also { +// // Shader bindings based on specialization constants are marked by the new "constant_id" layout qualifier: +// // layout (constant_id = 0) const int LIGHTING_MODEL = 0; +// // layout (constant_id = 1) const float PARAM_TOON_DESATURATION = 0.0f; +// +// // Map entry for the lighting model to be used by the fragment shader +// it[0].apply { +// constantId = 0 +// size = Int.BYTES.L +// offset = 0 +// } +// // Map entry for the toon shader parameter +// it[1].apply { +// constantId = 1 +// size = Float.BYTES.L +// offset = Int.BYTES +// } +// } +// // Prepare specialization info block for the shader stage +// val specializationInfo = vk.SpecializationInfo { +// mapEntries = specializationMapEntries +// data = specializationData +// } +// // Create pipelines +// // All pipelines will use the same "uber" shader and specialization constants to change branching and parameters of that shader +// shaderStages[0].loadShader("$assetPath/shaders/specializationconstants/uber.vert.spv", VkShaderStage.VERTEX_BIT) +// shaderStages[1].loadShader("$assetPath/shaders/specializationconstants/uber.frag.spv", VkShaderStage.FRAGMENT_BIT) +// // Specialization info is assigned is part of the shader stage (modul) and must be set after creating the module and before creating the pipeline +// shaderStages[1].specializationInfo = specializationInfo +// +// // Solid phong shading +// specializationData.putInt(0, 0) +// pipelines.phong = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// +// // Phong and textured +// specializationData.putInt(0, 1) +// pipelines.toon = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// +// // Textured discard +// specializationData.putInt(0, 2) +// pipelines.textured = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// +// // Prepare and initialize uniform buffer containing shader uniforms +// fun prepareUniformBuffers() { +// // Create the vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBuffer, +// VkDeviceSize(uboVS.size.L)) +// +// // Map persistent +// uniformBuffer.map() +// +// updateUniformBuffers() +// } +// +// fun updateUniformBuffers() { +// uboVS.projection = camera.matrices.perspective +// uboVS.modelView = camera.matrices.view +// +// uboVS to uniformBuffer.mapped +// } +// +// fun draw() { +// +// super.prepareFrame() +// +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// queue submit submitInfo +// +// super.submitFrame() +// } +// +// override fun prepare() { +// super.prepare() +// loadAssets() +// setupVertexDescriptions() +// prepareUniformBuffers() +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSet() +// buildCommandBuffers() +// prepared = true +// window.show() +// } +// +// override fun render() { +// if (!prepared) +// return +// draw() +// } +// +// override fun viewChanged() = updateUniformBuffers() +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/basics/07 Texture.kt b/src/main/kotlin/vulkan/basics/07 Texture.kt index fb5f1c3..f0cf478 100644 --- a/src/main/kotlin/vulkan/basics/07 Texture.kt +++ b/src/main/kotlin/vulkan/basics/07 Texture.kt @@ -1,814 +1,815 @@ -/* -* Vulkan Example - Texture loading (and display) example (including mip maps) -* -* Copyright (C) 2016-2017 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -package vulkan.basics - -import ab.appBuffer -import gli_.gli -import glm_.L -import glm_.buffer.adr -import glm_.f -import glm_.func.rad -import glm_.glm -import glm_.mat4x4.Mat4 -import glm_.vec2.Vec2 -import glm_.vec2.Vec2i -import glm_.vec3.Vec3 -import glm_.vec4.Vec4 -import org.lwjgl.system.MemoryUtil.* -import org.lwjgl.vulkan.* -import uno.kotlin.buffers.capacity -import vkk.* -import vulkan.USE_STAGING -import vulkan.VERTEX_BUFFER_BIND_ID -import vulkan.assetPath -import vulkan.base.Buffer -import vulkan.base.VulkanExampleBase -import vulkan.base.initializers -import vulkan.base.tools - - -fun main(args: Array) { - Texture().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - -private class Texture : VulkanExampleBase() { - - /** Vertex layout for this example */ - object Vertex { - // float pos[3]; -// float uv[2]; -// float normal[3]; - val size = Vec3.size * 2 + Vec2.size - val posOffset = 0 - val uvOffset = Vec3.size - val normalOffset = Vec3.size + Vec2.size - } - - /** Contains all Vulkan objects that are required to store and use a texture - * Note that this repository contains a texture class (VulkanTexture.hpp) that encapsulates texture loading functionality - * in a class that is used in subsequent demos */ - object texture { - var sampler: VkSampler = NULL - var image: VkImage = NULL - var imageLayout = VkImageLayout.UNDEFINED - var deviceMemory: VkDeviceMemory = NULL - var view: VkImageView = NULL - val size = Vec2i() - var mipLevels = 0 - } - - object vertices { - val inputState = cVkPipelineVertexInputStateCreateInfo { } - lateinit var bindingDescriptions: VkVertexInputBindingDescription.Buffer - lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer - } - - val vertexBuffer = Buffer() - val indexBuffer = Buffer() - var indexCount = 0 - - val uniformBufferVS = Buffer() - - object uboVS : Bufferizable() { - - val projection = Mat4() - @Order(1) - val model = Mat4() - val viewPos = Vec4() - @Order(3) - var lodBias = 0f - } - - object pipelines { - var solid: VkPipelineLayout = NULL - } - - var pipelineLayout: VkPipelineLayout = NULL - var descriptorSet: VkDescriptorSetLayout = NULL - var descriptorSetLayout: VkDescriptorSetLayout = NULL - - init { - zoom = -2.5f - rotation(0f, 15f, 0f) - title = "Texture loading" -// settings.overlay = true - } - - override fun destroy() { - // Clean up used Vulkan resources - // Note : Inherited destructor cleans up resources stored in base class - - destroyTextureImage() - - device.apply { - destroyPipeline(pipelines.solid) - - destroyPipelineLayout(pipelineLayout) - destroyDescriptorSetLayout(descriptorSetLayout) - } - - vertexBuffer.destroy() - indexBuffer.destroy() - uniformBufferVS.destroy() - - super.destroy() - } - - /** Enable physical device features required for this example */ - override fun getEnabledFeatures() { - // Enable anisotropic filtering if supported - if (deviceFeatures.samplerAnisotropy) - enabledFeatures.samplerAnisotropy = true - } - - /** Create an image memory barrier used to change the layout of an image and put it into an active command buffer */ - fun VkCommandBuffer.setImageLayout(image: VkImage, aspectMask: VkImageAspect, oldImageLayout: VkImageLayout, - newImageLayout: VkImageLayout, subresourceRange: VkImageSubresourceRange) { - // Create an image barrier object - val imageMemoryBarrier = initializers.cImageMemoryBarrier().apply { - oldLayout = oldImageLayout - newLayout = newImageLayout - this.image = image - this.subresourceRange = subresourceRange - } - - // Only sets masks for layouts used in this example - // For a more complete version that can be used with other layouts see vks::tools::setImageLayout - - // Source layouts (old) - imageMemoryBarrier.srcAccessMask = - when (oldImageLayout) { - /* Only valid as initial layout, memory contents are not preserved - Can be accessed directly, no source dependency required */ - VkImageLayout.UNDEFINED -> 0 - /* Only valid as initial layout for linear images, preserves memory contents - Make sure host writes to the image have been finished */ - VkImageLayout.PREINITIALIZED -> VkAccess.HOST_WRITE_BIT.i - /* Old layout is transfer destination - Make sure any writes to the image have been finished */ - VkImageLayout.TRANSFER_DST_OPTIMAL -> VkAccess.TRANSFER_WRITE_BIT.i - - else -> imageMemoryBarrier.srcAccessMask - } - - // Target layouts (new) - imageMemoryBarrier.dstAccessMask = - when (newImageLayout) { - /* Transfer source (copy, blit) - Make sure any reads from the image have been finished */ - VkImageLayout.TRANSFER_SRC_OPTIMAL -> VkAccess.TRANSFER_READ_BIT.i - /* Transfer destination (copy, blit) - Make sure any writes to the image have been finished */ - VkImageLayout.TRANSFER_DST_OPTIMAL -> VkAccess.TRANSFER_WRITE_BIT.i - // Shader read (sampler, input attachment) - VkImageLayout.SHADER_READ_ONLY_OPTIMAL -> VkAccess.SHADER_READ_BIT.i - - else -> imageMemoryBarrier.dstAccessMask - } - - // Put barrier on top of pipeline - val srcStageFlags: VkPipelineStageFlags = VkPipelineStage.TOP_OF_PIPE_BIT.i - val destStageFlags: VkPipelineStageFlags = VkPipelineStage.TOP_OF_PIPE_BIT.i - - // Put barrier inside setup command buffer - pipelineBarrier(srcStageFlags, destStageFlags, tools.VK_FLAGS_NONE, imageMemoryBarrier = imageMemoryBarrier) - } - - fun loadTexture() { - // We use the Khronos texture format (https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/) - val filename = "$assetPath/textures/metalplate01_rgba.ktx" - // Texture data contains 4 channels (RGBA) with unnormalized 8-bit values, this is the most commonly supported format - val format = VkFormat.R8G8B8A8_UNORM - - /* Set to true to use linear tiled images - This is just for learning purposes and not suggested, as linear tiled images are pretty restricted and - often only support a small set of features (e.g. no mips, etc.) */ - val forceLinearTiling = false - - val tex2D = gli_.Texture2d(gli.load(filename)) - - assert(tex2D.notEmpty()) - - texture.size(tex2D[0].extent()) - texture.mipLevels = tex2D.levels() - - // Get device properites for the requested texture format - val formatProperties = physicalDevice getFormatProperties format - - /* Only use linear tiling if requested (and supported by the device) - Support for linear tiling is mostly limited, so prefer to use optimal tiling instead - On most implementations linear tiling will only support a very limited amount of formats and features - (mip maps, cubemaps, arrays, etc.) */ - USE_STAGING = true - - // Only use linear tiling if forced - if (forceLinearTiling) - // Don't use linear if format is not supported for (linear) shader sampling - USE_STAGING = formatProperties.linearTilingFeatures hasnt VkFormatFeature.SAMPLED_IMAGE_BIT - - val memAllocInfo = vk.MemoryAllocateInfo { } - val memReqs = vk.MemoryRequirements { } - - if (USE_STAGING) { - // Create a host-visible staging buffer that contains the raw image data - - val bufferCreateInfo = vk.BufferCreateInfo { - size = tex2D.size.L - // This buffer is used as a transfer source for the buffer copy - usage = VkBufferUsage.TRANSFER_SRC_BIT.i - sharingMode = VkSharingMode.EXCLUSIVE - } - - val stagingBuffer: VkBuffer = device createBuffer bufferCreateInfo - - // Get memory requirements for the staging buffer (alignment, memory type bits) - device.getBufferMemoryRequirements(stagingBuffer, memReqs) - - memAllocInfo.allocationSize = memReqs.size - // Get memory type index for a host visible buffer - memAllocInfo.memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT) - - val stagingMemory: VkDeviceMemory = device allocateMemory memAllocInfo - device.bindBufferMemory(stagingBuffer, stagingMemory) - - // Copy texture data into staging buffer - val data = device.mapMemory(stagingMemory, 0, memReqs.size) - memCopy(tex2D.data().adr, data, tex2D.size.L) - device unmapMemory stagingMemory - - // Setup buffer copy regions for each mip level - val bufferCopyRegions = VkBufferImageCopy.calloc(texture.mipLevels) - var offset = 0L - - bufferCopyRegions.forEachIndexed { i, it -> - it.imageSubresource.apply { - aspectMask = VkImageAspect.COLOR_BIT.i - mipLevel = i - baseArrayLayer = 0 - layerCount = 1 - } - val (w, h) = tex2D[i].extent() - it.imageExtent.width = w // TODO BUG - it.imageExtent.height = h - it.imageExtent.depth = 1 - it.bufferOffset = offset - - offset += tex2D[i].size - } - - // Create optimal tiled target image - val imageCreateInfo = vk.ImageCreateInfo { - imageType = VkImageType.`2D` - this.format = format - mipLevels = texture.mipLevels - arrayLayers = 1 - samples = VkSampleCount.`1_BIT` - tiling = VkImageTiling.OPTIMAL - sharingMode = VkSharingMode.EXCLUSIVE - // Set initial layout of the image to undefined - initialLayout = VkImageLayout.UNDEFINED - extent.set(texture.size.x, texture.size.y, 1) - usage = VkImageUsage.TRANSFER_DST_BIT or VkImageUsage.SAMPLED_BIT - } - - texture.image = device createImage imageCreateInfo - device.getImageMemoryRequirements(texture.image, memReqs) - - memAllocInfo.allocationSize = memReqs.size - memAllocInfo.memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) - - texture.deviceMemory = device allocateMemory memAllocInfo - device.bindImageMemory(texture.image, texture.deviceMemory) - - val copyCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) - - // Image barrier for optimal image - - // The sub resource range describes the regions of the image we will be transition - val subresourceRange = VkImageSubresourceRange.calloc().apply { - // Image only contains color data - aspectMask = VkImageAspect.COLOR_BIT.i - // Start at first mip level - baseMipLevel = 0 - // We will transition on all mip levels - levelCount = texture.mipLevels - // The 2D texture only has one layer - layerCount = 1 - } - - // Optimal image will be used as destination for the copy, so we must transfer from our - // initial undefined image layout to the transfer destination layout - copyCmd.setImageLayout( - texture.image, - VkImageAspect.COLOR_BIT, - VkImageLayout.UNDEFINED, - VkImageLayout.TRANSFER_DST_OPTIMAL, - subresourceRange) - - // Copy mip levels from staging buffer - copyCmd.copyBufferToImage( - stagingBuffer, - texture.image, - VkImageLayout.TRANSFER_DST_OPTIMAL, - bufferCopyRegions) - - // Change texture image layout to shader read after all mip levels have been copied - texture.imageLayout = VkImageLayout.SHADER_READ_ONLY_OPTIMAL - copyCmd.setImageLayout( - texture.image, - VkImageAspect.COLOR_BIT, - VkImageLayout.TRANSFER_DST_OPTIMAL, - texture.imageLayout, - subresourceRange) - - super.flushCommandBuffer(copyCmd, queue, true) - - // Clean up staging resources - device freeMemory stagingMemory - device destroyBuffer stagingBuffer - } else { - TODO() -// VkImage mappableImage -// VkDeviceMemory mappableMemory -// -// // Load mip map level 0 to linear tiling image -// VkImageCreateInfo imageCreateInfo = vks ::initializers::imageCreateInfo() -// imageCreateInfo.imageType = VK_IMAGE_TYPE_2D -// imageCreateInfo.format = format -// imageCreateInfo.mipLevels = 1 -// imageCreateInfo.arrayLayers = 1 -// imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT -// imageCreateInfo.tiling = VK_IMAGE_TILING_LINEAR -// imageCreateInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT -// imageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE -// imageCreateInfo.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED -// imageCreateInfo.extent = { texture.width, texture.height, 1 } -// VK_CHECK_RESULT(vkCreateImage(device, & imageCreateInfo, nullptr, & mappableImage)) -// -// // Get memory requirements for this image -// // like size and alignment -// vkGetImageMemoryRequirements(device, mappableImage, & memReqs) -// // Set memory allocation size to required memory size -// memAllocInfo.allocationSize = memReqs.size +///* +//* Vulkan Example - Texture loading (and display) example (including mip maps) +//* +//* Copyright (C) 2016-2017 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +//package vulkan.basics +// +//import gli_.gli +//import glm_.L +//import glm_.f +//import glm_.func.rad +//import glm_.glm +//import glm_.mat4x4.Mat4 +//import glm_.vec2.Vec2 +//import glm_.vec2.Vec2i +//import glm_.vec3.Vec3 +//import glm_.vec4.Vec4 +//import kool.adr +//import kool.cap +//import kool.stak +//import org.lwjgl.system.MemoryUtil.NULL +//import org.lwjgl.system.MemoryUtil.memCopy +//import org.lwjgl.vulkan.* +//import vkk.* +//import vulkan.USE_STAGING +//import vulkan.VERTEX_BUFFER_BIND_ID +//import vulkan.assetPath +//import vulkan.base.Buffer +//import vulkan.base.VulkanExampleBase +//import vulkan.base.initializers +//import vulkan.base.tools +// +// +//fun main(args: Array) { +// Texture().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +//private class Texture : VulkanExampleBase() { +// +// /** Vertex layout for this example */ +// object Vertex { +// // float pos[3]; +//// float uv[2]; +//// float normal[3]; +// val size = Vec3.size * 2 + Vec2.size +// val posOffset = 0 +// val uvOffset = Vec3.size +// val normalOffset = Vec3.size + Vec2.size +// } +// +// /** Contains all Vulkan objects that are required to store and use a texture +// * Note that this repository contains a texture class (VulkanTexture.hpp) that encapsulates texture loading functionality +// * in a class that is used in subsequent demos */ +// object texture { +// var sampler = VkSampler(NULL) +// var image= VkImage (NULL) +// var imageLayout = VkImageLayout.UNDEFINED +// var deviceMemory = VkDeviceMemory(NULL) +// var view = VkImageView(NULL) +// val size = Vec2i() +// var mipLevels = 0 +// } +// +// object vertices { +// val inputState = cVkPipelineVertexInputStateCreateInfo { } +// lateinit var bindingDescriptions: VkVertexInputBindingDescription.Buffer +// lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer +// } +// +// val vertexBuffer = Buffer() +// val indexBuffer = Buffer() +// var indexCount = 0 +// +// val uniformBufferVS = Buffer() +// +// object uboVS : Bufferizable() { +// +// val projection = Mat4() +// @Order(1) +// val model = Mat4() +// val viewPos = Vec4() +// @Order(3) +// var lodBias = 0f +// } +// +// object pipelines { +// var solid = VkPipeline (NULL) +// } +// +// var pipelineLayout = VkPipelineLayout (NULL) +// var descriptorSet= VkDescriptorSet (NULL) +// var descriptorSetLayout= VkDescriptorSetLayout (NULL) +// +// init { +// zoom = -2.5f +// rotation(0f, 15f, 0f) +// title = "Texture loading" +//// settings.overlay = true +// } +// +// override fun destroy() { +// // Clean up used Vulkan resources +// // Note : Inherited destructor cleans up resources stored in base class +// +// destroyTextureImage() +// +// device.apply { +// destroyPipeline(pipelines.solid) +// +// destroyPipelineLayout(pipelineLayout) +// destroyDescriptorSetLayout(descriptorSetLayout) +// } +// +// vertexBuffer.destroy() +// indexBuffer.destroy() +// uniformBufferVS.destroy() +// +// super.destroy() +// } +// +// /** Enable physical device features required for this example */ +// override fun getEnabledFeatures() { +// // Enable anisotropic filtering if supported +// if (deviceFeatures.samplerAnisotropy) +// enabledFeatures.samplerAnisotropy = true +// } +// +// /** Create an image memory barrier used to change the layout of an image and put it into an active command buffer */ +// fun VkCommandBuffer.setImageLayout(image: VkImage, aspectMask: VkImageAspect, oldImageLayout: VkImageLayout, +// newImageLayout: VkImageLayout, subresourceRange: VkImageSubresourceRange) { +// // Create an image barrier object +// val imageMemoryBarrier = initializers.cImageMemoryBarrier().apply { +// oldLayout = oldImageLayout +// newLayout = newImageLayout +// this.image = image +// this.subresourceRange = subresourceRange +// } +// +// // Only sets masks for layouts used in this example +// // For a more complete version that can be used with other layouts see vks::tools::setImageLayout +// +// // Source layouts (old) +// imageMemoryBarrier.srcAccessMask = +// when (oldImageLayout) { +// /* Only valid as initial layout, memory contents are not preserved +// Can be accessed directly, no source dependency required */ +// VkImageLayout.UNDEFINED -> 0 +// /* Only valid as initial layout for linear images, preserves memory contents +// Make sure host writes to the image have been finished */ +// VkImageLayout.PREINITIALIZED -> VkAccess.HOST_WRITE_BIT.i +// /* Old layout is transfer destination +// Make sure any writes to the image have been finished */ +// VkImageLayout.TRANSFER_DST_OPTIMAL -> VkAccess.TRANSFER_WRITE_BIT.i // -// // Get memory type that can be mapped to host memory -// memAllocInfo.memoryTypeIndex = vulkanDevice->getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) +// else -> imageMemoryBarrier.srcAccessMask +// } // -// // Allocate host memory -// VK_CHECK_RESULT(vkAllocateMemory(device, & memAllocInfo, nullptr, & mappableMemory)) +// // Target layouts (new) +// imageMemoryBarrier.dstAccessMask = +// when (newImageLayout) { +// /* Transfer source (copy, blit) +// Make sure any reads from the image have been finished */ +// VkImageLayout.TRANSFER_SRC_OPTIMAL -> VkAccess.TRANSFER_READ_BIT.i +// /* Transfer destination (copy, blit) +// Make sure any writes to the image have been finished */ +// VkImageLayout.TRANSFER_DST_OPTIMAL -> VkAccess.TRANSFER_WRITE_BIT.i +// // Shader read (sampler, input attachment) +// VkImageLayout.SHADER_READ_ONLY_OPTIMAL -> VkAccess.SHADER_READ_BIT.i // -// // Bind allocated image for use -// VK_CHECK_RESULT(vkBindImageMemory(device, mappableImage, mappableMemory, 0)) +// else -> imageMemoryBarrier.dstAccessMask +// } // -// // Get sub resource layout -// // Mip map count, array layer, etc. -// VkImageSubresource subRes = {} -// subRes.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT +// // Put barrier on top of pipeline +// val srcStageFlags: VkPipelineStageFlags = VkPipelineStage.TOP_OF_PIPE_BIT.i +// val destStageFlags: VkPipelineStageFlags = VkPipelineStage.TOP_OF_PIPE_BIT.i // -// VkSubresourceLayout subResLayout -// void * data +// // Put barrier inside setup command buffer +// pipelineBarrier(srcStageFlags, destStageFlags, tools.VK_FLAGS_NONE, imageMemoryBarrier = imageMemoryBarrier) +// } +// +// fun loadTexture() { +// // We use the Khronos texture format (https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/) +// val filename = "$assetPath/textures/metalplate01_rgba.ktx" +// // Texture data contains 4 channels (RGBA) with unnormalized 8-bit values, this is the most commonly supported format +// val format = VkFormat.R8G8B8A8_UNORM +// +// /* Set to true to use linear tiled images +// This is just for learning purposes and not suggested, as linear tiled images are pretty restricted and +// often only support a small set of features (e.g. no mips, etc.) */ +// val forceLinearTiling = false +// +// val tex2D = gli_.Texture2d(gli.load(filename)) +// +// assert(tex2D.notEmpty()) +// +// texture.size(tex2D[0].extent()) +// texture.mipLevels = tex2D.levels() +// +// // Get device properites for the requested texture format +// val formatProperties = physicalDevice getFormatProperties format +// +// /* Only use linear tiling if requested (and supported by the device) +// Support for linear tiling is mostly limited, so prefer to use optimal tiling instead +// On most implementations linear tiling will only support a very limited amount of formats and features +// (mip maps, cubemaps, arrays, etc.) */ +// USE_STAGING = true +// +// // Only use linear tiling if forced +// if (forceLinearTiling) +// // Don't use linear if format is not supported for (linear) shader sampling +// USE_STAGING = formatProperties.linearTilingFeatures hasnt VkFormatFeature.SAMPLED_IMAGE_BIT // -// // Get sub resources layout -// // Includes row pitch, size offsets, etc. -// vkGetImageSubresourceLayout(device, mappableImage, & subRes, &subResLayout) +// val memAllocInfo = vk.MemoryAllocateInfo { } +// val memReqs = vk.MemoryRequirements { } // -// // Map image memory -// VK_CHECK_RESULT(vkMapMemory(device, mappableMemory, 0, memReqs.size, 0, & data)) +// if (USE_STAGING) { +// // Create a host-visible staging buffer that contains the raw image data // -// // Copy image data into memory -// memcpy(data, tex2D[subRes.mipLevel].data(), tex2D[subRes.mipLevel].size()) +// val bufferCreateInfo = vk.BufferCreateInfo { +// size = VkDeviceSize(tex2D.size.L) +// // This buffer is used as a transfer source for the buffer copy +// usage = VkBufferUsage.TRANSFER_SRC_BIT.i +// sharingMode = VkSharingMode.EXCLUSIVE +// } // -// vkUnmapMemory(device, mappableMemory) +// val stagingBuffer: VkBuffer = device createBuffer bufferCreateInfo // -// // Linear tiled images don't need to be staged -// // and can be directly used as textures -// texture.image = mappableImage -// texture.deviceMemory = mappableMemory -// texture.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL +// // Get memory requirements for the staging buffer (alignment, memory type bits) +// device.getBufferMemoryRequirements(stagingBuffer, memReqs) // -// VkCommandBuffer copyCmd = VulkanExampleBase ::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true) +// memAllocInfo.allocationSize = memReqs.size +// // Get memory type index for a host visible buffer +// memAllocInfo.memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT) +// +// val stagingMemory: VkDeviceMemory = device allocateMemory memAllocInfo +// device.bindBufferMemory(stagingBuffer, stagingMemory) +// +// // Copy texture data into staging buffer +// val data = device.mapMemory(stagingMemory, VkDeviceSize(0), memReqs.size) +// memCopy(tex2D.data().adr, data, tex2D.size.L) +// device unmapMemory stagingMemory +// +// // Setup buffer copy regions for each mip level +// val bufferCopyRegions = VkBufferImageCopy.calloc(texture.mipLevels) +// var offset = VkDeviceSize(0) +// +// bufferCopyRegions.forEachIndexed { i, it -> +// it.imageSubresource.apply { +// aspectMask = VkImageAspect.COLOR_BIT.i +// mipLevel = i +// baseArrayLayer = 0 +// layerCount = 1 +// } +// val (w, h) = tex2D[i].extent() +// it.imageExtent.width = w // TODO BUG +// it.imageExtent.height = h +// it.imageExtent.depth = 1 +// it.bufferOffset = offset // -// // Setup image memory barrier transfer image to shader read layout +// offset += tex2D[i].size +// } +// +// // Create optimal tiled target image +// val imageCreateInfo = vk.ImageCreateInfo { +// imageType = VkImageType.`2D` +// this.format = format +// mipLevels = texture.mipLevels +// arrayLayers = 1 +// samples = VkSampleCount.`1_BIT` +// tiling = VkImageTiling.OPTIMAL +// sharingMode = VkSharingMode.EXCLUSIVE +// // Set initial layout of the image to undefined +// initialLayout = VkImageLayout.UNDEFINED +// extent.set(texture.size.x, texture.size.y, 1) +// usage = VkImageUsage.TRANSFER_DST_BIT or VkImageUsage.SAMPLED_BIT +// } +// +// texture.image = device createImage imageCreateInfo +// device.getImageMemoryRequirements(texture.image, memReqs) +// +// memAllocInfo.allocationSize = memReqs.size +// memAllocInfo.memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) +// +// texture.deviceMemory = device allocateMemory memAllocInfo +// device.bindImageMemory(texture.image, texture.deviceMemory) +// +// val copyCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) +// +// // Image barrier for optimal image // // // The sub resource range describes the regions of the image we will be transition -// VkImageSubresourceRange subresourceRange = {} -// // Image only contains color data -// subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT -// // Start at first mip level -// subresourceRange.baseMipLevel = 0 -// // Only one mip level, most implementations won't support more for linear tiled images -// subresourceRange.levelCount = 1 -// // The 2D texture only has one layer -// subresourceRange.layerCount = 1 -// -// setImageLayout( -// copyCmd, +// val subresourceRange = VkImageSubresourceRange.calloc().apply { +// // Image only contains color data +// aspectMask = VkImageAspect.COLOR_BIT.i +// // Start at first mip level +// baseMipLevel = 0 +// // We will transition on all mip levels +// levelCount = texture.mipLevels +// // The 2D texture only has one layer +// layerCount = 1 +// } +// +// // Optimal image will be used as destination for the copy, so we must transfer from our +// // initial undefined image layout to the transfer destination layout +// copyCmd.setImageLayout( +// texture.image, +// VkImageAspect.COLOR_BIT, +// VkImageLayout.UNDEFINED, +// VkImageLayout.TRANSFER_DST_OPTIMAL, +// subresourceRange) +// +// // Copy mip levels from staging buffer +// copyCmd.copyBufferToImage( +// stagingBuffer, +// texture.image, +// VkImageLayout.TRANSFER_DST_OPTIMAL, +// bufferCopyRegions) +// +// // Change texture image layout to shader read after all mip levels have been copied +// texture.imageLayout = VkImageLayout.SHADER_READ_ONLY_OPTIMAL +// copyCmd.setImageLayout( // texture.image, -// VK_IMAGE_ASPECT_COLOR_BIT, -// VK_IMAGE_LAYOUT_PREINITIALIZED, +// VkImageAspect.COLOR_BIT, +// VkImageLayout.TRANSFER_DST_OPTIMAL, // texture.imageLayout, // subresourceRange) // -// VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true) - } - - // Create a texture sampler - // In Vulkan textures are accessed by samplers - // This separates all the sampling information from the texture data. This means you could have multiple sampler objects for the same texture with different settings - // Note: Similar to the samplers available with OpenGL 3.3 - val sampler = vk.SamplerCreateInfo { - magFilter = VkFilter.LINEAR - minFilter = VkFilter.LINEAR - mipmapMode = VkSamplerMipmapMode.LINEAR - addressModeU = VkSamplerAddressMode.REPEAT - addressModeV = VkSamplerAddressMode.REPEAT - addressModeW = VkSamplerAddressMode.REPEAT - mipLodBias = 0f - compareOp = VkCompareOp.NEVER - minLod = 0f - // Set max level-of-detail to mip level count of the texture - maxLod = if (USE_STAGING) texture.mipLevels.f else 0f - // Enable anisotropic filtering - // This feature is optional, so we must check if it's supported on the device - if (vulkanDevice.features.samplerAnisotropy) { - // Use max. level of anisotropy for this example - maxAnisotropy = vulkanDevice.properties.limits.maxSamplerAnisotropy - anisotropyEnable = true - } else { - // The device does not support anisotropic filtering - maxAnisotropy = 1f - anisotropyEnable = false - } - borderColor = VkBorderColor.FLOAT_OPAQUE_WHITE - } - texture.sampler = device createSampler sampler - - /* Create image view - Textures are not directly accessed by the shaders and are abstracted by image views containing additional - information and sub resource ranges */ - val view = vk.ImageViewCreateInfo { - viewType = VkImageViewType.`2D` - this.format = format - components(VkComponentSwizzle.R, VkComponentSwizzle.G, VkComponentSwizzle.B, VkComponentSwizzle.A) - // The subresource range describes the set of mip levels (and array layers) that can be accessed through this image view - // It's possible to create multiple image views for a single image referring to different (and/or overlapping) ranges of the image - subresourceRange.apply { - aspectMask = VkImageAspect.COLOR_BIT.i - baseMipLevel = 0 - baseArrayLayer = 0 - layerCount = 1 - // Linear tiling usually won't support mip maps - // Only set mip map count if optimal tiling is used - levelCount = if (USE_STAGING) texture.mipLevels else 1 - } - // The view will be based on the texture's image - image = texture.image - } - texture.view = device createImageView view - } - - /** Free all Vulkan resources used by a texture object */ - fun destroyTextureImage() { - device destroyImageView texture.view - device destroyImage texture.image - device destroySampler texture.sampler - device freeMemory texture.deviceMemory - } - - override fun buildCommandBuffers() { - - val cmdBufInfo = vk.CommandBufferBeginInfo { } - - val clearValues = vk.ClearValue(2).also { - it[0].color(defaultClearColor) - it[1].depthStencil(1f, 0) - } - val (w, h) = size - - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@Texture.renderPass - renderArea.apply { - offset.set(0, 0) - extent.set(w, h) // TODO BUG - } - this.clearValues = clearValues - } - - drawCmdBuffers.forEachIndexed { i, it -> - // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) // TODO BUG - - it begin cmdBufInfo - - it.beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - it setViewport initializers.viewport(size, 0f, 1f) - - it setScissor vk.Rect2D(size) - - it.bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) - it.bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.solid) - - it.bindVertexBuffers(VERTEX_BUFFER_BIND_ID, vertexBuffer.buffer) - it.bindIndexBuffer(indexBuffer.buffer, 0, VkIndexType.UINT32) - - it.drawIndexed(indexCount, 1, 0, 0, 0) - - it.endRenderPass() - - it.end() - } - } - - fun draw() { - - super.prepareFrame() - - // Command buffer to be sumitted to the queue - submitInfo.commandBuffers = appBuffer.pointerBufferOf(drawCmdBuffers[currentBuffer]) - - // Submit to queue - queue submit submitInfo - - super.submitFrame() - } - - fun generateQuad() { - // Setup vertices for a single uv-mapped quad made from two triangles - val vertices = appBuffer.floatBufferOf( - +1f, +1f, 0f, 1f, 1f, 0f, 0f, 1f, - -1f, +1f, 0f, 0f, 1f, 0f, 0f, 1f, - -1f, -1f, 0f, 0f, 0f, 0f, 0f, 1f, - +1f, -1f, 0f, 1f, 0f, 0f, 0f, 1f) - - // Setup indices - val indices = appBuffer.intBufferOf(0, 1, 2, 2, 3, 0) - indexCount = indices.capacity - - // Create buffers - // For the sake of simplicity we won't stage the vertex data to the gpu memory - // Vertex buffer - vulkanDevice.createBuffer( - VkBufferUsage.VERTEX_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - vertexBuffer, - vertices) - // Index buffer - vulkanDevice.createBuffer( - VkBufferUsage.INDEX_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - indexBuffer, - indices) - } - - fun setupVertexDescriptions() { - // Binding description - vertices.bindingDescriptions = VkVertexInputBindingDescription.calloc(1) - vertices.bindingDescriptions[0].apply { - binding = VERTEX_BUFFER_BIND_ID - stride = Vertex.size - inputRate = VkVertexInputRate.VERTEX - } - - // Attribute descriptions - // Describes memory layout and shader positions - vertices.attributeDescriptions = VkVertexInputAttributeDescription.calloc(3) - // Location 0 : Position - vertices.attributeDescriptions[0].apply { - binding = VERTEX_BUFFER_BIND_ID - location = 0 - format = VkFormat.R32G32B32_SFLOAT - offset = Vertex.posOffset - } - // Location 1 : Texture coordinates - vertices.attributeDescriptions[1].apply { - binding = VERTEX_BUFFER_BIND_ID - location = 1 - format = VkFormat.R32G32_SFLOAT - offset = Vertex.uvOffset - } - // Location 1 : Vertex normal - vertices.attributeDescriptions[2].apply { - binding = VERTEX_BUFFER_BIND_ID - location = 2 - format = VkFormat.R32G32B32_SFLOAT - offset = Vertex.normalOffset - } - - vertices.inputState.apply { - vertexBindingDescriptions = vertices.bindingDescriptions - vertexAttributeDescriptions = vertices.attributeDescriptions - } - } - - fun setupDescriptorPool() { - // Example uses one ubo and one image sampler - val poolSizes = VkDescriptorPoolSize.calloc(2).also { - it[0](VkDescriptorType.UNIFORM_BUFFER, 1) - it[1](VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1) - } - - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo { - this.poolSizes = poolSizes - maxSets = 2 - } - - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - - val setLayoutBindings = VkDescriptorSetLayoutBinding.calloc(2).also { - // Binding 0 : Vertex shader uniform buffer - it[0](0, VkDescriptorType.UNIFORM_BUFFER, 1, VkShaderStage.VERTEX_BIT.i) - // Binding 1 : Fragment shader image sampler - it[1](1, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, VkShaderStage.FRAGMENT_BIT.i) - } - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo { - bindings = setLayoutBindings - } - - descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo { - setLayouts = appBuffer.longBufferOf(descriptorSetLayout) - } - - pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - } - - fun setupDescriptorSet() { - - val allocInfo = vk.DescriptorSetAllocateInfo { - descriptorPool = this@Texture.descriptorPool - setLayouts = appBuffer.longBufferOf(descriptorSetLayout) - descriptorSetCount = 1 - } - - descriptorSet = device allocateDescriptorSets allocInfo - - // Setup a descriptor image info for the current texture to be used as a combined image sampler - val textureDescriptor = vk.DescriptorImageInfo(1) { - // The image's view (images are never directly accessed by the shader, but rather through views defining subresources) - imageView = texture.view - // The sampler (Telling the pipeline how to sample the texture, including repeat, border, etc.) - sampler = texture.sampler - // The current layout of the image (Note: Should always fit the actual use, e.g. shader read) - imageLayout = texture.imageLayout - } - - val writeDescriptorSets = VkWriteDescriptorSet.calloc(2) - // Binding 0 : Vertex shader uniform buffer - writeDescriptorSets[0].apply { - type = VkStructureType.WRITE_DESCRIPTOR_SET - dstSet = descriptorSet - descriptorType = VkDescriptorType.UNIFORM_BUFFER - dstBinding = 0 - bufferInfo_ = uniformBufferVS.descriptor - } - // Binding 1 : Fragment shader texture sampler - // Fragment shader: layout (binding = 1) uniform sampler2D samplerColor; - writeDescriptorSets[1].apply { - type = VkStructureType.WRITE_DESCRIPTOR_SET - dstSet = descriptorSet - // The descriptor set will use a combined image sampler (sampler and image could be split) - descriptorType = VkDescriptorType.COMBINED_IMAGE_SAMPLER - dstBinding = 1 // Shader binding point 1 - imageInfo = textureDescriptor // Pointer to the descriptor image for our texture - } - - device updateDescriptorSets writeDescriptorSets - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo { - topology = VkPrimitiveTopology.TRIANGLE_LIST - } - - val rasterizationState = initializers.pipelineRasterizationStateCreateInfo( - VkPolygonMode.FILL, - VkCullMode.NONE.i, - VkFrontFace.COUNTER_CLOCKWISE, - 0) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState { colorWriteMask = 0xf } - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo { attachment = blendAttachmentState } - - val depthStencilState = initializers.pipelineDepthStencilStateCreateInfo( - true, - true, - VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo { - viewportCount = 1 - scissorCount = 1 - } - - val multisampleState = vk.PipelineMultisampleStateCreateInfo { - rasterizationSamples = VkSampleCount.`1_BIT` - } - - val dynamicStateEnables = appBuffer.intBufferOf(VkDynamicState.VIEWPORT.i, VkDynamicState.SCISSOR.i) - val dynamicState = vk.PipelineDynamicStateCreateInfo { - dynamicStates = dynamicStateEnables - } - - // Load shaders - val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { - it[0].loadShader("$assetPath/shaders/texture/texture.vert", VkShaderStage.VERTEX_BIT) - it[1].loadShader("$assetPath/shaders/texture/texture.frag", VkShaderStage.FRAGMENT_BIT) - } - - val pipelineCreateInfo = initializers.pipelineCreateInfo( - pipelineLayout, - renderPass).apply { - vertexInputState = vertices.inputState - this.inputAssemblyState = inputAssemblyState - this.rasterizationState = rasterizationState - this.colorBlendState = colorBlendState - this.multisampleState = multisampleState - this.viewportState = viewportState - this.depthStencilState = depthStencilState - this.dynamicState = dynamicState - stages = shaderStages - } - - pipelines.solid = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - // Prepare and initialize uniform buffer containing shader uniforms - fun prepareUniformBuffers() { - // Vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBufferVS, - uboVS.size.L) - - updateUniformBuffers() - } - - val viewMatrix = Mat4(1f).translateAssign(0f, 0f, zoom) - fun updateUniformBuffers() { - // Vertex shader - glm.perspective(uboVS.projection, 60f.rad, size.aspect, 0.001f, 256f) - - uboVS.model.apply { - put(viewMatrix * Mat4(1f).translateAssign(cameraPos)) - rotateAssign(rotation.x.rad, Vec3(1f, 0f, 0f)) - rotateAssign(rotation.y.rad, Vec3(0f, 1f, 0f)) - rotateAssign(rotation.z.rad, Vec3(0f, 0f, 1f)) - } - - uboVS.viewPos put Vec4(0f, 0f, -zoom, 0f) - - uniformBufferVS.mapping { dst -> uboVS to dst } - } - - override fun prepare() { - super.prepare() - loadTexture() - generateQuad() - setupVertexDescriptions() - prepareUniformBuffers() - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSet() - buildCommandBuffers() - prepared = true - window.show() - } - - override fun render() { - if (!prepared) - return - draw() - } - - override fun viewChanged() = updateUniformBuffers() - -// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) -// { -// if (overlay->header("Settings")) { -// if (overlay->sliderFloat("LOD bias", &uboVS.lodBias, 0.0f, (float)texture.mipLevels)) { +// super.flushCommandBuffer(copyCmd, queue, true) +// +// // Clean up staging resources +// device freeMemory stagingMemory +// device destroyBuffer stagingBuffer +// } else { +// TODO() +//// VkImage mappableImage +//// VkDeviceMemory mappableMemory +//// +//// // Load mip map level 0 to linear tiling image +//// VkImageCreateInfo imageCreateInfo = vks ::initializers::imageCreateInfo() +//// imageCreateInfo.imageType = VK_IMAGE_TYPE_2D +//// imageCreateInfo.format = format +//// imageCreateInfo.mipLevels = 1 +//// imageCreateInfo.arrayLayers = 1 +//// imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT +//// imageCreateInfo.tiling = VK_IMAGE_TILING_LINEAR +//// imageCreateInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT +//// imageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE +//// imageCreateInfo.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED +//// imageCreateInfo.extent = { texture.width, texture.height, 1 } +//// VK_CHECK_RESULT(vkCreateImage(device, & imageCreateInfo, nullptr, & mappableImage)) +//// +//// // Get memory requirements for this image +//// // like size and alignment +//// vkGetImageMemoryRequirements(device, mappableImage, & memReqs) +//// // Set memory allocation size to required memory size +//// memAllocInfo.allocationSize = memReqs.size +//// +//// // Get memory type that can be mapped to host memory +//// memAllocInfo.memoryTypeIndex = vulkanDevice->getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) +//// +//// // Allocate host memory +//// VK_CHECK_RESULT(vkAllocateMemory(device, & memAllocInfo, nullptr, & mappableMemory)) +//// +//// // Bind allocated image for use +//// VK_CHECK_RESULT(vkBindImageMemory(device, mappableImage, mappableMemory, 0)) +//// +//// // Get sub resource layout +//// // Mip map count, array layer, etc. +//// VkImageSubresource subRes = {} +//// subRes.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT +//// +//// VkSubresourceLayout subResLayout +//// void * data +//// +//// // Get sub resources layout +//// // Includes row pitch, size offsets, etc. +//// vkGetImageSubresourceLayout(device, mappableImage, & subRes, &subResLayout) +//// +//// // Map image memory +//// VK_CHECK_RESULT(vkMapMemory(device, mappableMemory, 0, memReqs.size, 0, & data)) +//// +//// // Copy image data into memory +//// memcpy(data, tex2D[subRes.mipLevel].data(), tex2D[subRes.mipLevel].size()) +//// +//// vkUnmapMemory(device, mappableMemory) +//// +//// // Linear tiled images don't need to be staged +//// // and can be directly used as textures +//// texture.image = mappableImage +//// texture.deviceMemory = mappableMemory +//// texture.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL +//// +//// VkCommandBuffer copyCmd = VulkanExampleBase ::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true) +//// +//// // Setup image memory barrier transfer image to shader read layout +//// +//// // The sub resource range describes the regions of the image we will be transition +//// VkImageSubresourceRange subresourceRange = {} +//// // Image only contains color data +//// subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT +//// // Start at first mip level +//// subresourceRange.baseMipLevel = 0 +//// // Only one mip level, most implementations won't support more for linear tiled images +//// subresourceRange.levelCount = 1 +//// // The 2D texture only has one layer +//// subresourceRange.layerCount = 1 +//// +//// setImageLayout( +//// copyCmd, +//// texture.image, +//// VK_IMAGE_ASPECT_COLOR_BIT, +//// VK_IMAGE_LAYOUT_PREINITIALIZED, +//// texture.imageLayout, +//// subresourceRange) +//// +//// VulkanExampleBase::flushCommandBuffer(copyCmd, queue, true) +// } +// +// // Create a texture sampler +// // In Vulkan textures are accessed by samplers +// // This separates all the sampling information from the texture data. This means you could have multiple sampler objects for the same texture with different settings +// // Note: Similar to the samplers available with OpenGL 3.3 +// val sampler = vk.SamplerCreateInfo { +// magFilter = VkFilter.LINEAR +// minFilter = VkFilter.LINEAR +// mipmapMode = VkSamplerMipmapMode.LINEAR +// addressModeU = VkSamplerAddressMode.REPEAT +// addressModeV = VkSamplerAddressMode.REPEAT +// addressModeW = VkSamplerAddressMode.REPEAT +// mipLodBias = 0f +// compareOp = VkCompareOp.NEVER +// minLod = 0f +// // Set max level-of-detail to mip level count of the texture +// maxLod = if (USE_STAGING) texture.mipLevels.f else 0f +// // Enable anisotropic filtering +// // This feature is optional, so we must check if it's supported on the device +// if (vulkanDevice.features.samplerAnisotropy) { +// // Use max. level of anisotropy for this example +// maxAnisotropy = vulkanDevice.properties.limits.maxSamplerAnisotropy +// anisotropyEnable = true +// } else { +// // The device does not support anisotropic filtering +// maxAnisotropy = 1f +// anisotropyEnable = false +// } +// borderColor = VkBorderColor.FLOAT_OPAQUE_WHITE +// } +// texture.sampler = device createSampler sampler +// +// /* Create image view +// Textures are not directly accessed by the shaders and are abstracted by image views containing additional +// information and sub resource ranges */ +// val view = vk.ImageViewCreateInfo { +// viewType = VkImageViewType.`2D` +// this.format = format +// components(VkComponentSwizzle.R, VkComponentSwizzle.G, VkComponentSwizzle.B, VkComponentSwizzle.A) +// // The subresource range describes the set of mip levels (and array layers) that can be accessed through this image view +// // It's possible to create multiple image views for a single image referring to different (and/or overlapping) ranges of the image +// subresourceRange.apply { +// aspectMask = VkImageAspect.COLOR_BIT.i +// baseMipLevel = 0 +// baseArrayLayer = 0 +// layerCount = 1 +// // Linear tiling usually won't support mip maps +// // Only set mip map count if optimal tiling is used +// levelCount = if (USE_STAGING) texture.mipLevels else 1 +// } +// // The view will be based on the texture's image +// image = texture.image +// } +// texture.view = device createImageView view +// } +// +// /** Free all Vulkan resources used by a texture object */ +// fun destroyTextureImage() { +// device destroyImageView texture.view +// device destroyImage texture.image +// device destroySampler texture.sampler +// device freeMemory texture.deviceMemory +// } +// +// override fun buildCommandBuffers() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo { } +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(defaultClearColor) +// it[1].depthStencil(1f, 0) +// } +// val (w, h) = size +// +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@Texture.renderPass +// renderArea.apply { +// offset.set(0, 0) +// extent.set(w, h) // TODO BUG +// } +// this.clearValues = clearValues +// } +// +// drawCmdBuffers.forEachIndexed { i, it -> +// // Set target frame buffer +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) // TODO BUG +// +// it begin cmdBufInfo +// +// it.beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// it setViewport initializers.viewport(size, 0f, 1f) +// +// it setScissor vk.Rect2D(size) +// +// it.bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) +// it.bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.solid) +// +// it.bindVertexBuffers(VERTEX_BUFFER_BIND_ID, vertexBuffer.buffer) +// it.bindIndexBuffer(indexBuffer.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// +// it.drawIndexed(indexCount, 1, 0, 0, 0) +// +// it.endRenderPass() +// +// it.end() +// } +// } +// +// fun draw() { +// +// super.prepareFrame() +// +// // Command buffer to be sumitted to the queue +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// +// // Submit to queue +// queue submit submitInfo +// +// super.submitFrame() +// } +// +// fun generateQuad() = stak { +// // Setup vertices for a single uv-mapped quad made from two triangles +// val vertices = it.floats( +// +1f, +1f, 0f, 1f, 1f, 0f, 0f, 1f, +// -1f, +1f, 0f, 0f, 1f, 0f, 0f, 1f, +// -1f, -1f, 0f, 0f, 0f, 0f, 0f, 1f, +// +1f, -1f, 0f, 1f, 0f, 0f, 0f, 1f) +// +// // Setup indices +// val indices = it.ints(0, 1, 2, 2, 3, 0) +// indexCount = indices.cap +// +// // Create buffers +// // For the sake of simplicity we won't stage the vertex data to the gpu memory +// // Vertex buffer +// vulkanDevice.createBuffer( +// VkBufferUsage.VERTEX_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// vertexBuffer, +// vertices) +// // Index buffer +// vulkanDevice.createBuffer( +// VkBufferUsage.INDEX_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// indexBuffer, +// indices) +// } +// +// fun setupVertexDescriptions() { +// // Binding description +// vertices.bindingDescriptions = VkVertexInputBindingDescription.calloc(1) +// vertices.bindingDescriptions[0].apply { +// binding = VERTEX_BUFFER_BIND_ID +// stride = Vertex.size +// inputRate = VkVertexInputRate.VERTEX +// } +// +// // Attribute descriptions +// // Describes memory layout and shader positions +// vertices.attributeDescriptions = VkVertexInputAttributeDescription.calloc(3) +// // Location 0 : Position +// vertices.attributeDescriptions[0].apply { +// binding = VERTEX_BUFFER_BIND_ID +// location = 0 +// format = VkFormat.R32G32B32_SFLOAT +// offset = Vertex.posOffset +// } +// // Location 1 : Texture coordinates +// vertices.attributeDescriptions[1].apply { +// binding = VERTEX_BUFFER_BIND_ID +// location = 1 +// format = VkFormat.R32G32_SFLOAT +// offset = Vertex.uvOffset +// } +// // Location 1 : Vertex normal +// vertices.attributeDescriptions[2].apply { +// binding = VERTEX_BUFFER_BIND_ID +// location = 2 +// format = VkFormat.R32G32B32_SFLOAT +// offset = Vertex.normalOffset +// } +// +// vertices.inputState.apply { +// vertexBindingDescriptions = vertices.bindingDescriptions +// vertexAttributeDescriptions = vertices.attributeDescriptions +// } +// } +// +// fun setupDescriptorPool() { +// // Example uses one ubo and one image sampler +// val poolSizes = VkDescriptorPoolSize.calloc(2).also { +// it[0](VkDescriptorType.UNIFORM_BUFFER, 1) +// it[1](VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1) +// } +// +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo { +// this.poolSizes = poolSizes +// maxSets = 2 +// } +// +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// +// val setLayoutBindings = VkDescriptorSetLayoutBinding.calloc(2).also { +// // Binding 0 : Vertex shader uniform buffer +// it[0](0, VkDescriptorType.UNIFORM_BUFFER, 1, VkShaderStage.VERTEX_BIT.i) +// // Binding 1 : Fragment shader image sampler +// it[1](1, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, VkShaderStage.FRAGMENT_BIT.i) +// } +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo { +// bindings = setLayoutBindings +// } +// +// descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo { +// setLayout = descriptorSetLayout +// } +// +// pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// } +// +// fun setupDescriptorSet() { +// +// val allocInfo = vk.DescriptorSetAllocateInfo { +// descriptorPool = this@Texture.descriptorPool +// setLayout = descriptorSetLayout +// descriptorSetCount = 1 +// } +// +// descriptorSet = device allocateDescriptorSets allocInfo +// +// // Setup a descriptor image info for the current texture to be used as a combined image sampler +// val textureDescriptor = vk.DescriptorImageInfo(1) { +// // The image's view (images are never directly accessed by the shader, but rather through views defining subresources) +// imageView = texture.view +// // The sampler (Telling the pipeline how to sample the texture, including repeat, border, etc.) +// sampler = texture.sampler +// // The current layout of the image (Note: Should always fit the actual use, e.g. shader read) +// imageLayout = texture.imageLayout +// } +// +// val writeDescriptorSets = VkWriteDescriptorSet.calloc(2) +// // Binding 0 : Vertex shader uniform buffer +// writeDescriptorSets[0].apply { +// type = VkStructureType.WRITE_DESCRIPTOR_SET +// dstSet = descriptorSet +// descriptorType = VkDescriptorType.UNIFORM_BUFFER +// dstBinding = 0 +// bufferInfo_ = uniformBufferVS.descriptor +// } +// // Binding 1 : Fragment shader texture sampler +// // Fragment shader: layout (binding = 1) uniform sampler2D samplerColor; +// writeDescriptorSets[1].apply { +// type = VkStructureType.WRITE_DESCRIPTOR_SET +// dstSet = descriptorSet +// // The descriptor set will use a combined image sampler (sampler and image could be split) +// descriptorType = VkDescriptorType.COMBINED_IMAGE_SAMPLER +// dstBinding = 1 // Shader binding point 1 +// imageInfo = textureDescriptor // Pointer to the descriptor image for our texture +// } +// +// device updateDescriptorSets writeDescriptorSets +// } +// +// fun preparePipelines() = stak { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo { +// topology = VkPrimitiveTopology.TRIANGLE_LIST +// } +// +// val rasterizationState = initializers.pipelineRasterizationStateCreateInfo( +// VkPolygonMode.FILL, +// VkCullMode.NONE.i, +// VkFrontFace.COUNTER_CLOCKWISE, +// 0) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState { colorWriteMask = 0xf } +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo { attachment = blendAttachmentState } +// +// val depthStencilState = initializers.pipelineDepthStencilStateCreateInfo( +// true, +// true, +// VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo { +// viewportCount = 1 +// scissorCount = 1 +// } +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo { +// rasterizationSamples = VkSampleCount.`1_BIT` +// } +// +// val dynamicStateEnables = it.vkDynamicStateBufferOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo { +// dynamicStates = dynamicStateEnables +// } +// +// // Load shaders +// val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { +// it[0].loadShader("$assetPath/shaders/texture/texture.vert", VkShaderStage.VERTEX_BIT) +// it[1].loadShader("$assetPath/shaders/texture/texture.frag", VkShaderStage.FRAGMENT_BIT) +// } +// +// val pipelineCreateInfo = initializers.pipelineCreateInfo( +// pipelineLayout, +// renderPass).apply { +// vertexInputState = vertices.inputState +// this.inputAssemblyState = inputAssemblyState +// this.rasterizationState = rasterizationState +// this.colorBlendState = colorBlendState +// this.multisampleState = multisampleState +// this.viewportState = viewportState +// this.depthStencilState = depthStencilState +// this.dynamicState = dynamicState +// stages = shaderStages +// } +// +// pipelines.solid = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// +// // Prepare and initialize uniform buffer containing shader uniforms +// fun prepareUniformBuffers() { +// // Vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBufferVS, +// VkDeviceSize(uboVS.size.L)) +// // updateUniformBuffers() // } +// +// val viewMatrix = Mat4(1f).translateAssign(0f, 0f, zoom) +// fun updateUniformBuffers() { +// // Vertex shader +// glm.perspective(uboVS.projection, 60f.rad, size.aspect, 0.001f, 256f) +// +// uboVS.model.apply { +// put(viewMatrix * Mat4(1f).translateAssign(cameraPos)) +// rotateAssign(rotation.x.rad, Vec3(1f, 0f, 0f)) +// rotateAssign(rotation.y.rad, Vec3(0f, 1f, 0f)) +// rotateAssign(rotation.z.rad, Vec3(0f, 0f, 1f)) +// } +// +// uboVS.viewPos put Vec4(0f, 0f, -zoom, 0f) +// +// uniformBufferVS.mapping { dst -> uboVS to dst } +// } +// +// override fun prepare() { +// super.prepare() +// loadTexture() +// generateQuad() +// setupVertexDescriptions() +// prepareUniformBuffers() +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSet() +// buildCommandBuffers() +// prepared = true +// window.show() // } +// +// override fun render() { +// if (!prepared) +// return +// draw() // } -} \ No newline at end of file +// +// override fun viewChanged() = updateUniformBuffers() +// +//// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) +//// { +//// if (overlay->header("Settings")) { +//// if (overlay->sliderFloat("LOD bias", &uboVS.lodBias, 0.0f, (float)texture.mipLevels)) { +//// updateUniformBuffers() +//// } +//// } +//// } +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/basics/08 Texture Cubemap.kt b/src/main/kotlin/vulkan/basics/08 Texture Cubemap.kt index 069e783..917b1f0 100644 --- a/src/main/kotlin/vulkan/basics/08 Texture Cubemap.kt +++ b/src/main/kotlin/vulkan/basics/08 Texture Cubemap.kt @@ -1,587 +1,587 @@ -/* -* Vulkan Example - Cube map texture loading and displaying -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -package vulkan.basics - -import gli_.gli -import glm_.L -import glm_.f -import glm_.func.rad -import glm_.glm -import glm_.mat4x4.Mat4 -import glm_.vec3.Vec3 -import org.lwjgl.system.MemoryUtil.* -import vkk.* -import vulkan.assetPath -import vulkan.base.* - -fun main(args: Array) { - TextureCubemap().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - -private class TextureCubemap : VulkanExampleBase() { - - var displaySkybox = true - - val cubeMap = Texture() - - // Vertex layout for the models - val vertexLayout = VertexLayout( - VertexComponent.POSITION, - VertexComponent.NORMAL, - VertexComponent.UV) - - object models { - val skybox = Model() - val objects = ArrayList() - var objectIndex = 0 - } - - object uniformBuffers { - val `object` = Buffer() - val skybox = Buffer() - } - - object uboVS : Bufferizable() { - var projection = Mat4() - @Order(1) - var model = Mat4() - @Order(2) - var lodBias = 0f - } - - object pipelines { - var skybox: VkPipeline = NULL - var reflect: VkPipeline = NULL - } - - object descriptorSets { - var `object`: VkDescriptorSet = NULL - var skybox: VkDescriptorSet = NULL - } - - var pipelineLayout: VkPipelineLayout = NULL - var descriptorSetLayout: VkDescriptorSetLayout = NULL - - val objectNames = ArrayList() - - init { - zoom = -4f - rotationSpeed = 0.25f - rotation(-7.25f, -120f, 0f) - title = "Cube map textures" -// settings.overlay = true - } - - override fun destroy() { - - // Clean up used Vulkan resources - // Note : Inherited destructor cleans up resources stored in base class - - device.apply { - // Clean up texture resources - destroyImageView(cubeMap.view) - destroyImage(cubeMap.image) - destroySampler(cubeMap.sampler) - freeMemory(cubeMap.deviceMemory) - - destroyPipeline(pipelines.skybox) - destroyPipeline(pipelines.reflect) - - destroyPipelineLayout(pipelineLayout) - destroyDescriptorSetLayout(descriptorSetLayout) - } - for (model in models.objects) - model.destroy() - - models.skybox.destroy() - - uniformBuffers.`object`.destroy() - uniformBuffers.skybox.destroy() - - super.destroy() - } - - // Enable physical device features required for this example - override fun getEnabledFeatures() { - if (deviceFeatures.samplerAnisotropy) - enabledFeatures.samplerAnisotropy = true - - when { - deviceFeatures.textureCompressionBC -> enabledFeatures.textureCompressionBC = true - deviceFeatures.textureCompressionASTC_LDR -> enabledFeatures.textureCompressionASTC_LDR = true - deviceFeatures.textureCompressionETC2 -> enabledFeatures.textureCompressionETC2 = true - } - } - - fun loadCubemap(filename: String, format: VkFormat, forceLinearTiling: Boolean) { - - val texCube = gli_.TextureCube(gli.load(filename)) - - assert(texCube.notEmpty()) - - cubeMap.size(texCube.extent()) - cubeMap.mipLevels = texCube.levels() - - - // Create a host-visible staging buffer that contains the raw image data - - val bufferCreateInfo = vk.BufferCreateInfo { - size = texCube.size.L - // This buffer is used as a transfer source for the buffer copy - usage = VkBufferUsage.TRANSFER_SRC_BIT.i - sharingMode = VkSharingMode.EXCLUSIVE - } - val stagingBuffer = device createBuffer bufferCreateInfo - - // Get memory requirements for the staging buffer (alignment, memory type bits) - val memReqs = device getBufferMemoryRequirements stagingBuffer - val memAllocInfo = vk.MemoryAllocateInfo { - allocationSize = memReqs.size - // Get memory type index for a host visible buffer - memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT) - } - val stagingMemory = device allocateMemory memAllocInfo - device.bindBufferMemory(stagingBuffer, stagingMemory) - - // Copy texture data into staging buffer - device.mappingMemory(stagingMemory, 0, memReqs.size, 0) { data -> - memCopy(memAddress(texCube.data()), data, texCube.size.L) - } - - // Create optimal tiled target image - val imageCreateInfo = vk.ImageCreateInfo { - imageType = VkImageType.`2D` - this.format = format - mipLevels = cubeMap.mipLevels - samples = VkSampleCount.`1_BIT` - tiling = VkImageTiling.OPTIMAL - sharingMode = VkSharingMode.EXCLUSIVE - initialLayout = VkImageLayout.UNDEFINED - extent.set(cubeMap.size.x, cubeMap.size.y, 1) - usage = VkImageUsage.TRANSFER_DST_BIT or VkImageUsage.SAMPLED_BIT - // Cube faces count as array layers in Vulkan - arrayLayers = 6 - // This flag is required for cube map images - flags = VkImageCreate.CUBE_COMPATIBLE_BIT.i - } - cubeMap.image = device createImage imageCreateInfo - - device.getImageMemoryRequirements(cubeMap.image, memReqs) - - memAllocInfo.allocationSize = memReqs.size - memAllocInfo.memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) - - cubeMap.deviceMemory = device allocateMemory memAllocInfo - device.bindImageMemory(cubeMap.image, cubeMap.deviceMemory) - - val copyCmd = createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) - - // Setup buffer copy regions for each face including all of it's miplevels - val bufferCopyRegions = vk.BufferImageCopy(6 * cubeMap.mipLevels) - var offset = 0L - - for (face in 0..5) - for (level in 0 until cubeMap.mipLevels) { - - bufferCopyRegions[face * cubeMap.mipLevels + level].apply { - imageSubresource.apply { - aspectMask = VkImageAspect.COLOR_BIT.i - mipLevel = level - baseArrayLayer = face - layerCount = 1 - } - val extent = texCube[face][level].extent() - imageExtent.set(extent.x, extent.y, 1) - bufferOffset = offset - } - // Increase offset into staging buffer for next level / face - offset += texCube[face][level].size - } - - // Image barrier for optimal image (target) - // Set initial layout for all array layers (faces) of the optimal (target) tiled texture - val subresourceRange = vk.ImageSubresourceRange { - aspectMask = VkImageAspect.COLOR_BIT.i - baseMipLevel = 0 - levelCount = cubeMap.mipLevels - layerCount = 6 - } - tools.setImageLayout( - copyCmd, - cubeMap.image, - VkImageLayout.UNDEFINED, - VkImageLayout.TRANSFER_DST_OPTIMAL, - subresourceRange) - - // Copy the cube map faces from the staging buffer to the optimal tiled image - copyCmd.copyBufferToImage( - stagingBuffer, - cubeMap.image, - VkImageLayout.TRANSFER_DST_OPTIMAL, - bufferCopyRegions) - - // Change texture image layout to shader read after all faces have been copied - cubeMap.imageLayout = VkImageLayout.SHADER_READ_ONLY_OPTIMAL - tools.setImageLayout( - copyCmd, - cubeMap.image, - VkImageLayout.TRANSFER_DST_OPTIMAL, - cubeMap.imageLayout, - subresourceRange) - - super.flushCommandBuffer(copyCmd, queue, true) - - // Create sampler - val sampler = vk.SamplerCreateInfo { - magFilter = VkFilter.LINEAR - minFilter = VkFilter.LINEAR - mipmapMode = VkSamplerMipmapMode.LINEAR - addressModeU = VkSamplerAddressMode.CLAMP_TO_EDGE - addressModeV = addressModeU - addressModeW = addressModeU - mipLodBias = 0f - compareOp = VkCompareOp.NEVER - minLod = 0f - maxLod = cubeMap.mipLevels.f - borderColor = VkBorderColor.FLOAT_OPAQUE_WHITE - maxAnisotropy = 1f - } - if (vulkanDevice.features.samplerAnisotropy) { - sampler.maxAnisotropy = vulkanDevice.properties.limits.maxSamplerAnisotropy - sampler.anisotropyEnable = true - } - cubeMap.sampler = device createSampler sampler - - // Create image view - val view = vk.ImageViewCreateInfo { - // Cube map view type - viewType = VkImageViewType.CUBE - this.format = format - components(VkComponentSwizzle.R, VkComponentSwizzle.G, VkComponentSwizzle.B, VkComponentSwizzle.A) - this.subresourceRange.apply { - set(VkImageAspect.COLOR_BIT.i, 0, 1, 0, 1) - // 6 array layers (faces) - layerCount = 6 - // Set number of mip levels - levelCount = cubeMap.mipLevels - } - image = cubeMap.image - } - cubeMap.view = device createImageView view - - // Clean up staging resources - device freeMemory stagingMemory - device destroyBuffer stagingBuffer - } - - fun loadTextures() { - // Vulkan core supports three different compressed texture formats - // As the support differs between implemementations we need to check device features and select a proper format and file - val (filename, format) = when { - - deviceFeatures.textureCompressionBC -> "cubemap_yokohama_bc3_unorm.ktx" to VkFormat.BC2_UNORM_BLOCK - - deviceFeatures.textureCompressionASTC_LDR -> "cubemap_yokohama_astc_8x8_unorm.ktx" to VkFormat.ASTC_8x8_UNORM_BLOCK - - deviceFeatures.textureCompressionETC2 -> "cubemap_yokohama_etc2_unorm.ktx" to VkFormat.ETC2_R8G8B8_UNORM_BLOCK - - else -> tools.exitFatal("Device does not support any compressed texture format!", VkResult.ERROR_FEATURE_NOT_PRESENT) - } - - loadCubemap("$assetPath/textures/$filename", format, false) - } - - override fun buildCommandBuffers() { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(defaultClearColor) - it[1].depthStencil.set(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@TextureCubemap.renderPass - renderArea.offset.set(0, 0) - renderArea.extent.set(size.x, size.y) - this.clearValues = clearValues - } - for (i in drawCmdBuffers.indices) { - - // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) // TODO BUG - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - setViewport(size) - setScissor(size) - - // Skybox - if (displaySkybox) { - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSets.skybox) - bindVertexBuffers(0, models.skybox.vertices.buffer) - bindIndexBuffer(models.skybox.indices.buffer, 0, VkIndexType.UINT32) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.skybox) - drawIndexed(models.skybox.indexCount, 1, 0, 0, 0) - } - - // 3D object - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSets.`object`) - bindVertexBuffers(models.objects[models.objectIndex].vertices.buffer) - bindIndexBuffer(models.objects[models.objectIndex].indices.buffer, 0, VkIndexType.UINT32) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.reflect) - drawIndexed(models.objects[models.objectIndex].indexCount, 1, 0, 0, 0) - - endRenderPass() - - end() - } - } - } - - fun loadAssets() { - // Skybox - models.skybox.loadFromFile("$assetPath/models/cube.obj", vertexLayout, 0.05f, vulkanDevice, queue) - // Objects - val filenames = listOf("sphere.obj", "teapot.dae", "torusknot.obj") - objectNames += listOf("Sphere", "Teapot", "Torusknot", "Venus") - for (file in filenames) { - val model = Model() - val scale = 0.05f * if (file == "venus.fbx") 3f else 1f - model.loadFromFile("$assetPath/models/$file", vertexLayout, scale, vulkanDevice, queue) - models.objects += model - } - } - - fun setupDescriptorPool() { - - val poolSizes = vk.DescriptorPoolSize( - VkDescriptorType.UNIFORM_BUFFER, 2, - VkDescriptorType.COMBINED_IMAGE_SAMPLER, 2) - - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) - - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - // Binding 0 : Vertex shader uniform buffer - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, - // Binding 1 : Fragment shader image sampler - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - - descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) - - pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - } - - fun setupDescriptorSets() { - - // Image descriptor for the cube map texture - val textureDescriptor = vk.DescriptorImageInfo(cubeMap.sampler, cubeMap.view, cubeMap.imageLayout) - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) - - // 3D object descriptor set - descriptorSets.`object` = device allocateDescriptorSets allocInfo - - val writeDescriptorSets = vk.WriteDescriptorSet(2).also { - // Binding 0 : Vertex shader uniform buffer - it[0](descriptorSets.`object`, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.`object`.descriptor) - // Binding 1 : Fragment shader cubemap sampler - it[1](descriptorSets.`object`, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textureDescriptor) - } - device.updateDescriptorSets(writeDescriptorSets) - - // Sky box descriptor set - descriptorSets.skybox = device allocateDescriptorSets allocInfo - - writeDescriptorSets.also { - // Binding 0 : Vertex shader uniform buffer - it[0](descriptorSets.skybox, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.skybox.descriptor) - // Binding 1 : Fragment shader cubemap sampler - it[1](descriptorSets.skybox, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textureDescriptor) - } - device updateDescriptorSets writeDescriptorSets - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.BACK_BIT.i, VkFrontFace.COUNTER_CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(false, false, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - // Vertex bindings and attributes - val vertexInputBinding = vk.VertexInputBindingDescription(0, vertexLayout.stride, VkVertexInputRate.VERTEX) - - val vertexInputAttributes = vk.VertexInputAttributeDescription( - 0, 0, VkFormat.R32G32B32_SFLOAT, 0, // Location 0: Position - 0, 1, VkFormat.R32G32B32_SFLOAT, Vec3.size) // Location 1: Normal - - val vertexInputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertexInputBinding - vertexAttributeDescriptions = vertexInputAttributes - } - - val shaderStages = vk.PipelineShaderStageCreateInfo(2) - - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass, 0).also { - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - it.vertexInputState = vertexInputState - } - // Skybox pipeline (background cube) - shaderStages[0].loadShader("$assetPath/shaders/texturecubemap/skybox.vert.spv", VkShaderStage.VERTEX_BIT) - shaderStages[1].loadShader("$assetPath/shaders/texturecubemap/skybox.frag.spv", VkShaderStage.FRAGMENT_BIT) - pipelines.skybox = device.createPipeline(pipelineCache, pipelineCreateInfo) - - // Cube map reflect pipeline - shaderStages[0].loadShader("$assetPath/shaders/texturecubemap/reflect.vert.spv", VkShaderStage.VERTEX_BIT) - shaderStages[1].loadShader("$assetPath/shaders/texturecubemap/reflect.frag.spv", VkShaderStage.FRAGMENT_BIT) - // Enable depth test and write - depthStencilState.depthWriteEnable = true - depthStencilState.depthTestEnable = true - // Flip cull mode - rasterizationState.cullMode = VkCullMode.FRONT_BIT.i - pipelines.reflect = device.createPipeline(pipelineCache, pipelineCreateInfo) - } - - /** Prepare and initialize uniform buffer containing shader uniforms */ - fun prepareUniformBuffers() { - - // Objact vertex shader uniform buffer - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBuffers.`object`, - uboVS.size.L) - - // Skybox vertex shader uniform buffer - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBuffers.skybox, - uboVS.size.L) - - // Map persistent - uniformBuffers.`object`.map() - uniformBuffers.skybox.map() - - updateUniformBuffers() - } - - fun updateUniformBuffers() { - - // 3D object - var viewMatrix = Mat4(1f) - uboVS.projection = glm.perspective(60.0f.rad, size.aspect, 0.001f, 256f) - viewMatrix = glm.translate(viewMatrix, 0f, 0f, zoom) - - uboVS.model put 1f - uboVS.model = viewMatrix * glm.translate(uboVS.model, cameraPos) - .rotateAssign(rotation.x.rad, 1f, 0f, 0f) - .rotateAssign(rotation.y.rad, 0f, 1f, 0f) - .rotateAssign(rotation.z.rad, 0f, 0f, 1f) - - uboVS to uniformBuffers.`object`.mapped - - // Skybox - viewMatrix put 1f - uboVS.projection = glm.perspective(60f.rad, size.aspect, 0.001f, 256f) - - uboVS.model put viewMatrix - uboVS.model - .rotateAssign(rotation.x.rad, 1f, 0f, 0f) - .rotateAssign(rotation.y.rad, 0f, 1f, 0f) - .rotateAssign(rotation.z.rad, 0f, 0f, 1f) - - uboVS to uniformBuffers.skybox.mapped - } - - fun draw() { - - super.prepareFrame() - - submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] - queue submit submitInfo - - super.submitFrame() - } - - override fun prepare() { - super.prepare() - loadTextures() - loadAssets() - prepareUniformBuffers() - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSets() - buildCommandBuffers() - prepared = true - window.show() - } - - override fun render() { - if (!prepared) - return - draw() - } - - override fun viewChanged() = updateUniformBuffers() - -// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) -// { -// if (overlay->header("Settings")) { -// if (overlay->sliderFloat("LOD bias", &uboVS.lodBias, 0.0f, (float)cubeMap.mipLevels)) { +///* +//* Vulkan Example - Cube map texture loading and displaying +//* +//* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +//package vulkan.basics +// +//import gli_.gli +//import glm_.L +//import glm_.f +//import glm_.func.rad +//import glm_.glm +//import glm_.mat4x4.Mat4 +//import glm_.vec3.Vec3 +//import org.lwjgl.system.MemoryUtil.* +//import vkk.* +//import vulkan.assetPath +//import vulkan.base.* +// +//fun main(args: Array) { +// TextureCubemap().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +//private class TextureCubemap : VulkanExampleBase() { +// +// var displaySkybox = true +// +// val cubeMap = Texture() +// +// // Vertex layout for the models +// val vertexLayout = VertexLayout( +// VertexComponent.POSITION, +// VertexComponent.NORMAL, +// VertexComponent.UV) +// +// object models { +// val skybox = Model() +// val objects = ArrayList() +// var objectIndex = 0 +// } +// +// object uniformBuffers { +// val `object` = Buffer() +// val skybox = Buffer() +// } +// +// object uboVS : Bufferizable() { +// var projection = Mat4() +// @Order(1) +// var model = Mat4() +// @Order(2) +// var lodBias = 0f +// } +// +// object pipelines { +// var skybox = VkPipeline (NULL) +// var reflect = VkPipeline(NULL) +// } +// +// object descriptorSets { +// var `object` = VkDescriptorSet (NULL) +// var skybox = VkDescriptorSet (NULL) +// } +// +// var pipelineLayout = VkPipelineLayout(NULL) +// var descriptorSetLayout = VkDescriptorSetLayout(NULL) +// +// val objectNames = ArrayList() +// +// init { +// zoom = -4f +// rotationSpeed = 0.25f +// rotation(-7.25f, -120f, 0f) +// title = "Cube map textures" +//// settings.overlay = true +// } +// +// override fun destroy() { +// +// // Clean up used Vulkan resources +// // Note : Inherited destructor cleans up resources stored in base class +// +// device.apply { +// // Clean up texture resources +// destroyImageView(cubeMap.view) +// destroyImage(cubeMap.image) +// destroySampler(cubeMap.sampler) +// freeMemory(cubeMap.deviceMemory) +// +// destroyPipeline(pipelines.skybox) +// destroyPipeline(pipelines.reflect) +// +// destroyPipelineLayout(pipelineLayout) +// destroyDescriptorSetLayout(descriptorSetLayout) +// } +// for (model in models.objects) +// model.destroy() +// +// models.skybox.destroy() +// +// uniformBuffers.`object`.destroy() +// uniformBuffers.skybox.destroy() +// +// super.destroy() +// } +// +// // Enable physical device features required for this example +// override fun getEnabledFeatures() { +// if (deviceFeatures.samplerAnisotropy) +// enabledFeatures.samplerAnisotropy = true +// +// when { +// deviceFeatures.textureCompressionBC -> enabledFeatures.textureCompressionBC = true +// deviceFeatures.textureCompressionASTC_LDR -> enabledFeatures.textureCompressionASTC_LDR = true +// deviceFeatures.textureCompressionETC2 -> enabledFeatures.textureCompressionETC2 = true +// } +// } +// +// fun loadCubemap(filename: String, format: VkFormat, forceLinearTiling: Boolean) { +// +// val texCube = gli_.TextureCube(gli.load(filename)) +// +// assert(texCube.notEmpty()) +// +// cubeMap.size(texCube.extent()) +// cubeMap.mipLevels = texCube.levels() +// +// +// // Create a host-visible staging buffer that contains the raw image data +// +// val bufferCreateInfo = vk.BufferCreateInfo { +// size = VkDeviceSize(texCube.size.L) +// // This buffer is used as a transfer source for the buffer copy +// usage = VkBufferUsage.TRANSFER_SRC_BIT.i +// sharingMode = VkSharingMode.EXCLUSIVE +// } +// val stagingBuffer = device createBuffer bufferCreateInfo +// +// // Get memory requirements for the staging buffer (alignment, memory type bits) +// val memReqs = device getBufferMemoryRequirements stagingBuffer +// val memAllocInfo = vk.MemoryAllocateInfo { +// allocationSize = memReqs.size +// // Get memory type index for a host visible buffer +// memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT) +// } +// val stagingMemory = device allocateMemory memAllocInfo +// device.bindBufferMemory(stagingBuffer, stagingMemory) +// +// // Copy texture data into staging buffer +// device.mappingMemory(stagingMemory, VkDeviceSize(0), memReqs.size) { data -> +// memCopy(memAddress(texCube.data()), data, texCube.size.L) +// } +// +// // Create optimal tiled target image +// val imageCreateInfo = vk.ImageCreateInfo { +// imageType = VkImageType.`2D` +// this.format = format +// mipLevels = cubeMap.mipLevels +// samples = VkSampleCount.`1_BIT` +// tiling = VkImageTiling.OPTIMAL +// sharingMode = VkSharingMode.EXCLUSIVE +// initialLayout = VkImageLayout.UNDEFINED +// extent.set(cubeMap.size.x, cubeMap.size.y, 1) +// usage = VkImageUsage.TRANSFER_DST_BIT or VkImageUsage.SAMPLED_BIT +// // Cube faces count as array layers in Vulkan +// arrayLayers = 6 +// // This flag is required for cube map images +// flags = VkImageCreate.CUBE_COMPATIBLE_BIT.i +// } +// cubeMap.image = device createImage imageCreateInfo +// +// device.getImageMemoryRequirements(cubeMap.image, memReqs) +// +// memAllocInfo.allocationSize = memReqs.size +// memAllocInfo.memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) +// +// cubeMap.deviceMemory = device allocateMemory memAllocInfo +// device.bindImageMemory(cubeMap.image, cubeMap.deviceMemory) +// +// val copyCmd = createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) +// +// // Setup buffer copy regions for each face including all of it's miplevels +// val bufferCopyRegions = vk.BufferImageCopy(6 * cubeMap.mipLevels) +// var offset = VkDeviceSize(0) +// +// for (face in 0..5) +// for (level in 0 until cubeMap.mipLevels) { +// +// bufferCopyRegions[face * cubeMap.mipLevels + level].apply { +// imageSubresource.apply { +// aspectMask = VkImageAspect.COLOR_BIT.i +// mipLevel = level +// baseArrayLayer = face +// layerCount = 1 +// } +// val extent = texCube[face][level].extent() +// imageExtent.set(extent.x, extent.y, 1) +// bufferOffset = offset +// } +// // Increase offset into staging buffer for next level / face +// offset += texCube[face][level].size +// } +// +// // Image barrier for optimal image (target) +// // Set initial layout for all array layers (faces) of the optimal (target) tiled texture +// val subresourceRange = vk.ImageSubresourceRange { +// aspectMask = VkImageAspect.COLOR_BIT.i +// baseMipLevel = 0 +// levelCount = cubeMap.mipLevels +// layerCount = 6 +// } +// tools.setImageLayout( +// copyCmd, +// cubeMap.image, +// VkImageLayout.UNDEFINED, +// VkImageLayout.TRANSFER_DST_OPTIMAL, +// subresourceRange) +// +// // Copy the cube map faces from the staging buffer to the optimal tiled image +// copyCmd.copyBufferToImage( +// stagingBuffer, +// cubeMap.image, +// VkImageLayout.TRANSFER_DST_OPTIMAL, +// bufferCopyRegions) +// +// // Change texture image layout to shader read after all faces have been copied +// cubeMap.imageLayout = VkImageLayout.SHADER_READ_ONLY_OPTIMAL +// tools.setImageLayout( +// copyCmd, +// cubeMap.image, +// VkImageLayout.TRANSFER_DST_OPTIMAL, +// cubeMap.imageLayout, +// subresourceRange) +// +// super.flushCommandBuffer(copyCmd, queue, true) +// +// // Create sampler +// val sampler = vk.SamplerCreateInfo { +// magFilter = VkFilter.LINEAR +// minFilter = VkFilter.LINEAR +// mipmapMode = VkSamplerMipmapMode.LINEAR +// addressModeU = VkSamplerAddressMode.CLAMP_TO_EDGE +// addressModeV = addressModeU +// addressModeW = addressModeU +// mipLodBias = 0f +// compareOp = VkCompareOp.NEVER +// minLod = 0f +// maxLod = cubeMap.mipLevels.f +// borderColor = VkBorderColor.FLOAT_OPAQUE_WHITE +// maxAnisotropy = 1f +// } +// if (vulkanDevice.features.samplerAnisotropy) { +// sampler.maxAnisotropy = vulkanDevice.properties.limits.maxSamplerAnisotropy +// sampler.anisotropyEnable = true +// } +// cubeMap.sampler = device createSampler sampler +// +// // Create image view +// val view = vk.ImageViewCreateInfo { +// // Cube map view type +// viewType = VkImageViewType.CUBE +// this.format = format +// components(VkComponentSwizzle.R, VkComponentSwizzle.G, VkComponentSwizzle.B, VkComponentSwizzle.A) +// this.subresourceRange.apply { +// set(VkImageAspect.COLOR_BIT.i, 0, 1, 0, 1) +// // 6 array layers (faces) +// layerCount = 6 +// // Set number of mip levels +// levelCount = cubeMap.mipLevels +// } +// image = cubeMap.image +// } +// cubeMap.view = device createImageView view +// +// // Clean up staging resources +// device freeMemory stagingMemory +// device destroyBuffer stagingBuffer +// } +// +// fun loadTextures() { +// // Vulkan core supports three different compressed texture formats +// // As the support differs between implemementations we need to check device features and select a proper format and file +// val (filename, format) = when { +// +// deviceFeatures.textureCompressionBC -> "cubemap_yokohama_bc3_unorm.ktx" to VkFormat.BC2_UNORM_BLOCK +// +// deviceFeatures.textureCompressionASTC_LDR -> "cubemap_yokohama_astc_8x8_unorm.ktx" to VkFormat.ASTC_8x8_UNORM_BLOCK +// +// deviceFeatures.textureCompressionETC2 -> "cubemap_yokohama_etc2_unorm.ktx" to VkFormat.ETC2_R8G8B8_UNORM_BLOCK +// +// else -> tools.exitFatal("Device does not support any compressed texture format!", ERROR_FEATURE_NOT_PRESENT) +// } +// +// loadCubemap("$assetPath/textures/$filename", format, false) +// } +// +// override fun buildCommandBuffers() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(defaultClearColor) +// it[1].depthStencil.set(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@TextureCubemap.renderPass +// renderArea.offset.set(0, 0) +// renderArea.extent.set(size.x, size.y) +// this.clearValues = clearValues +// } +// for (i in drawCmdBuffers.indices) { +// +// // Set target frame buffer +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) // TODO BUG +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// setViewport(size) +// setScissor(size) +// +// // Skybox +// if (displaySkybox) { +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSets.skybox) +// bindVertexBuffers(0, models.skybox.vertices.buffer) +// bindIndexBuffer(models.skybox.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.skybox) +// drawIndexed(models.skybox.indexCount, 1, 0, 0, 0) +// } +// +// // 3D object +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSets.`object`) +// bindVertexBuffers(models.objects[models.objectIndex].vertices.buffer) +// bindIndexBuffer(models.objects[models.objectIndex].indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.reflect) +// drawIndexed(models.objects[models.objectIndex].indexCount, 1, 0, 0, 0) +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// fun loadAssets() { +// // Skybox +// models.skybox.loadFromFile("$assetPath/models/cube.obj", vertexLayout, 0.05f, vulkanDevice, queue) +// // Objects +// val filenames = listOf("sphere.obj", "teapot.dae", "torusknot.obj") +// objectNames += listOf("Sphere", "Teapot", "Torusknot", "Venus") +// for (file in filenames) { +// val model = Model() +// val scale = 0.05f * if (file == "venus.fbx") 3f else 1f +// model.loadFromFile("$assetPath/models/$file", vertexLayout, scale, vulkanDevice, queue) +// models.objects += model +// } +// } +// +// fun setupDescriptorPool() { +// +// val poolSizes = vk.DescriptorPoolSize( +// VkDescriptorType.UNIFORM_BUFFER, 2, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, 2) +// +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) +// +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// // Binding 0 : Vertex shader uniform buffer +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, +// // Binding 1 : Fragment shader image sampler +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// +// descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) +// +// pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// } +// +// fun setupDescriptorSets() { +// +// // Image descriptor for the cube map texture +// val textureDescriptor = vk.DescriptorImageInfo(cubeMap.sampler, cubeMap.view, cubeMap.imageLayout) +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) +// +// // 3D object descriptor set +// descriptorSets.`object` = device allocateDescriptorSets allocInfo +// +// val writeDescriptorSets = vk.WriteDescriptorSet(2).also { +// // Binding 0 : Vertex shader uniform buffer +// it[0](descriptorSets.`object`, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.`object`.descriptor) +// // Binding 1 : Fragment shader cubemap sampler +// it[1](descriptorSets.`object`, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textureDescriptor) +// } +// device.updateDescriptorSets(writeDescriptorSets) +// +// // Sky box descriptor set +// descriptorSets.skybox = device allocateDescriptorSets allocInfo +// +// writeDescriptorSets.also { +// // Binding 0 : Vertex shader uniform buffer +// it[0](descriptorSets.skybox, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.skybox.descriptor) +// // Binding 1 : Fragment shader cubemap sampler +// it[1](descriptorSets.skybox, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textureDescriptor) +// } +// device updateDescriptorSets writeDescriptorSets +// } +// +// fun preparePipelines() { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.BACK_BIT.i, VkFrontFace.COUNTER_CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(false, false, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// // Vertex bindings and attributes +// val vertexInputBinding = vk.VertexInputBindingDescription(0, vertexLayout.stride, VkVertexInputRate.VERTEX) +// +// val vertexInputAttributes = vk.VertexInputAttributeDescription( +// 0, 0, VkFormat.R32G32B32_SFLOAT, 0, // Location 0: Position +// 0, 1, VkFormat.R32G32B32_SFLOAT, Vec3.size) // Location 1: Normal +// +// val vertexInputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertexInputBinding +// vertexAttributeDescriptions = vertexInputAttributes +// } +// +// val shaderStages = vk.PipelineShaderStageCreateInfo(2) +// +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass, 0).also { +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// it.vertexInputState = vertexInputState +// } +// // Skybox pipeline (background cube) +// shaderStages[0].loadShader("$assetPath/shaders/texturecubemap/skybox.vert.spv", VkShaderStage.VERTEX_BIT) +// shaderStages[1].loadShader("$assetPath/shaders/texturecubemap/skybox.frag.spv", VkShaderStage.FRAGMENT_BIT) +// pipelines.skybox = device.createPipeline(pipelineCache, pipelineCreateInfo) +// +// // Cube map reflect pipeline +// shaderStages[0].loadShader("$assetPath/shaders/texturecubemap/reflect.vert.spv", VkShaderStage.VERTEX_BIT) +// shaderStages[1].loadShader("$assetPath/shaders/texturecubemap/reflect.frag.spv", VkShaderStage.FRAGMENT_BIT) +// // Enable depth test and write +// depthStencilState.depthWriteEnable = true +// depthStencilState.depthTestEnable = true +// // Flip cull mode +// rasterizationState.cullMode = VkCullMode.FRONT_BIT.i +// pipelines.reflect = device.createPipeline(pipelineCache, pipelineCreateInfo) +// } +// +// /** Prepare and initialize uniform buffer containing shader uniforms */ +// fun prepareUniformBuffers() { +// +// // Objact vertex shader uniform buffer +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBuffers.`object`, +// VkDeviceSize(uboVS.size.L)) +// +// // Skybox vertex shader uniform buffer +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBuffers.skybox, +// VkDeviceSize(uboVS.size.L)) +// +// // Map persistent +// uniformBuffers.`object`.map() +// uniformBuffers.skybox.map() +// // updateUniformBuffers() // } -// if (overlay->comboBox("Object type", &models.objectIndex, objectNames)) { -// buildCommandBuffers() +// +// fun updateUniformBuffers() { +// +// // 3D object +// var viewMatrix = Mat4(1f) +// uboVS.projection = glm.perspective(60.0f.rad, size.aspect, 0.001f, 256f) +// viewMatrix = glm.translate(viewMatrix, 0f, 0f, zoom) +// +// uboVS.model put 1f +// uboVS.model = viewMatrix * glm.translate(uboVS.model, cameraPos) +// .rotateAssign(rotation.x.rad, 1f, 0f, 0f) +// .rotateAssign(rotation.y.rad, 0f, 1f, 0f) +// .rotateAssign(rotation.z.rad, 0f, 0f, 1f) +// +// uboVS to uniformBuffers.`object`.mapped +// +// // Skybox +// viewMatrix put 1f +// uboVS.projection = glm.perspective(60f.rad, size.aspect, 0.001f, 256f) +// +// uboVS.model put viewMatrix +// uboVS.model +// .rotateAssign(rotation.x.rad, 1f, 0f, 0f) +// .rotateAssign(rotation.y.rad, 0f, 1f, 0f) +// .rotateAssign(rotation.z.rad, 0f, 0f, 1f) +// +// uboVS to uniformBuffers.skybox.mapped // } -// if (overlay->checkBox("Skybox", &displaySkybox)) { -// buildCommandBuffers() +// +// fun draw() { +// +// super.prepareFrame() +// +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// queue submit submitInfo +// +// super.submitFrame() // } +// +// override fun prepare() { +// super.prepare() +// loadTextures() +// loadAssets() +// prepareUniformBuffers() +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSets() +// buildCommandBuffers() +// prepared = true +// window.show() // } +// +// override fun render() { +// if (!prepared) +// return +// draw() // } -} \ No newline at end of file +// +// override fun viewChanged() = updateUniformBuffers() +// +//// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) +//// { +//// if (overlay->header("Settings")) { +//// if (overlay->sliderFloat("LOD bias", &uboVS.lodBias, 0.0f, (float)cubeMap.mipLevels)) { +//// updateUniformBuffers() +//// } +//// if (overlay->comboBox("Object type", &models.objectIndex, objectNames)) { +//// buildCommandBuffers() +//// } +//// if (overlay->checkBox("Skybox", &displaySkybox)) { +//// buildCommandBuffers() +//// } +//// } +//// } +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/basics/09 Texture Array.kt b/src/main/kotlin/vulkan/basics/09 Texture Array.kt index fa059e1..50ce525 100644 --- a/src/main/kotlin/vulkan/basics/09 Texture Array.kt +++ b/src/main/kotlin/vulkan/basics/09 Texture Array.kt @@ -1,579 +1,579 @@ -/* -* Vulkan Example - Texture arrays and instanced rendering -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -package vulkan.basics - -import ab.appBuffer -import gli_.Texture2dArray -import gli_.gli -import glm_.L -import glm_.buffer.bufferBig -import glm_.f -import glm_.func.rad -import glm_.glm -import glm_.mat4x4.Mat4 -import glm_.vec2.Vec2 -import glm_.vec3.Vec3 -import glm_.vec4.Vec4 -import org.lwjgl.system.MemoryUtil.* -import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo -import org.lwjgl.vulkan.VkVertexInputAttributeDescription -import org.lwjgl.vulkan.VkVertexInputBindingDescription -import uno.kotlin.buffers.capacity -import vkk.* -import vulkan.VERTEX_BUFFER_BIND_ID -import vulkan.assetPath -import vulkan.base.Buffer -import vulkan.base.Texture -import vulkan.base.VulkanExampleBase -import vulkan.base.tools -import java.nio.ByteBuffer - -fun main(args: Array) { - TextureArray().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - -class TextureArray : VulkanExampleBase() { - - /** Vertex layout for this example */ - object Vertex { - // float pos[3]; -// float uv[2]; - val size = Vec3.size + Vec2.size - } - - // Number of array layers in texture array - // Also used as instance count - var layerCount = 0 - val textureArray = Texture() - - object vertices { - lateinit var inputState: VkPipelineVertexInputStateCreateInfo - lateinit var bindingDescription: VkVertexInputBindingDescription - lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer - } - - val vertexBuffer = Buffer() - val indexBuffer = Buffer() - var indexCount = 0 - - val uniformBufferVS = Buffer() - - class UboInstanceData { - // Model matrix - var model = Mat4() - // Texture array index - // Vec4 due to padding - var arrayIndex = Vec4() - - fun to(bytes: ByteBuffer, offset: Int) { - model.to(bytes, offset) - bytes.putFloat(offset + Mat4.size, arrayIndex.x) - } - - companion object { - val size = Mat4.size + Vec4.size - } - } - - object uboVS { - // Global matrices - object matrices : Bufferizable() { - var projection = Mat4() - var view = Mat4() - } - // Seperate data for each instance - val instance = ArrayList() - - fun prepare() { - buffer = bufferBig(matrices.size + instance.size * UboInstanceData.size) - address = memAddress(buffer) - for (i in instance.indices) - instance[i].to(buffer, matrices.size + UboInstanceData.size * i) - } - - lateinit var buffer: ByteBuffer - var address = NULL - } - - - var pipeline: VkPipeline = NULL - var pipelineLayout: VkPipelineLayout = NULL - var descriptorSet: VkDescriptorSet = NULL - var descriptorSetLayout: VkDescriptorSetLayout = NULL - - init { - zoom = -15f - rotationSpeed = 0.25f - rotation(-15f, 35f, 0f) - title = "Texture arrays" -// settings.overlay = true - } - - override fun destroy() { - - // Clean up used Vulkan resources - // Note : Inherited destructor cleans up resources stored in base class - - // Clean up texture resources - device.apply { - destroyImageView(textureArray.view) - destroyImage(textureArray.image) - destroySampler(textureArray.sampler) - freeMemory(textureArray.deviceMemory) - - destroyPipeline(pipeline) - - destroyPipelineLayout(pipelineLayout) - destroyDescriptorSetLayout(descriptorSetLayout) - } - vertexBuffer.destroy() - indexBuffer.destroy() - - uniformBufferVS.destroy() - - super.destroy() - } - - fun loadTextureArray(filename: String, format: VkFormat) { - - val tex2DArray = Texture2dArray(gli.load(filename)) - - assert(tex2DArray.notEmpty()) - - textureArray.size(tex2DArray.extent()) - layerCount = tex2DArray.layers() - - // Create a host-visible staging buffer that contains the raw image data - - val bufferCreateInfo = vk.BufferCreateInfo { - size = tex2DArray.size.L - // This buffer is used as a transfer source for the buffer copy - usage = VkBufferUsage.TRANSFER_SRC_BIT.i - sharingMode = VkSharingMode.EXCLUSIVE - } - val stagingBuffer = device createBuffer bufferCreateInfo - - // Get memory requirements for the staging buffer (alignment, memory type bits) - val memReqs = device getBufferMemoryRequirements stagingBuffer - val memAllocInfo = vk.MemoryAllocateInfo { - allocationSize = memReqs.size - // Get memory type index for a host visible buffer - memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT) - } - val stagingMemory = device allocateMemory memAllocInfo - device.bindBufferMemory(stagingBuffer, stagingMemory) - - // Copy texture data into staging buffer - device.mappingMemory(stagingMemory, 0, memReqs.size, 0) { data -> - memCopy(memAddress(tex2DArray.data()), data, tex2DArray.size.L) - } - - // Setup buffer copy regions for array layers - val bufferCopyRegions = vk.BufferImageCopy(layerCount) - var offset = 0L - - for (layer in 0 until layerCount) { - - bufferCopyRegions[layer].apply { - imageSubresource.apply { - aspectMask = VkImageAspect.COLOR_BIT.i - mipLevel = 0 - baseArrayLayer = layer - layerCount = 1 - } - imageExtent.apply { - val (w, h) = tex2DArray[layer][0].extent() // TODO BUG - width = w - height = h - depth = 1 - } - bufferOffset = offset - } - - // Increase offset into staging buffer for next level / face - offset += tex2DArray[layer][0].size - } - - // Create optimal tiled target image - val imageCreateInfo = vk.ImageCreateInfo { - imageType = VkImageType.`2D` - this.format = format - mipLevels = 1 - samples = VkSampleCount.`1_BIT` - tiling = VkImageTiling.OPTIMAL - sharingMode = VkSharingMode.EXCLUSIVE - initialLayout = VkImageLayout.UNDEFINED - extent.set(textureArray.size.x, textureArray.size.y, 1) - usage = VkImageUsage.TRANSFER_DST_BIT or VkImageUsage.SAMPLED_BIT - arrayLayers = layerCount - } - textureArray.image = device createImage imageCreateInfo - - device.getImageMemoryRequirements(textureArray.image, memReqs) - - memAllocInfo.allocationSize = memReqs.size - memAllocInfo.memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) - - textureArray.deviceMemory = device allocateMemory memAllocInfo - device.bindImageMemory(textureArray.image, textureArray.deviceMemory) - - val copyCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) - - // Image barrier for optimal image (target) - // Set initial layout for all array layers (faces) of the optimal (target) tiled texture - val subresourceRange = vk.ImageSubresourceRange { - aspectMask = VkImageAspect.COLOR_BIT.i - baseMipLevel = 0 - levelCount = 1 - layerCount = this@TextureArray.layerCount - } - tools.setImageLayout( - copyCmd, - textureArray.image, - VkImageLayout.UNDEFINED, - VkImageLayout.TRANSFER_DST_OPTIMAL, - subresourceRange) - - // Copy the cube map faces from the staging buffer to the optimal tiled image - copyCmd.copyBufferToImage( - stagingBuffer, - textureArray.image, - VkImageLayout.TRANSFER_DST_OPTIMAL, - bufferCopyRegions) - - // Change texture image layout to shader read after all faces have been copied - textureArray.imageLayout = VkImageLayout.SHADER_READ_ONLY_OPTIMAL - tools.setImageLayout( - copyCmd, - textureArray.image, - VkImageLayout.TRANSFER_DST_OPTIMAL, - textureArray.imageLayout, - subresourceRange) - - super.flushCommandBuffer(copyCmd, queue, true) - - // Create sampler - val sampler = vk.SamplerCreateInfo { - magFilter = VkFilter.LINEAR - minFilter = VkFilter.LINEAR - mipmapMode = VkSamplerMipmapMode.LINEAR - addressModeU = VkSamplerAddressMode.CLAMP_TO_EDGE - addressModeV = addressModeU - addressModeW = addressModeU - mipLodBias = 0f - maxAnisotropy = 8f - compareOp = VkCompareOp.NEVER - minLod = 0f - maxLod = 0f - borderColor = VkBorderColor.FLOAT_OPAQUE_WHITE - } - textureArray.sampler = device createSampler sampler - - // Create image view - val view = vk.ImageViewCreateInfo { - viewType = VkImageViewType.`2D_ARRAY` - this.format = format - components(VkComponentSwizzle.R, VkComponentSwizzle.G, VkComponentSwizzle.B, VkComponentSwizzle.A) - this.subresourceRange.apply { - set(VkImageAspect.COLOR_BIT.i, 0, 1, 0, 1) - layerCount = this@TextureArray.layerCount // TODO move in ::set - levelCount = 1 - } - image = textureArray.image - } - textureArray.view = device createImageView view - - // Clean up staging resources - device freeMemory stagingMemory - device destroyBuffer stagingBuffer - } - - fun loadTextures() { - // Vulkan core supports three different compressed texture formats - // As the support differs between implemementations we need to check device features and select a proper format and file - val (filename, format) = when { - deviceFeatures.textureCompressionBC -> "texturearray_bc3_unorm.ktx" to VkFormat.BC3_UNORM_BLOCK - deviceFeatures.textureCompressionASTC_LDR -> "texturearray_astc_8x8_unorm.ktx" to VkFormat.ASTC_8x8_UNORM_BLOCK - deviceFeatures.textureCompressionETC2 -> "texturearray_etc2_unorm.ktx" to VkFormat.ETC2_R8G8B8_UNORM_BLOCK - else -> tools.exitFatal("Device does not support any compressed texture format!", VkResult.ERROR_FEATURE_NOT_PRESENT) - } - loadTextureArray("$assetPath/textures/$filename", format) - } - - override fun buildCommandBuffers() { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(defaultClearColor) - it[1].depthStencil.set(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@TextureArray.renderPass - renderArea.apply { - offset.set(0, 0) - extent.set(size.x, size.y) - } - this.clearValues = clearValues - } - for (i in drawCmdBuffers.indices) { - // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) // TODO BUG - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - setViewport(size) - setScissor(size) - - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipeline) - - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, vertexBuffer.buffer) - bindIndexBuffer(indexBuffer.buffer, 0, VkIndexType.UINT32) - - drawIndexed(indexCount, layerCount, 0, 0, 0) - - endRenderPass() - - end() - } - } - } - - fun generateQuad() { - // Setup vertices for a single uv-mapped quad made from two triangles - val vertices = appBuffer.floatBufferOf( - +2.5f, +2.5f, 0f, 1f, 1f, - -2.5f, +2.5f, 0f, 0f, 1f, - -2.5f, -2.5f, 0f, 0f, 0f, - +2.5f, -2.5f, 0f, 1f, 0f) - - // Setup indices - val indices = appBuffer.intBufferOf(0, 1, 2, 2, 3, 0) - indexCount = indices.capacity - - // Create buffers - // For the sake of simplicity we won't stage the vertex data to the gpu memory - // Vertex buffer - vulkanDevice.createBuffer( - VkBufferUsage.VERTEX_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - vertexBuffer, - vertices) - // Index buffer - vulkanDevice.createBuffer( - VkBufferUsage.INDEX_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - indexBuffer, - indices) - } - - fun setupVertexDescriptions() { - // Binding description - vertices.bindingDescription = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, Vertex.size, VkVertexInputRate.VERTEX) - - // Attribute descriptions - // Describes memory layout and shader positions - vertices.attributeDescriptions = vk.VertexInputAttributeDescription( - // Location 0 : Position - VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, 0, - // Location 1 : Texture coordinates - VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32_SFLOAT, Vec3.size) - - vertices.inputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertices.bindingDescription - vertexAttributeDescriptions = vertices.attributeDescriptions - } - } - - fun setupDescriptorPool() { - - val poolSizes = vk.DescriptorPoolSize( - VkDescriptorType.UNIFORM_BUFFER, 1, - VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1) - - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) - - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - // Binding 0 : Vertex shader uniform buffer - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, - // Binding 1 : Fragment shader image sampler (texture array) - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - - descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) - - pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - } - - fun setupDescriptorSet() { - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) - - descriptorSet = device allocateDescriptorSets allocInfo - - // Image descriptor for the texture array - val textureDescriptor = vk.DescriptorImageInfo(textureArray.sampler, textureArray.view, textureArray.imageLayout) - - val writeDescriptorSets = vk.WriteDescriptorSet( - // Binding 0 : Vertex shader uniform buffer - descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBufferVS.descriptor, - // Binding 1 : Fragment shader cubemap sampler - descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textureDescriptor) - - device updateDescriptorSets writeDescriptorSets - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.COUNTER_CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - // Instacing pipeline - // Load shaders - val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { - it[0].loadShader("$assetPath/shaders/texturearray/instancing.vert.spv", VkShaderStage.VERTEX_BIT) - it[1].loadShader("$assetPath/shaders/texturearray/instancing.frag.spv", VkShaderStage.FRAGMENT_BIT) - } - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { - it.vertexInputState = vertices.inputState - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - } - pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - fun prepareUniformBuffers() { - - for (i in 0 until layerCount) - uboVS.instance += UboInstanceData() - - val uboSize = uboVS.matrices.size + layerCount * UboInstanceData.size - - // Vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBufferVS, - uboSize.L) - - // Array indices and model matrices are fixed - val offset = -1.5f - val center = (layerCount * offset) / 2 - for (i in 0 until layerCount) { - // Instance model matrix - uboVS.instance[i].model = glm.translate(Mat4(1f), 0f, i * offset - center, 0f) - .rotateAssign(60f.rad, 1f, 0f, 0f) - // Instance texture array index - uboVS.instance[i].arrayIndex.x = i.f - } - - // Update instanced part of the uniform buffer - val dataOffset = uboVS.matrices.size.L - val dataSize = layerCount * UboInstanceData.size.L - uboVS.prepare() - device.mappingMemory(uniformBufferVS.memory, dataOffset, dataSize, 0) { data -> - memCopy(uboVS.address + dataOffset, data, dataSize) - } - - // Map persistent - uniformBufferVS.map() - - updateUniformBufferMatrices() - } - - fun updateUniformBufferMatrices() { - - // Only updates the uniform buffer block part containing the global matrices - - // Projection - uboVS.matrices.projection = glm.perspective(60f.rad, size.aspect, 0.001f, 256f) - - // View - uboVS.matrices.view = glm.translate(Mat4(1f), 0f, -1f, zoom) - .rotateAssign(rotation.x.rad, 1f, 0f, 0f) - .rotateAssign(rotation.y.rad, 0f, 1f, 0f) - .rotateAssign(rotation.z.rad, 0f, 0f, 1f) - - // Only update the matrices part of the uniform buffer - uboVS.matrices to uniformBufferVS.mapped - } - - fun draw() { - - super.prepareFrame() - - submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] - queue submit submitInfo - - super.submitFrame() - } - - override fun prepare() { - - super.prepare() - loadTextures() - setupVertexDescriptions() - generateQuad() - prepareUniformBuffers() - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSet() - buildCommandBuffers() - prepared = true - window.show() - } - - override fun render() { - if (!prepared) - return - draw() - } - - override fun viewChanged() = updateUniformBufferMatrices() -} \ No newline at end of file +///* +//* Vulkan Example - Texture arrays and instanced rendering +//* +//* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +//package vulkan.basics +// +//import gli_.Texture2dArray +//import gli_.gli +//import glm_.L +//import glm_.f +//import glm_.func.rad +//import glm_.glm +//import glm_.mat4x4.Mat4 +//import glm_.vec2.Vec2 +//import glm_.vec3.Vec3 +//import glm_.vec4.Vec4 +//import kool.bufferBig +//import kool.cap +//import kool.stak +//import org.lwjgl.system.MemoryUtil.* +//import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo +//import org.lwjgl.vulkan.VkVertexInputAttributeDescription +//import org.lwjgl.vulkan.VkVertexInputBindingDescription +//import vkk.* +//import vulkan.VERTEX_BUFFER_BIND_ID +//import vulkan.assetPath +//import vulkan.base.Buffer +//import vulkan.base.Texture +//import vulkan.base.VulkanExampleBase +//import vulkan.base.tools +//import java.nio.ByteBuffer +// +//fun main(args: Array) { +// TextureArray().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +//class TextureArray : VulkanExampleBase() { +// +// /** Vertex layout for this example */ +// object Vertex { +// // float pos[3]; +//// float uv[2]; +// val size = Vec3.size + Vec2.size +// } +// +// // Number of array layers in texture array +// // Also used as instance count +// var layerCount = 0 +// val textureArray = Texture() +// +// object vertices { +// lateinit var inputState: VkPipelineVertexInputStateCreateInfo +// lateinit var bindingDescription: VkVertexInputBindingDescription +// lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer +// } +// +// val vertexBuffer = Buffer() +// val indexBuffer = Buffer() +// var indexCount = 0 +// +// val uniformBufferVS = Buffer() +// +// class UboInstanceData { +// // Model matrix +// var model = Mat4() +// // Texture array index +// // Vec4 due to padding +// var arrayIndex = Vec4() +// +// fun to(bytes: ByteBuffer, offset: Int) { +// model.to(bytes, offset) +// bytes.putFloat(offset + Mat4.size, arrayIndex.x) +// } +// +// companion object { +// val size = Mat4.size + Vec4.size +// } +// } +// +// object uboVS { +// // Global matrices +// object matrices : Bufferizable() { +// var projection = Mat4() +// var view = Mat4() +// } +// // Seperate data for each instance +// val instance = ArrayList() +// +// fun prepare() { +// buffer = bufferBig(matrices.size + instance.size * UboInstanceData.size) +// address = memAddress(buffer) +// for (i in instance.indices) +// instance[i].to(buffer, matrices.size + UboInstanceData.size * i) +// } +// +// lateinit var buffer: ByteBuffer +// var address = NULL +// } +// +// +// var pipeline = VkPipeline(NULL) +// var pipelineLayout = VkPipelineLayout(NULL) +// var descriptorSet= VkDescriptorSet (NULL) +// var descriptorSetLayout= VkDescriptorSetLayout (NULL) +// +// init { +// zoom = -15f +// rotationSpeed = 0.25f +// rotation(-15f, 35f, 0f) +// title = "Texture arrays" +//// settings.overlay = true +// } +// +// override fun destroy() { +// +// // Clean up used Vulkan resources +// // Note : Inherited destructor cleans up resources stored in base class +// +// // Clean up texture resources +// device.apply { +// destroyImageView(textureArray.view) +// destroyImage(textureArray.image) +// destroySampler(textureArray.sampler) +// freeMemory(textureArray.deviceMemory) +// +// destroyPipeline(pipeline) +// +// destroyPipelineLayout(pipelineLayout) +// destroyDescriptorSetLayout(descriptorSetLayout) +// } +// vertexBuffer.destroy() +// indexBuffer.destroy() +// +// uniformBufferVS.destroy() +// +// super.destroy() +// } +// +// fun loadTextureArray(filename: String, format: VkFormat) { +// +// val tex2DArray = Texture2dArray(gli.load(filename)) +// +// assert(tex2DArray.notEmpty()) +// +// textureArray.size(tex2DArray.extent()) +// layerCount = tex2DArray.layers() +// +// // Create a host-visible staging buffer that contains the raw image data +// +// val bufferCreateInfo = vk.BufferCreateInfo { +// size = VkDeviceSize(tex2DArray.size.L) +// // This buffer is used as a transfer source for the buffer copy +// usage = VkBufferUsage.TRANSFER_SRC_BIT.i +// sharingMode = VkSharingMode.EXCLUSIVE +// } +// val stagingBuffer = device createBuffer bufferCreateInfo +// +// // Get memory requirements for the staging buffer (alignment, memory type bits) +// val memReqs = device getBufferMemoryRequirements stagingBuffer +// val memAllocInfo = vk.MemoryAllocateInfo { +// allocationSize = memReqs.size +// // Get memory type index for a host visible buffer +// memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT) +// } +// val stagingMemory = device allocateMemory memAllocInfo +// device.bindBufferMemory(stagingBuffer, stagingMemory) +// +// // Copy texture data into staging buffer +// device.mappingMemory(stagingMemory, VkDeviceSize(0), memReqs.size, 0) { data -> +// memCopy(memAddress(tex2DArray.data()), data, tex2DArray.size.L) +// } +// +// // Setup buffer copy regions for array layers +// val bufferCopyRegions = vk.BufferImageCopy(layerCount) +// var offset = VkDeviceSize(0) +// +// for (layer in 0 until layerCount) { +// +// bufferCopyRegions[layer].apply { +// imageSubresource.apply { +// aspectMask = VkImageAspect.COLOR_BIT.i +// mipLevel = 0 +// baseArrayLayer = layer +// layerCount = 1 +// } +// imageExtent.apply { +// val (w, h) = tex2DArray[layer][0].extent() // TODO BUG +// width = w +// height = h +// depth = 1 +// } +// bufferOffset = offset +// } +// +// // Increase offset into staging buffer for next level / face +// offset += tex2DArray[layer][0].size +// } +// +// // Create optimal tiled target image +// val imageCreateInfo = vk.ImageCreateInfo { +// imageType = VkImageType.`2D` +// this.format = format +// mipLevels = 1 +// samples = VkSampleCount.`1_BIT` +// tiling = VkImageTiling.OPTIMAL +// sharingMode = VkSharingMode.EXCLUSIVE +// initialLayout = VkImageLayout.UNDEFINED +// extent.set(textureArray.size.x, textureArray.size.y, 1) +// usage = VkImageUsage.TRANSFER_DST_BIT or VkImageUsage.SAMPLED_BIT +// arrayLayers = layerCount +// } +// textureArray.image = device createImage imageCreateInfo +// +// device.getImageMemoryRequirements(textureArray.image, memReqs) +// +// memAllocInfo.allocationSize = memReqs.size +// memAllocInfo.memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) +// +// textureArray.deviceMemory = device allocateMemory memAllocInfo +// device.bindImageMemory(textureArray.image, textureArray.deviceMemory) +// +// val copyCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) +// +// // Image barrier for optimal image (target) +// // Set initial layout for all array layers (faces) of the optimal (target) tiled texture +// val subresourceRange = vk.ImageSubresourceRange { +// aspectMask = VkImageAspect.COLOR_BIT.i +// baseMipLevel = 0 +// levelCount = 1 +// layerCount = this@TextureArray.layerCount +// } +// tools.setImageLayout( +// copyCmd, +// textureArray.image, +// VkImageLayout.UNDEFINED, +// VkImageLayout.TRANSFER_DST_OPTIMAL, +// subresourceRange) +// +// // Copy the cube map faces from the staging buffer to the optimal tiled image +// copyCmd.copyBufferToImage( +// stagingBuffer, +// textureArray.image, +// VkImageLayout.TRANSFER_DST_OPTIMAL, +// bufferCopyRegions) +// +// // Change texture image layout to shader read after all faces have been copied +// textureArray.imageLayout = VkImageLayout.SHADER_READ_ONLY_OPTIMAL +// tools.setImageLayout( +// copyCmd, +// textureArray.image, +// VkImageLayout.TRANSFER_DST_OPTIMAL, +// textureArray.imageLayout, +// subresourceRange) +// +// super.flushCommandBuffer(copyCmd, queue, true) +// +// // Create sampler +// val sampler = vk.SamplerCreateInfo { +// magFilter = VkFilter.LINEAR +// minFilter = VkFilter.LINEAR +// mipmapMode = VkSamplerMipmapMode.LINEAR +// addressModeU = VkSamplerAddressMode.CLAMP_TO_EDGE +// addressModeV = addressModeU +// addressModeW = addressModeU +// mipLodBias = 0f +// maxAnisotropy = 8f +// compareOp = VkCompareOp.NEVER +// minLod = 0f +// maxLod = 0f +// borderColor = VkBorderColor.FLOAT_OPAQUE_WHITE +// } +// textureArray.sampler = device createSampler sampler +// +// // Create image view +// val view = vk.ImageViewCreateInfo { +// viewType = VkImageViewType.`2D_ARRAY` +// this.format = format +// components(VkComponentSwizzle.R, VkComponentSwizzle.G, VkComponentSwizzle.B, VkComponentSwizzle.A) +// this.subresourceRange.apply { +// set(VkImageAspect.COLOR_BIT.i, 0, 1, 0, 1) +// layerCount = this@TextureArray.layerCount // TODO move in ::set +// levelCount = 1 +// } +// image = textureArray.image +// } +// textureArray.view = device createImageView view +// +// // Clean up staging resources +// device freeMemory stagingMemory +// device destroyBuffer stagingBuffer +// } +// +// fun loadTextures() { +// // Vulkan core supports three different compressed texture formats +// // As the support differs between implemementations we need to check device features and select a proper format and file +// val (filename, format) = when { +// deviceFeatures.textureCompressionBC -> "texturearray_bc3_unorm.ktx" to VkFormat.BC3_UNORM_BLOCK +// deviceFeatures.textureCompressionASTC_LDR -> "texturearray_astc_8x8_unorm.ktx" to VkFormat.ASTC_8x8_UNORM_BLOCK +// deviceFeatures.textureCompressionETC2 -> "texturearray_etc2_unorm.ktx" to VkFormat.ETC2_R8G8B8_UNORM_BLOCK +// else -> tools.exitFatal("Device does not support any compressed texture format!", ERROR_FEATURE_NOT_PRESENT) +// } +// loadTextureArray("$assetPath/textures/$filename", format) +// } +// +// override fun buildCommandBuffers() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(defaultClearColor) +// it[1].depthStencil.set(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@TextureArray.renderPass +// renderArea.apply { +// offset.set(0, 0) +// extent.set(size.x, size.y) +// } +// this.clearValues = clearValues +// } +// for (i in drawCmdBuffers.indices) { +// // Set target frame buffer +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) // TODO BUG +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// setViewport(size) +// setScissor(size) +// +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipeline) +// +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, vertexBuffer.buffer) +// bindIndexBuffer(indexBuffer.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// +// drawIndexed(indexCount, layerCount, 0, 0, 0) +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// fun generateQuad() = stak { +// // Setup vertices for a single uv-mapped quad made from two triangles +// val vertices = it.floats( +// +2.5f, +2.5f, 0f, 1f, 1f, +// -2.5f, +2.5f, 0f, 0f, 1f, +// -2.5f, -2.5f, 0f, 0f, 0f, +// +2.5f, -2.5f, 0f, 1f, 0f) +// +// // Setup indices +// val indices = it.ints(0, 1, 2, 2, 3, 0) +// indexCount = indices.cap +// +// // Create buffers +// // For the sake of simplicity we won't stage the vertex data to the gpu memory +// // Vertex buffer +// vulkanDevice.createBuffer( +// VkBufferUsage.VERTEX_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// vertexBuffer, +// vertices) +// // Index buffer +// vulkanDevice.createBuffer( +// VkBufferUsage.INDEX_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// indexBuffer, +// indices) +// } +// +// fun setupVertexDescriptions() { +// // Binding description +// vertices.bindingDescription = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, Vertex.size, VkVertexInputRate.VERTEX) +// +// // Attribute descriptions +// // Describes memory layout and shader positions +// vertices.attributeDescriptions = vk.VertexInputAttributeDescription( +// // Location 0 : Position +// VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, 0, +// // Location 1 : Texture coordinates +// VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32_SFLOAT, Vec3.size) +// +// vertices.inputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertices.bindingDescription +// vertexAttributeDescriptions = vertices.attributeDescriptions +// } +// } +// +// fun setupDescriptorPool() { +// +// val poolSizes = vk.DescriptorPoolSize( +// VkDescriptorType.UNIFORM_BUFFER, 1, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1) +// +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) +// +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// // Binding 0 : Vertex shader uniform buffer +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, +// // Binding 1 : Fragment shader image sampler (texture array) +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// +// descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) +// +// pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// } +// +// fun setupDescriptorSet() { +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) +// +// descriptorSet = device allocateDescriptorSets allocInfo +// +// // Image descriptor for the texture array +// val textureDescriptor = vk.DescriptorImageInfo(textureArray.sampler, textureArray.view, textureArray.imageLayout) +// +// val writeDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0 : Vertex shader uniform buffer +// descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBufferVS.descriptor, +// // Binding 1 : Fragment shader cubemap sampler +// descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textureDescriptor) +// +// device updateDescriptorSets writeDescriptorSets +// } +// +// fun preparePipelines() { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.COUNTER_CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// // Instacing pipeline +// // Load shaders +// val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { +// it[0].loadShader("$assetPath/shaders/texturearray/instancing.vert.spv", VkShaderStage.VERTEX_BIT) +// it[1].loadShader("$assetPath/shaders/texturearray/instancing.frag.spv", VkShaderStage.FRAGMENT_BIT) +// } +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { +// it.vertexInputState = vertices.inputState +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// } +// pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// +// fun prepareUniformBuffers() { +// +// for (i in 0 until layerCount) +// uboVS.instance += UboInstanceData() +// +// val uboSize = uboVS.matrices.size + layerCount * UboInstanceData.size +// +// // Vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBufferVS, +// VkDeviceSize(uboSize.L)) +// +// // Array indices and model matrices are fixed +// val offset = -1.5f +// val center = (layerCount * offset) / 2 +// for (i in 0 until layerCount) { +// // Instance model matrix +// uboVS.instance[i].model = glm.translate(Mat4(1f), 0f, i * offset - center, 0f) +// .rotateAssign(60f.rad, 1f, 0f, 0f) +// // Instance texture array index +// uboVS.instance[i].arrayIndex.x = i.f +// } +// +// // Update instanced part of the uniform buffer +// val dataOffset = VkDeviceSize(uboVS.matrices.size.L) +// val dataSize = VkDeviceSize(layerCount * UboInstanceData.size.L) +// uboVS.prepare() +// device.mappingMemory(uniformBufferVS.memory, dataOffset, dataSize, 0) { data -> +// memCopy(uboVS.address + dataOffset, data, dataSize) +// } +// +// // Map persistent +// uniformBufferVS.map() +// +// updateUniformBufferMatrices() +// } +// +// fun updateUniformBufferMatrices() { +// +// // Only updates the uniform buffer block part containing the global matrices +// +// // Projection +// uboVS.matrices.projection = glm.perspective(60f.rad, size.aspect, 0.001f, 256f) +// +// // View +// uboVS.matrices.view = glm.translate(Mat4(1f), 0f, -1f, zoom) +// .rotateAssign(rotation.x.rad, 1f, 0f, 0f) +// .rotateAssign(rotation.y.rad, 0f, 1f, 0f) +// .rotateAssign(rotation.z.rad, 0f, 0f, 1f) +// +// // Only update the matrices part of the uniform buffer +// uboVS.matrices to uniformBufferVS.mapped +// } +// +// fun draw() { +// +// super.prepareFrame() +// +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// queue submit submitInfo +// +// super.submitFrame() +// } +// +// override fun prepare() { +// +// super.prepare() +// loadTextures() +// setupVertexDescriptions() +// generateQuad() +// prepareUniformBuffers() +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSet() +// buildCommandBuffers() +// prepared = true +// window.show() +// } +// +// override fun render() { +// if (!prepared) +// return +// draw() +// } +// +// override fun viewChanged() = updateUniformBufferMatrices() +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/basics/10 Texture 3d.kt b/src/main/kotlin/vulkan/basics/10 Texture 3d.kt index a29fd38..3df8a7b 100644 --- a/src/main/kotlin/vulkan/basics/10 Texture 3d.kt +++ b/src/main/kotlin/vulkan/basics/10 Texture 3d.kt @@ -1,707 +1,707 @@ -/* -* Vulkan Example - 3D texture loading (and generation using perlin noise) example -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -package vulkan.basics - -import ab.appBuffer -import glm_.L -import glm_.b -import glm_.buffer.bufferBig -import glm_.buffer.free -import glm_.func.rad -import glm_.glm -import glm_.mat4x4.Mat4 -import glm_.set -import glm_.vec2.Vec2 -import glm_.vec3.Vec3 -import glm_.vec3.Vec3i -import glm_.vec4.Vec4 -import org.lwjgl.system.MemoryUtil.* -import org.lwjgl.vulkan.VkDescriptorImageInfo -import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo -import org.lwjgl.vulkan.VkVertexInputAttributeDescription -import org.lwjgl.vulkan.VkVertexInputBindingDescription -import uno.kotlin.buffers.capacity -import uno.kotlin.buffers.indices -import vkk.* -import vulkan.VERTEX_BUFFER_BIND_ID -import vulkan.assetPath -import vulkan.base.Buffer -import vulkan.base.Model -import vulkan.base.VulkanExampleBase -import vulkan.base.tools -import java.util.concurrent.ThreadLocalRandom -import java.util.stream.IntStream -import kotlin.system.measureTimeMillis - - -fun main(args: Array) { - Texture3d().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - -private class Texture3d : VulkanExampleBase() { - - /** Vertex layout for this example */ - object Vertex : Bufferizable() { - lateinit var pos: Vec3 - lateinit var uv: Vec2 - @Order(2) - lateinit var normal: Vec3 - } - - /** Fractal noise generator based on perlin noise above */ - class FractalNoise { - - val octaves = 6 - var frequency = 0f - var amplitude = 0f - var persistence = 0.5f - - fun noise(v: Vec3): Float { - var sum = 0f - frequency = 1f - amplitude = 1f - var max = 0f - for (i in 0 until octaves) { - sum += glm.perlin(v * frequency) * amplitude - max += amplitude - amplitude *= persistence - frequency *= 2f - } - - sum /= max - return (sum + 1f) / 2f - } - } - - /** Contains all Vulkan objects that are required to store and use a 3D texture */ - object texture { - var sampler: VkSampler = NULL - var image: VkImage = NULL - var imageLayout = VkImageLayout.UNDEFINED - var deviceMemory: VkDeviceMemory = NULL - var view: VkImageView = NULL - lateinit var descriptor: VkDescriptorImageInfo - var format = VkFormat.UNDEFINED - val extent = Vec3i() - var mipLevels = 0 - } - - var regenerateNoise = true - - object models { - val cube = Model() - } - - object vertices { - lateinit var inputState: VkPipelineVertexInputStateCreateInfo - lateinit var inputBinding: VkVertexInputBindingDescription - lateinit var inputAttributes: VkVertexInputAttributeDescription.Buffer - } - - val vertexBuffer = Buffer() - val indexBuffer = Buffer() - var indexCount = 0 - - val uniformBufferVS = Buffer() - - object uboVS : Bufferizable() { - lateinit var projection: Mat4 - @Order(1) - lateinit var model: Mat4 - lateinit var viewPos: Vec4 - @Order(3) - var depth = 0f - } - - object pipelines { - var solid: VkPipeline = NULL - } - - var pipelineLayout: VkPipelineLayout = NULL - var descriptorSet: VkDescriptorSet = NULL - var descriptorSetLayout: VkDescriptorSetLayout = NULL - - init { - zoom = -2.5f - rotation(0f, 15f, 0f) - title = "3D textures" -// settings.overlay = true -// srand((unsigned int) time (NULL)) - } - - override fun destroy() { - // Clean up used Vulkan resources - // Note : Inherited destructor cleans up resources stored in base class - - destroyTextureImage() - - device.apply { - destroyPipeline(pipelines.solid) - - destroyPipelineLayout(pipelineLayout) - destroyDescriptorSetLayout(descriptorSetLayout) - } - vertexBuffer.destroy() - indexBuffer.destroy() - uniformBufferVS.destroy() - - super.destroy() - } - - /** Prepare all Vulkan resources for the 3D texture (including descriptors) - * Does not fill the texture with data */ - fun prepareNoiseTexture(width: Int, height: Int, depth: Int) { - // A 3D texture is described as width x height x depth - texture.extent.put(width, height, depth) // TODO glm - texture.mipLevels = 1 - texture.format = VkFormat.R8_UNORM - - // Format support check - // 3D texture support in Vulkan is mandatory (in contrast to OpenGL) so no need to check if it's supported - val formatProperties = physicalDevice getFormatProperties texture.format - // Check if format supports transfer - if (formatProperties.optimalTilingFeatures hasnt VkFormatFeature.TRANSFER_DST_BIT) { - System.err.println("Error: Device does not support flag TRANSFER_DST for selected texture format!") - return - } - // Check if GPU supports requested 3D texture dimensions - val maxImageDimension3D = vulkanDevice.properties.limits.maxImageDimension3D - if (width > maxImageDimension3D || height > maxImageDimension3D || depth > maxImageDimension3D) { - System.out.println("Error: Requested texture dimensions is greater than supported 3D texture dimension!") - return - } - - // Create optimal tiled target image - val imageCreateInfo = vk.ImageCreateInfo { - imageType = VkImageType.`3D` - format = texture.format - mipLevels = texture.mipLevels - arrayLayers = 1 - samples = VkSampleCount.`1_BIT` - tiling = VkImageTiling.OPTIMAL - sharingMode = VkSharingMode.EXCLUSIVE - extent(texture.extent) - // Set initial layout of the image to undefined - initialLayout = VkImageLayout.UNDEFINED - usage = VkImageUsage.TRANSFER_DST_BIT or VkImageUsage.SAMPLED_BIT - } - texture.image = device createImage imageCreateInfo - - // Device local memory to back up image - val memReqs = device getImageMemoryRequirements texture.image - val memAllocInfo = vk.MemoryAllocateInfo { - allocationSize = memReqs.size - memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) - } - texture.deviceMemory = device allocateMemory memAllocInfo - device.bindImageMemory(texture.image, texture.deviceMemory, 0) - - // Create sampler - val sampler = vk.SamplerCreateInfo { - magFilter = VkFilter.LINEAR - minFilter = VkFilter.LINEAR - mipmapMode = VkSamplerMipmapMode.LINEAR - addressModeU = VkSamplerAddressMode.CLAMP_TO_EDGE - addressModeV = VkSamplerAddressMode.CLAMP_TO_EDGE - addressModeW = VkSamplerAddressMode.CLAMP_TO_EDGE - mipLodBias = 0f - compareOp = VkCompareOp.NEVER - minLod = 0f - maxLod = 0f - maxAnisotropy = 1f - anisotropyEnable = false - borderColor = VkBorderColor.FLOAT_OPAQUE_WHITE - } - texture.sampler = device createSampler sampler - - // Create image view - val view = vk.ImageViewCreateInfo { - image = texture.image - viewType = VkImageViewType.`3D` - format = texture.format - components(VkComponentSwizzle.R, VkComponentSwizzle.G, VkComponentSwizzle.B, VkComponentSwizzle.A) - subresourceRange.apply { - aspectMask = VkImageAspect.COLOR_BIT.i - baseMipLevel = 0 - baseArrayLayer = 0 - layerCount = 1 - levelCount = 1 - } - } - texture.view = device createImageView view - - // Fill image descriptor image info to be used descriptor set setup - texture.descriptor = vk.DescriptorImageInfo { - imageLayout = VkImageLayout.SHADER_READ_ONLY_OPTIMAL - imageView = texture.view - this.sampler = texture.sampler - } - } - - /** Generate randomized noise and upload it to the 3D texture using staging */ - fun updateNoiseTexture() { - - val ext = texture.extent - val texMemSize = ext.x * ext.y * ext.z - - val data = bufferBig(texMemSize) - val adr = memAddress(data) - for (i in data.indices) - memPutByte(adr + i, i.b) - - // Generate perlin based noise - println("Generating ${ext.x} x ${ext.y} x ${ext.z} noise texture...") - -// auto tStart = std ::chrono::high_resolution_clock::now() - - /* Maximum value that can be returned by the rand function: - define RAND_MAX 0x7fff - 0111 1111 1111 1111 - */ - fun rand() = ThreadLocalRandom.current().nextInt() ushr 1 - - val time = measureTimeMillis { - - val FRACTAL = true - val noiseScale = rand() % 10 + 4f - - val parallel = true - - if (!parallel) - for (z in 0 until ext.z) { - println(z) - for (y in 0 until ext.y) - for (x in 0 until ext.x) { - println("x $x, y $y, z $z") - val v = Vec3(x, y, z) / ext - var n = when { - FRACTAL -> FractalNoise().noise(v * noiseScale) - else -> 20f * glm.perlin(v) - } - n -= glm.floor(n) - - data[x + y * ext.x + z * ext.x * ext.y] = glm.floor(n * 255).b - } - } - else { -// runBlocking { -// for (z in 0 until 1) { -// println(z) -//// for (z in 0 until 1) { -// for (y in 0 until 1) -// for (x in 0 until 100) { -// launch { -// val v = Vec3(x, y, z) / texture.extent -// var n = when { -// FRACTAL -> FractalNoise().noise(v * noiseScale) -// else -> 20f * glm.perlin(v) -// } -// n -= glm.floor(n) -// -// val offset = x + y * texture.extent.x + z * texture.extent.x * texture.extent.y -// println("$adr, "+offset) -// memPutByte(adr + offset, glm.floor(n * 255).b) -//// data[x + y * texture.extent.x + z * texture.extent.x * texture.extent.y] = glm.floor(n * 255).b -// } +///* +//* Vulkan Example - 3D texture loading (and generation using perlin noise) example +//* +//* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +//package vulkan.basics +// +//import glm_.L +//import glm_.b +//import glm_.func.rad +//import glm_.glm +//import glm_.mat4x4.Mat4 +//import glm_.set +//import glm_.vec2.Vec2 +//import glm_.vec3.Vec3 +//import glm_.vec3.Vec3i +//import glm_.vec4.Vec4 +//import kool.bufferBig +//import kool.cap +//import kool.free +//import kool.stak +//import org.lwjgl.system.MemoryUtil.* +//import org.lwjgl.vulkan.VkDescriptorImageInfo +//import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo +//import org.lwjgl.vulkan.VkVertexInputAttributeDescription +//import org.lwjgl.vulkan.VkVertexInputBindingDescription +//import uno.kotlin.buffers.indices +//import vkk.* +//import vulkan.VERTEX_BUFFER_BIND_ID +//import vulkan.assetPath +//import vulkan.base.Buffer +//import vulkan.base.Model +//import vulkan.base.VulkanExampleBase +//import vulkan.base.tools +//import java.util.concurrent.ThreadLocalRandom +//import java.util.stream.IntStream +//import kotlin.system.measureTimeMillis +// +// +//fun main(args: Array) { +// Texture3d().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +//private class Texture3d : VulkanExampleBase() { +// +// /** Vertex layout for this example */ +// object Vertex : Bufferizable() { +// lateinit var pos: Vec3 +// lateinit var uv: Vec2 +// @Order(2) +// lateinit var normal: Vec3 +// } +// +// /** Fractal noise generator based on perlin noise above */ +// class FractalNoise { +// +// val octaves = 6 +// var frequency = 0f +// var amplitude = 0f +// var persistence = 0.5f +// +// fun noise(v: Vec3): Float { +// var sum = 0f +// frequency = 1f +// amplitude = 1f +// var max = 0f +// for (i in 0 until octaves) { +// sum += glm.perlin(v * frequency) * amplitude +// max += amplitude +// amplitude *= persistence +// frequency *= 2f +// } +// +// sum /= max +// return (sum + 1f) / 2f +// } +// } +// +// /** Contains all Vulkan objects that are required to store and use a 3D texture */ +// object texture { +// var sampler = VkSampler(NULL) +// var image = VkImage(NULL) +// var imageLayout = VkImageLayout.UNDEFINED +// var deviceMemory = VkDeviceMemory(NULL) +// var view = VkImageView(NULL) +// lateinit var descriptor: VkDescriptorImageInfo +// var format = VkFormat.UNDEFINED +// val extent = Vec3i() +// var mipLevels = 0 +// } +// +// var regenerateNoise = true +// +// object models { +// val cube = Model() +// } +// +// object vertices { +// lateinit var inputState: VkPipelineVertexInputStateCreateInfo +// lateinit var inputBinding: VkVertexInputBindingDescription +// lateinit var inputAttributes: VkVertexInputAttributeDescription.Buffer +// } +// +// val vertexBuffer = Buffer() +// val indexBuffer = Buffer() +// var indexCount = 0 +// +// val uniformBufferVS = Buffer() +// +// object uboVS : Bufferizable() { +// lateinit var projection: Mat4 +// @Order(1) +// lateinit var model: Mat4 +// lateinit var viewPos: Vec4 +// @Order(3) +// var depth = 0f +// } +// +// object pipelines { +// var solid = VkPipeline (NULL) +// } +// +// var pipelineLayout= VkPipelineLayout (NULL) +// var descriptorSet= VkDescriptorSet (NULL) +// var descriptorSetLayout= VkDescriptorSetLayout (NULL) +// +// init { +// zoom = -2.5f +// rotation(0f, 15f, 0f) +// title = "3D textures" +//// settings.overlay = true +//// srand((unsigned int) time (NULL)) +// } +// +// override fun destroy() { +// // Clean up used Vulkan resources +// // Note : Inherited destructor cleans up resources stored in base class +// +// destroyTextureImage() +// +// device.apply { +// destroyPipeline(pipelines.solid) +// +// destroyPipelineLayout(pipelineLayout) +// destroyDescriptorSetLayout(descriptorSetLayout) +// } +// vertexBuffer.destroy() +// indexBuffer.destroy() +// uniformBufferVS.destroy() +// +// super.destroy() +// } +// +// /** Prepare all Vulkan resources for the 3D texture (including descriptors) +// * Does not fill the texture with data */ +// fun prepareNoiseTexture(width: Int, height: Int, depth: Int) { +// // A 3D texture is described as width x height x depth +// texture.extent.put(width, height, depth) // TODO glm +// texture.mipLevels = 1 +// texture.format = VkFormat.R8_UNORM +// +// // Format support check +// // 3D texture support in Vulkan is mandatory (in contrast to OpenGL) so no need to check if it's supported +// val formatProperties = physicalDevice getFormatProperties texture.format +// // Check if format supports transfer +// if (formatProperties.optimalTilingFeatures hasnt VkFormatFeature.TRANSFER_DST_BIT) { +// System.err.println("Error: Device does not support flag TRANSFER_DST for selected texture format!") +// return +// } +// // Check if GPU supports requested 3D texture dimensions +// val maxImageDimension3D = vulkanDevice.properties.limits.maxImageDimension3D +// if (width > maxImageDimension3D || height > maxImageDimension3D || depth > maxImageDimension3D) { +// System.out.println("Error: Requested texture dimensions is greater than supported 3D texture dimension!") +// return +// } +// +// // Create optimal tiled target image +// val imageCreateInfo = vk.ImageCreateInfo { +// imageType = VkImageType.`3D` +// format = texture.format +// mipLevels = texture.mipLevels +// arrayLayers = 1 +// samples = VkSampleCount.`1_BIT` +// tiling = VkImageTiling.OPTIMAL +// sharingMode = VkSharingMode.EXCLUSIVE +// extent(texture.extent) +// // Set initial layout of the image to undefined +// initialLayout = VkImageLayout.UNDEFINED +// usage = VkImageUsage.TRANSFER_DST_BIT or VkImageUsage.SAMPLED_BIT +// } +// texture.image = device createImage imageCreateInfo +// +// // Device local memory to back up image +// val memReqs = device getImageMemoryRequirements texture.image +// val memAllocInfo = vk.MemoryAllocateInfo { +// allocationSize = memReqs.size +// memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) +// } +// texture.deviceMemory = device allocateMemory memAllocInfo +// device.bindImageMemory(texture.image, texture.deviceMemory, VkDeviceSize(0)) +// +// // Create sampler +// val sampler = vk.SamplerCreateInfo { +// magFilter = VkFilter.LINEAR +// minFilter = VkFilter.LINEAR +// mipmapMode = VkSamplerMipmapMode.LINEAR +// addressModeU = VkSamplerAddressMode.CLAMP_TO_EDGE +// addressModeV = VkSamplerAddressMode.CLAMP_TO_EDGE +// addressModeW = VkSamplerAddressMode.CLAMP_TO_EDGE +// mipLodBias = 0f +// compareOp = VkCompareOp.NEVER +// minLod = 0f +// maxLod = 0f +// maxAnisotropy = 1f +// anisotropyEnable = false +// borderColor = VkBorderColor.FLOAT_OPAQUE_WHITE +// } +// texture.sampler = device createSampler sampler +// +// // Create image view +// val view = vk.ImageViewCreateInfo { +// image = texture.image +// viewType = VkImageViewType.`3D` +// format = texture.format +// components(VkComponentSwizzle.R, VkComponentSwizzle.G, VkComponentSwizzle.B, VkComponentSwizzle.A) +// subresourceRange.apply { +// aspectMask = VkImageAspect.COLOR_BIT.i +// baseMipLevel = 0 +// baseArrayLayer = 0 +// layerCount = 1 +// levelCount = 1 +// } +// } +// texture.view = device createImageView view +// +// // Fill image descriptor image info to be used descriptor set setup +// texture.descriptor = vk.DescriptorImageInfo { +// imageLayout = VkImageLayout.SHADER_READ_ONLY_OPTIMAL +// imageView = texture.view +// this.sampler = texture.sampler +// } +// } +// +// /** Generate randomized noise and upload it to the 3D texture using staging */ +// fun updateNoiseTexture() { +// +// val ext = texture.extent +// val texMemSize = VkDeviceSize(ext.x * ext.y * ext.z.L) +// +// val data = bufferBig(texMemSize) +// val adr = memAddress(data) +// for (i in data.indices) +// memPutByte(adr + i, i.b) +// +// // Generate perlin based noise +// println("Generating ${ext.x} x ${ext.y} x ${ext.z} noise texture...") +// +//// auto tStart = std ::chrono::high_resolution_clock::now() +// +// /* Maximum value that can be returned by the rand function: +// define RAND_MAX 0x7fff +// 0111 1111 1111 1111 +// */ +// fun rand() = ThreadLocalRandom.current().nextInt() ushr 1 +// +// val time = measureTimeMillis { +// +// val FRACTAL = true +// val noiseScale = rand() % 10 + 4f +// +// val parallel = true +// +// if (!parallel) +// for (z in 0 until ext.z) { +// println(z) +// for (y in 0 until ext.y) +// for (x in 0 until ext.x) { +// println("x $x, y $y, z $z") +// val v = Vec3(x, y, z) / ext +// var n = when { +// FRACTAL -> FractalNoise().noise(v * noiseScale) +// else -> 20f * glm.perlin(v) // } -// } +// n -= glm.floor(n) +// +// data[x + y * ext.x + z * ext.x * ext.y] = glm.floor(n * 255).b +// } // } - IntStream - .range(0, ext.x * ext.y * ext.z) - .parallel() - .forEach { - val z = it / (ext.x * ext.y) - val remainder = it - z * ext.x * ext.y - val y = remainder / ext.x - val x = remainder % ext.x - val v = Vec3(x, y, z) / ext - var n = when { - FRACTAL -> FractalNoise().noise(v * noiseScale) - else -> 20f * glm.perlin(v) - } - n -= glm.floor(n) - - data[x + y * ext.x + z * ext.x * ext.y] = glm.floor(n * 255).b - } -// -// val channel = Channel() -// -// val processingPool = newThreadPool -// -// launch(processingPool) { for (request in channel) doProcessing(it) } -// -// -// -// for ... -// -// for ... -// -// channel.sendBlocking(ProcessingRequest(...)) - } - } - println("Done in ${time}ms") - - // Create a host-visible staging buffer that contains the raw image data - - // Buffer object - val bufferCreateInfo = vk.BufferCreateInfo { - size = texMemSize.L - usage = VkBufferUsage.TRANSFER_SRC_BIT.i - sharingMode = VkSharingMode.EXCLUSIVE - } - val stagingBuffer: VkBuffer = device createBuffer bufferCreateInfo - - // Allocate host visible memory for data upload - val memReqs = device getBufferMemoryRequirements stagingBuffer - val memAllocInfo = vk.MemoryAllocateInfo { - allocationSize = memReqs.size - memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT) - } - val stagingMemory = device allocateMemory memAllocInfo - device.bindBufferMemory(stagingBuffer, stagingMemory) - - // Copy texture data into staging buffer - device.mappingMemory(stagingMemory, 0, memReqs.size) { mapped -> - memCopy(memAddress(data), mapped, texMemSize.L) - } - - val copyCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) - - // Image barrier for optimal image - - // The sub resource range describes the regions of the image we will be transition - val subresourceRange = vk.ImageSubresourceRange { - aspectMask = VkImageAspect.COLOR_BIT.i - baseMipLevel = 0 - levelCount = 1 - layerCount = 1 - } - // Optimal image will be used as destination for the copy, so we must transfer from our - // initial undefined image layout to the transfer destination layout - tools.setImageLayout( - copyCmd, - texture.image, - VkImageLayout.UNDEFINED, - VkImageLayout.TRANSFER_DST_OPTIMAL, - subresourceRange) - - // Copy 3D noise data to texture - - // Setup buffer copy regions - val bufferCopyRegion = vk.BufferImageCopy { - imageSubresource.apply { - aspectMask = VkImageAspect.COLOR_BIT.i - mipLevel = 0 - baseArrayLayer = 0 - layerCount = 1 - } - imageExtent(texture.extent) - } - copyCmd.copyBufferToImage( - stagingBuffer, - texture.image, - VkImageLayout.TRANSFER_DST_OPTIMAL, - bufferCopyRegion) - - // Change texture image layout to shader read after all mip levels have been copied - texture.imageLayout = VkImageLayout.SHADER_READ_ONLY_OPTIMAL - tools.setImageLayout( - copyCmd, - texture.image, - VkImageLayout.TRANSFER_DST_OPTIMAL, - texture.imageLayout, - subresourceRange) - - super.flushCommandBuffer(copyCmd, queue, true) - - // Clean up staging resources - data.free() - device freeMemory stagingMemory - device destroyBuffer stagingBuffer - regenerateNoise = false - } - - /** Free all Vulkan resources used a texture object */ - fun destroyTextureImage() { - device.apply { - if (texture.view != NULL) - destroyImageView(texture.view) - if (texture.image != NULL) - destroyImage(texture.image) - if (texture.sampler != NULL) - destroySampler(texture.sampler) - if (texture.deviceMemory != NULL) - freeMemory(texture.deviceMemory) - } - } - - override fun buildCommandBuffers() { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(defaultClearColor) - it[1].depthStencil(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@Texture3d.renderPass - renderArea.apply { - offset(0) - extent(size) - } - this.clearValues = clearValues - } - for (i in drawCmdBuffers.indices) { - // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - setViewport(size) - - setScissor(size) - - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.solid) - - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, vertexBuffer.buffer) - bindIndexBuffer(indexBuffer.buffer, 0, VkIndexType.UINT32) - drawIndexed(indexCount, 1, 0, 0, 0) - - endRenderPass() - - end() - } - } - } - - fun draw() { - - super.prepareFrame() - - // Command buffer to be sumitted to the queue - submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] - - // Submit to queue - queue submit submitInfo - - super.submitFrame() - } - - fun generateQuad() { - // Setup vertices for a single uv-mapped quad made from two triangles - val vertices = appBuffer.floatBufferOf( - +1f, +1f, 0f, 1f, 1f, 0f, 0f, 1f, - -1f, +1f, 0f, 0f, 1f, 0f, 0f, 1f, - -1f, -1f, 0f, 0f, 0f, 0f, 0f, 1f, - +1f, -1f, 0f, 1f, 0f, 0f, 0f, 1f) - - // Setup indices - val indices = appBuffer.intBufferOf(0, 1, 2, 2, 3, 0) - indexCount = indices.capacity - - // Create buffers - // For the sake of simplicity we won't stage the vertex data to the gpu memory - // Vertex buffer - vulkanDevice.createBuffer( - VkBufferUsage.VERTEX_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - vertexBuffer, - vertices) - // Index buffer - vulkanDevice.createBuffer( - VkBufferUsage.INDEX_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - indexBuffer, - indices) - } - - fun setupVertexDescriptions() { - // Binding description - vertices.inputBinding = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, Vertex.size, VkVertexInputRate.VERTEX) - - // Attribute descriptions - // Describes memory layout and shader positions - vertices.inputAttributes = vk.VertexInputAttributeDescription( - // Location 0 : Position - VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, Vertex.offsetOf("pos"), - // Location 1 : Texture coordinates - VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32_SFLOAT, Vertex.offsetOf("uv"), - // Location 1 : Vertex normal - VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32G32B32_SFLOAT, Vertex.offsetOf("normal")) - - vertices.inputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertices.inputBinding - vertexAttributeDescriptions = vertices.inputAttributes - } - } - - fun setupDescriptorPool() { - // Example uses one ubo and one image sampler - val poolSizes = vk.DescriptorPoolSize( - VkDescriptorType.UNIFORM_BUFFER, 1, - VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1) - - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) - - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - // Binding 0 : Vertex shader uniform buffer - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, - // Binding 1 : Fragment shader image sampler - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - - descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) - - pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - } - - fun setupDescriptorSet() { - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) - - descriptorSet = device allocateDescriptorSets allocInfo - - val writeDescriptorSets = vk.WriteDescriptorSet( - // Binding 0 : Vertex shader uniform buffer - descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBufferVS.descriptor, - // Binding 1 : Fragment shader texture sampler - descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, texture.descriptor) - - device updateDescriptorSets writeDescriptorSets - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - // Load shaders - val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { - it[0].loadShader("$assetPath/shaders/texture3d/texture3d.vert.spv", VkShaderStage.VERTEX_BIT) - it[1].loadShader("$assetPath/shaders/texture3d/texture3d.frag.spv", VkShaderStage.FRAGMENT_BIT) - } - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { - it.vertexInputState = vertices.inputState - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - } - pipelines.solid = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - /** Prepare and initialize uniform buffer containing shader uniforms */ - fun prepareUniformBuffers() { - // Vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBufferVS, - uboVS.size.L) - - updateUniformBuffers() - } - - fun updateUniformBuffers(viewchanged: Boolean = true) { - if (viewchanged) { - uboVS.projection = glm.perspective(60f.rad, size.aspect, 0.001f, 256f) - val viewMatrix = glm.translate(Mat4(1f), 0f, 0f, zoom) - - uboVS.model = viewMatrix * glm.translate(Mat4(1f), cameraPos) - .rotateAssign(rotation.x.rad, 1f, 0f, 0f) - .rotateAssign(rotation.y.rad, 0f, 1f, 0f) - .rotateAssign(rotation.z.rad, 0f, 0f, 1f) - - uboVS.viewPos = Vec4(0f, 0f, -zoom, 0f) - } else { - uboVS.depth += frameTimer * 0.15f - if (uboVS.depth > 1f) - uboVS.depth = uboVS.depth - 1f - } - - uniformBufferVS.mapping { mapped -> uboVS to mapped } - } - - override fun prepare() { - super.prepare() - generateQuad() - setupVertexDescriptions() - prepareUniformBuffers() - prepareNoiseTexture(256, 256, 256) - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSet() - buildCommandBuffers() - prepared = true - window.show() - } - - override fun render() { - if (!prepared) - return - draw() - if (regenerateNoise) - updateNoiseTexture() - if (!paused) - updateUniformBuffers(false) - } - - override fun viewChanged() = updateUniformBuffers() - -// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) -// { -// if (overlay->header("Settings")) { -// if (regenerateNoise) { overlay -> -// text("Generating new noise texture...") -// } else { -// if (overlay->button("Generate new texture")) { -// regenerateNoise = true +// else { +//// runBlocking { +//// for (z in 0 until 1) { +//// println(z) +////// for (z in 0 until 1) { +//// for (y in 0 until 1) +//// for (x in 0 until 100) { +//// launch { +//// val v = Vec3(x, y, z) / texture.extent +//// var n = when { +//// FRACTAL -> FractalNoise().noise(v * noiseScale) +//// else -> 20f * glm.perlin(v) +//// } +//// n -= glm.floor(n) +//// +//// val offset = x + y * texture.extent.x + z * texture.extent.x * texture.extent.y +//// println("$adr, "+offset) +//// memPutByte(adr + offset, glm.floor(n * 255).b) +////// data[x + y * texture.extent.x + z * texture.extent.x * texture.extent.y] = glm.floor(n * 255).b +//// } +//// } +//// } +//// } +// IntStream +// .range(0, ext.x * ext.y * ext.z) +// .parallel() +// .forEach { +// val z = it / (ext.x * ext.y) +// val remainder = it - z * ext.x * ext.y +// val y = remainder / ext.x +// val x = remainder % ext.x +// val v = Vec3(x, y, z) / ext +// var n = when { +// FRACTAL -> FractalNoise().noise(v * noiseScale) +// else -> 20f * glm.perlin(v) +// } +// n -= glm.floor(n) +// +// data[x + y * ext.x + z * ext.x * ext.y] = glm.floor(n * 255).b +// } +//// +//// val channel = Channel() +//// +//// val processingPool = newThreadPool +//// +//// launch(processingPool) { for (request in channel) doProcessing(it) } +//// +//// +//// +//// for ... +//// +//// for ... +//// +//// channel.sendBlocking(ProcessingRequest(...)) +// } +// } +// println("Done in ${time}ms") +// +// // Create a host-visible staging buffer that contains the raw image data +// +// // Buffer object +// val bufferCreateInfo = vk.BufferCreateInfo { +// size = texMemSize +// usage = VkBufferUsage.TRANSFER_SRC_BIT.i +// sharingMode = VkSharingMode.EXCLUSIVE +// } +// val stagingBuffer: VkBuffer = device createBuffer bufferCreateInfo +// +// // Allocate host visible memory for data upload +// val memReqs = device getBufferMemoryRequirements stagingBuffer +// val memAllocInfo = vk.MemoryAllocateInfo { +// allocationSize = memReqs.size +// memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT) +// } +// val stagingMemory = device allocateMemory memAllocInfo +// device.bindBufferMemory(stagingBuffer, stagingMemory) +// +// // Copy texture data into staging buffer +// device.mappingMemory(stagingMemory, VkDeviceSize(0), memReqs.size) { mapped -> +// memCopy(memAddress(data), mapped, texMemSize) +// } +// +// val copyCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) +// +// // Image barrier for optimal image +// +// // The sub resource range describes the regions of the image we will be transition +// val subresourceRange = vk.ImageSubresourceRange { +// aspectMask = VkImageAspect.COLOR_BIT.i +// baseMipLevel = 0 +// levelCount = 1 +// layerCount = 1 +// } +// // Optimal image will be used as destination for the copy, so we must transfer from our +// // initial undefined image layout to the transfer destination layout +// tools.setImageLayout( +// copyCmd, +// texture.image, +// VkImageLayout.UNDEFINED, +// VkImageLayout.TRANSFER_DST_OPTIMAL, +// subresourceRange) +// +// // Copy 3D noise data to texture +// +// // Setup buffer copy regions +// val bufferCopyRegion = vk.BufferImageCopy { +// imageSubresource.apply { +// aspectMask = VkImageAspect.COLOR_BIT.i +// mipLevel = 0 +// baseArrayLayer = 0 +// layerCount = 1 // } +// imageExtent(texture.extent) // } +// copyCmd.copyBufferToImage( +// stagingBuffer, +// texture.image, +// VkImageLayout.TRANSFER_DST_OPTIMAL, +// bufferCopyRegion) +// +// // Change texture image layout to shader read after all mip levels have been copied +// texture.imageLayout = VkImageLayout.SHADER_READ_ONLY_OPTIMAL +// tools.setImageLayout( +// copyCmd, +// texture.image, +// VkImageLayout.TRANSFER_DST_OPTIMAL, +// texture.imageLayout, +// subresourceRange) +// +// super.flushCommandBuffer(copyCmd, queue, true) +// +// // Clean up staging resources +// data.free() +// device freeMemory stagingMemory +// device destroyBuffer stagingBuffer +// regenerateNoise = false +// } +// +// /** Free all Vulkan resources used a texture object */ +// fun destroyTextureImage() { +// device.apply { +// if (texture.view.isValid()) +// destroyImageView(texture.view) +// if (texture.image.isValid()) +// destroyImage(texture.image) +// if (texture.sampler.isValid()) +// destroySampler(texture.sampler) +// if (texture.deviceMemory.isValid()) +// freeMemory(texture.deviceMemory) +// } +// } +// +// override fun buildCommandBuffers() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(defaultClearColor) +// it[1].depthStencil(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@Texture3d.renderPass +// renderArea.apply { +// offset(0) +// extent(size) +// } +// this.clearValues = clearValues +// } +// for (i in drawCmdBuffers.indices) { +// // Set target frame buffer +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// setViewport(size) +// +// setScissor(size) +// +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.solid) +// +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, vertexBuffer.buffer) +// bindIndexBuffer(indexBuffer.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// drawIndexed(indexCount, 1, 0, 0, 0) +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// fun draw() { +// +// super.prepareFrame() +// +// // Command buffer to be sumitted to the queue +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// +// // Submit to queue +// queue submit submitInfo +// +// super.submitFrame() +// } +// +// fun generateQuad() = stak { +// // Setup vertices for a single uv-mapped quad made from two triangles +// val vertices = it.floats( +// +1f, +1f, 0f, 1f, 1f, 0f, 0f, 1f, +// -1f, +1f, 0f, 0f, 1f, 0f, 0f, 1f, +// -1f, -1f, 0f, 0f, 0f, 0f, 0f, 1f, +// +1f, -1f, 0f, 1f, 0f, 0f, 0f, 1f) +// +// // Setup indices +// val indices = it.ints(0, 1, 2, 2, 3, 0) +// indexCount = indices.cap +// +// // Create buffers +// // For the sake of simplicity we won't stage the vertex data to the gpu memory +// // Vertex buffer +// vulkanDevice.createBuffer( +// VkBufferUsage.VERTEX_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// vertexBuffer, +// vertices) +// // Index buffer +// vulkanDevice.createBuffer( +// VkBufferUsage.INDEX_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// indexBuffer, +// indices) +// } +// +// fun setupVertexDescriptions() { +// // Binding description +// vertices.inputBinding = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, Vertex.size, VkVertexInputRate.VERTEX) +// +// // Attribute descriptions +// // Describes memory layout and shader positions +// vertices.inputAttributes = vk.VertexInputAttributeDescription( +// // Location 0 : Position +// VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, Vertex.offsetOf("pos"), +// // Location 1 : Texture coordinates +// VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32_SFLOAT, Vertex.offsetOf("uv"), +// // Location 1 : Vertex normal +// VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32G32B32_SFLOAT, Vertex.offsetOf("normal")) +// +// vertices.inputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertices.inputBinding +// vertexAttributeDescriptions = vertices.inputAttributes +// } +// } +// +// fun setupDescriptorPool() { +// // Example uses one ubo and one image sampler +// val poolSizes = vk.DescriptorPoolSize( +// VkDescriptorType.UNIFORM_BUFFER, 1, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1) +// +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) +// +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// // Binding 0 : Vertex shader uniform buffer +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, +// // Binding 1 : Fragment shader image sampler +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// +// descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) +// +// pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// } +// +// fun setupDescriptorSet() { +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) +// +// descriptorSet = device allocateDescriptorSets allocInfo +// +// val writeDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0 : Vertex shader uniform buffer +// descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBufferVS.descriptor, +// // Binding 1 : Fragment shader texture sampler +// descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, texture.descriptor) +// +// device updateDescriptorSets writeDescriptorSets +// } +// +// fun preparePipelines() { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// // Load shaders +// val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { +// it[0].loadShader("$assetPath/shaders/texture3d/texture3d.vert.spv", VkShaderStage.VERTEX_BIT) +// it[1].loadShader("$assetPath/shaders/texture3d/texture3d.frag.spv", VkShaderStage.FRAGMENT_BIT) +// } +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { +// it.vertexInputState = vertices.inputState +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// } +// pipelines.solid = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) // } +// +// /** Prepare and initialize uniform buffer containing shader uniforms */ +// fun prepareUniformBuffers() { +// // Vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBufferVS, +// VkDeviceSize(uboVS.size.L)) +// +// updateUniformBuffers() // } -} \ No newline at end of file +// +// fun updateUniformBuffers(viewchanged: Boolean = true) { +// if (viewchanged) { +// uboVS.projection = glm.perspective(60f.rad, size.aspect, 0.001f, 256f) +// val viewMatrix = glm.translate(Mat4(1f), 0f, 0f, zoom) +// +// uboVS.model = viewMatrix * glm.translate(Mat4(1f), cameraPos) +// .rotateAssign(rotation.x.rad, 1f, 0f, 0f) +// .rotateAssign(rotation.y.rad, 0f, 1f, 0f) +// .rotateAssign(rotation.z.rad, 0f, 0f, 1f) +// +// uboVS.viewPos = Vec4(0f, 0f, -zoom, 0f) +// } else { +// uboVS.depth += frameTimer * 0.15f +// if (uboVS.depth > 1f) +// uboVS.depth = uboVS.depth - 1f +// } +// +// uniformBufferVS.mapping { mapped -> uboVS to mapped } +// } +// +// override fun prepare() { +// super.prepare() +// generateQuad() +// setupVertexDescriptions() +// prepareUniformBuffers() +// prepareNoiseTexture(256, 256, 256) +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSet() +// buildCommandBuffers() +// prepared = true +// window.show() +// } +// +// override fun render() { +// if (!prepared) +// return +// draw() +// if (regenerateNoise) +// updateNoiseTexture() +// if (!paused) +// updateUniformBuffers(false) +// } +// +// override fun viewChanged() = updateUniformBuffers() +// +//// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) +//// { +//// if (overlay->header("Settings")) { +//// if (regenerateNoise) { overlay -> +//// text("Generating new noise texture...") +//// } else { +//// if (overlay->button("Generate new texture")) { +//// regenerateNoise = true +//// } +//// } +//// } +//// } +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/basics/11 Model Rendering.kt b/src/main/kotlin/vulkan/basics/11 Model Rendering.kt index 0dd744f..efa6fcc 100644 --- a/src/main/kotlin/vulkan/basics/11 Model Rendering.kt +++ b/src/main/kotlin/vulkan/basics/11 Model Rendering.kt @@ -1,531 +1,533 @@ -/* -* Vulkan Example - Model loading and rendering -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -package vulkan.basics - -import assimp.AiPostProcessStepsFlags -import assimp.Importer -import assimp.or -import glm_.L -import glm_.buffer.adr -import glm_.func.rad -import glm_.glm -import glm_.mat4x4.Mat4 -import glm_.size -import glm_.vec2.Vec2 -import glm_.vec3.Vec3 -import glm_.vec4.Vec4 -import org.lwjgl.system.MemoryUtil.NULL -import org.lwjgl.vulkan.VkDevice -import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo -import org.lwjgl.vulkan.VkVertexInputAttributeDescription -import org.lwjgl.vulkan.VkVertexInputBindingDescription -import vkk.* -import vulkan.USE_STAGING -import vulkan.VERTEX_BUFFER_BIND_ID -import vulkan.assetPath -import vulkan.base.Buffer -import vulkan.base.Texture2D -import vulkan.base.VulkanExampleBase -import vulkan.base.tools -import assimp.AiPostProcessStep as Pp - - -fun main(args: Array) { - ModelRendering().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - - -private class ModelRendering : VulkanExampleBase() { - - var wireframe = false - - object textures { - val colorMap = Texture2D() - } - - object vertices { - lateinit var inputState: VkPipelineVertexInputStateCreateInfo - lateinit var bindingDescriptions: VkVertexInputBindingDescription - lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer - } - - // Vertex layout used in this example - // This must fit input locations of the vertex shader used to render the model - class Vertex : Bufferizable() { - lateinit var pos: Vec3 - @Order(1) - lateinit var normal: Vec3 - lateinit var uv: Vec2 - @Order(3) - lateinit var color: Vec3 - } - - // Contains all Vulkan resources required to represent vertex and index buffers for a model - // This is for demonstration and learning purposes, the other examples use a model loader class for easy access - object model { - object vertices { - var buffer: VkBuffer = NULL - var memory: VkDeviceMemory = NULL - } - - object indices { - var count = 0 - var buffer: VkBuffer = NULL - var memory: VkDeviceMemory = NULL - } - - // Destroys all Vulkan resources created for this model - fun destroy(device: VkDevice) = device.apply { - destroyBuffer(vertices.buffer) - freeMemory(vertices.memory) - destroyBuffer(indices.buffer) - freeMemory(indices.memory) - } - } - - object uniformBuffers { - val scene = Buffer() - } - - object uboVS : Bufferizable() { - lateinit var projection: Mat4 - @Order(1) - lateinit var model: Mat4 - @Order(2) - val lightPos = Vec4(25f, 5f, 5f, 1f) - } - - object pipelines { - var solid: VkPipeline = NULL - var wireframe: VkPipeline = NULL - } - - var pipelineLayout: VkPipelineLayout = NULL - var descriptorSet: VkDescriptorSet = NULL - var descriptorSetLayout: VkDescriptorSetLayout = NULL - - init { - zoom = -5.5f - zoomSpeed = 2.5f - rotationSpeed = 0.5f - rotation(-0.5f, -112.75f, 0f) - cameraPos(0.1f, 1.1f, 0f) - title = "Model rendering" - settings.overlay = false // TODO - } - - override fun destroy() { - // Clean up used Vulkan resources - // Note : Inherited destructor cleans up resources stored in base class - device.apply { - destroyPipeline(pipelines.solid) - if (pipelines.wireframe != NULL) - destroyPipeline(pipelines.wireframe) - - destroyPipelineLayout(pipelineLayout) - destroyDescriptorSetLayout(descriptorSetLayout) - } - model.destroy(device) - - textures.colorMap.destroy() - uniformBuffers.scene.destroy() - - super.destroy() - } - - override fun getEnabledFeatures() { - // Fill mode non solid is required for wireframe display - if (deviceFeatures.fillModeNonSolid) - enabledFeatures.fillModeNonSolid = true - } - - override fun buildCommandBuffers() { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(defaultClearColor) - it[1].depthStencil(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@ModelRendering.renderPass - renderArea.apply { - offset(0) - extent(size) - } - this.clearValues = clearValues - } - for (i in drawCmdBuffers.indices) { - // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - setViewport(size) - - setScissor(size) - - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) - bindPipeline(VkPipelineBindPoint.GRAPHICS, if (wireframe) pipelines.wireframe else pipelines.solid) - - // Bind mesh vertex buffer - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, model.vertices.buffer) - // Bind mesh index buffer - bindIndexBuffer(model.indices.buffer, 0, VkIndexType.UINT32) - // Render mesh vertex buffer using it's indices - drawIndexed(model.indices.count, 1, 0, 0, 0) - - endRenderPass() - - end() - } - } - } - - /** Load a model from file using the ASSIMP model loader and generate all resources required to render the model */ - fun loadModel(filename: String) { - // Load the model from file using ASSIMP - - // Flags for loading the mesh - val assimpFlags: AiPostProcessStepsFlags = Pp.FlipWindingOrder or Pp.Triangulate or Pp.PreTransformVertices - - val scene = Importer().readFile(filename, assimpFlags)!! - - // Generate vertex buffer from ASSIMP scene data - val scale = 1f - val vertices = ArrayList() - - // Iterate through all meshes in the file and extract the vertex components - for (m in 0 until scene.numMeshes) - for (v in 0 until scene.meshes[m].numVertices) { - - val vertex = Vertex().apply { - // Use glm make_* functions to convert ASSIMP vectors to glm vectors - pos = scene.meshes[m].vertices[v] * scale - normal = scene.meshes[m].normals[v] - // Texture coordinates and colors may have multiple channels, we only use the first [0] one - uv = Vec2(scene.meshes[m].textureCoords[0][v]) - // Mesh may not have vertex colors - color = scene.meshes[m].colors.getOrNull(0)?.let { Vec3(it[v]) } ?: Vec3(1f) - // Vulkan uses a right-handed NDC (contrary to OpenGL), so simply flip Y-Axis - pos.y *= -1f - } - vertices += vertex - } - val vertexBuffer = bufferOf(vertices) - - // Generate index buffer from ASSIMP scene data - val indices = ArrayList() - for (m in 0 until scene.numMeshes) { - val indexBase = indices.size - for (f in 0 until scene.meshes[m].numFaces) - // We assume that all faces are triangulated - for (i in 0..2) - indices += scene.meshes[m].faces[f][i] + indexBase - } - val indexBuffer = intArrayOf(indices) - model.indices.count = indices.size - - // Static mesh should always be device local - - if (USE_STAGING) { - - val vertexStaging = object { - var buffer: VkBuffer = NULL - var memory: VkDeviceMemory = NULL - } - val indexStaging = object { - var buffer: VkBuffer = NULL - var memory: VkDeviceMemory = NULL - } - - // Create staging buffers - // Vertex data - vulkanDevice.createBuffer( - VkBufferUsage.TRANSFER_SRC_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - vertexBuffer.size.L, - vertexStaging::buffer, - vertexStaging::memory, - vertexBuffer.adr) - // Index data - vulkanDevice.createBuffer( - VkBufferUsage.TRANSFER_SRC_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - indexBuffer.size.L, - indexStaging::buffer, - indexStaging::memory, - indexBuffer.adr) - - // Create device local buffers - // Vertex buffer - vulkanDevice.createBuffer( - VkBufferUsage.VERTEX_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT, - VkMemoryProperty.DEVICE_LOCAL_BIT.i, - vertexBuffer.size.L, - model.vertices::buffer, - model.vertices::memory) - // Index buffer - vulkanDevice.createBuffer( - VkBufferUsage.INDEX_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT, - VkMemoryProperty.DEVICE_LOCAL_BIT.i, - indexBuffer.size.L, - model.indices::buffer, - model.indices::memory) - - // Copy from staging buffers - val copyCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) - - val copyRegion = vk.BufferCopy { size = vertexBuffer.size.L } - copyCmd.copyBuffer( - vertexStaging.buffer, - model.vertices.buffer, - copyRegion) - - copyRegion.size = indexBuffer.size.L - copyCmd.copyBuffer( - indexStaging.buffer, - model.indices.buffer, - copyRegion) - - super.flushCommandBuffer(copyCmd, queue, true) - - device.apply { - destroyBuffer(vertexStaging.buffer) - freeMemory(vertexStaging.memory) - destroyBuffer(indexStaging.buffer) - freeMemory(indexStaging.memory) - } - } else { - // Vertex buffer - vulkanDevice.createBuffer( - VkBufferUsage.VERTEX_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT.i, - vertexBuffer.size.L, - model.vertices::buffer, - model.vertices::memory, - vertexBuffer.adr) - // Index buffer - vulkanDevice.createBuffer( - VkBufferUsage.INDEX_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT.i, - indexBuffer.size.L, - model.indices::buffer, - model.indices::memory, - indexBuffer.adr) - } - } - - fun loadAssets() { - loadModel("$assetPath/models/voyager/voyager.dae") - val (texture, format) = when { - deviceFeatures.textureCompressionBC -> "voyager_bc3_unorm.ktx" to VkFormat.BC3_UNORM_BLOCK - deviceFeatures.textureCompressionASTC_LDR -> "voyager_astc_8x8_unorm.ktx" to VkFormat.ASTC_8x8_UNORM_BLOCK - deviceFeatures.textureCompressionETC2 -> "voyager_etc2_unorm.ktx" to VkFormat.ETC2_R8G8B8A8_UNORM_BLOCK - else -> tools.exitFatal("Device does not support any compressed texture format!", VkResult.ERROR_FEATURE_NOT_PRESENT) - } - textures.colorMap.loadFromFile("$assetPath/models/voyager/$texture", format, vulkanDevice, queue) - } - - fun setupVertexDescriptions() { - val vertex = Vertex() - // Binding description - vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, vertex.size, VkVertexInputRate.VERTEX) - - // Attribute descriptions - // Describes memory layout and shader positions - vertices.attributeDescriptions = vk.VertexInputAttributeDescription( - // Location 0 : Position - VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, vertex.offsetOf("pos"), - // Location 1 : Normal - VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32_SFLOAT, vertex.offsetOf("normal"), - // Location 2 : Texture coordinates - VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32G32_SFLOAT, vertex.offsetOf("uv"), - // Location 3 : Color - VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32G32B32_SFLOAT, vertex.offsetOf("color")) - - vertices.inputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertices.bindingDescriptions - vertexAttributeDescriptions = vertices.attributeDescriptions - } - } - - fun setupDescriptorPool() { - // Example uses one ubo and one combined image sampler - val poolSizes = vk.DescriptorPoolSize( - VkDescriptorType.UNIFORM_BUFFER, 1, - VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1) - - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 1) - - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - // Binding 0 : Vertex shader uniform buffer - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, - // Binding 1 : Fragment shader combined sampler - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - - descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) - - pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - } - - fun setupDescriptorSet() { - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) - - descriptorSet = device allocateDescriptorSets allocInfo - - val texDescriptor = vk.DescriptorImageInfo(textures.colorMap.sampler, textures.colorMap.view, VkImageLayout.GENERAL) - - val writeDescriptorSets = vk.WriteDescriptorSet( - // Binding 0 : Vertex shader uniform buffer - descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.scene.descriptor, - // Binding 1 : Color map - descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, texDescriptor) - - device updateDescriptorSets writeDescriptorSets - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.BACK_BIT.i, VkFrontFace.CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - // Solid rendering pipeline - // Load shaders - val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { - it[0].loadShader("$assetPath/shaders/mesh/mesh.vert.spv", VkShaderStage.VERTEX_BIT) - it[1].loadShader("$assetPath/shaders/mesh/mesh.frag.spv", VkShaderStage.FRAGMENT_BIT) - } - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { - it.vertexInputState = vertices.inputState - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - } - pipelines.solid = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - - // Wire frame rendering pipeline - if (deviceFeatures.fillModeNonSolid) { - rasterizationState.polygonMode = VkPolygonMode.LINE - rasterizationState.lineWidth = 1f - pipelines.wireframe = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - } - - /** Prepare and initialize uniform buffer containing shader uniforms */ - fun prepareUniformBuffers() { - // Vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBuffers.scene, - uboVS.size.L) - - // Map persistent - uniformBuffers.scene.map() - - updateUniformBuffers() - } - - fun updateUniformBuffers() { - - uboVS.projection = glm.perspective(60f.rad, size.aspect, 0.1f, 256f) - val viewMatrix = glm.translate(Mat4(1f), Vec3(0f, 0f, zoom)) - - uboVS.model = viewMatrix * glm.translate(Mat4(1f), cameraPos) - .rotateAssign(rotation.x.rad, 1f, 0f, 0f) - .rotateAssign(rotation.y.rad, 0f, 1f, 0f) - .rotateAssign(rotation.z.rad, 0f, 0f, 1f) - - uboVS to uniformBuffers.scene.mapped - } - - fun draw() { - - super.prepareFrame() - - // Command buffer to be sumitted to the queue - submitInfo.commandBuffer = drawCmdBuffers [currentBuffer] - - // Submit to queue - queue submit submitInfo - - super.submitFrame() - } - - override fun prepare() { - super.prepare() - loadAssets() - setupVertexDescriptions() - prepareUniformBuffers() - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSet() - buildCommandBuffers() - prepared = true - window.show() - } - - override fun render() { - if (!prepared) - return - draw() - } - - override fun viewChanged() = updateUniformBuffers() - -// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) -// { -// if (overlay->header("Settings")) { -// if (overlay->checkBox("Wireframe", &wireframe)) { -// buildCommandBuffers() +///* +//* Vulkan Example - Model loading and rendering +//* +//* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +//package vulkan.basics +// +//import assimp.AiPostProcessStepsFlags +//import assimp.Importer +//import assimp.or +//import glm_.L +//import glm_.func.rad +//import glm_.glm +//import glm_.mat4x4.Mat4 +//import glm_.size +//import glm_.vec2.Vec2 +//import glm_.vec3.Vec3 +//import glm_.vec4.Vec4 +//import kool.adr +//import org.lwjgl.system.MemoryUtil.NULL +//import org.lwjgl.vulkan.VkDevice +//import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo +//import org.lwjgl.vulkan.VkVertexInputAttributeDescription +//import org.lwjgl.vulkan.VkVertexInputBindingDescription +//import vkk.* +//import vulkan.USE_STAGING +//import vulkan.VERTEX_BUFFER_BIND_ID +//import vulkan.assetPath +//import vulkan.base.Buffer +//import vulkan.base.Texture2D +//import vulkan.base.VulkanExampleBase +//import vulkan.base.tools +//import assimp.AiPostProcessStep as Pp +// +// +//fun main(args: Array) { +// ModelRendering().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +// +//private class ModelRendering : VulkanExampleBase() { +// +// var wireframe = false +// +// object textures { +// val colorMap = Texture2D() +// } +// +// object vertices { +// lateinit var inputState: VkPipelineVertexInputStateCreateInfo +// lateinit var bindingDescriptions: VkVertexInputBindingDescription +// lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer +// } +// +// // Vertex layout used in this example +// // This must fit input locations of the vertex shader used to render the model +// class Vertex : Bufferizable() { +// lateinit var pos: Vec3 +// @Order(1) +// lateinit var normal: Vec3 +// lateinit var uv: Vec2 +// @Order(3) +// lateinit var color: Vec3 +// } +// +// // Contains all Vulkan resources required to represent vertex and index buffers for a model +// // This is for demonstration and learning purposes, the other examples use a model loader class for easy access +// object model { +// object vertices { +// var buffer = VkBuffer(NULL) +// var memory = VkDeviceMemory(NULL) +// } +// +// object indices { +// var count = 0 +// var buffer = VkBuffer(NULL) +// var memory = VkDeviceMemory(NULL) +// } +// +// // Destroys all Vulkan resources created for this model +// fun destroy(device: VkDevice) = device.apply { +// destroyBuffer(vertices.buffer) +// freeMemory(vertices.memory) +// destroyBuffer(indices.buffer) +// freeMemory(indices.memory) +// } +// } +// +// object uniformBuffers { +// val scene = Buffer() +// } +// +// object uboVS : Bufferizable() { +// lateinit var projection: Mat4 +// @Order(1) +// lateinit var model: Mat4 +// @Order(2) +// val lightPos = Vec4(25f, 5f, 5f, 1f) +// } +// +// object pipelines { +// var solid = VkPipeline(NULL) +// var wireframe = VkPipeline(NULL) +// } +// +// var pipelineLayout = VkPipelineLayout(NULL) +// var descriptorSet = VkDescriptorSet(NULL) +// var descriptorSetLayout = VkDescriptorSetLayout(NULL) +// +// init { +// zoom = -5.5f +// zoomSpeed = 2.5f +// rotationSpeed = 0.5f +// rotation(-0.5f, -112.75f, 0f) +// cameraPos(0.1f, 1.1f, 0f) +// title = "Model rendering" +// settings.overlay = false // TODO +// } +// +// override fun destroy() { +// // Clean up used Vulkan resources +// // Note : Inherited destructor cleans up resources stored in base class +// device.apply { +// destroyPipeline(pipelines.solid) +// if (pipelines.wireframe.isValid()) +// destroyPipeline(pipelines.wireframe) +// +// destroyPipelineLayout(pipelineLayout) +// destroyDescriptorSetLayout(descriptorSetLayout) +// } +// model.destroy(device) +// +// textures.colorMap.destroy() +// uniformBuffers.scene.destroy() +// +// super.destroy() +// } +// +// override fun getEnabledFeatures() { +// // Fill mode non solid is required for wireframe display +// if (deviceFeatures.fillModeNonSolid) +// enabledFeatures.fillModeNonSolid = true +// } +// +// override fun buildCommandBuffers() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(defaultClearColor) +// it[1].depthStencil(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@ModelRendering.renderPass +// renderArea.apply { +// offset(0) +// extent(size) +// } +// this.clearValues = clearValues +// } +// for (i in drawCmdBuffers.indices) { +// // Set target frame buffer +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// setViewport(size) +// +// setScissor(size) +// +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, if (wireframe) pipelines.wireframe else pipelines.solid) +// +// // Bind mesh vertex buffer +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, model.vertices.buffer) +// // Bind mesh index buffer +// bindIndexBuffer(model.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// // Render mesh vertex buffer using it's indices +// drawIndexed(model.indices.count, 1, 0, 0, 0) +// +// endRenderPass() +// +// end() +// } +// } // } +// +// /** Load a model from file using the ASSIMP model loader and generate all resources required to render the model */ +// fun loadModel(filename: String) { +// // Load the model from file using ASSIMP +// +// // Flags for loading the mesh +// val assimpFlags: AiPostProcessStepsFlags = Pp.FlipWindingOrder or Pp.Triangulate or Pp.PreTransformVertices +// +// val scene = Importer().readFile(filename, assimpFlags)!! +// +// // Generate vertex buffer from ASSIMP scene data +// val scale = 1f +// val vertices = ArrayList() +// +// // Iterate through all meshes in the file and extract the vertex components +// for (m in 0 until scene.numMeshes) +// for (v in 0 until scene.meshes[m].numVertices) { +// +// val vertex = Vertex().apply { +// // Use glm make_* functions to convert ASSIMP vectors to glm vectors +// pos = scene.meshes[m].vertices[v] * scale +// normal = scene.meshes[m].normals[v] +// // Texture coordinates and colors may have multiple channels, we only use the first [0] one +// uv = Vec2(scene.meshes[m].textureCoords[0][v]) +// // Mesh may not have vertex colors +// color = scene.meshes[m].colors.getOrNull(0)?.let { Vec3(it[v]) } ?: Vec3(1f) +// // Vulkan uses a right-handed NDC (contrary to OpenGL), so simply flip Y-Axis +// pos.y *= -1f +// } +// vertices += vertex +// } +// val vertexBuffer = bufferOf(vertices) +// val vertexBufferSize = VkDeviceSize(vertexBuffer.size.L) +// +// // Generate index buffer from ASSIMP scene data +// val indices = ArrayList() +// for (m in 0 until scene.numMeshes) { +// val indexBase = indices.size +// for (f in 0 until scene.meshes[m].numFaces) +// // We assume that all faces are triangulated +// for (i in 0..2) +// indices += scene.meshes[m].faces[f][i] + indexBase +// } +// val indexBuffer = intArrayOf(indices) +// val indexBufferSize = VkDeviceSize(indexBuffer.size.L) +// model.indices.count = indices.size +// +// // Static mesh should always be device local +// +// if (USE_STAGING) { +// +// val vertexStaging = object { +// var buffer = VkBuffer(NULL) +// var memory = VkDeviceMemory(NULL) +// } +// val indexStaging = object { +// var buffer = VkBuffer(NULL) +// var memory= VkDeviceMemory (NULL) +// } +// +// // Create staging buffers +// // Vertex data +// vulkanDevice.createBuffer( +// VkBufferUsage.TRANSFER_SRC_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// vertexBufferSize, +// vertexStaging::buffer, +// vertexStaging::memory, +// vertexBuffer.adr) +// // Index data +// vulkanDevice.createBuffer( +// VkBufferUsage.TRANSFER_SRC_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// indexBufferSize, +// indexStaging::buffer, +// indexStaging::memory, +// indexBuffer.adr) +// +// // Create device local buffers +// // Vertex buffer +// vulkanDevice.createBuffer( +// VkBufferUsage.VERTEX_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT, +// VkMemoryProperty.DEVICE_LOCAL_BIT.i, +// vertexBufferSize, +// model.vertices::buffer, +// model.vertices::memory) +// // Index buffer +// vulkanDevice.createBuffer( +// VkBufferUsage.INDEX_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT, +// VkMemoryProperty.DEVICE_LOCAL_BIT.i, +// indexBufferSize, +// model.indices::buffer, +// model.indices::memory) +// +// // Copy from staging buffers +// val copyCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) +// +// val copyRegion = vk.BufferCopy { size = vertexBufferSize } +// copyCmd.copyBuffer( +// vertexStaging.buffer, +// model.vertices.buffer, +// copyRegion) +// +// copyRegion.size = indexBufferSize +// copyCmd.copyBuffer( +// indexStaging.buffer, +// model.indices.buffer, +// copyRegion) +// +// super.flushCommandBuffer(copyCmd, queue, true) +// +// device.apply { +// destroyBuffer(vertexStaging.buffer) +// freeMemory(vertexStaging.memory) +// destroyBuffer(indexStaging.buffer) +// freeMemory(indexStaging.memory) +// } +// } else { +// // Vertex buffer +// vulkanDevice.createBuffer( +// VkBufferUsage.VERTEX_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT.i, +// vertexBufferSize, +// model.vertices::buffer, +// model.vertices::memory, +// vertexBuffer.adr) +// // Index buffer +// vulkanDevice.createBuffer( +// VkBufferUsage.INDEX_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT.i, +// indexBufferSize, +// model.indices::buffer, +// model.indices::memory, +// indexBuffer.adr) +// } +// } +// +// fun loadAssets() { +// loadModel("$assetPath/models/voyager/voyager.dae") +// val (texture, format) = when { +// deviceFeatures.textureCompressionBC -> "voyager_bc3_unorm.ktx" to VkFormat.BC3_UNORM_BLOCK +// deviceFeatures.textureCompressionASTC_LDR -> "voyager_astc_8x8_unorm.ktx" to VkFormat.ASTC_8x8_UNORM_BLOCK +// deviceFeatures.textureCompressionETC2 -> "voyager_etc2_unorm.ktx" to VkFormat.ETC2_R8G8B8A8_UNORM_BLOCK +// else -> tools.exitFatal("Device does not support any compressed texture format!", ERROR_FEATURE_NOT_PRESENT) +// } +// textures.colorMap.loadFromFile("$assetPath/models/voyager/$texture", format, vulkanDevice, queue) +// } +// +// fun setupVertexDescriptions() { +// val vertex = Vertex() +// // Binding description +// vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, vertex.size, VkVertexInputRate.VERTEX) +// +// // Attribute descriptions +// // Describes memory layout and shader positions +// vertices.attributeDescriptions = vk.VertexInputAttributeDescription( +// // Location 0 : Position +// VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, vertex.offsetOf("pos"), +// // Location 1 : Normal +// VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32_SFLOAT, vertex.offsetOf("normal"), +// // Location 2 : Texture coordinates +// VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32G32_SFLOAT, vertex.offsetOf("uv"), +// // Location 3 : Color +// VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32G32B32_SFLOAT, vertex.offsetOf("color")) +// +// vertices.inputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertices.bindingDescriptions +// vertexAttributeDescriptions = vertices.attributeDescriptions +// } +// } +// +// fun setupDescriptorPool() { +// // Example uses one ubo and one combined image sampler +// val poolSizes = vk.DescriptorPoolSize( +// VkDescriptorType.UNIFORM_BUFFER, 1, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1) +// +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 1) +// +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// // Binding 0 : Vertex shader uniform buffer +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, +// // Binding 1 : Fragment shader combined sampler +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// +// descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) +// +// pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// } +// +// fun setupDescriptorSet() { +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) +// +// descriptorSet = device allocateDescriptorSets allocInfo +// +// val texDescriptor = vk.DescriptorImageInfo(textures.colorMap.sampler, textures.colorMap.view, VkImageLayout.GENERAL) +// +// val writeDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0 : Vertex shader uniform buffer +// descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.scene.descriptor, +// // Binding 1 : Color map +// descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, texDescriptor) +// +// device updateDescriptorSets writeDescriptorSets +// } +// +// fun preparePipelines() { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.BACK_BIT.i, VkFrontFace.CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// // Solid rendering pipeline +// // Load shaders +// val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { +// it[0].loadShader("$assetPath/shaders/mesh/mesh.vert.spv", VkShaderStage.VERTEX_BIT) +// it[1].loadShader("$assetPath/shaders/mesh/mesh.frag.spv", VkShaderStage.FRAGMENT_BIT) +// } +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { +// it.vertexInputState = vertices.inputState +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// } +// pipelines.solid = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// +// // Wire frame rendering pipeline +// if (deviceFeatures.fillModeNonSolid) { +// rasterizationState.polygonMode = VkPolygonMode.LINE +// rasterizationState.lineWidth = 1f +// pipelines.wireframe = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// } +// +// /** Prepare and initialize uniform buffer containing shader uniforms */ +// fun prepareUniformBuffers() { +// // Vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBuffers.scene, +// VkDeviceSize(uboVS.size.L)) +// +// // Map persistent +// uniformBuffers.scene.map() +// +// updateUniformBuffers() +// } +// +// fun updateUniformBuffers() { +// +// uboVS.projection = glm.perspective(60f.rad, size.aspect, 0.1f, 256f) +// val viewMatrix = glm.translate(Mat4(1f), Vec3(0f, 0f, zoom)) +// +// uboVS.model = viewMatrix * glm.translate(Mat4(1f), cameraPos) +// .rotateAssign(rotation.x.rad, 1f, 0f, 0f) +// .rotateAssign(rotation.y.rad, 0f, 1f, 0f) +// .rotateAssign(rotation.z.rad, 0f, 0f, 1f) +// +// uboVS to uniformBuffers.scene.mapped +// } +// +// fun draw() { +// +// super.prepareFrame() +// +// // Command buffer to be sumitted to the queue +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// +// // Submit to queue +// queue submit submitInfo +// +// super.submitFrame() +// } +// +// override fun prepare() { +// super.prepare() +// loadAssets() +// setupVertexDescriptions() +// prepareUniformBuffers() +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSet() +// buildCommandBuffers() +// prepared = true +// window.show() // } +// +// override fun render() { +// if (!prepared) +// return +// draw() // } -} \ No newline at end of file +// +// override fun viewChanged() = updateUniformBuffers() +// +//// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) +//// { +//// if (overlay->header("Settings")) { +//// if (overlay->checkBox("Wireframe", &wireframe)) { +//// buildCommandBuffers() +//// } +//// } +//// } +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/basics/12 Subpasses.kt b/src/main/kotlin/vulkan/basics/12 Subpasses.kt index d454a0a..b8b56cf 100644 --- a/src/main/kotlin/vulkan/basics/12 Subpasses.kt +++ b/src/main/kotlin/vulkan/basics/12 Subpasses.kt @@ -1,931 +1,932 @@ -/* -* Vulkan Example - Using subpasses for G-Buffer compositing -* -* Copyright (C) 2016-2017 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -* -* Summary: -* Implements a deferred rendering setup with a forward transparency pass using sub passes -* -* Sub passes allow reading from the previous framebuffer (in the same render pass) at -* the same pixel position. -* -* This is a feature that was especially designed for tile-based-renderers -* (mostly mobile GPUs) and is a new optomization feature in Vulkan for those GPU types. -* -*/ - -package vulkan.basics - -import ab.appBuffer -import glm_.BYTES -import glm_.L -import glm_.glm -import glm_.mat4x4.Mat4 -import glm_.set -import glm_.vec3.Vec3 -import glm_.vec4.Vec4 -import org.lwjgl.system.MemoryUtil.NULL -import org.lwjgl.vulkan.VK10.VK_SUBPASS_EXTERNAL -import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo -import org.lwjgl.vulkan.VkVertexInputAttributeDescription -import org.lwjgl.vulkan.VkVertexInputBindingDescription -import vkk.* -import vulkan.NUM_LIGHTS -import vulkan.VERTEX_BUFFER_BIND_ID -import vulkan.assetPath -import vulkan.base.* -import java.lang.Math.abs - - -fun main(args: Array) { - Subpasses().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - -private class Subpasses : VulkanExampleBase() { - - object textures { - val glass = Texture2D() - } - - // Vertex layout for the models - val vertexLayout = VertexLayout( - VertexComponent.POSITION, - VertexComponent.COLOR, - VertexComponent.NORMAL, - VertexComponent.UV) - - object models { - val scene = Model() - val transparent = Model() - } - - object vertices { - lateinit var inputState: VkPipelineVertexInputStateCreateInfo - lateinit var bindingDescriptions: VkVertexInputBindingDescription - lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer - } - - object uboGBuffer : Bufferizable() { - lateinit var projection: Mat4 - @Order(1) - lateinit var model: Mat4 - lateinit var view: Mat4 - } - - class Light { - lateinit var position: Vec4 - lateinit var color: Vec3 - var radius = 0f - } - - object uboLights : Bufferizable() { - lateinit var viewPos: Vec4 - val lights = Array(NUM_LIGHTS) { Light() } - } - - object uniformBuffers { - val GBuffer = Buffer() - val lights = Buffer() - } - - object pipelines { - var offscreen: VkPipeline = NULL - var composition: VkPipeline = NULL - var transparent: VkPipeline = NULL - } - - object pipelineLayouts { - var offscreen: VkPipelineLayout = NULL - var composition: VkPipelineLayout = NULL - var transparent: VkPipelineLayout = NULL - } - - object descriptorSets { - var scene: VkDescriptorSet = NULL - var composition: VkDescriptorSet = NULL - var transparent: VkDescriptorSet = NULL - } - - object descriptorSetLayouts { - var scene: VkDescriptorSetLayout = NULL - var composition: VkDescriptorSetLayout = NULL - var transparent: VkDescriptorSetLayout = NULL - } - - // G-Buffer framebuffer attachments - class FrameBufferAttachment { - var image: VkImage = NULL - var mem: VkDeviceMemory = 0L - var view: VkImageView = NULL - var format = VkFormat.UNDEFINED - } - - object attachments { - val position = FrameBufferAttachment() - val normal = FrameBufferAttachment() - val albedo = FrameBufferAttachment() - } - - var uiRenderPass: VkRenderPass = NULL - - init { - title = "Subpasses" - camera.type = Camera.CameraType.firstPerson - camera.movementSpeed = 5f - camera.setPosition(Vec3(-3.2f, 1f, 5.9f)) - camera.setRotation(Vec3(0.5f, 210.05f, 0f)) - camera.setPerspective(60f, size.aspect, 0.1f, 256f) - settings.overlay = false // TODO - } - - override fun destroy() { - - device.apply { - // Clean up used Vulkan resources - // Note : Inherited destructor cleans up resources stored in base class - - destroyImageView(attachments.position.view) - destroyImage(attachments.position.image) - freeMemory(attachments.position.mem) - - destroyImageView(attachments.normal.view) - destroyImage(attachments.normal.image) - freeMemory(attachments.normal.mem) - - destroyImageView(attachments.albedo.view) - destroyImage(attachments.albedo.image) - freeMemory(attachments.albedo.mem) - - destroyPipeline(pipelines.offscreen) - destroyPipeline(pipelines.composition) - destroyPipeline(pipelines.transparent) - - destroyPipelineLayout(pipelineLayouts.offscreen) - destroyPipelineLayout(pipelineLayouts.composition) - destroyPipelineLayout(pipelineLayouts.transparent) - - destroyDescriptorSetLayout(descriptorSetLayouts.scene) - destroyDescriptorSetLayout(descriptorSetLayouts.composition) - destroyDescriptorSetLayout(descriptorSetLayouts.transparent) - - destroyRenderPass(uiRenderPass) - } - textures.glass.destroy() - models.scene.destroy() - models.transparent.destroy() - uniformBuffers.GBuffer.destroy() - uniformBuffers.lights.destroy() - - super.destroy() - } - - /** Enable physical device features required for this example */ - override fun getEnabledFeatures() { - // Enable anisotropic filtering if supported - if (deviceFeatures.samplerAnisotropy) - enabledFeatures.samplerAnisotropy = true - // Enable texture compression - when { - deviceFeatures.textureCompressionBC -> enabledFeatures.textureCompressionBC = true - deviceFeatures.textureCompressionASTC_LDR -> enabledFeatures.textureCompressionASTC_LDR = true - deviceFeatures.textureCompressionETC2 -> enabledFeatures.textureCompressionETC2 = true - } - } - - /** Create a frame buffer attachment */ - fun createAttachment(format: VkFormat, usage: VkImageUsageFlags, attachment: FrameBufferAttachment) { - - var aspectMask: VkImageAspectFlags = 0 - var imageLayout = VkImageLayout.UNDEFINED - - attachment.format = format - - if (usage has VkImageUsage.COLOR_ATTACHMENT_BIT) { - aspectMask = VkImageAspect.COLOR_BIT.i - imageLayout = VkImageLayout.COLOR_ATTACHMENT_OPTIMAL - } - if (usage has VkImageUsage.DEPTH_STENCIL_ATTACHMENT_BIT) { - aspectMask = VkImageAspect.DEPTH_BIT or VkImageAspect.STENCIL_BIT - imageLayout = VkImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL - } - - assert(aspectMask > 0) - - val image = vk.ImageCreateInfo { - imageType = VkImageType.`2D` - this.format = format - extent(size, 1) - mipLevels = 1 - arrayLayers = 1 - samples = VkSampleCount.`1_BIT` - tiling = VkImageTiling.OPTIMAL - this.usage = usage or VkImageUsage.INPUT_ATTACHMENT_BIT // VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT flag is required for input attachments; - initialLayout = VkImageLayout.UNDEFINED - } - - attachment.image = device createImage image - val memReqs = device getImageMemoryRequirements attachment.image - val memAlloc = vk.MemoryAllocateInfo { - allocationSize = memReqs.size - memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) - } - attachment.mem = device allocateMemory memAlloc - device.bindImageMemory(attachment.image, attachment.mem) - - val imageView = vk.ImageViewCreateInfo { - viewType = VkImageViewType.`2D` - this.format = format - subresourceRange.apply { - this.aspectMask = aspectMask - baseMipLevel = 0 - levelCount = 1 - baseArrayLayer = 0 - layerCount = 1 - } - this.image = attachment.image - } - attachment.view = device createImageView imageView - } - - /** Create color attachments for the G-Buffer components */ - fun createGBufferAttachments() { - createAttachment(VkFormat.R16G16B16A16_SFLOAT, VkImageUsage.COLOR_ATTACHMENT_BIT.i, attachments.position) // (World space) Positions - createAttachment(VkFormat.R16G16B16A16_SFLOAT, VkImageUsage.COLOR_ATTACHMENT_BIT.i, attachments.normal) // (World space) Normals - createAttachment(VkFormat.R8G8B8A8_UNORM, VkImageUsage.COLOR_ATTACHMENT_BIT.i, attachments.albedo) // Albedo (color) - } - - /** Override framebuffer setup from base class - * Deferred components will be used as frame buffer attachments */ - override fun setupFrameBuffer() { - - val attachments = appBuffer.longBuffer(5) - - val frameBufferCreateInfo = vk.FramebufferCreateInfo { - renderPass = this@Subpasses.renderPass - this.attachments = attachments - width = size.x - height = size.y - layers = 1 - } - // Create frame buffers for every swap chain image - repeat(swapChain.imageCount) { - attachments[0] = swapChain.buffers[it].view - attachments[1] = Subpasses.attachments.position.view - attachments[2] = Subpasses.attachments.normal.view - attachments[3] = Subpasses.attachments.albedo.view - attachments[4] = depthStencil.view - frameBuffers += device createFramebuffer frameBufferCreateInfo - } - } - - /** Override render pass setup from base class */ - override fun setupRenderPass() { - - createGBufferAttachments() - - val attachments = vk.AttachmentDescription(5).also { - // Color attachment - it[0].apply { - format = swapChain.colorFormat - samples = VkSampleCount.`1_BIT` - loadOp = VkAttachmentLoadOp.CLEAR - storeOp = VkAttachmentStoreOp.STORE - stencilLoadOp = VkAttachmentLoadOp.DONT_CARE - stencilStoreOp = VkAttachmentStoreOp.DONT_CARE - initialLayout = VkImageLayout.UNDEFINED - finalLayout = VkImageLayout.PRESENT_SRC_KHR - } - // Deferred attachments - // Position - it[1].apply { - format = Subpasses.attachments.position.format - samples = VkSampleCount.`1_BIT` - loadOp = VkAttachmentLoadOp.CLEAR - storeOp = VkAttachmentStoreOp.DONT_CARE - stencilLoadOp = VkAttachmentLoadOp.DONT_CARE - stencilStoreOp = VkAttachmentStoreOp.DONT_CARE - initialLayout = VkImageLayout.UNDEFINED - finalLayout = VkImageLayout.COLOR_ATTACHMENT_OPTIMAL - } - // Normals - it[2].apply { - format = Subpasses.attachments.normal.format - samples = VkSampleCount.`1_BIT` - loadOp = VkAttachmentLoadOp.CLEAR - storeOp = VkAttachmentStoreOp.DONT_CARE - stencilLoadOp = VkAttachmentLoadOp.DONT_CARE - stencilStoreOp = VkAttachmentStoreOp.DONT_CARE - initialLayout = VkImageLayout.UNDEFINED - finalLayout = VkImageLayout.COLOR_ATTACHMENT_OPTIMAL - } - // Albedo - it[3].apply { - format = Subpasses.attachments.albedo.format - samples = VkSampleCount.`1_BIT` - loadOp = VkAttachmentLoadOp.CLEAR - storeOp = VkAttachmentStoreOp.DONT_CARE - stencilLoadOp = VkAttachmentLoadOp.DONT_CARE - stencilStoreOp = VkAttachmentStoreOp.DONT_CARE - initialLayout = VkImageLayout.UNDEFINED - finalLayout = VkImageLayout.COLOR_ATTACHMENT_OPTIMAL - } - // Depth attachment - it[4].apply { - format = depthFormat - samples = VkSampleCount.`1_BIT` - loadOp = VkAttachmentLoadOp.CLEAR - storeOp = VkAttachmentStoreOp.DONT_CARE - stencilLoadOp = VkAttachmentLoadOp.DONT_CARE - stencilStoreOp = VkAttachmentStoreOp.DONT_CARE - initialLayout = VkImageLayout.UNDEFINED - finalLayout = VkImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL - } - } - // Three subpasses - val subpassDescriptions = vk.SubpassDescription(3) - - // First subpass: Fill G-Buffer components - // ---------------------------------------------------------------------------------------- - - val colorReferences = vk.AttachmentReference( - 0, VkImageLayout.COLOR_ATTACHMENT_OPTIMAL, - 1, VkImageLayout.COLOR_ATTACHMENT_OPTIMAL, - 2, VkImageLayout.COLOR_ATTACHMENT_OPTIMAL, - 3, VkImageLayout.COLOR_ATTACHMENT_OPTIMAL) - val depthReference = vk.AttachmentReference(4, VkImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL) - - subpassDescriptions[0].apply { - pipelineBindPoint = VkPipelineBindPoint.GRAPHICS - colorAttachmentCount = 4 - colorAttachments = colorReferences - depthStencilAttachment = depthReference - } - // Second subpass: Final composition (using G-Buffer components) - // ---------------------------------------------------------------------------------------- - - val colorReference = vk.AttachmentReference(0, VkImageLayout.COLOR_ATTACHMENT_OPTIMAL) - - val inputReferences = vk.AttachmentReference( - 1, VkImageLayout.SHADER_READ_ONLY_OPTIMAL, - 2, VkImageLayout.SHADER_READ_ONLY_OPTIMAL, - 3, VkImageLayout.SHADER_READ_ONLY_OPTIMAL) - - subpassDescriptions[1].apply { - pipelineBindPoint = VkPipelineBindPoint.GRAPHICS - colorAttachmentCount = 1 - colorAttachment = colorReference - depthStencilAttachment = depthReference - // Use the color attachments filled in the first pass as input attachments - inputAttachments = inputReferences - } - // Third subpass: Forward transparency - // ---------------------------------------------------------------------------------------- - colorReference(0, VkImageLayout.COLOR_ATTACHMENT_OPTIMAL) - - inputReferences[0](1, VkImageLayout.SHADER_READ_ONLY_OPTIMAL) - - subpassDescriptions[2].apply { - pipelineBindPoint = VkPipelineBindPoint.GRAPHICS - colorAttachmentCount = 1 - colorAttachment = colorReference - depthStencilAttachment = depthReference - // Use the color/depth attachments filled in the first pass as input attachments - inputAttachments = inputReferences - } - // Subpass dependencies for layout transitions - val dependencies = vk.SubpassDependency(4).also { - it[0].apply { - srcSubpass = VK_SUBPASS_EXTERNAL - dstSubpass = 0 - srcStageMask = VkPipelineStage.BOTTOM_OF_PIPE_BIT.i - dstStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i - srcAccessMask = VkAccess.MEMORY_READ_BIT.i - dstAccessMask = VkAccess.COLOR_ATTACHMENT_READ_BIT or VkAccess.COLOR_ATTACHMENT_WRITE_BIT - dependencyFlags = VkDependency.BY_REGION_BIT.i - } - // This dependency transitions the input attachment from color attachment to shader read - it[1].apply { - srcSubpass = 0 - dstSubpass = 1 - srcStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i - dstStageMask = VkPipelineStage.FRAGMENT_SHADER_BIT.i - srcAccessMask = VkAccess.COLOR_ATTACHMENT_WRITE_BIT.i - dstAccessMask = VkAccess.SHADER_READ_BIT.i - dependencyFlags = VkDependency.BY_REGION_BIT.i - } - it[2].apply { - srcSubpass = 1 - dstSubpass = 2 - srcStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i - dstStageMask = VkPipelineStage.FRAGMENT_SHADER_BIT.i - srcAccessMask = VkAccess.COLOR_ATTACHMENT_WRITE_BIT.i - dstAccessMask = VkAccess.SHADER_READ_BIT.i - dependencyFlags = VkDependency.BY_REGION_BIT.i - } - it[3].apply { - srcSubpass = 0 - dstSubpass = VK_SUBPASS_EXTERNAL - srcStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i - dstStageMask = VkPipelineStage.BOTTOM_OF_PIPE_BIT.i - srcAccessMask = VkAccess.COLOR_ATTACHMENT_READ_BIT or VkAccess.COLOR_ATTACHMENT_WRITE_BIT - dstAccessMask = VkAccess.MEMORY_READ_BIT.i - dependencyFlags = VkDependency.BY_REGION_BIT.i - } - } - val renderPassInfo = vk.RenderPassCreateInfo { - this.attachments = attachments - subpasses = subpassDescriptions - this.dependencies = dependencies - } - renderPass = device createRenderPass renderPassInfo - - // Create custom overlay render pass - attachments[0].loadOp = VkAttachmentLoadOp.LOAD - attachments[0].initialLayout = VkImageLayout.PRESENT_SRC_KHR - uiRenderPass = device createRenderPass renderPassInfo - } - - override fun buildCommandBuffers() { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(5).also { - it[0].color(0f, 0f, 0f, 0f) - it[1].color(0f, 0f, 0f, 0f) - it[2].color(0f, 0f, 0f, 0f) - it[3].color(0f, 0f, 0f, 0f) - it[4].depthStencil(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@Subpasses.renderPass - renderArea.offset(0) - renderArea.extent(size) - this.clearValues = clearValues - } - for (i in drawCmdBuffers.indices) { - // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) // TODO BUG - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - setViewport(size) - setScissor(size) - - // First sub pass - // Renders the components of the scene to the G-Buffer atttachments - debugMarker.withRegion(this, "Subpass 0: Deferred G-Buffer creation", Vec4(1f)) { - - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.offscreen) - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayouts.offscreen, descriptorSets.scene) - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.scene.vertices.buffer) - bindIndexBuffer(models.scene.indices.buffer, 0, VkIndexType.UINT32) - drawIndexed(models.scene.indexCount, 1, 0, 0, 0) - } - - // Second sub pass - // This subpass will use the G-Buffer components that have been filled in the first subpass as input attachment for the final compositing - debugMarker.withRegion(this, "Subpass 1: Deferred composition", Vec4(1f)) { - - nextSubpass(VkSubpassContents.INLINE) - - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.composition) - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayouts.composition, descriptorSets.composition) - draw(3, 1, 0, 0) - } - - // Third subpass - // Render transparent geometry using a forward pass that compares against depth generted during G-Buffer fill - debugMarker.withRegion(this, "Subpass 2: Forward transparency", Vec4(1f)) { - - nextSubpass(VkSubpassContents.INLINE) - - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.transparent) - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayouts.transparent, descriptorSets.transparent) - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.transparent.vertices.buffer) - bindIndexBuffer(models.transparent.indices.buffer, 0, VkIndexType.UINT32) - drawIndexed(models.transparent.indexCount, 1, 0, 0, 0) - } - - endRenderPass() - - end() - } - } - } - - fun loadAssets() { - - models.scene.loadFromFile("$assetPath/models/samplebuilding.dae", vertexLayout, 1f, vulkanDevice, queue) - models.transparent.loadFromFile("$assetPath/models/samplebuilding_glass.dae", vertexLayout, 1f, vulkanDevice, queue) - // Textures - val (text, format) = when { - vulkanDevice.features.textureCompressionBC -> "bc3_unorm.ktx" to VkFormat.BC3_UNORM_BLOCK - vulkanDevice.features.textureCompressionASTC_LDR -> "astc_8x8_unorm.ktx" to VkFormat.ASTC_8x8_UNORM_BLOCK - vulkanDevice.features.textureCompressionETC2 -> "etc2_unorm.ktx" to VkFormat.ETC2_R8G8B8A8_UNORM_BLOCK - else -> tools.exitFatal("Device does not support any compressed texture format!", VkResult.ERROR_FEATURE_NOT_PRESENT) - } - textures.glass.loadFromFile("$assetPath/textures/colored_glass_$text", format, vulkanDevice, queue) - } - - fun setupVertexDescriptions() { - // Binding description - vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, vertexLayout.stride, VkVertexInputRate.VERTEX) - - // Attribute descriptions - vertices.attributeDescriptions = vk.VertexInputAttributeDescription( - // Location 0: Position - VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, 0, - // Location 1: Color - VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32_SFLOAT, Vec3.size, - // Location 2: Normal - VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2, - // Location 3: UV - VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32G32_SFLOAT, Vec3.size * 3) - - vertices.inputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertices.bindingDescriptions - vertexAttributeDescriptions = vertices.attributeDescriptions - } - } - - fun setupDescriptorPool() { - - val poolSizes = vk.DescriptorPoolSize( - VkDescriptorType.UNIFORM_BUFFER, 4, - VkDescriptorType.COMBINED_IMAGE_SAMPLER, 4, - VkDescriptorType.INPUT_ATTACHMENT, 4) - - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 4) - - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - // Deferred shading layout - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - // Binding 0 : Vertex shader uniform buffer - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - - descriptorSetLayouts.scene = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayouts.scene) - - // Offscreen (scene) rendering pipeline layout - pipelineLayouts.offscreen = device createPipelineLayout pipelineLayoutCreateInfo - } - - fun setupDescriptorSet() { - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayouts.scene) - - descriptorSets.scene = device allocateDescriptorSets allocInfo - - val writeDescriptorSets = vk.WriteDescriptorSet( - // Binding 0: Vertex shader uniform buffer - descriptorSets.scene, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.GBuffer.descriptor) - - device updateDescriptorSets writeDescriptorSets - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.BACK_BIT.i, VkFrontFace.CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - // Final fullscreen pass pipeline - val shaderStages = vk.PipelineShaderStageCreateInfo(2) - - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayouts.offscreen, renderPass).also { - it.vertexInputState = vertices.inputState - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - it.subpass = 0 - } - val blendAttachmentStates = vk.PipelineColorBlendAttachmentState( - 0xf, false, - 0xf, false, - 0xf, false, - 0xf, false) - - colorBlendState.attachments = blendAttachmentStates - - // Offscreen scene rendering pipeline - shaderStages[0].loadShader("$assetPath/shaders/subpasses/gbuffer.vert.spv", VkShaderStage.VERTEX_BIT) - shaderStages[1].loadShader("$assetPath/shaders/subpasses/gbuffer.frag.spv", VkShaderStage.FRAGMENT_BIT) - - pipelines.offscreen = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - /** Create the Vulkan objects used in the composition pass (descriptor sets, pipelines, etc.) */ - fun prepareCompositionPass() { - // Descriptor set layout - var setLayoutBindings = vk.DescriptorSetLayoutBinding( - // Binding 0: Position input attachment - VkDescriptorType.INPUT_ATTACHMENT, VkShaderStage.FRAGMENT_BIT.i, 0, - // Binding 1: Normal input attachment - VkDescriptorType.INPUT_ATTACHMENT, VkShaderStage.FRAGMENT_BIT.i, 1, - // Binding 2: Albedo input attachment - VkDescriptorType.INPUT_ATTACHMENT, VkShaderStage.FRAGMENT_BIT.i, 2, - // Binding 3: Light positions - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.FRAGMENT_BIT.i, 3) - - var descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - - descriptorSetLayouts.composition = device createDescriptorSetLayout descriptorLayout - - // Pipeline layout - var pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayouts.composition) - - pipelineLayouts.composition = device createPipelineLayout pipelineLayoutCreateInfo - - // Descriptor sets - var allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayouts.composition) - - descriptorSets.composition = device allocateDescriptorSets allocInfo - - // Image descriptors for the offscreen color attachments - val texDescriptorPosition = vk.DescriptorImageInfo(NULL, attachments.position.view, VkImageLayout.SHADER_READ_ONLY_OPTIMAL) - - val texDescriptorNormal = vk.DescriptorImageInfo(NULL, attachments.normal.view, VkImageLayout.SHADER_READ_ONLY_OPTIMAL) - - val texDescriptorAlbedo = vk.DescriptorImageInfo(NULL, attachments.albedo.view, VkImageLayout.SHADER_READ_ONLY_OPTIMAL) - - var writeDescriptorSets = vk.WriteDescriptorSet( - // Binding 0: Position texture target - descriptorSets.composition, VkDescriptorType.INPUT_ATTACHMENT, 0, texDescriptorPosition, - // Binding 1: Normals texture target - descriptorSets.composition, VkDescriptorType.INPUT_ATTACHMENT, 1, texDescriptorNormal, - // Binding 2: Albedo texture target - descriptorSets.composition, VkDescriptorType.INPUT_ATTACHMENT, 2, texDescriptorAlbedo, - // Binding 4: Fragment shader lights - descriptorSets.composition, VkDescriptorType.UNIFORM_BUFFER, 3, uniformBuffers.lights.descriptor) - - device updateDescriptorSets writeDescriptorSets - - // Pipeline - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { - it[0].loadShader("$assetPath/shaders/subpasses/composition.vert.spv", VkShaderStage.VERTEX_BIT) - it[1].loadShader("$assetPath/shaders/subpasses/composition.frag.spv", VkShaderStage.FRAGMENT_BIT) - } - - // Use specialization constants to pass number of lights to the shader - val specializationEntry = vk.SpecializationMapEntry { - constantId = 0 - offset = 0 - size = Int.BYTES.L - } - val specializationData = appBuffer.buffer(Int.BYTES).apply { putInt(0, NUM_LIGHTS) } - - val specializationInfo = vk.SpecializationInfo { - mapEntry = specializationEntry - data = specializationData - } - shaderStages[1].specializationInfo = specializationInfo - - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayouts.composition, renderPass).also { - - val emptyInputState = vk.PipelineVertexInputStateCreateInfo() - - it.vertexInputState = emptyInputState - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - // Index of the subpass that this pipeline will be used in - it.subpass = 1 - } - depthStencilState.depthWriteEnable = false - - pipelines.composition = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - - // Transparent (forward) pipeline - - // Descriptor set layout - setLayoutBindings = vk.DescriptorSetLayoutBinding( - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, - VkDescriptorType.INPUT_ATTACHMENT, VkShaderStage.FRAGMENT_BIT.i, 1, - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 2) - - descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - descriptorSetLayouts.transparent = device createDescriptorSetLayout descriptorLayout - - // Pipeline layout - pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayouts.transparent) - pipelineLayouts.transparent = device createPipelineLayout pipelineLayoutCreateInfo - - // Descriptor sets - allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayouts.transparent) - descriptorSets.transparent = device allocateDescriptorSets allocInfo - - writeDescriptorSets = vk.WriteDescriptorSet( - descriptorSets.transparent, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.GBuffer.descriptor, - descriptorSets.transparent, VkDescriptorType.INPUT_ATTACHMENT, 1, texDescriptorPosition, - descriptorSets.transparent, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 2, textures.glass.descriptor) - device updateDescriptorSets writeDescriptorSets - - // Enable blending - blendAttachmentState.apply { - blendEnable = true - srcColorBlendFactor = VkBlendFactor.SRC_ALPHA - dstColorBlendFactor = VkBlendFactor.ONE_MINUS_SRC_ALPHA - colorBlendOp = VkBlendOp.ADD - srcAlphaBlendFactor = VkBlendFactor.ONE - dstAlphaBlendFactor = VkBlendFactor.ZERO - alphaBlendOp = VkBlendOp.ADD - colorWriteMask = VkColorComponent.R_BIT or VkColorComponent.G_BIT or VkColorComponent.B_BIT or VkColorComponent.A_BIT - } - pipelineCreateInfo.apply { - vertexInputState = vertices.inputState - layout = pipelineLayouts.transparent - subpass = 2 - } - shaderStages[0].loadShader("$assetPath/shaders/subpasses/transparent.vert.spv", VkShaderStage.VERTEX_BIT) - shaderStages[1].loadShader("$assetPath/shaders/subpasses/transparent.frag.spv", VkShaderStage.FRAGMENT_BIT) - - pipelines.transparent = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - /** Prepare and initialize uniform buffer containing shader uniforms */ - fun prepareUniformBuffers() { - // Deferred vertex shader - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBuffers.GBuffer, - uboGBuffer.size.L) - - // Deferred fragment shader - TODO() +///* +//* Vulkan Example - Using subpasses for G-Buffer compositing +//* +//* Copyright (C) 2016-2017 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//* +//* Summary: +//* Implements a deferred rendering setup with a forward transparency pass using sub passes +//* +//* Sub passes allow reading from the previous framebuffer (in the same render pass) at +//* the same pixel position. +//* +//* This is a feature that was especially designed for tile-based-renderers +//* (mostly mobile GPUs) and is a new optomization feature in Vulkan for those GPU types. +//* +//*/ +// +//package vulkan.basics +// +//import glm_.BYTES +//import glm_.L +//import glm_.glm +//import glm_.mat4x4.Mat4 +//import glm_.vec3.Vec3 +//import glm_.vec4.Vec4 +//import kool.stak +//import org.lwjgl.system.MemoryUtil.NULL +//import org.lwjgl.vulkan.VK10.VK_SUBPASS_EXTERNAL +//import org.lwjgl.vulkan.VkPipelineVertexInputStateCreateInfo +//import org.lwjgl.vulkan.VkVertexInputAttributeDescription +//import org.lwjgl.vulkan.VkVertexInputBindingDescription +//import vkk.* +//import vulkan.NUM_LIGHTS +//import vulkan.VERTEX_BUFFER_BIND_ID +//import vulkan.assetPath +//import vulkan.base.* +//import java.lang.Math.abs +// +// +//fun main(args: Array) { +// Subpasses().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +//private class Subpasses : VulkanExampleBase() { +// +// object textures { +// val glass = Texture2D() +// } +// +// // Vertex layout for the models +// val vertexLayout = VertexLayout( +// VertexComponent.POSITION, +// VertexComponent.COLOR, +// VertexComponent.NORMAL, +// VertexComponent.UV) +// +// object models { +// val scene = Model() +// val transparent = Model() +// } +// +// object vertices { +// lateinit var inputState: VkPipelineVertexInputStateCreateInfo +// lateinit var bindingDescriptions: VkVertexInputBindingDescription +// lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer +// } +// +// object uboGBuffer : Bufferizable() { +// lateinit var projection: Mat4 +// @Order(1) +// lateinit var model: Mat4 +// lateinit var view: Mat4 +// } +// +// class Light { +// lateinit var position: Vec4 +// lateinit var color: Vec3 +// var radius = 0f +// } +// +// object uboLights : Bufferizable() { +// lateinit var viewPos: Vec4 +// val lights = Array(NUM_LIGHTS) { Light() } +// } +// +// object uniformBuffers { +// val GBuffer = Buffer() +// val lights = Buffer() +// } +// +// object pipelines { +// var offscreen = VkPipeline(NULL) +// var composition = VkPipeline(NULL) +// var transparent = VkPipeline(NULL) +// } +// +// object pipelineLayouts { +// var offscreen = VkPipelineLayout(NULL) +// var composition = VkPipelineLayout(NULL) +// var transparent = VkPipelineLayout(NULL) +// } +// +// object descriptorSets { +// var scene = VkDescriptorSet(NULL) +// var composition = VkDescriptorSet(NULL) +// var transparent = VkDescriptorSet(NULL) +// } +// +// object descriptorSetLayouts { +// var scene = VkDescriptorSetLayout(NULL) +// var composition = VkDescriptorSetLayout(NULL) +// var transparent = VkDescriptorSetLayout(NULL) +// } +// +// // G-Buffer framebuffer attachments +// class FrameBufferAttachment { +// var image = VkImage(NULL) +// var mem = VkDeviceMemory(0) +// var view = VkImageView(NULL) +// var format = VkFormat.UNDEFINED +// } +// +// object attachments { +// val position = FrameBufferAttachment() +// val normal = FrameBufferAttachment() +// val albedo = FrameBufferAttachment() +// } +// +// var uiRenderPass = VkRenderPass(NULL) +// +// init { +// title = "Subpasses" +// camera.type = Camera.CameraType.firstPerson +// camera.movementSpeed = 5f +// camera.setPosition(Vec3(-3.2f, 1f, 5.9f)) +// camera.setRotation(Vec3(0.5f, 210.05f, 0f)) +// camera.setPerspective(60f, size.aspect, 0.1f, 256f) +// settings.overlay = false // TODO +// } +// +// override fun destroy() { +// +// device.apply { +// // Clean up used Vulkan resources +// // Note : Inherited destructor cleans up resources stored in base class +// +// destroyImageView(attachments.position.view) +// destroyImage(attachments.position.image) +// freeMemory(attachments.position.mem) +// +// destroyImageView(attachments.normal.view) +// destroyImage(attachments.normal.image) +// freeMemory(attachments.normal.mem) +// +// destroyImageView(attachments.albedo.view) +// destroyImage(attachments.albedo.image) +// freeMemory(attachments.albedo.mem) +// +// destroyPipeline(pipelines.offscreen) +// destroyPipeline(pipelines.composition) +// destroyPipeline(pipelines.transparent) +// +// destroyPipelineLayout(pipelineLayouts.offscreen) +// destroyPipelineLayout(pipelineLayouts.composition) +// destroyPipelineLayout(pipelineLayouts.transparent) +// +// destroyDescriptorSetLayout(descriptorSetLayouts.scene) +// destroyDescriptorSetLayout(descriptorSetLayouts.composition) +// destroyDescriptorSetLayout(descriptorSetLayouts.transparent) +// +// destroyRenderPass(uiRenderPass) +// } +// textures.glass.destroy() +// models.scene.destroy() +// models.transparent.destroy() +// uniformBuffers.GBuffer.destroy() +// uniformBuffers.lights.destroy() +// +// super.destroy() +// } +// +// /** Enable physical device features required for this example */ +// override fun getEnabledFeatures() { +// // Enable anisotropic filtering if supported +// if (deviceFeatures.samplerAnisotropy) +// enabledFeatures.samplerAnisotropy = true +// // Enable texture compression +// when { +// deviceFeatures.textureCompressionBC -> enabledFeatures.textureCompressionBC = true +// deviceFeatures.textureCompressionASTC_LDR -> enabledFeatures.textureCompressionASTC_LDR = true +// deviceFeatures.textureCompressionETC2 -> enabledFeatures.textureCompressionETC2 = true +// } +// } +// +// /** Create a frame buffer attachment */ +// fun createAttachment(format: VkFormat, usage: VkImageUsageFlags, attachment: FrameBufferAttachment) { +// +// var aspectMask: VkImageAspectFlags = 0 +// var imageLayout = VkImageLayout.UNDEFINED +// +// attachment.format = format +// +// if (usage has VkImageUsage.COLOR_ATTACHMENT_BIT) { +// aspectMask = VkImageAspect.COLOR_BIT.i +// imageLayout = VkImageLayout.COLOR_ATTACHMENT_OPTIMAL +// } +// if (usage has VkImageUsage.DEPTH_STENCIL_ATTACHMENT_BIT) { +// aspectMask = VkImageAspect.DEPTH_BIT or VkImageAspect.STENCIL_BIT +// imageLayout = VkImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL +// } +// +// assert(aspectMask > 0) +// +// val image = vk.ImageCreateInfo { +// imageType = VkImageType.`2D` +// this.format = format +// extent(size, 1) +// mipLevels = 1 +// arrayLayers = 1 +// samples = VkSampleCount.`1_BIT` +// tiling = VkImageTiling.OPTIMAL +// this.usage = usage or VkImageUsage.INPUT_ATTACHMENT_BIT // VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT flag is required for input attachments; +// initialLayout = VkImageLayout.UNDEFINED +// } +// +// attachment.image = device createImage image +// val memReqs = device getImageMemoryRequirements attachment.image +// val memAlloc = vk.MemoryAllocateInfo { +// allocationSize = memReqs.size +// memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) +// } +// attachment.mem = device allocateMemory memAlloc +// device.bindImageMemory(attachment.image, attachment.mem) +// +// val imageView = vk.ImageViewCreateInfo { +// viewType = VkImageViewType.`2D` +// this.format = format +// subresourceRange.apply { +// this.aspectMask = aspectMask +// baseMipLevel = 0 +// levelCount = 1 +// baseArrayLayer = 0 +// layerCount = 1 +// } +// this.image = attachment.image +// } +// attachment.view = device createImageView imageView +// } +// +// /** Create color attachments for the G-Buffer components */ +// fun createGBufferAttachments() { +// createAttachment(VkFormat.R16G16B16A16_SFLOAT, VkImageUsage.COLOR_ATTACHMENT_BIT.i, attachments.position) // (World space) Positions +// createAttachment(VkFormat.R16G16B16A16_SFLOAT, VkImageUsage.COLOR_ATTACHMENT_BIT.i, attachments.normal) // (World space) Normals +// createAttachment(VkFormat.R8G8B8A8_UNORM, VkImageUsage.COLOR_ATTACHMENT_BIT.i, attachments.albedo) // Albedo (color) +// } +// +// /** Override framebuffer setup from base class +// * Deferred components will be used as frame buffer attachments */ +// override fun setupFrameBuffer() = stak { +// +// val attachments = it.vkImageViewBufferBig(5) +// +// val frameBufferCreateInfo = vk.FramebufferCreateInfo { +// renderPass = this@Subpasses.renderPass +// this.attachments = attachments +// width = size.x +// height = size.y +// layers = 1 +// } +// // Create frame buffers for every swap chain image +// frameBuffers = initVkFramebufferArray(swapChain.imageCount) { i -> +// attachments[0] = swapChain.buffers[i].view // TODO put(vararg)? +// attachments[1] = Subpasses.attachments.position.view +// attachments[2] = Subpasses.attachments.normal.view +// attachments[3] = Subpasses.attachments.albedo.view +// attachments[4] = depthStencil.view +// device createFramebuffer frameBufferCreateInfo +// } +// } +// +// /** Override render pass setup from base class */ +// override fun setupRenderPass() { +// +// createGBufferAttachments() +// +// val attachments = vk.AttachmentDescription(5).also { +// // Color attachment +// it[0].apply { +// format = swapChain.colorFormat +// samples = VkSampleCount.`1_BIT` +// loadOp = VkAttachmentLoadOp.CLEAR +// storeOp = VkAttachmentStoreOp.STORE +// stencilLoadOp = VkAttachmentLoadOp.DONT_CARE +// stencilStoreOp = VkAttachmentStoreOp.DONT_CARE +// initialLayout = VkImageLayout.UNDEFINED +// finalLayout = VkImageLayout.PRESENT_SRC_KHR +// } +// // Deferred attachments +// // Position +// it[1].apply { +// format = Subpasses.attachments.position.format +// samples = VkSampleCount.`1_BIT` +// loadOp = VkAttachmentLoadOp.CLEAR +// storeOp = VkAttachmentStoreOp.DONT_CARE +// stencilLoadOp = VkAttachmentLoadOp.DONT_CARE +// stencilStoreOp = VkAttachmentStoreOp.DONT_CARE +// initialLayout = VkImageLayout.UNDEFINED +// finalLayout = VkImageLayout.COLOR_ATTACHMENT_OPTIMAL +// } +// // Normals +// it[2].apply { +// format = Subpasses.attachments.normal.format +// samples = VkSampleCount.`1_BIT` +// loadOp = VkAttachmentLoadOp.CLEAR +// storeOp = VkAttachmentStoreOp.DONT_CARE +// stencilLoadOp = VkAttachmentLoadOp.DONT_CARE +// stencilStoreOp = VkAttachmentStoreOp.DONT_CARE +// initialLayout = VkImageLayout.UNDEFINED +// finalLayout = VkImageLayout.COLOR_ATTACHMENT_OPTIMAL +// } +// // Albedo +// it[3].apply { +// format = Subpasses.attachments.albedo.format +// samples = VkSampleCount.`1_BIT` +// loadOp = VkAttachmentLoadOp.CLEAR +// storeOp = VkAttachmentStoreOp.DONT_CARE +// stencilLoadOp = VkAttachmentLoadOp.DONT_CARE +// stencilStoreOp = VkAttachmentStoreOp.DONT_CARE +// initialLayout = VkImageLayout.UNDEFINED +// finalLayout = VkImageLayout.COLOR_ATTACHMENT_OPTIMAL +// } +// // Depth attachment +// it[4].apply { +// format = depthFormat +// samples = VkSampleCount.`1_BIT` +// loadOp = VkAttachmentLoadOp.CLEAR +// storeOp = VkAttachmentStoreOp.DONT_CARE +// stencilLoadOp = VkAttachmentLoadOp.DONT_CARE +// stencilStoreOp = VkAttachmentStoreOp.DONT_CARE +// initialLayout = VkImageLayout.UNDEFINED +// finalLayout = VkImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL +// } +// } +// // Three subpasses +// val subpassDescriptions = vk.SubpassDescription(3) +// +// // First subpass: Fill G-Buffer components +// // ---------------------------------------------------------------------------------------- +// +// val colorReferences = vk.AttachmentReference( +// 0, VkImageLayout.COLOR_ATTACHMENT_OPTIMAL, +// 1, VkImageLayout.COLOR_ATTACHMENT_OPTIMAL, +// 2, VkImageLayout.COLOR_ATTACHMENT_OPTIMAL, +// 3, VkImageLayout.COLOR_ATTACHMENT_OPTIMAL) +// val depthReference = vk.AttachmentReference(4, VkImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL) +// +// subpassDescriptions[0].apply { +// pipelineBindPoint = VkPipelineBindPoint.GRAPHICS +// colorAttachmentCount = 4 +// colorAttachments = colorReferences +// depthStencilAttachment = depthReference +// } +// // Second subpass: Final composition (using G-Buffer components) +// // ---------------------------------------------------------------------------------------- +// +// val colorReference = vk.AttachmentReference(0, VkImageLayout.COLOR_ATTACHMENT_OPTIMAL) +// +// val inputReferences = vk.AttachmentReference( +// 1, VkImageLayout.SHADER_READ_ONLY_OPTIMAL, +// 2, VkImageLayout.SHADER_READ_ONLY_OPTIMAL, +// 3, VkImageLayout.SHADER_READ_ONLY_OPTIMAL) +// +// subpassDescriptions[1].apply { +// pipelineBindPoint = VkPipelineBindPoint.GRAPHICS +// colorAttachmentCount = 1 +// colorAttachment = colorReference +// depthStencilAttachment = depthReference +// // Use the color attachments filled in the first pass as input attachments +// inputAttachments = inputReferences +// } +// // Third subpass: Forward transparency +// // ---------------------------------------------------------------------------------------- +// colorReference(0, VkImageLayout.COLOR_ATTACHMENT_OPTIMAL) +// +// inputReferences[0](1, VkImageLayout.SHADER_READ_ONLY_OPTIMAL) +// +// subpassDescriptions[2].apply { +// pipelineBindPoint = VkPipelineBindPoint.GRAPHICS +// colorAttachmentCount = 1 +// colorAttachment = colorReference +// depthStencilAttachment = depthReference +// // Use the color/depth attachments filled in the first pass as input attachments +// inputAttachments = inputReferences +// } +// // Subpass dependencies for layout transitions +// val dependencies = vk.SubpassDependency(4).also { +// it[0].apply { +// srcSubpass = VK_SUBPASS_EXTERNAL +// dstSubpass = 0 +// srcStageMask = VkPipelineStage.BOTTOM_OF_PIPE_BIT.i +// dstStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i +// srcAccessMask = VkAccess.MEMORY_READ_BIT.i +// dstAccessMask = VkAccess.COLOR_ATTACHMENT_READ_BIT or VkAccess.COLOR_ATTACHMENT_WRITE_BIT +// dependencyFlags = VkDependency.BY_REGION_BIT.i +// } +// // This dependency transitions the input attachment from color attachment to shader read +// it[1].apply { +// srcSubpass = 0 +// dstSubpass = 1 +// srcStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i +// dstStageMask = VkPipelineStage.FRAGMENT_SHADER_BIT.i +// srcAccessMask = VkAccess.COLOR_ATTACHMENT_WRITE_BIT.i +// dstAccessMask = VkAccess.SHADER_READ_BIT.i +// dependencyFlags = VkDependency.BY_REGION_BIT.i +// } +// it[2].apply { +// srcSubpass = 1 +// dstSubpass = 2 +// srcStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i +// dstStageMask = VkPipelineStage.FRAGMENT_SHADER_BIT.i +// srcAccessMask = VkAccess.COLOR_ATTACHMENT_WRITE_BIT.i +// dstAccessMask = VkAccess.SHADER_READ_BIT.i +// dependencyFlags = VkDependency.BY_REGION_BIT.i +// } +// it[3].apply { +// srcSubpass = 0 +// dstSubpass = VK_SUBPASS_EXTERNAL +// srcStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i +// dstStageMask = VkPipelineStage.BOTTOM_OF_PIPE_BIT.i +// srcAccessMask = VkAccess.COLOR_ATTACHMENT_READ_BIT or VkAccess.COLOR_ATTACHMENT_WRITE_BIT +// dstAccessMask = VkAccess.MEMORY_READ_BIT.i +// dependencyFlags = VkDependency.BY_REGION_BIT.i +// } +// } +// val renderPassInfo = vk.RenderPassCreateInfo { +// this.attachments = attachments +// subpasses = subpassDescriptions +// this.dependencies = dependencies +// } +// renderPass = device createRenderPass renderPassInfo +// +// // Create custom overlay render pass +// attachments[0].loadOp = VkAttachmentLoadOp.LOAD +// attachments[0].initialLayout = VkImageLayout.PRESENT_SRC_KHR +// uiRenderPass = device createRenderPass renderPassInfo +// } +// +// override fun buildCommandBuffers() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(5).also { +// it[0].color(0f, 0f, 0f, 0f) +// it[1].color(0f, 0f, 0f, 0f) +// it[2].color(0f, 0f, 0f, 0f) +// it[3].color(0f, 0f, 0f, 0f) +// it[4].depthStencil(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@Subpasses.renderPass +// renderArea.offset(0) +// renderArea.extent(size) +// this.clearValues = clearValues +// } +// for (i in drawCmdBuffers.indices) { +// // Set target frame buffer +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) // TODO BUG +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// setViewport(size) +// setScissor(size) +// +// // First sub pass +// // Renders the components of the scene to the G-Buffer atttachments +// debugMarker.withRegion(this, "Subpass 0: Deferred G-Buffer creation", Vec4(1f)) { +// +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.offscreen) +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayouts.offscreen, descriptorSets.scene) +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.scene.vertices.buffer) +// bindIndexBuffer(models.scene.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// drawIndexed(models.scene.indexCount, 1, 0, 0, 0) +// } +// +// // Second sub pass +// // This subpass will use the G-Buffer components that have been filled in the first subpass as input attachment for the final compositing +// debugMarker.withRegion(this, "Subpass 1: Deferred composition", Vec4(1f)) { +// +// nextSubpass(VkSubpassContents.INLINE) +// +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.composition) +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayouts.composition, descriptorSets.composition) +// draw(3, 1, 0, 0) +// } +// +// // Third subpass +// // Render transparent geometry using a forward pass that compares against depth generted during G-Buffer fill +// debugMarker.withRegion(this, "Subpass 2: Forward transparency", Vec4(1f)) { +// +// nextSubpass(VkSubpassContents.INLINE) +// +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.transparent) +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayouts.transparent, descriptorSets.transparent) +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.transparent.vertices.buffer) +// bindIndexBuffer(models.transparent.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// drawIndexed(models.transparent.indexCount, 1, 0, 0, 0) +// } +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// fun loadAssets() { +// +// models.scene.loadFromFile("$assetPath/models/samplebuilding.dae", vertexLayout, 1f, vulkanDevice, queue) +// models.transparent.loadFromFile("$assetPath/models/samplebuilding_glass.dae", vertexLayout, 1f, vulkanDevice, queue) +// // Textures +// val (text, format) = when { +// vulkanDevice.features.textureCompressionBC -> "bc3_unorm.ktx" to VkFormat.BC3_UNORM_BLOCK +// vulkanDevice.features.textureCompressionASTC_LDR -> "astc_8x8_unorm.ktx" to VkFormat.ASTC_8x8_UNORM_BLOCK +// vulkanDevice.features.textureCompressionETC2 -> "etc2_unorm.ktx" to VkFormat.ETC2_R8G8B8A8_UNORM_BLOCK +// else -> tools.exitFatal("Device does not support any compressed texture format!", ERROR_FEATURE_NOT_PRESENT) +// } +// textures.glass.loadFromFile("$assetPath/textures/colored_glass_$text", format, vulkanDevice, queue) +// } +// +// fun setupVertexDescriptions() { +// // Binding description +// vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, vertexLayout.stride, VkVertexInputRate.VERTEX) +// +// // Attribute descriptions +// vertices.attributeDescriptions = vk.VertexInputAttributeDescription( +// // Location 0: Position +// VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, 0, +// // Location 1: Color +// VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32_SFLOAT, Vec3.size, +// // Location 2: Normal +// VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2, +// // Location 3: UV +// VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32G32_SFLOAT, Vec3.size * 3) +// +// vertices.inputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertices.bindingDescriptions +// vertexAttributeDescriptions = vertices.attributeDescriptions +// } +// } +// +// fun setupDescriptorPool() { +// +// val poolSizes = vk.DescriptorPoolSize( +// VkDescriptorType.UNIFORM_BUFFER, 4, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, 4, +// VkDescriptorType.INPUT_ATTACHMENT, 4) +// +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 4) +// +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// // Deferred shading layout +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// // Binding 0 : Vertex shader uniform buffer +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// +// descriptorSetLayouts.scene = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayouts.scene) +// +// // Offscreen (scene) rendering pipeline layout +// pipelineLayouts.offscreen = device createPipelineLayout pipelineLayoutCreateInfo +// } +// +// fun setupDescriptorSet() { +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayouts.scene) +// +// descriptorSets.scene = device allocateDescriptorSets allocInfo +// +// val writeDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0: Vertex shader uniform buffer +// descriptorSets.scene, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.GBuffer.descriptor) +// +// device updateDescriptorSets writeDescriptorSets +// } +// +// fun preparePipelines() { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.BACK_BIT.i, VkFrontFace.CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// // Final fullscreen pass pipeline +// val shaderStages = vk.PipelineShaderStageCreateInfo(2) +// +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayouts.offscreen, renderPass).also { +// it.vertexInputState = vertices.inputState +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// it.subpass = 0 +// } +// val blendAttachmentStates = vk.PipelineColorBlendAttachmentState( +// 0xf, false, +// 0xf, false, +// 0xf, false, +// 0xf, false) +// +// colorBlendState.attachments = blendAttachmentStates +// +// // Offscreen scene rendering pipeline +// shaderStages[0].loadShader("$assetPath/shaders/subpasses/gbuffer.vert.spv", VkShaderStage.VERTEX_BIT) +// shaderStages[1].loadShader("$assetPath/shaders/subpasses/gbuffer.frag.spv", VkShaderStage.FRAGMENT_BIT) +// +// pipelines.offscreen = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// +// /** Create the Vulkan objects used in the composition pass (descriptor sets, pipelines, etc.) */ +// fun prepareCompositionPass() = stak { +// // Descriptor set layout +// var setLayoutBindings = vk.DescriptorSetLayoutBinding( +// // Binding 0: Position input attachment +// VkDescriptorType.INPUT_ATTACHMENT, VkShaderStage.FRAGMENT_BIT.i, 0, +// // Binding 1: Normal input attachment +// VkDescriptorType.INPUT_ATTACHMENT, VkShaderStage.FRAGMENT_BIT.i, 1, +// // Binding 2: Albedo input attachment +// VkDescriptorType.INPUT_ATTACHMENT, VkShaderStage.FRAGMENT_BIT.i, 2, +// // Binding 3: Light positions +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.FRAGMENT_BIT.i, 3) +// +// var descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// +// descriptorSetLayouts.composition = device createDescriptorSetLayout descriptorLayout +// +// // Pipeline layout +// var pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayouts.composition) +// +// pipelineLayouts.composition = device createPipelineLayout pipelineLayoutCreateInfo +// +// // Descriptor sets +// var allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayouts.composition) +// +// descriptorSets.composition = device allocateDescriptorSets allocInfo +// +// // Image descriptors for the offscreen color attachments +// val nullSampler = VkSampler(NULL) +// +// val texDescriptorPosition = vk.DescriptorImageInfo(nullSampler, attachments.position.view, VkImageLayout.SHADER_READ_ONLY_OPTIMAL) +// +// val texDescriptorNormal = vk.DescriptorImageInfo(nullSampler, attachments.normal.view, VkImageLayout.SHADER_READ_ONLY_OPTIMAL) +// +// val texDescriptorAlbedo = vk.DescriptorImageInfo(nullSampler, attachments.albedo.view, VkImageLayout.SHADER_READ_ONLY_OPTIMAL) +// +// var writeDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0: Position texture target +// descriptorSets.composition, VkDescriptorType.INPUT_ATTACHMENT, 0, texDescriptorPosition, +// // Binding 1: Normals texture target +// descriptorSets.composition, VkDescriptorType.INPUT_ATTACHMENT, 1, texDescriptorNormal, +// // Binding 2: Albedo texture target +// descriptorSets.composition, VkDescriptorType.INPUT_ATTACHMENT, 2, texDescriptorAlbedo, +// // Binding 4: Fragment shader lights +// descriptorSets.composition, VkDescriptorType.UNIFORM_BUFFER, 3, uniformBuffers.lights.descriptor) +// +// device updateDescriptorSets writeDescriptorSets +// +// // Pipeline +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { +// it[0].loadShader("$assetPath/shaders/subpasses/composition.vert.spv", VkShaderStage.VERTEX_BIT) +// it[1].loadShader("$assetPath/shaders/subpasses/composition.frag.spv", VkShaderStage.FRAGMENT_BIT) +// } +// +// // Use specialization constants to pass number of lights to the shader +// val specializationEntry = vk.SpecializationMapEntry { +// constantId = 0 +// offset = 0 +// size = Int.BYTES.L +// } +// val specializationData = it.malloc(Int.BYTES).apply { putInt(0, NUM_LIGHTS) } +// +// val specializationInfo = vk.SpecializationInfo { +// mapEntry = specializationEntry +// data = specializationData +// } +// shaderStages[1].specializationInfo = specializationInfo +// +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayouts.composition, renderPass).also { +// +// val emptyInputState = vk.PipelineVertexInputStateCreateInfo() +// +// it.vertexInputState = emptyInputState +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// // Index of the subpass that this pipeline will be used in +// it.subpass = 1 +// } +// depthStencilState.depthWriteEnable = false +// +// pipelines.composition = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// +// // Transparent (forward) pipeline +// +// // Descriptor set layout +// setLayoutBindings = vk.DescriptorSetLayoutBinding( +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, +// VkDescriptorType.INPUT_ATTACHMENT, VkShaderStage.FRAGMENT_BIT.i, 1, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 2) +// +// descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// descriptorSetLayouts.transparent = device createDescriptorSetLayout descriptorLayout +// +// // Pipeline layout +// pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayouts.transparent) +// pipelineLayouts.transparent = device createPipelineLayout pipelineLayoutCreateInfo +// +// // Descriptor sets +// allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayouts.transparent) +// descriptorSets.transparent = device allocateDescriptorSets allocInfo +// +// writeDescriptorSets = vk.WriteDescriptorSet( +// descriptorSets.transparent, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.GBuffer.descriptor, +// descriptorSets.transparent, VkDescriptorType.INPUT_ATTACHMENT, 1, texDescriptorPosition, +// descriptorSets.transparent, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 2, textures.glass.descriptor) +// device updateDescriptorSets writeDescriptorSets +// +// // Enable blending +// blendAttachmentState.apply { +// blendEnable = true +// srcColorBlendFactor = VkBlendFactor.SRC_ALPHA +// dstColorBlendFactor = VkBlendFactor.ONE_MINUS_SRC_ALPHA +// colorBlendOp = VkBlendOp.ADD +// srcAlphaBlendFactor = VkBlendFactor.ONE +// dstAlphaBlendFactor = VkBlendFactor.ZERO +// alphaBlendOp = VkBlendOp.ADD +// colorWriteMask = VkColorComponent.R_BIT or VkColorComponent.G_BIT or VkColorComponent.B_BIT or VkColorComponent.A_BIT +// } +// pipelineCreateInfo.apply { +// vertexInputState = vertices.inputState +// layout = pipelineLayouts.transparent +// subpass = 2 +// } +// shaderStages[0].loadShader("$assetPath/shaders/subpasses/transparent.vert.spv", VkShaderStage.VERTEX_BIT) +// shaderStages[1].loadShader("$assetPath/shaders/subpasses/transparent.frag.spv", VkShaderStage.FRAGMENT_BIT) +// +// pipelines.transparent = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// +// /** Prepare and initialize uniform buffer containing shader uniforms */ +// fun prepareUniformBuffers() { +// // Deferred vertex shader // vulkanDevice.createBuffer( // VkBufferUsage.UNIFORM_BUFFER_BIT.i, // VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, -// uniformBuffers.lights, -// uboLights.size) - - // Update - updateUniformBufferDeferredMatrices() - updateUniformBufferDeferredLights() - } - - fun updateUniformBufferDeferredMatrices() { - - uboGBuffer.projection = camera.matrices.perspective - uboGBuffer.view = camera.matrices.view - uboGBuffer.model put 1f - - uniformBuffers.GBuffer.mapping { mapped -> uboGBuffer to mapped } - } - - fun initLights() { - - val colors = arrayOf( - Vec3(1f, 1f, 1f), - Vec3(1f, 0f, 0f), - Vec3(0f, 1f, 0f), - Vec3(0f, 0f, 1f), - Vec3(1f, 1f, 0f)) - - fun rndDist() = glm.linearRand(-1f, 1f) - fun rndCol() = glm.linearRand(0, colors.lastIndex) - - for (light in uboLights.lights) { - light.position.put(rndDist() * 6f, 0.25f + abs(rndDist()) * 4f, rndDist() * 6f, 1f) - light.color put colors[rndCol()] - light.radius = 1f + abs(rndDist()) - } - } - - /** Update fragment shader light position uniform block */ - fun updateUniformBufferDeferredLights() { - // Current view position - uboLights.viewPos = Vec4(camera.position, 0f) * Vec4(-1f, 1f, -1f, 1f) - - uniformBuffers.lights.mapping { mapped -> uboLights to mapped } - } - - fun draw() { - - super.prepareFrame() - - // Command buffer to be sumitted to the queue - submitInfo.commandBuffer = drawCmdBuffers [currentBuffer] - - // Submit to queue - queue submit submitInfo - - super.submitFrame() - } - - override fun prepare() { - super.prepare() - loadAssets() - setupVertexDescriptions() - initLights() - prepareUniformBuffers() - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSet() - prepareCompositionPass() - buildCommandBuffers() - prepared = true - window.show() - } - - override fun render() { - if (!prepared) - return - draw() - } - - override fun viewChanged() { - updateUniformBufferDeferredMatrices() - updateUniformBufferDeferredLights() - } - - // UI overlay configuration needs to be adjusted for this example (renderpass setup, attachment count, etc.) -// virtual void OnSetupUIOverlay(vks::UIOverlayCreateInfo &createInfo) -// { -// createInfo.renderPass = uiRenderPass -// createInfo.framebuffers = frameBuffers -// createInfo.subpassCount = 3 -// createInfo.attachmentCount = 4 -// createInfo.clearValues = { -// { { 0.0f, 0.0f, 0.0f, 0.0f } }, -// { { 0.0f, 0.0f, 0.0f, 0.0f } }, -// { { 0.0f, 0.0f, 0.0f, 0.0f } }, -// { { 0.0f, 0.0f, 0.0f, 0.0f } }, -// { { 1.0f, 0 } }, +// uniformBuffers.GBuffer, +// VkDeviceSize(uboGBuffer.size.L)) +// +// // Deferred fragment shader +// TODO() +//// vulkanDevice.createBuffer( +//// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +//// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +//// uniformBuffers.lights, +//// uboLights.size) +// +// // Update +// updateUniformBufferDeferredMatrices() +// updateUniformBufferDeferredLights() +// } +// +// fun updateUniformBufferDeferredMatrices() { +// +// uboGBuffer.projection = camera.matrices.perspective +// uboGBuffer.view = camera.matrices.view +// uboGBuffer.model put 1f +// +// uniformBuffers.GBuffer.mapping { mapped -> uboGBuffer to mapped } +// } +// +// fun initLights() { +// +// val colors = arrayOf( +// Vec3(1f, 1f, 1f), +// Vec3(1f, 0f, 0f), +// Vec3(0f, 1f, 0f), +// Vec3(0f, 0f, 1f), +// Vec3(1f, 1f, 0f)) +// +// fun rndDist() = glm.linearRand(-1f, 1f) +// fun rndCol() = glm.linearRand(0, colors.lastIndex) +// +// for (light in uboLights.lights) { +// light.position.put(rndDist() * 6f, 0.25f + abs(rndDist()) * 4f, rndDist() * 6f, 1f) +// light.color put colors[rndCol()] +// light.radius = 1f + abs(rndDist()) // } // } // -// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) -// { -// if (overlay->header("Subpasses")) { overlay -> -// text("0: Deferred G-Buffer creation") -// overlay->text("1: Deferred composition") -// overlay->text("2: Forward transparency") +// /** Update fragment shader light position uniform block */ +// fun updateUniformBufferDeferredLights() { +// // Current view position +// uboLights.viewPos = Vec4(camera.position, 0f) * Vec4(-1f, 1f, -1f, 1f) +// +// uniformBuffers.lights.mapping { mapped -> uboLights to mapped } +// } +// +// fun draw() { +// +// super.prepareFrame() +// +// // Command buffer to be sumitted to the queue +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// +// // Submit to queue +// queue submit submitInfo +// +// super.submitFrame() // } -// if (overlay->header("Settings")) { -// if (overlay->button("Randomize lights")) { +// +// override fun prepare() { +// super.prepare() +// loadAssets() +// setupVertexDescriptions() // initLights() -// updateUniformBufferDeferredLights() +// prepareUniformBuffers() +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSet() +// prepareCompositionPass() +// buildCommandBuffers() +// prepared = true +// window.show() // } +// +// override fun render() { +// if (!prepared) +// return +// draw() // } +// +// override fun viewChanged() { +// updateUniformBufferDeferredMatrices() +// updateUniformBufferDeferredLights() // } -} \ No newline at end of file +// +// // UI overlay configuration needs to be adjusted for this example (renderpass setup, attachment count, etc.) +//// virtual void OnSetupUIOverlay(vks::UIOverlayCreateInfo &createInfo) +//// { +//// createInfo.renderPass = uiRenderPass +//// createInfo.framebuffers = frameBuffers +//// createInfo.subpassCount = 3 +//// createInfo.attachmentCount = 4 +//// createInfo.clearValues = { +//// { { 0.0f, 0.0f, 0.0f, 0.0f } }, +//// { { 0.0f, 0.0f, 0.0f, 0.0f } }, +//// { { 0.0f, 0.0f, 0.0f, 0.0f } }, +//// { { 0.0f, 0.0f, 0.0f, 0.0f } }, +//// { { 1.0f, 0 } }, +//// } +//// } +//// +//// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) +//// { +//// if (overlay->header("Subpasses")) { overlay -> +//// text("0: Deferred G-Buffer creation") +//// overlay->text("1: Deferred composition") +//// overlay->text("2: Forward transparency") +//// } +//// if (overlay->header("Settings")) { +//// if (overlay->button("Randomize lights")) { +//// initLights() +//// updateUniformBufferDeferredLights() +//// } +//// } +//// } +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/basics/13 Offscreen Rendering.kt b/src/main/kotlin/vulkan/basics/13 Offscreen Rendering.kt index 94b3160..6a70f69 100644 --- a/src/main/kotlin/vulkan/basics/13 Offscreen Rendering.kt +++ b/src/main/kotlin/vulkan/basics/13 Offscreen Rendering.kt @@ -1,866 +1,868 @@ -/* -* Vulkan Example - Offscreen rendering using a separate framebuffer -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -package vulkan.basics - -import ab.appBuffer -import glm_.L -import glm_.buffer.adr -import glm_.func.rad -import glm_.glm -import glm_.mat4x4.Mat4 -import glm_.size -import glm_.vec2.Vec2 -import glm_.vec2.Vec2i -import glm_.vec3.Vec3 -import glm_.vec4.Vec4 -import org.lwjgl.system.MemoryUtil.NULL -import org.lwjgl.vulkan.* -import org.lwjgl.vulkan.VK10.VK_SUBPASS_EXTERNAL -import vkk.* -import vulkan.VERTEX_BUFFER_BIND_ID -import vulkan.assetPath -import vulkan.base.* - - -fun main(args: Array) { - OffscreenRendering().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - -// Offscreen frame buffer properties -private const val FB_DIM = 512 -private val FB_COLOR_FORMAT = VkFormat.R8G8B8A8_UNORM - -private class OffscreenRendering : VulkanExampleBase() { - - var debugDisplay = false - - object textures { - val colorMap = Texture2D() - } - - // Vertex layout for the models - val vertexLayout = VertexLayout( - VertexComponent.POSITION, - VertexComponent.UV, - VertexComponent.COLOR, - VertexComponent.NORMAL) - - object models { - val example = Model() - val quad = Model() - val plane = Model() - } - - object vertices { - lateinit var inputState: VkPipelineVertexInputStateCreateInfo - lateinit var bindingDescriptions: VkVertexInputBindingDescription - lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer - } - - object uniformBuffers { - val vsShared = Buffer() - val vsMirror = Buffer() - val vsOffScreen = Buffer() - val vsDebugQuad = Buffer() - } - - object uboShared : Bufferizable() { - lateinit var projection: Mat4 - @Order(1) - lateinit var model: Mat4 - @Order(2) - val lightPos = Vec4(0f, 0f, 0f, 1f) - } - - object pipelines { - var debug: VkPipeline = NULL - var shaded: VkPipeline = NULL - var shadedOffscreen: VkPipeline = NULL - var mirror: VkPipeline = NULL - } - - object pipelineLayouts { - var textured: VkPipelineLayout = NULL - var shaded: VkPipelineLayout = NULL - } - - object descriptorSets { - var offscreen: VkDescriptorSet = NULL - var mirror: VkDescriptorSet = NULL - var model: VkDescriptorSet = NULL - var debugQuad: VkDescriptorSet = NULL - } - - object descriptorSetLayouts { - var textured: VkDescriptorSetLayout = NULL - var shaded: VkDescriptorSetLayout = NULL - } - - // Framebuffer for offscreen rendering - class FrameBufferAttachment { - var image: VkImage = NULL - var mem: VkDeviceMemory = NULL - var view: VkImageView = NULL - } - - object offscreenPass { - val size = Vec2i() - var frameBuffer: VkFramebuffer = NULL - val color = FrameBufferAttachment() - val depth = FrameBufferAttachment() - var renderPass: VkRenderPass = NULL - var sampler: VkSampler = NULL - lateinit var descriptor: VkDescriptorImageInfo - var commandBuffer: VkCommandBuffer? = null - // Semaphore used to synchronize between offscreen and final scene render pass - var semaphore: VkSemaphore = NULL - } - - val meshPos = Vec3(0f, -1.5f, 0f) - val meshRot = Vec3() - - init { - zoom = -6f - rotation(-2.5f, 0f, 0f) - cameraPos(0f, 1f, 0f) - timerSpeed *= 0.25f - title = "Offscreen rendering" -// settings.overlay = true - enabledFeatures.shaderClipDistance = true - } - - override fun destroy() { - - // Clean up used Vulkan resources - // Note : Inherited destructor cleans up resources stored in base class - - // Textures - textures.colorMap.destroy() - - device.apply { - // Frame buffer - - // Color attachment - destroyImageView(offscreenPass.color.view) - destroyImage(offscreenPass.color.image) - freeMemory(offscreenPass.color.mem) - - // Depth attachment - destroyImageView(offscreenPass.depth.view) - destroyImage(offscreenPass.depth.image) - freeMemory(offscreenPass.depth.mem) - - destroyRenderPass(offscreenPass.renderPass) - destroySampler(offscreenPass.sampler) - destroyFramebuffer(offscreenPass.frameBuffer) - - destroyPipeline(pipelines.debug) - destroyPipeline(pipelines.shaded) - destroyPipeline(pipelines.shadedOffscreen) - destroyPipeline(pipelines.mirror) - - destroyPipelineLayout(pipelineLayouts.textured) - destroyPipelineLayout(pipelineLayouts.shaded) - - destroyDescriptorSetLayout(descriptorSetLayouts.shaded) - destroyDescriptorSetLayout(descriptorSetLayouts.textured) - - // Models - models.apply { - example.destroy() - quad.destroy() - plane.destroy() - } - // Uniform buffers - uniformBuffers.apply { - vsShared.destroy() - vsMirror.destroy() - vsOffScreen.destroy() - vsDebugQuad.destroy() - } - freeCommandBuffer(cmdPool, offscreenPass.commandBuffer!!) - destroySemaphore(offscreenPass.semaphore) - } - super.destroy() - } - - /** Setup the offscreen framebuffer for rendering the mirrored scene - * The color attachment of this framebuffer will then be used to sample from in the fragment shader of the final pass */ - fun prepareOffscreen() { - - offscreenPass.size put FB_DIM - - // Find a suitable depth format - val fbDepthFormat = tools getSupportedDepthFormat physicalDevice - assert(fbDepthFormat != VkFormat.UNDEFINED) - - // Color attachment - val image = vk.ImageCreateInfo { - imageType = VkImageType.`2D` - format = FB_COLOR_FORMAT - extent(offscreenPass.size, 1) - mipLevels = 1 - arrayLayers = 1 - samples = VkSampleCount.`1_BIT` - tiling = VkImageTiling.OPTIMAL - // We will sample directly from the color attachment - usage = VkImageUsage.COLOR_ATTACHMENT_BIT or VkImageUsage.SAMPLED_BIT - } - - offscreenPass.color.image = device createImage image - val memReqs = device getImageMemoryRequirements offscreenPass.color.image - val memAlloc = vk.MemoryAllocateInfo { - allocationSize = memReqs.size - memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) - } - offscreenPass.color.mem = device allocateMemory memAlloc - device.bindImageMemory(offscreenPass.color.image, offscreenPass.color.mem) - - val colorImageView = vk.ImageViewCreateInfo { - viewType = VkImageViewType.`2D` - format = FB_COLOR_FORMAT - subresourceRange.apply { - aspectMask = VkImageAspect.COLOR_BIT.i - baseMipLevel = 0 - levelCount = 1 - baseArrayLayer = 0 - layerCount = 1 - } - this.image = offscreenPass.color.image - } - offscreenPass.color.view = device createImageView colorImageView - - // Create sampler to sample from the attachment in the fragment shader - val samplerInfo = vk.SamplerCreateInfo { - magFilter = VkFilter.LINEAR - minFilter = VkFilter.LINEAR - mipmapMode = VkSamplerMipmapMode.LINEAR - addressModeU = VkSamplerAddressMode.CLAMP_TO_EDGE - addressModeV = addressModeU // TODO custom func? - addressModeW = addressModeU - mipLodBias = 0f - maxAnisotropy = 1f - minLod = 0f - maxLod = 1f - borderColor = VkBorderColor.FLOAT_OPAQUE_WHITE - } - offscreenPass.sampler = device createSampler samplerInfo - - // Depth stencil attachment - image.format = fbDepthFormat - image.usage = VkImageUsage.DEPTH_STENCIL_ATTACHMENT_BIT.i - - offscreenPass.depth.image = device createImage image - device.getImageMemoryRequirements(offscreenPass.depth.image, memReqs) - memAlloc.allocationSize = memReqs.size - memAlloc.memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) - offscreenPass.depth.mem = device allocateMemory memAlloc - device.bindImageMemory(offscreenPass.depth.image, offscreenPass.depth.mem) - - val depthStencilView = vk.ImageViewCreateInfo { - viewType = VkImageViewType.`2D` - format = fbDepthFormat - flags = 0 - subresourceRange.apply { - aspectMask = VkImageAspect.DEPTH_BIT or VkImageAspect.STENCIL_BIT - baseMipLevel = 0 - levelCount = 1 - baseArrayLayer = 0 - layerCount = 1 - } - this.image = offscreenPass.depth.image - } - offscreenPass.depth.view = device createImageView depthStencilView - - // Create a separate render pass for the offscreen rendering as it may differ from the one used for scene rendering - - val attchmentDescriptions = vk.AttachmentDescription(2).also { - // Color attachment - it[0].apply { - format = FB_COLOR_FORMAT - samples = VkSampleCount.`1_BIT` - loadOp = VkAttachmentLoadOp.CLEAR - storeOp = VkAttachmentStoreOp.STORE - stencilLoadOp = VkAttachmentLoadOp.DONT_CARE - stencilStoreOp = VkAttachmentStoreOp.DONT_CARE - initialLayout = VkImageLayout.UNDEFINED - finalLayout = VkImageLayout.SHADER_READ_ONLY_OPTIMAL - } - // Depth attachment - it[1].apply { - format = fbDepthFormat - samples = VkSampleCount.`1_BIT` - loadOp = VkAttachmentLoadOp.CLEAR - storeOp = VkAttachmentStoreOp.DONT_CARE - stencilLoadOp = VkAttachmentLoadOp.DONT_CARE - stencilStoreOp = VkAttachmentStoreOp.DONT_CARE - initialLayout = VkImageLayout.UNDEFINED - finalLayout = VkImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL - } - } - val colorReference = vk.AttachmentReference(0, VkImageLayout.COLOR_ATTACHMENT_OPTIMAL) - val depthReference = vk.AttachmentReference(1, VkImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL) - - val subpassDescription = vk.SubpassDescription { - pipelineBindPoint = VkPipelineBindPoint.GRAPHICS - colorAttachmentCount = 1 - colorAttachment = colorReference - depthStencilAttachment = depthReference - } - // Use subpass dependencies for layout transitions - val dependencies = vk.SubpassDependency(2).also { - it[0].apply { - srcSubpass = VK_SUBPASS_EXTERNAL - dstSubpass = 0 - srcStageMask = VkPipelineStage.BOTTOM_OF_PIPE_BIT.i - dstStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i - srcAccessMask = VkAccess.MEMORY_READ_BIT.i - dstAccessMask = VkAccess.COLOR_ATTACHMENT_READ_BIT or VkAccess.COLOR_ATTACHMENT_WRITE_BIT - dependencyFlags = VkDependency.BY_REGION_BIT.i - } - it[1].apply { - srcSubpass = 0 - dstSubpass = VK_SUBPASS_EXTERNAL - srcStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i - dstStageMask = VkPipelineStage.BOTTOM_OF_PIPE_BIT.i - srcAccessMask = VkAccess.COLOR_ATTACHMENT_READ_BIT or VkAccess.COLOR_ATTACHMENT_WRITE_BIT - dstAccessMask = VkAccess.MEMORY_READ_BIT.i - dependencyFlags = VkDependency.BY_REGION_BIT.i - } - } - // Create the actual renderpass - val renderPassInfo = vk.RenderPassCreateInfo { - attachments = attchmentDescriptions - subpass = subpassDescription - this.dependencies = dependencies - } - offscreenPass.renderPass = device createRenderPass renderPassInfo - - val attachments = appBuffer.longBufferOf(offscreenPass.color.view, offscreenPass.depth.view) - - val fbufCreateInfo = vk.FramebufferCreateInfo { - renderPass = offscreenPass.renderPass - this.attachments = attachments - extent(offscreenPass.size, 1) - } - offscreenPass.frameBuffer = device createFramebuffer fbufCreateInfo - - // Fill a descriptor for later use in a descriptor set - offscreenPass.descriptor = vk.DescriptorImageInfo { - imageLayout = VkImageLayout.SHADER_READ_ONLY_OPTIMAL - imageView = offscreenPass.color.view - sampler = offscreenPass.sampler - } - } - - /** Sets up the command buffer that renders the scene to the offscreen frame buffer */ - fun buildOffscreenCommandBuffer() { - - if (offscreenPass.commandBuffer == null) - offscreenPass.commandBuffer = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, false) - - if (offscreenPass.semaphore == NULL) { - // Create a semaphore used to synchronize offscreen rendering and usage - val semaphoreCreateInfo = vk.SemaphoreCreateInfo() - offscreenPass.semaphore = device createSemaphore semaphoreCreateInfo - } - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(0f) - it[1].depthStencil(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = offscreenPass.renderPass - framebuffer = offscreenPass.frameBuffer - renderArea.extent(offscreenPass.size) - this.clearValues = clearValues - } - - offscreenPass.commandBuffer!!.apply { - - begin(cmdBufInfo) - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - setViewport(offscreenPass.size) - - setScissor(offscreenPass.size) - - // Mirrored scene - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayouts.shaded, descriptorSets.offscreen) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.shadedOffscreen) - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.example.vertices.buffer) - bindIndexBuffer(models.example.indices.buffer, 0, VkIndexType.UINT32) - drawIndexed(models.example.indexCount, 1, 0, 0, 0) - - endRenderPass() - - end() - } - } - - override fun buildCommandBuffers() { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(defaultClearColor) - it[1].depthStencil(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@OffscreenRendering.renderPass - renderArea.offset(0) - renderArea.extent(size) - this.clearValues = clearValues - } - for (i in drawCmdBuffers.indices) { - // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - setViewport(size) - - setScissor(size) - - if (debugDisplay) { - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayouts.textured, descriptorSets.debugQuad) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.debug) - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.quad.vertices.buffer) - bindIndexBuffer(models.quad.indices.buffer, 0, VkIndexType.UINT32) - drawIndexed(models.quad.indexCount, 1, 0, 0, 0) - } - - // Scene - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.debug) - - // Reflection plane - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayouts.textured, descriptorSets.mirror) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.mirror) - - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.plane.vertices.buffer) - bindIndexBuffer(models.plane.indices.buffer, 0, VkIndexType.UINT32) - drawIndexed(models.plane.indexCount, 1, 0, 0, 0) - - // Model - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayouts.shaded, descriptorSets.model) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.shaded) - - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.example.vertices.buffer) - bindIndexBuffer(models.example.indices.buffer, 0, VkIndexType.UINT32) - drawIndexed(models.example.indexCount, 1, 0, 0, 0) - - endRenderPass() - - end() - } - } - } - - fun loadAssets() { - - models.plane.loadFromFile("$assetPath/models/plane.obj", vertexLayout, 0.5f, vulkanDevice, queue) - models.example.loadFromFile("$assetPath/models/chinesedragon.dae", vertexLayout, 0.3f, vulkanDevice, queue) - - // Textures - val (texFormat, format) = vulkanDevice.features.run { - when { - textureCompressionBC -> "bc3" to VkFormat.BC3_UNORM_BLOCK - textureCompressionASTC_LDR -> "astc_8x8" to VkFormat.ASTC_8x8_UNORM_BLOCK - textureCompressionETC2 -> "etc2" to VkFormat.ETC2_R8G8B8_UNORM_BLOCK - else -> tools.exitFatal("Device does not support any compressed texture format!", VkResult.ERROR_FEATURE_NOT_PRESENT) - } - } - textures.colorMap.loadFromFile("$assetPath/textures/darkmetal_${texFormat}_unorm.ktx", format, vulkanDevice, queue) - } - - fun generateQuad() { - // Setup vertices for a single uv-mapped quad -// struct Vertex { -// float pos [3] -// float uv [2] -// float col [3] -// float normal [3] +///* +//* Vulkan Example - Offscreen rendering using a separate framebuffer +//* +//* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +//package vulkan.basics +// +//import glm_.L +//import glm_.func.rad +//import glm_.glm +//import glm_.mat4x4.Mat4 +//import glm_.size +//import glm_.vec2.Vec2 +//import glm_.vec2.Vec2i +//import glm_.vec3.Vec3 +//import glm_.vec4.Vec4 +//import kool.adr +//import kool.stak +//import org.lwjgl.system.MemoryUtil.NULL +//import org.lwjgl.vulkan.* +//import org.lwjgl.vulkan.VK10.VK_SUBPASS_EXTERNAL +//import vkk.* +//import vulkan.VERTEX_BUFFER_BIND_ID +//import vulkan.assetPath +//import vulkan.base.* +// +// +//fun main(args: Array) { +// OffscreenRendering().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +//// Offscreen frame buffer properties +//private const val FB_DIM = 512 +//private val FB_COLOR_FORMAT = VkFormat.R8G8B8A8_UNORM +// +//private class OffscreenRendering : VulkanExampleBase() { +// +// var debugDisplay = false +// +// object textures { +// val colorMap = Texture2D() +// } +// +// // Vertex layout for the models +// val vertexLayout = VertexLayout( +// VertexComponent.POSITION, +// VertexComponent.UV, +// VertexComponent.COLOR, +// VertexComponent.NORMAL) +// +// object models { +// val example = Model() +// val quad = Model() +// val plane = Model() +// } +// +// object vertices { +// lateinit var inputState: VkPipelineVertexInputStateCreateInfo +// lateinit var bindingDescriptions: VkVertexInputBindingDescription +// lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer +// } +// +// object uniformBuffers { +// val vsShared = Buffer() +// val vsMirror = Buffer() +// val vsOffScreen = Buffer() +// val vsDebugQuad = Buffer() +// } +// +// object uboShared : Bufferizable() { +// lateinit var projection: Mat4 +// @Order(1) +// lateinit var model: Mat4 +// @Order(2) +// val lightPos = Vec4(0f, 0f, 0f, 1f) +// } +// +// object pipelines { +// var debug = VkPipeline(NULL) +// var shaded = VkPipeline(NULL) +// var shadedOffscreen = VkPipeline(NULL) +// var mirror = VkPipeline(NULL) +// } +// +// object pipelineLayouts { +// var textured = VkPipelineLayout(NULL) +// var shaded = VkPipelineLayout(NULL) +// } +// +// object descriptorSets { +// var offscreen = VkDescriptorSet(NULL) +// var mirror = VkDescriptorSet(NULL) +// var model = VkDescriptorSet(NULL) +// var debugQuad = VkDescriptorSet(NULL) +// } +// +// object descriptorSetLayouts { +// var textured = VkDescriptorSetLayout(NULL) +// var shaded = VkDescriptorSetLayout(NULL) +// } +// +// // Framebuffer for offscreen rendering +// class FrameBufferAttachment { +// var image = VkImage(NULL) +// var mem = VkDeviceMemory(NULL) +// var view = VkImageView(NULL) +// } +// +// object offscreenPass { +// val size = Vec2i() +// var frameBuffer = VkFramebuffer(NULL) +// val color = FrameBufferAttachment() +// val depth = FrameBufferAttachment() +// var renderPass = VkRenderPass(NULL) +// var sampler = VkSampler(NULL) +// lateinit var descriptor: VkDescriptorImageInfo +// var commandBuffer: VkCommandBuffer? = null +// // Semaphore used to synchronize between offscreen and final scene render pass +// var semaphore = VkSemaphore(NULL) +// } +// +// val meshPos = Vec3(0f, -1.5f, 0f) +// val meshRot = Vec3() +// +// init { +// zoom = -6f +// rotation(-2.5f, 0f, 0f) +// cameraPos(0f, 1f, 0f) +// timerSpeed *= 0.25f +// title = "Offscreen rendering" +//// settings.overlay = true +// enabledFeatures.shaderClipDistance = true +// } +// +// override fun destroy() { +// +// // Clean up used Vulkan resources +// // Note : Inherited destructor cleans up resources stored in base class +// +// // Textures +// textures.colorMap.destroy() +// +// device.apply { +// // Frame buffer +// +// // Color attachment +// destroyImageView(offscreenPass.color.view) +// destroyImage(offscreenPass.color.image) +// freeMemory(offscreenPass.color.mem) +// +// // Depth attachment +// destroyImageView(offscreenPass.depth.view) +// destroyImage(offscreenPass.depth.image) +// freeMemory(offscreenPass.depth.mem) +// +// destroyRenderPass(offscreenPass.renderPass) +// destroySampler(offscreenPass.sampler) +// destroyFramebuffer(offscreenPass.frameBuffer) +// +// destroyPipeline(pipelines.debug) +// destroyPipeline(pipelines.shaded) +// destroyPipeline(pipelines.shadedOffscreen) +// destroyPipeline(pipelines.mirror) +// +// destroyPipelineLayout(pipelineLayouts.textured) +// destroyPipelineLayout(pipelineLayouts.shaded) +// +// destroyDescriptorSetLayout(descriptorSetLayouts.shaded) +// destroyDescriptorSetLayout(descriptorSetLayouts.textured) +// +// // Models +// models.apply { +// example.destroy() +// quad.destroy() +// plane.destroy() +// } +// // Uniform buffers +// uniformBuffers.apply { +// vsShared.destroy() +// vsMirror.destroy() +// vsOffScreen.destroy() +// vsDebugQuad.destroy() +// } +// freeCommandBuffer(cmdPool, offscreenPass.commandBuffer!!) +// destroySemaphore(offscreenPass.semaphore) +// } +// super.destroy() +// } +// +// /** Setup the offscreen framebuffer for rendering the mirrored scene +// * The color attachment of this framebuffer will then be used to sample from in the fragment shader of the final pass */ +// fun prepareOffscreen() = stak { +// +// offscreenPass.size put FB_DIM +// +// // Find a suitable depth format +// val fbDepthFormat = tools getSupportedDepthFormat physicalDevice +// assert(fbDepthFormat != VkFormat.UNDEFINED) +// +// // Color attachment +// val image = vk.ImageCreateInfo { +// imageType = VkImageType.`2D` +// format = FB_COLOR_FORMAT +// extent(offscreenPass.size, 1) +// mipLevels = 1 +// arrayLayers = 1 +// samples = VkSampleCount.`1_BIT` +// tiling = VkImageTiling.OPTIMAL +// // We will sample directly from the color attachment +// usage = VkImageUsage.COLOR_ATTACHMENT_BIT or VkImageUsage.SAMPLED_BIT +// } +// +// offscreenPass.color.image = device createImage image +// val memReqs = device getImageMemoryRequirements offscreenPass.color.image +// val memAlloc = vk.MemoryAllocateInfo { +// allocationSize = memReqs.size +// memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) +// } +// offscreenPass.color.mem = device allocateMemory memAlloc +// device.bindImageMemory(offscreenPass.color.image, offscreenPass.color.mem) +// +// val colorImageView = vk.ImageViewCreateInfo { +// viewType = VkImageViewType.`2D` +// format = FB_COLOR_FORMAT +// subresourceRange.apply { +// aspectMask = VkImageAspect.COLOR_BIT.i +// baseMipLevel = 0 +// levelCount = 1 +// baseArrayLayer = 0 +// layerCount = 1 +// } +// this.image = offscreenPass.color.image +// } +// offscreenPass.color.view = device createImageView colorImageView +// +// // Create sampler to sample from the attachment in the fragment shader +// val samplerInfo = vk.SamplerCreateInfo { +// magFilter = VkFilter.LINEAR +// minFilter = VkFilter.LINEAR +// mipmapMode = VkSamplerMipmapMode.LINEAR +// addressModeU = VkSamplerAddressMode.CLAMP_TO_EDGE +// addressModeV = addressModeU // TODO custom func? +// addressModeW = addressModeU +// mipLodBias = 0f +// maxAnisotropy = 1f +// minLod = 0f +// maxLod = 1f +// borderColor = VkBorderColor.FLOAT_OPAQUE_WHITE +// } +// offscreenPass.sampler = device createSampler samplerInfo +// +// // Depth stencil attachment +// image.format = fbDepthFormat +// image.usage = VkImageUsage.DEPTH_STENCIL_ATTACHMENT_BIT.i +// +// offscreenPass.depth.image = device createImage image +// device.getImageMemoryRequirements(offscreenPass.depth.image, memReqs) +// memAlloc.allocationSize = memReqs.size +// memAlloc.memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) +// offscreenPass.depth.mem = device allocateMemory memAlloc +// device.bindImageMemory(offscreenPass.depth.image, offscreenPass.depth.mem) +// +// val depthStencilView = vk.ImageViewCreateInfo { +// viewType = VkImageViewType.`2D` +// format = fbDepthFormat +// flags = 0 +// subresourceRange.apply { +// aspectMask = VkImageAspect.DEPTH_BIT or VkImageAspect.STENCIL_BIT +// baseMipLevel = 0 +// levelCount = 1 +// baseArrayLayer = 0 +// layerCount = 1 +// } +// this.image = offscreenPass.depth.image +// } +// offscreenPass.depth.view = device createImageView depthStencilView +// +// // Create a separate render pass for the offscreen rendering as it may differ from the one used for scene rendering +// +// val attchmentDescriptions = vk.AttachmentDescription(2).also { +// // Color attachment +// it[0].apply { +// format = FB_COLOR_FORMAT +// samples = VkSampleCount.`1_BIT` +// loadOp = VkAttachmentLoadOp.CLEAR +// storeOp = VkAttachmentStoreOp.STORE +// stencilLoadOp = VkAttachmentLoadOp.DONT_CARE +// stencilStoreOp = VkAttachmentStoreOp.DONT_CARE +// initialLayout = VkImageLayout.UNDEFINED +// finalLayout = VkImageLayout.SHADER_READ_ONLY_OPTIMAL +// } +// // Depth attachment +// it[1].apply { +// format = fbDepthFormat +// samples = VkSampleCount.`1_BIT` +// loadOp = VkAttachmentLoadOp.CLEAR +// storeOp = VkAttachmentStoreOp.DONT_CARE +// stencilLoadOp = VkAttachmentLoadOp.DONT_CARE +// stencilStoreOp = VkAttachmentStoreOp.DONT_CARE +// initialLayout = VkImageLayout.UNDEFINED +// finalLayout = VkImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL +// } +// } +// val colorReference = vk.AttachmentReference(0, VkImageLayout.COLOR_ATTACHMENT_OPTIMAL) +// val depthReference = vk.AttachmentReference(1, VkImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL) +// +// val subpassDescription = vk.SubpassDescription { +// pipelineBindPoint = VkPipelineBindPoint.GRAPHICS +// colorAttachmentCount = 1 +// colorAttachment = colorReference +// depthStencilAttachment = depthReference +// } +// // Use subpass dependencies for layout transitions +// val dependencies = vk.SubpassDependency(2).also { +// it[0].apply { +// srcSubpass = VK_SUBPASS_EXTERNAL +// dstSubpass = 0 +// srcStageMask = VkPipelineStage.BOTTOM_OF_PIPE_BIT.i +// dstStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i +// srcAccessMask = VkAccess.MEMORY_READ_BIT.i +// dstAccessMask = VkAccess.COLOR_ATTACHMENT_READ_BIT or VkAccess.COLOR_ATTACHMENT_WRITE_BIT +// dependencyFlags = VkDependency.BY_REGION_BIT.i +// } +// it[1].apply { +// srcSubpass = 0 +// dstSubpass = VK_SUBPASS_EXTERNAL +// srcStageMask = VkPipelineStage.COLOR_ATTACHMENT_OUTPUT_BIT.i +// dstStageMask = VkPipelineStage.BOTTOM_OF_PIPE_BIT.i +// srcAccessMask = VkAccess.COLOR_ATTACHMENT_READ_BIT or VkAccess.COLOR_ATTACHMENT_WRITE_BIT +// dstAccessMask = VkAccess.MEMORY_READ_BIT.i +// dependencyFlags = VkDependency.BY_REGION_BIT.i +// } +// } +// // Create the actual renderpass +// val renderPassInfo = vk.RenderPassCreateInfo { +// attachments = attchmentDescriptions +// subpass = subpassDescription +// this.dependencies = dependencies +// } +// offscreenPass.renderPass = device createRenderPass renderPassInfo +// +// val attachments = it.vkImageViewBufferOf(offscreenPass.color.view, offscreenPass.depth.view) +// +// val fbufCreateInfo = vk.FramebufferCreateInfo { +// renderPass = offscreenPass.renderPass +// this.attachments = attachments +// extent(offscreenPass.size, 1) +// } +// offscreenPass.frameBuffer = device createFramebuffer fbufCreateInfo +// +// // Fill a descriptor for later use in a descriptor set +// offscreenPass.descriptor = vk.DescriptorImageInfo { +// imageLayout = VkImageLayout.SHADER_READ_ONLY_OPTIMAL +// imageView = offscreenPass.color.view +// sampler = offscreenPass.sampler +// } +// } +// +// /** Sets up the command buffer that renders the scene to the offscreen frame buffer */ +// fun buildOffscreenCommandBuffer() { +// +// if (offscreenPass.commandBuffer == null) +// offscreenPass.commandBuffer = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, false) +// +// if (offscreenPass.semaphore.isInvalid()) { +// // Create a semaphore used to synchronize offscreen rendering and usage +// val semaphoreCreateInfo = vk.SemaphoreCreateInfo() +// offscreenPass.semaphore = device createSemaphore semaphoreCreateInfo +// } +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(0f) +// it[1].depthStencil(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = offscreenPass.renderPass +// framebuffer = offscreenPass.frameBuffer +// renderArea.extent(offscreenPass.size) +// this.clearValues = clearValues +// } +// +// offscreenPass.commandBuffer!!.apply { +// +// begin(cmdBufInfo) +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// setViewport(offscreenPass.size) +// +// setScissor(offscreenPass.size) +// +// // Mirrored scene +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayouts.shaded, descriptorSets.offscreen) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.shadedOffscreen) +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.example.vertices.buffer) +// bindIndexBuffer(models.example.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// drawIndexed(models.example.indexCount, 1, 0, 0, 0) +// +// endRenderPass() +// +// end() +// } +// } +// +// override fun buildCommandBuffers() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(defaultClearColor) +// it[1].depthStencil(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@OffscreenRendering.renderPass +// renderArea.offset(0) +// renderArea.extent(size) +// this.clearValues = clearValues +// } +// for (i in drawCmdBuffers.indices) { +// // Set target frame buffer +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// setViewport(size) +// +// setScissor(size) +// +// if (debugDisplay) { +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayouts.textured, descriptorSets.debugQuad) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.debug) +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.quad.vertices.buffer) +// bindIndexBuffer(models.quad.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// drawIndexed(models.quad.indexCount, 1, 0, 0, 0) +// } +// +// // Scene +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.debug) +// +// // Reflection plane +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayouts.textured, descriptorSets.mirror) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.mirror) +// +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.plane.vertices.buffer) +// bindIndexBuffer(models.plane.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// drawIndexed(models.plane.indexCount, 1, 0, 0, 0) +// +// // Model +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayouts.shaded, descriptorSets.model) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.shaded) +// +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.example.vertices.buffer) +// bindIndexBuffer(models.example.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// drawIndexed(models.example.indexCount, 1, 0, 0, 0) +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// fun loadAssets() { +// +// models.plane.loadFromFile("$assetPath/models/plane.obj", vertexLayout, 0.5f, vulkanDevice, queue) +// models.example.loadFromFile("$assetPath/models/chinesedragon.dae", vertexLayout, 0.3f, vulkanDevice, queue) +// +// // Textures +// val (texFormat, format) = vulkanDevice.features.run { +// when { +// textureCompressionBC -> "bc3" to VkFormat.BC3_UNORM_BLOCK +// textureCompressionASTC_LDR -> "astc_8x8" to VkFormat.ASTC_8x8_UNORM_BLOCK +// textureCompressionETC2 -> "etc2" to VkFormat.ETC2_R8G8B8_UNORM_BLOCK +// else -> tools.exitFatal("Device does not support any compressed texture format!", ERROR_FEATURE_NOT_PRESENT) +// } +// } +// textures.colorMap.loadFromFile("$assetPath/textures/darkmetal_${texFormat}_unorm.ktx", format, vulkanDevice, queue) +// } +// +// fun generateQuad() = stak { +// // Setup vertices for a single uv-mapped quad +//// struct Vertex { +//// float pos [3] +//// float uv [2] +//// float col [3] +//// float normal [3] +//// } +// +// val QUAD_COLOR_NORMAL = floatArrayOf( +// 1f, 1f, 1f, +// 0f, 0f, 1f) +// val vertexBuffer = it.floats( +// 1f, 1f, 0f, 1f, 1f, *QUAD_COLOR_NORMAL, +// 0f, 1f, 0f, 0f, 1f, *QUAD_COLOR_NORMAL, +// 0f, 0f, 0f, 0f, 0f, *QUAD_COLOR_NORMAL, +// 1f, 0f, 0f, 1f, 0f, *QUAD_COLOR_NORMAL) +// val vertexBufferSize = VkDeviceSize(vertexBuffer.size.L) +// +// vulkanDevice.createBuffer( +// VkBufferUsage.VERTEX_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// vertexBufferSize, +// models.quad.vertices::buffer, +// models.quad.vertices::memory, +// vertexBuffer.adr) +// +// // Setup indices +// val indexBuffer = it.ints(0, 1, 2, 2, 3, 0) +// val indexBufferSize = VkDeviceSize(indexBuffer.size.L) +// models.quad.indexCount = indexBuffer.size +// +// vulkanDevice.createBuffer( +// VkBufferUsage.INDEX_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// indexBufferSize, +// models.quad.indices::buffer, +// models.quad.indices::memory, +// indexBuffer.adr) +// +// models.quad.device = device +// } +// +// fun setupVertexDescriptions() { +// // Binding description +// vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, vertexLayout.stride, VkVertexInputRate.VERTEX) +// +// // Attribute descriptions +// vertices.attributeDescriptions = vk.VertexInputAttributeDescription( +// // Location 0 : Position +// VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, 0, +// // Location 1 : Texture coordinates +// VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32_SFLOAT, Vec3.size, +// // Location 2 : Color +// VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32G32B32_SFLOAT, Vec3.size + Vec2.size, +// // Location 3 : Normal +// VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2 + Vec2.size) +// +// vertices.inputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertices.bindingDescriptions +// vertexAttributeDescriptions = vertices.attributeDescriptions // } - - val QUAD_COLOR_NORMAL = floatArrayOf( - 1f, 1f, 1f, - 0f, 0f, 1f) - val vertexBuffer = appBuffer.floatBufferOf( - 1f, 1f, 0f, 1f, 1f, *QUAD_COLOR_NORMAL, - 0f, 1f, 0f, 0f, 1f, *QUAD_COLOR_NORMAL, - 0f, 0f, 0f, 0f, 0f, *QUAD_COLOR_NORMAL, - 1f, 0f, 0f, 1f, 0f, *QUAD_COLOR_NORMAL) - - vulkanDevice.createBuffer( - VkBufferUsage.VERTEX_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - vertexBuffer.size.L, - models.quad.vertices::buffer, - models.quad.vertices::memory, - vertexBuffer.adr) - - // Setup indices - val indexBuffer = appBuffer.intBufferOf(0, 1, 2, 2, 3, 0) - models.quad.indexCount = indexBuffer.size - - vulkanDevice.createBuffer( - VkBufferUsage.INDEX_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - indexBuffer.size.L, - models.quad.indices::buffer, - models.quad.indices::memory, - indexBuffer.adr) - - models.quad.device = device - } - - fun setupVertexDescriptions() { - // Binding description - vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, vertexLayout.stride, VkVertexInputRate.VERTEX) - - // Attribute descriptions - vertices.attributeDescriptions = vk.VertexInputAttributeDescription( - // Location 0 : Position - VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, 0, - // Location 1 : Texture coordinates - VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32_SFLOAT, Vec3.size, - // Location 2 : Color - VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32G32B32_SFLOAT, Vec3.size + Vec2.size, - // Location 3 : Normal - VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2 + Vec2.size) - - vertices.inputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertices.bindingDescriptions - vertexAttributeDescriptions = vertices.attributeDescriptions - } - } - - fun setupDescriptorPool() { - - val poolSizes = vk.DescriptorPoolSize( - VkDescriptorType.UNIFORM_BUFFER, 6, - VkDescriptorType.COMBINED_IMAGE_SAMPLER, 8) - - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 5) - - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - // Binding 0 : Vertex shader uniform buffer - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, - // Binding 1 : Fragment shader image sampler - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1, - // Binding 2 : Fragment shader image sampler - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 2) - - // Shaded layouts (only use first layout binding, that is [0]) - var descriptorLayoutInfo = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings[0]) - descriptorSetLayouts.shaded = device createDescriptorSetLayout descriptorLayoutInfo - - var pipelineLayoutInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayouts.shaded) - pipelineLayouts.shaded = device createPipelineLayout pipelineLayoutInfo - - // Textured layouts (use all layout bindings) - descriptorLayoutInfo = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - descriptorSetLayouts.textured = device createDescriptorSetLayout descriptorLayoutInfo - - pipelineLayoutInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayouts.textured) - pipelineLayouts.textured = device createPipelineLayout pipelineLayoutInfo - } - - fun setupDescriptorSet() { - // Mirror plane descriptor set - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayouts.textured) - - descriptorSets.mirror = device allocateDescriptorSets allocInfo - - val writeDescriptorSets = vk.WriteDescriptorSet( - // Binding 0 : Vertex shader uniform buffer - descriptorSets.mirror, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.vsMirror.descriptor, - // Binding 1 : Fragment shader texture sampler - descriptorSets.mirror, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, offscreenPass.descriptor, - // Binding 2 : Fragment shader texture sampler - descriptorSets.mirror, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 2, textures.colorMap.descriptor) - - device updateDescriptorSets writeDescriptorSets - - // Debug quad - descriptorSets.debugQuad = device allocateDescriptorSets allocInfo - - val debugQuadWriteDescriptorSets = vk.WriteDescriptorSet( - // Binding 0 : Vertex shader uniform buffer - descriptorSets.debugQuad, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.vsDebugQuad.descriptor, - // Binding 1 : Fragment shader texture sampler - descriptorSets.debugQuad, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, offscreenPass.descriptor) - - device updateDescriptorSets debugQuadWriteDescriptorSets - - // Shaded descriptor sets - allocInfo.setLayout = descriptorSetLayouts.shaded - - // Model - // No texture - descriptorSets.model = device allocateDescriptorSets allocInfo - - val modelWriteDescriptorSets = vk.WriteDescriptorSet( - // Binding 0 : Vertex shader uniform buffer - descriptorSets.model, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.vsShared.descriptor) - - device updateDescriptorSets modelWriteDescriptorSets - - // Offscreen - descriptorSets.offscreen = device allocateDescriptorSets allocInfo - - val offScreenWriteDescriptorSets = vk.WriteDescriptorSet( - // Binding 0 : Vertex shader uniform buffer - descriptorSets.offscreen, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.vsOffScreen.descriptor) - - device updateDescriptorSets offScreenWriteDescriptorSets - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.FRONT_BIT.i, VkFrontFace.CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - // Solid rendering pipeline - // Load shaders - val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { - it[0].loadShader("$assetPath/shaders/offscreen/quad.vert.spv", VkShaderStage.VERTEX_BIT) - it[1].loadShader("$assetPath/shaders/offscreen/quad.frag.spv", VkShaderStage.FRAGMENT_BIT) - } - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayouts.textured, renderPass).also { - it.vertexInputState = vertices.inputState - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - } - pipelines.debug = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - - // Mirror - shaderStages[0].loadShader("$assetPath/shaders/offscreen/mirror.vert.spv", VkShaderStage.VERTEX_BIT) - shaderStages[1].loadShader("$assetPath/shaders/offscreen/mirror.frag.spv", VkShaderStage.FRAGMENT_BIT) - rasterizationState.cullMode = VkCullMode.NONE.i - pipelines.mirror = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - - // Flip culling - rasterizationState.cullMode = VkCullMode.BACK_BIT.i - - // Phong shading pipelines - pipelineCreateInfo.layout = pipelineLayouts.shaded - // Scene - shaderStages[0].loadShader("$assetPath/shaders/offscreen/phong.vert.spv", VkShaderStage.VERTEX_BIT) - shaderStages[1].loadShader("$assetPath/shaders/offscreen/phong.frag.spv", VkShaderStage.FRAGMENT_BIT) - pipelines.shaded = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - // Offscreen - // Flip culling - rasterizationState.cullMode = VkCullMode.FRONT_BIT.i - pipelineCreateInfo.renderPass = offscreenPass.renderPass - pipelines.shadedOffscreen = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - /** Prepare and initialize uniform buffer containing shader uniforms */ - fun prepareUniformBuffers() { - // Mesh vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBuffers.vsShared, - uboShared.size.L) - - // Mirror plane vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBuffers.vsMirror, - uboShared.size.L) - - // Offscreen vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBuffers.vsOffScreen, - uboShared.size.L) - - // Debug quad vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBuffers.vsDebugQuad, - uboShared.size.L) - - // Map persistent - uniformBuffers.apply { - vsShared.map() - vsMirror.map() - vsOffScreen.map() - vsDebugQuad.map() - } - updateUniformBuffers() - updateUniformBufferOffscreen() - } - - fun updateUniformBuffers() { - // Mesh - uboShared.projection = glm.perspective(60f.rad, size.aspect, 0.1f, 256f) - val viewMatrix = glm.translate(Mat4(1f), Vec3(0f, 0f, zoom)) - - uboShared.model = viewMatrix * glm.translate(Mat4(1f), cameraPos) - .rotateAssign(rotation.x.rad, 1f, 0f, 0f) - .rotateAssign((rotation.y + meshRot.y).rad, 0f, 1f, 0f) - .rotateAssign(rotation.z.rad, 0f, 0f, 1f) - - uboShared.model = glm.translate(uboShared.model, meshPos) - - uboShared to uniformBuffers.vsShared.mapped - - // Mirror - uboShared.model = viewMatrix * glm.translate(Mat4(1f), cameraPos) - .rotateAssign(rotation.x.rad, 1f, 0f, 0f) - .rotateAssign(rotation.y.rad, 0f, 1f, 0f) - .rotateAssign(rotation.z.rad, 0f, 0f, 1f) - - uboShared to uniformBuffers.vsMirror.mapped - - // Debug quad - uboShared.projection = glm.ortho(4f, 0f, 0f, 4f * size.aspect, -1f, 1f) - uboShared.model = glm.translate(Mat4(1f), 0f, 0f, 0f) - - uboShared to uniformBuffers.vsDebugQuad.mapped - } - - fun updateUniformBufferOffscreen() { - - uboShared.projection = glm.perspective(60f.rad, size.aspect, 0.1f, 256f) - val viewMatrix = glm.translate(Mat4(1f), 0f, 0f, zoom) - - uboShared.model = viewMatrix * glm.translate(Mat4(1f), cameraPos) - .rotateAssign(rotation.x.rad, 1f, 0f, 0f) - .rotateAssign((rotation.y + meshRot.y).rad, 0f, 1f, 0f) - .rotateAssign(rotation.z.rad, 0f, 0f, 1f) - - uboShared.model = glm.scale(uboShared.model, 1f, -1f, 1f) - uboShared.model = glm.translate(uboShared.model, meshPos) - - uboShared to uniformBuffers.vsOffScreen.mapped - } - - fun draw() { - - super.prepareFrame() - - /* The scene render command buffer has to wait for the offscreen rendering to be finished before we can use - the framebuffer color image for sampling during final rendering - To ensure this we use a dedicated offscreen synchronization semaphore that will be signaled when offscreen - rendering has been finished - This is necessary as an implementation may start both command buffers at the same time, there is no guarantee - that command buffers will be executed in the order they have been submitted by the application */ - - // Offscreen rendering - - // Wait for swap chain presentation to finish - submitInfo.waitSemaphore = semaphores.presentComplete - // Signal ready with offscreen semaphore - submitInfo.signalSemaphore = offscreenPass.semaphore - - // Submit work - submitInfo.commandBuffer = offscreenPass.commandBuffer - queue submit submitInfo - - // Scene rendering - - // Wait for offscreen semaphore - submitInfo.waitSemaphore = offscreenPass.semaphore - // Signal ready with render complete semaphpre - submitInfo.signalSemaphore = semaphores.renderComplete - - // Submit work - submitInfo.commandBuffer = drawCmdBuffers [currentBuffer] - queue submit submitInfo - - super.submitFrame() - } - - override fun prepare() { - super.prepare() - loadAssets() - generateQuad() - prepareOffscreen() - setupVertexDescriptions() - prepareUniformBuffers() - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSet() - buildCommandBuffers() - buildOffscreenCommandBuffer() - prepared = true - window.show() - } - - override fun render() { - if (!prepared) - return - draw() - if (!paused) { - meshRot.y += frameTimer * 10f - updateUniformBuffers() - updateUniformBufferOffscreen() - } - } - - override fun viewChanged() { - updateUniformBuffers() - updateUniformBufferOffscreen() - } - -// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) -// { -// if (overlay->header("Settings")) { -// if (overlay->checkBox("Display render target", &debugDisplay)) { +// } +// +// fun setupDescriptorPool() { +// +// val poolSizes = vk.DescriptorPoolSize( +// VkDescriptorType.UNIFORM_BUFFER, 6, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, 8) +// +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 5) +// +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// // Binding 0 : Vertex shader uniform buffer +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, +// // Binding 1 : Fragment shader image sampler +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1, +// // Binding 2 : Fragment shader image sampler +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 2) +// +// // Shaded layouts (only use first layout binding, that is [0]) +// var descriptorLayoutInfo = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings[0]) +// descriptorSetLayouts.shaded = device createDescriptorSetLayout descriptorLayoutInfo +// +// var pipelineLayoutInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayouts.shaded) +// pipelineLayouts.shaded = device createPipelineLayout pipelineLayoutInfo +// +// // Textured layouts (use all layout bindings) +// descriptorLayoutInfo = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// descriptorSetLayouts.textured = device createDescriptorSetLayout descriptorLayoutInfo +// +// pipelineLayoutInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayouts.textured) +// pipelineLayouts.textured = device createPipelineLayout pipelineLayoutInfo +// } +// +// fun setupDescriptorSet() { +// // Mirror plane descriptor set +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayouts.textured) +// +// descriptorSets.mirror = device allocateDescriptorSets allocInfo +// +// val writeDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0 : Vertex shader uniform buffer +// descriptorSets.mirror, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.vsMirror.descriptor, +// // Binding 1 : Fragment shader texture sampler +// descriptorSets.mirror, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, offscreenPass.descriptor, +// // Binding 2 : Fragment shader texture sampler +// descriptorSets.mirror, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 2, textures.colorMap.descriptor) +// +// device updateDescriptorSets writeDescriptorSets +// +// // Debug quad +// descriptorSets.debugQuad = device allocateDescriptorSets allocInfo +// +// val debugQuadWriteDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0 : Vertex shader uniform buffer +// descriptorSets.debugQuad, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.vsDebugQuad.descriptor, +// // Binding 1 : Fragment shader texture sampler +// descriptorSets.debugQuad, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, offscreenPass.descriptor) +// +// device updateDescriptorSets debugQuadWriteDescriptorSets +// +// // Shaded descriptor sets +// allocInfo.setLayout = descriptorSetLayouts.shaded +// +// // Model +// // No texture +// descriptorSets.model = device allocateDescriptorSets allocInfo +// +// val modelWriteDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0 : Vertex shader uniform buffer +// descriptorSets.model, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.vsShared.descriptor) +// +// device updateDescriptorSets modelWriteDescriptorSets +// +// // Offscreen +// descriptorSets.offscreen = device allocateDescriptorSets allocInfo +// +// val offScreenWriteDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0 : Vertex shader uniform buffer +// descriptorSets.offscreen, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.vsOffScreen.descriptor) +// +// device updateDescriptorSets offScreenWriteDescriptorSets +// } +// +// fun preparePipelines() { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.FRONT_BIT.i, VkFrontFace.CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// // Solid rendering pipeline +// // Load shaders +// val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { +// it[0].loadShader("$assetPath/shaders/offscreen/quad.vert.spv", VkShaderStage.VERTEX_BIT) +// it[1].loadShader("$assetPath/shaders/offscreen/quad.frag.spv", VkShaderStage.FRAGMENT_BIT) +// } +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayouts.textured, renderPass).also { +// it.vertexInputState = vertices.inputState +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// } +// pipelines.debug = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// +// // Mirror +// shaderStages[0].loadShader("$assetPath/shaders/offscreen/mirror.vert.spv", VkShaderStage.VERTEX_BIT) +// shaderStages[1].loadShader("$assetPath/shaders/offscreen/mirror.frag.spv", VkShaderStage.FRAGMENT_BIT) +// rasterizationState.cullMode = VkCullMode.NONE.i +// pipelines.mirror = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// +// // Flip culling +// rasterizationState.cullMode = VkCullMode.BACK_BIT.i +// +// // Phong shading pipelines +// pipelineCreateInfo.layout = pipelineLayouts.shaded +// // Scene +// shaderStages[0].loadShader("$assetPath/shaders/offscreen/phong.vert.spv", VkShaderStage.VERTEX_BIT) +// shaderStages[1].loadShader("$assetPath/shaders/offscreen/phong.frag.spv", VkShaderStage.FRAGMENT_BIT) +// pipelines.shaded = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// // Offscreen +// // Flip culling +// rasterizationState.cullMode = VkCullMode.FRONT_BIT.i +// pipelineCreateInfo.renderPass = offscreenPass.renderPass +// pipelines.shadedOffscreen = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// +// /** Prepare and initialize uniform buffer containing shader uniforms */ +// fun prepareUniformBuffers() { +// // Mesh vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBuffers.vsShared, +// VkDeviceSize(uboShared.size.L)) +// +// // Mirror plane vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBuffers.vsMirror, +// VkDeviceSize( uboShared.size.L)) +// +// // Offscreen vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBuffers.vsOffScreen, +// VkDeviceSize( uboShared.size.L)) +// +// // Debug quad vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBuffers.vsDebugQuad, +// VkDeviceSize(uboShared.size.L)) +// +// // Map persistent +// uniformBuffers.apply { +// vsShared.map() +// vsMirror.map() +// vsOffScreen.map() +// vsDebugQuad.map() +// } +// updateUniformBuffers() +// updateUniformBufferOffscreen() +// } +// +// fun updateUniformBuffers() { +// // Mesh +// uboShared.projection = glm.perspective(60f.rad, size.aspect, 0.1f, 256f) +// val viewMatrix = glm.translate(Mat4(1f), Vec3(0f, 0f, zoom)) +// +// uboShared.model = viewMatrix * glm.translate(Mat4(1f), cameraPos) +// .rotateAssign(rotation.x.rad, 1f, 0f, 0f) +// .rotateAssign((rotation.y + meshRot.y).rad, 0f, 1f, 0f) +// .rotateAssign(rotation.z.rad, 0f, 0f, 1f) +// +// uboShared.model = glm.translate(uboShared.model, meshPos) +// +// uboShared to uniformBuffers.vsShared.mapped +// +// // Mirror +// uboShared.model = viewMatrix * glm.translate(Mat4(1f), cameraPos) +// .rotateAssign(rotation.x.rad, 1f, 0f, 0f) +// .rotateAssign(rotation.y.rad, 0f, 1f, 0f) +// .rotateAssign(rotation.z.rad, 0f, 0f, 1f) +// +// uboShared to uniformBuffers.vsMirror.mapped +// +// // Debug quad +// uboShared.projection = glm.ortho(4f, 0f, 0f, 4f * size.aspect, -1f, 1f) +// uboShared.model = glm.translate(Mat4(1f), 0f, 0f, 0f) +// +// uboShared to uniformBuffers.vsDebugQuad.mapped +// } +// +// fun updateUniformBufferOffscreen() { +// +// uboShared.projection = glm.perspective(60f.rad, size.aspect, 0.1f, 256f) +// val viewMatrix = glm.translate(Mat4(1f), 0f, 0f, zoom) +// +// uboShared.model = viewMatrix * glm.translate(Mat4(1f), cameraPos) +// .rotateAssign(rotation.x.rad, 1f, 0f, 0f) +// .rotateAssign((rotation.y + meshRot.y).rad, 0f, 1f, 0f) +// .rotateAssign(rotation.z.rad, 0f, 0f, 1f) +// +// uboShared.model = glm.scale(uboShared.model, 1f, -1f, 1f) +// uboShared.model = glm.translate(uboShared.model, meshPos) +// +// uboShared to uniformBuffers.vsOffScreen.mapped +// } +// +// fun draw() { +// +// super.prepareFrame() +// +// /* The scene render command buffer has to wait for the offscreen rendering to be finished before we can use +// the framebuffer color image for sampling during final rendering +// To ensure this we use a dedicated offscreen synchronization semaphore that will be signaled when offscreen +// rendering has been finished +// This is necessary as an implementation may start both command buffers at the same time, there is no guarantee +// that command buffers will be executed in the order they have been submitted by the application */ +// +// // Offscreen rendering +// +// // Wait for swap chain presentation to finish +// submitInfo.waitSemaphore = semaphores.presentComplete +// // Signal ready with offscreen semaphore +// submitInfo.signalSemaphore = offscreenPass.semaphore +// +// // Submit work +// submitInfo.commandBuffer = offscreenPass.commandBuffer +// queue submit submitInfo +// +// // Scene rendering +// +// // Wait for offscreen semaphore +// submitInfo.waitSemaphore = offscreenPass.semaphore +// // Signal ready with render complete semaphpre +// submitInfo.signalSemaphore = semaphores.renderComplete +// +// // Submit work +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// queue submit submitInfo +// +// super.submitFrame() +// } +// +// override fun prepare() { +// super.prepare() +// loadAssets() +// generateQuad() +// prepareOffscreen() +// setupVertexDescriptions() +// prepareUniformBuffers() +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSet() // buildCommandBuffers() +// buildOffscreenCommandBuffer() +// prepared = true +// window.show() // } +// +// override fun render() { +// if (!prepared) +// return +// draw() +// if (!paused) { +// meshRot.y += frameTimer * 10f +// updateUniformBuffers() +// updateUniformBufferOffscreen() +// } // } +// +// override fun viewChanged() { +// updateUniformBuffers() +// updateUniformBufferOffscreen() // } -} \ No newline at end of file +// +//// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) +//// { +//// if (overlay->header("Settings")) { +//// if (overlay->checkBox("Display render target", &debugDisplay)) { +//// buildCommandBuffers() +//// } +//// } +//// } +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/basics/14 Cpu Particle System.kt b/src/main/kotlin/vulkan/basics/14 Cpu Particle System.kt index ae90fbb..b5512a7 100644 --- a/src/main/kotlin/vulkan/basics/14 Cpu Particle System.kt +++ b/src/main/kotlin/vulkan/basics/14 Cpu Particle System.kt @@ -1,637 +1,637 @@ -/* -* Vulkan Example - CPU based fire particle system -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -package vulkan.basics - -import glm_.* -import glm_.buffer.adr -import glm_.buffer.bufferBig -import glm_.func.rad -import glm_.mat4x4.Mat4 -import glm_.vec2.Vec2 -import glm_.vec3.Vec3 -import glm_.vec4.Vec4 -import org.lwjgl.system.MemoryUtil.NULL -import org.lwjgl.system.MemoryUtil.memCopy -import vkk.* -import vulkan.VERTEX_BUFFER_BIND_ID -import vulkan.assetPath -import vulkan.base.* -import java.nio.ByteBuffer -import kotlin.math.abs -import kotlin.math.cos -import kotlin.math.sin - - -private const val FLAME_RADIUS = 8f - -private object particle { - const val COUNT = 512 - const val SIZE = 10f - - enum class Type { Flame, Smoke } -} - - -fun main(args: Array) { - CpuParticleSystem().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - -private class CpuParticleSystem : VulkanExampleBase() { - - object textures { - object particles { - val smoke = Texture2D() - val fire = Texture2D() - // Use a custom sampler to change sampler attributes required for rotating the uvs in the shader for alpha blended textures - var sampler: VkSampler = NULL - } - - object floor { - val colorMap = Texture2D() - val normalMap = Texture2D() - } - } - - // Vertex layout for the models - val vertexLayout = VertexLayout( - VertexComponent.POSITION, - VertexComponent.UV, - VertexComponent.NORMAL, - VertexComponent.TANGENT, - VertexComponent.BITANGENT) - - object models { - val environment = Model() - } - - val emitterPos = Vec3(0f, -FLAME_RADIUS + 2f, 0f) - val minVel = Vec3(-3f, 0.5f, -3f) - val maxVel = Vec3(3f, 7f, 3f) - - fun rnd(range: Float) = glm.linearRand(0f, range) - - private inner class Particle : Bufferizable() { - val pos = Vec4() - lateinit var color: Vec4 - var alpha = 0f - var size_ = 0f - var rotation = 0f - var type = particle.Type.Flame - // Attributes not used in shader - lateinit var vel: Vec4 - var rotationSpeed = 0f - - fun init(emitterPos: Vec3) { - - vel = Vec4(0f, minVel.y + rnd(maxVel.y - minVel.y), 0f, 0f) - alpha = rnd(0.75f) - size_ = 1f + rnd(0.5f) - color = Vec4(1f) - type = particle.Type.Flame - rotation = rnd(2f * glm.PIf) - rotationSpeed = rnd(2f) - rnd(2f) - - // Get random sphere point - val theta = rnd(2f * glm.PIf) - val phi = rnd(glm.PIf) - glm.HPIf - val r = rnd(FLAME_RADIUS) - - pos.x = r * cos(theta) * cos(phi) - pos.y = r * sin(phi) - pos.z = r * sin(theta) * cos(phi) - - pos plusAssign Vec4(emitterPos, 0f) - } - } - - val particleSize = Vec4.size * 3 + Float.BYTES * 4 + Int.BYTES - - object particlesData { - var buffer: VkBuffer = NULL - var memory: VkDeviceMemory = 0 - // Store the mapped address of the particle data for reuse - var mappedMemory = NULL - // Size of the particle buffer in bytes - var size = 0 - } - - object uniformBuffers { - val fire = Buffer() - val environment = Buffer() - } - - object uboVS : Bufferizable() { - lateinit var projection: Mat4 - @Order(1) - lateinit var model: Mat4 - lateinit var viewportDim: Vec2 - @Order(3) - val pointSize = particle.SIZE - } - - object uboEnv : Bufferizable() { - lateinit var projection: Mat4 - lateinit var model: Mat4 - lateinit var normal: Mat4 - val lightPos = Vec4(0f) - lateinit var cameraPos: Vec4 - override var fieldOrder = arrayOf("projection", "model", "normal", "lightPos", "cameraPos") - } - - object pipelines { - var particles: VkPipeline = NULL - var environment: VkPipeline = NULL - } - - var pipelineLayout: VkPipelineLayout = NULL - var descriptorSetLayout: VkDescriptorSetLayout = NULL - - object descriptorSets { - var particles: VkDescriptorSet = NULL - var environment: VkDescriptorSet = NULL - } - - lateinit var particleBuffer: ByteBuffer - private val particles = ArrayList() - - init { - zoom = -75.0f - rotation(-15f, 45f, 0f) - title = "CPU based particle system" - settings.overlay = false // TODO - zoomSpeed *= 1.5f - timerSpeed *= 8f - } - - override fun destroy() { - - // Clean up used Vulkan resources - // Note : Inherited destructor cleans up resources stored in base class - - textures.particles.smoke.destroy() - textures.particles.fire.destroy() - textures.floor.colorMap.destroy() - textures.floor.normalMap.destroy() - - device.apply { - - destroyPipeline(pipelines.particles) - destroyPipeline(pipelines.environment) - - destroyPipelineLayout(pipelineLayout) - destroyDescriptorSetLayout(descriptorSetLayout) - - unmapMemory(particlesData.memory) - destroyBuffer(particlesData.buffer) - freeMemory(particlesData.memory) - - uniformBuffers.environment.destroy() - uniformBuffers.fire.destroy() - - models.environment.destroy() - - destroySampler(textures.particles.sampler) - } - super.destroy() - } - - override fun buildCommandBuffers() { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(defaultClearColor) - it[1].depthStencil(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@CpuParticleSystem.renderPass - renderArea.offset(0) - renderArea.extent(size) - this.clearValues = clearValues - } - for (i in drawCmdBuffers.indices) { - // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - setViewport(size) - setScissor(size) - - // Environment - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSets.environment) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.environment) - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.environment.vertices.buffer) - bindIndexBuffer(models.environment.indices.buffer, 0, VkIndexType.UINT32) - drawIndexed(models.environment.indexCount, 1, 0, 0, 0) - - // Particle system (no index buffer) - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSets.particles) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.particles) - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, particlesData.buffer) - draw(particle.COUNT, 1, 0, 0) - - endRenderPass() - - end() - } - } - } - - - private fun Particle.transition() = when (type) { - particle.Type.Flame -> { - // Flame particles have a chance of turning into smoke - if (rnd(1f) < 0.05f) { - alpha = 0f - color = Vec4(0.25f + rnd(0.25f)) - pos.x *= 0.5f - pos.z *= 0.5f - vel = Vec4(rnd(1f) - rnd(1f), (minVel.y * 2) + rnd(maxVel.y - minVel.y), rnd(1f) - rnd(1f), 0f) - size_ = 1f + rnd(0.5f) - rotationSpeed = rnd(1f) - rnd(1f) - type = particle.Type.Smoke - } else init(emitterPos) - } - // Respawn at end of life - particle.Type.Smoke -> init(emitterPos) - } - - fun prepareParticles() { - - particles += List(particle.COUNT) { - Particle().apply { - init(emitterPos) - alpha = 1f - abs(pos.y) / (FLAME_RADIUS * 2f) - } - } - - particleBuffer = bufferBig(particleSize * particles.size) - - for (i in particles.indices) - particles[i] to (particleBuffer.adr + particleSize * i) - - particlesData.size = particleBuffer.size - - vulkanDevice.createBuffer( - VkBufferUsage.VERTEX_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - particlesData.size.L, - particlesData::buffer, - particlesData::memory, - particleBuffer.adr) - - // Map the memory and store the pointer for reuse - particlesData.mappedMemory = device.mapMemory(particlesData.memory, 0, particlesData.size.L) - } - - fun updateParticles() { - - val particleTimer = frameTimer * 0.45f - for (p in particles) { - when (p.type) { - particle.Type.Flame -> { - p.pos.y -= p.vel.y * particleTimer * 3.5f - p.alpha += particleTimer * 2.5f - p.size_ -= particleTimer * 0.5f - } - particle.Type.Smoke -> { - p.pos -= p.vel * frameTimer * 1.0f - p.alpha += particleTimer * 1.25f - p.size_ += particleTimer * 0.125f - p.color minusAssign particleTimer * 0.05f - } - } - p.rotation += particleTimer * p.rotationSpeed - // Transition particle state - if (p.alpha > 2f) - p.transition() - } - - memCopy(particleBuffer.adr, particlesData.mappedMemory, particleBuffer.size.L) - } - - fun loadAssets() { - // Textures - val (texFormatSuffix, texFormat) = vulkanDevice.features.run { - when { - // Get supported compressed texture format - textureCompressionBC -> "_bc3_unorm" to VkFormat.BC3_UNORM_BLOCK - textureCompressionASTC_LDR -> "_astc_8x8_unorm" to VkFormat.ASTC_8x8_UNORM_BLOCK - textureCompressionETC2 -> "_etc2_unorm" to VkFormat.ETC2_R8G8B8_UNORM_BLOCK - else -> tools.exitFatal("Device does not support any compressed texture format!", VkResult.ERROR_FEATURE_NOT_PRESENT) - } - } - - // Particles - textures.particles.smoke.loadFromFile("$assetPath/textures/particle_smoke.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) - textures.particles.fire.loadFromFile("$assetPath/textures/particle_fire.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) - - // Floor - textures.floor.colorMap.loadFromFile("$assetPath/textures/fireplace_colormap$texFormatSuffix.ktx", texFormat, vulkanDevice, queue) - textures.floor.normalMap.loadFromFile("$assetPath/textures/fireplace_normalmap$texFormatSuffix.ktx", texFormat, vulkanDevice, queue) - - // Create a custom sampler to be used with the particle textures - // Create sampler - val samplerCreateInfo = vk.SamplerCreateInfo { - magFilter = VkFilter.LINEAR - minFilter = VkFilter.LINEAR - mipmapMode = VkSamplerMipmapMode.LINEAR - // Different address mode - addressMode = VkSamplerAddressMode.CLAMP_TO_BORDER - mipLodBias = 0f - compareOp = VkCompareOp.NEVER - minLod = 0f - // Both particle textures have the same number of mip maps - maxLod = textures.particles.fire.mipLevels.f - // Enable anisotropic filtering - maxAnisotropy = 8f - anisotropyEnable = true - // Use a different border color (than the normal texture loader) for additive blending - borderColor = VkBorderColor.FLOAT_TRANSPARENT_BLACK - } - textures.particles.sampler = device createSampler samplerCreateInfo - - models.environment.loadFromFile("$assetPath/models/fireplace.obj", vertexLayout, 10f, vulkanDevice, queue) - } - - fun setupDescriptorPool() { - // Example uses one ubo and one image sampler - val poolSizes = vk.DescriptorPoolSize( - VkDescriptorType.UNIFORM_BUFFER, 2, - VkDescriptorType.COMBINED_IMAGE_SAMPLER, 4) - - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) - - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - // Binding 0 : Vertex shader uniform buffer - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, - // Binding 1 : Fragment shader image sampler - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1, - // Binding 1 : Fragment shader image sampler - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 2) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - - descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) - - pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - } - - fun setupDescriptorSets() { - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) - - descriptorSets.particles = device allocateDescriptorSets allocInfo - - // Image descriptor for the color map texture - val texDescriptorSmoke = vk.DescriptorImageInfo( - textures.particles.sampler, - textures.particles.smoke.view, - VkImageLayout.GENERAL) - val texDescriptorFire = vk.DescriptorImageInfo( - textures.particles.sampler, - textures.particles.fire.view, - VkImageLayout.GENERAL) - - var writeDescriptorSets = vk.WriteDescriptorSet( - // Binding 0: Vertex shader uniform buffer - descriptorSets.particles, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.fire.descriptor, - // Binding 1: Smoke texture - descriptorSets.particles, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, texDescriptorSmoke, - // Binding 1: Fire texture array - descriptorSets.particles, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 2, texDescriptorFire) - - device updateDescriptorSets writeDescriptorSets - - // Environment - descriptorSets.environment = device allocateDescriptorSets allocInfo - - writeDescriptorSets = vk.WriteDescriptorSet( - // Binding 0: Vertex shader uniform buffer - descriptorSets.environment, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.environment.descriptor, - // Binding 1: Color map - descriptorSets.environment, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textures.floor.colorMap.descriptor, - // Binding 2: Normal map - descriptorSets.environment, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 2, textures.floor.normalMap.descriptor) - - device updateDescriptorSets writeDescriptorSets - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.POINT_LIST, 0, false) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.BACK_BIT.i, VkFrontFace.CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - // Load shaders - val shaderStages = vk.PipelineShaderStageCreateInfo(2) - - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - } - // Particle rendering pipeline - run { - // Shaders - shaderStages[0].loadShader("$assetPath/shaders/particlefire/particle.vert.spv", VkShaderStage.VERTEX_BIT) - shaderStages[1].loadShader("$assetPath/shaders/particlefire/particle.frag.spv", VkShaderStage.FRAGMENT_BIT) - - // Vertex input state - val vertexInputBinding = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, particleSize, VkVertexInputRate.VERTEX) - - val vertexInputAttributes = vk.VertexInputAttributeDescription( - VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32A32_SFLOAT, 0, // Location 0: Position - VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32A32_SFLOAT, Vec4.size, // Location 1: Color - VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32_SFLOAT, Vec4.size * 2, // Location 2: Alpha - VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32_SFLOAT, Vec4.size * 2 + Float.BYTES, // Location 3: Size - VERTEX_BUFFER_BIND_ID, 4, VkFormat.R32_SFLOAT, Vec4.size * 2 + Float.BYTES * 2, // Location 4: Rotation - VERTEX_BUFFER_BIND_ID, 5, VkFormat.R32_SINT, Vec4.size * 2 + Float.BYTES * 3) // Location 5: Particle type - - val vertexInputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertexInputBinding - vertexAttributeDescriptions = vertexInputAttributes - } - pipelineCreateInfo.vertexInputState = vertexInputState - - // Dont' write to depth buffer - depthStencilState.depthWriteEnable = false - - // Premulitplied alpha - blendAttachmentState.apply { - blendEnable = true - srcColorBlendFactor = VkBlendFactor.ONE - dstColorBlendFactor = VkBlendFactor.ONE_MINUS_SRC_ALPHA - colorBlendOp = VkBlendOp.ADD - srcAlphaBlendFactor = VkBlendFactor.ONE - dstAlphaBlendFactor = VkBlendFactor.ZERO - alphaBlendOp = VkBlendOp.ADD - colorWriteMask = VkColorComponent.R_BIT or VkColorComponent.G_BIT or VkColorComponent.B_BIT or VkColorComponent.A_BIT - } - pipelines.particles = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - // Environment rendering pipeline (normal mapped) - run { - // Shaders - shaderStages[0].loadShader("$assetPath/shaders/particlefire/normalmap.vert.spv", VkShaderStage.VERTEX_BIT) - shaderStages[1].loadShader("$assetPath/shaders/particlefire/normalmap.frag.spv", VkShaderStage.FRAGMENT_BIT) - - // Vertex input state - val vertexInputBinding = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, vertexLayout.stride, VkVertexInputRate.VERTEX) - - val vertexInputAttributes = vk.VertexInputAttributeDescription( - VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, 0, // Location 0: Position - VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32_SFLOAT, Vec3.size, // Location 1: UV - VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32G32B32_SFLOAT, Vec3.size + Vec2.size, // Location 2: Normal - VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2 + Vec2.size, // Location 3: Tangent - VERTEX_BUFFER_BIND_ID, 4, VkFormat.R32G32B32_SFLOAT, Vec3.size * 3 + Vec2.size) // Location 4: Bitangen - - val vertexInputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertexInputBinding - vertexAttributeDescriptions = vertexInputAttributes - } - pipelineCreateInfo.vertexInputState = vertexInputState - - blendAttachmentState.blendEnable = false - depthStencilState.depthWriteEnable = true - inputAssemblyState.topology = VkPrimitiveTopology.TRIANGLE_LIST - - pipelines.environment = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - } - - /** Prepare and initialize uniform buffer containing shader uniforms */ - fun prepareUniformBuffers() { - // Vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBuffers.fire, - uboVS.size.L) - - // Vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBuffers.environment, - uboEnv.size.L) - - // Map persistent - uniformBuffers.fire.map() - uniformBuffers.environment.map() - - updateUniformBuffers() - } - - fun updateUniformBufferLight() { - // Environment - uboEnv.lightPos.x = sin(timer * 2f * glm.PIf) * 1.5f - uboEnv.lightPos.y = 0f - uboEnv.lightPos.z = cos(timer * 2f * glm.PIf) * 1.5f - uboEnv to uniformBuffers.environment.mapped - } - - fun updateUniformBuffers() { - // Vertex shader - uboVS.projection = glm.perspective(60f.rad, size.aspect, 0.001f, 256f) - val viewMatrix = glm.translate(Mat4(), 0f, 0f, zoom) - - uboVS.model = viewMatrix * glm.translate(uboVS.model, 0f, 15f, 0f) - .rotateAssign(rotation.x.rad, 1f, 0f, 0f) - .rotateAssign(rotation.y.rad, 0f, 1f, 0f) - .rotateAssign(rotation.z.rad, 0f, 0f, 1f) - - uboVS.viewportDim put size - uboVS to uniformBuffers.fire.mapped - - // Environment - uboEnv.projection = uboVS.projection - uboEnv.model = uboVS.model -// uboEnv.normal = glm.inverseTranspose(uboEnv.model) - uboEnv.normal = uboEnv.model.inverse().transposeAssign() - uboEnv.cameraPos = Vec4(0f, 0f, zoom, 0f) - uboEnv to uniformBuffers.environment.mapped - } - - fun draw() { - - super.prepareFrame() - - // Command buffer to be sumitted to the queue - submitInfo.commandBuffer = drawCmdBuffers [currentBuffer] - - // Submit to queue - queue submit submitInfo - - super.submitFrame() - } - - override fun prepare() { - super.prepare() - loadAssets() - prepareParticles() - prepareUniformBuffers() - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSets() - buildCommandBuffers() - prepared = true - window.show() - } - - override fun render() { - if (!prepared) - return - draw() - if (!paused) { - updateUniformBufferLight() - updateParticles() - } - } - - override fun viewChanged() = updateUniformBuffers() -} \ No newline at end of file +///* +//* Vulkan Example - CPU based fire particle system +//* +//* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +//package vulkan.basics +// +//import glm_.* +//import glm_.func.rad +//import glm_.mat4x4.Mat4 +//import glm_.vec2.Vec2 +//import glm_.vec3.Vec3 +//import glm_.vec4.Vec4 +//import kool.adr +//import kool.bufferBig +//import org.lwjgl.system.MemoryUtil.NULL +//import org.lwjgl.system.MemoryUtil.memCopy +//import vkk.* +//import vulkan.VERTEX_BUFFER_BIND_ID +//import vulkan.assetPath +//import vulkan.base.* +//import java.nio.ByteBuffer +//import kotlin.math.abs +//import kotlin.math.cos +//import kotlin.math.sin +// +// +//private const val FLAME_RADIUS = 8f +// +//private object particle { +// const val COUNT = 512 +// const val SIZE = 10f +// +// enum class Type { Flame, Smoke } +//} +// +// +//fun main(args: Array) { +// CpuParticleSystem().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +//private class CpuParticleSystem : VulkanExampleBase() { +// +// object textures { +// object particles { +// val smoke = Texture2D() +// val fire = Texture2D() +// // Use a custom sampler to change sampler attributes required for rotating the uvs in the shader for alpha blended textures +// var sampler = VkSampler(NULL) +// } +// +// object floor { +// val colorMap = Texture2D() +// val normalMap = Texture2D() +// } +// } +// +// // Vertex layout for the models +// val vertexLayout = VertexLayout( +// VertexComponent.POSITION, +// VertexComponent.UV, +// VertexComponent.NORMAL, +// VertexComponent.TANGENT, +// VertexComponent.BITANGENT) +// +// object models { +// val environment = Model() +// } +// +// val emitterPos = Vec3(0f, -FLAME_RADIUS + 2f, 0f) +// val minVel = Vec3(-3f, 0.5f, -3f) +// val maxVel = Vec3(3f, 7f, 3f) +// +// fun rnd(range: Float) = glm.linearRand(0f, range) +// +// private inner class Particle : Bufferizable() { +// val pos = Vec4() +// lateinit var color: Vec4 +// var alpha = 0f +// var size_ = 0f +// var rotation = 0f +// var type = particle.Type.Flame +// // Attributes not used in shader +// lateinit var vel: Vec4 +// var rotationSpeed = 0f +// +// fun init(emitterPos: Vec3) { +// +// vel = Vec4(0f, minVel.y + rnd(maxVel.y - minVel.y), 0f, 0f) +// alpha = rnd(0.75f) +// size_ = 1f + rnd(0.5f) +// color = Vec4(1f) +// type = particle.Type.Flame +// rotation = rnd(2f * glm.PIf) +// rotationSpeed = rnd(2f) - rnd(2f) +// +// // Get random sphere point +// val theta = rnd(2f * glm.PIf) +// val phi = rnd(glm.PIf) - glm.HPIf +// val r = rnd(FLAME_RADIUS) +// +// pos.x = r * cos(theta) * cos(phi) +// pos.y = r * sin(phi) +// pos.z = r * sin(theta) * cos(phi) +// +// pos plusAssign Vec4(emitterPos, 0f) +// } +// } +// +// val particleSize = Vec4.size * 3 + Float.BYTES * 4 + Int.BYTES +// +// object particlesData { +// var buffer = VkBuffer(NULL) +// var memory = VkDeviceMemory(0) +// // Store the mapped address of the particle data for reuse +// var mappedMemory = NULL +// // Size of the particle buffer in bytes +// var size = 0 +// } +// +// object uniformBuffers { +// val fire = Buffer() +// val environment = Buffer() +// } +// object uboVS : Bufferizable() { +// lateinit var projection: Mat4 +// @Order(1) +// lateinit var model: Mat4 +// lateinit var viewportDim: Vec2 +// @Order(3) +// val pointSize = particle.SIZE +// } +// +// object uboEnv : Bufferizable() { +// lateinit var projection: Mat4 +// lateinit var model: Mat4 +// lateinit var normal: Mat4 +// val lightPos = Vec4(0f) +// lateinit var cameraPos: Vec4 +// override var fieldOrder = arrayOf("projection", "model", "normal", "lightPos", "cameraPos") +// } +// +// object pipelines { +// var particles = VkPipeline(NULL) +// var environment = VkPipeline(NULL) +// } +// +// var pipelineLayout = VkPipelineLayout(NULL) +// var descriptorSetLayout = VkDescriptorSetLayout(NULL) +// +// object descriptorSets { +// var particles = VkDescriptorSet(NULL) +// var environment = VkDescriptorSet(NULL) +// } +// +// lateinit var particleBuffer: ByteBuffer +// private val particles = ArrayList() +// +// init { +// zoom = -75.0f +// rotation(-15f, 45f, 0f) +// title = "CPU based particle system" +// settings.overlay = false // TODO +// zoomSpeed *= 1.5f +// timerSpeed *= 8f +// } +// +// override fun destroy() { +// +// // Clean up used Vulkan resources +// // Note : Inherited destructor cleans up resources stored in base class +// +// textures.particles.smoke.destroy() +// textures.particles.fire.destroy() +// textures.floor.colorMap.destroy() +// textures.floor.normalMap.destroy() +// +// device.apply { +// +// destroyPipeline(pipelines.particles) +// destroyPipeline(pipelines.environment) +// +// destroyPipelineLayout(pipelineLayout) +// destroyDescriptorSetLayout(descriptorSetLayout) +// +// unmapMemory(particlesData.memory) +// destroyBuffer(particlesData.buffer) +// freeMemory(particlesData.memory) +// +// uniformBuffers.environment.destroy() +// uniformBuffers.fire.destroy() +// +// models.environment.destroy() +// +// destroySampler(textures.particles.sampler) +// } +// super.destroy() +// } +// +// override fun buildCommandBuffers() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(defaultClearColor) +// it[1].depthStencil(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@CpuParticleSystem.renderPass +// renderArea.offset(0) +// renderArea.extent(size) +// this.clearValues = clearValues +// } +// for (i in drawCmdBuffers.indices) { +// // Set target frame buffer +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// setViewport(size) +// setScissor(size) +// +// // Environment +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSets.environment) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.environment) +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, models.environment.vertices.buffer) +// bindIndexBuffer(models.environment.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// drawIndexed(models.environment.indexCount, 1, 0, 0, 0) +// +// // Particle system (no index buffer) +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSets.particles) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.particles) +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, particlesData.buffer) +// draw(particle.COUNT, 1, 0, 0) +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// +// private fun Particle.transition() = when (type) { +// particle.Type.Flame -> { +// // Flame particles have a chance of turning into smoke +// if (rnd(1f) < 0.05f) { +// alpha = 0f +// color = Vec4(0.25f + rnd(0.25f)) +// pos.x *= 0.5f +// pos.z *= 0.5f +// vel = Vec4(rnd(1f) - rnd(1f), (minVel.y * 2) + rnd(maxVel.y - minVel.y), rnd(1f) - rnd(1f), 0f) +// size_ = 1f + rnd(0.5f) +// rotationSpeed = rnd(1f) - rnd(1f) +// type = particle.Type.Smoke +// } else init(emitterPos) +// } +// // Respawn at end of life +// particle.Type.Smoke -> init(emitterPos) +// } +// +// fun prepareParticles() { +// +// particles += List(particle.COUNT) { +// Particle().apply { +// init(emitterPos) +// alpha = 1f - abs(pos.y) / (FLAME_RADIUS * 2f) +// } +// } +// +// particleBuffer = bufferBig(particleSize * particles.size) +// +// for (i in particles.indices) +// particles[i] to (particleBuffer.adr + particleSize * i) +// +// particlesData.size = particleBuffer.size +// val particlesSize = VkDeviceSize(particlesData.size.L) +// +// vulkanDevice.createBuffer( +// VkBufferUsage.VERTEX_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// particlesSize, +// particlesData::buffer, +// particlesData::memory, +// particleBuffer.adr) +// +// // Map the memory and store the pointer for reuse +// particlesData.mappedMemory = device.mapMemory(particlesData.memory, VkDeviceSize(0), particlesSize) +// } +// +// fun updateParticles() { +// +// val particleTimer = frameTimer * 0.45f +// for (p in particles) { +// when (p.type) { +// particle.Type.Flame -> { +// p.pos.y -= p.vel.y * particleTimer * 3.5f +// p.alpha += particleTimer * 2.5f +// p.size_ -= particleTimer * 0.5f +// } +// particle.Type.Smoke -> { +// p.pos -= p.vel * frameTimer * 1.0f +// p.alpha += particleTimer * 1.25f +// p.size_ += particleTimer * 0.125f +// p.color minusAssign particleTimer * 0.05f +// } +// } +// p.rotation += particleTimer * p.rotationSpeed +// // Transition particle state +// if (p.alpha > 2f) +// p.transition() +// } +// +// memCopy(particleBuffer.adr, particlesData.mappedMemory, particleBuffer.size.L) +// } +// +// fun loadAssets() { +// // Textures +// val (texFormatSuffix, texFormat) = vulkanDevice.features.run { +// when { +// // Get supported compressed texture format +// textureCompressionBC -> "_bc3_unorm" to VkFormat.BC3_UNORM_BLOCK +// textureCompressionASTC_LDR -> "_astc_8x8_unorm" to VkFormat.ASTC_8x8_UNORM_BLOCK +// textureCompressionETC2 -> "_etc2_unorm" to VkFormat.ETC2_R8G8B8_UNORM_BLOCK +// else -> tools.exitFatal("Device does not support any compressed texture format!", ERROR_FEATURE_NOT_PRESENT) +// } +// } +// +// // Particles +// textures.particles.smoke.loadFromFile("$assetPath/textures/particle_smoke.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) +// textures.particles.fire.loadFromFile("$assetPath/textures/particle_fire.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) +// +// // Floor +// textures.floor.colorMap.loadFromFile("$assetPath/textures/fireplace_colormap$texFormatSuffix.ktx", texFormat, vulkanDevice, queue) +// textures.floor.normalMap.loadFromFile("$assetPath/textures/fireplace_normalmap$texFormatSuffix.ktx", texFormat, vulkanDevice, queue) +// +// // Create a custom sampler to be used with the particle textures +// // Create sampler +// val samplerCreateInfo = vk.SamplerCreateInfo { +// magFilter = VkFilter.LINEAR +// minFilter = VkFilter.LINEAR +// mipmapMode = VkSamplerMipmapMode.LINEAR +// // Different address mode +// addressMode = VkSamplerAddressMode.CLAMP_TO_BORDER +// mipLodBias = 0f +// compareOp = VkCompareOp.NEVER +// minLod = 0f +// // Both particle textures have the same number of mip maps +// maxLod = textures.particles.fire.mipLevels.f +// // Enable anisotropic filtering +// maxAnisotropy = 8f +// anisotropyEnable = true +// // Use a different border color (than the normal texture loader) for additive blending +// borderColor = VkBorderColor.FLOAT_TRANSPARENT_BLACK +// } +// textures.particles.sampler = device createSampler samplerCreateInfo +// +// models.environment.loadFromFile("$assetPath/models/fireplace.obj", vertexLayout, 10f, vulkanDevice, queue) +// } +// +// fun setupDescriptorPool() { +// // Example uses one ubo and one image sampler +// val poolSizes = vk.DescriptorPoolSize( +// VkDescriptorType.UNIFORM_BUFFER, 2, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, 4) +// +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) +// +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// // Binding 0 : Vertex shader uniform buffer +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, +// // Binding 1 : Fragment shader image sampler +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1, +// // Binding 1 : Fragment shader image sampler +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 2) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// +// descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) +// +// pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// } +// +// fun setupDescriptorSets() { +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) +// +// descriptorSets.particles = device allocateDescriptorSets allocInfo +// +// // Image descriptor for the color map texture +// val texDescriptorSmoke = vk.DescriptorImageInfo( +// textures.particles.sampler, +// textures.particles.smoke.view, +// VkImageLayout.GENERAL) +// val texDescriptorFire = vk.DescriptorImageInfo( +// textures.particles.sampler, +// textures.particles.fire.view, +// VkImageLayout.GENERAL) +// +// var writeDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0: Vertex shader uniform buffer +// descriptorSets.particles, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.fire.descriptor, +// // Binding 1: Smoke texture +// descriptorSets.particles, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, texDescriptorSmoke, +// // Binding 1: Fire texture array +// descriptorSets.particles, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 2, texDescriptorFire) +// +// device updateDescriptorSets writeDescriptorSets +// +// // Environment +// descriptorSets.environment = device allocateDescriptorSets allocInfo +// +// writeDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0: Vertex shader uniform buffer +// descriptorSets.environment, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBuffers.environment.descriptor, +// // Binding 1: Color map +// descriptorSets.environment, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textures.floor.colorMap.descriptor, +// // Binding 2: Normal map +// descriptorSets.environment, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 2, textures.floor.normalMap.descriptor) +// +// device updateDescriptorSets writeDescriptorSets +// } +// +// fun preparePipelines() { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.POINT_LIST, 0, false) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.BACK_BIT.i, VkFrontFace.CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// // Load shaders +// val shaderStages = vk.PipelineShaderStageCreateInfo(2) +// +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// } +// // Particle rendering pipeline +// run { +// // Shaders +// shaderStages[0].loadShader("$assetPath/shaders/particlefire/particle.vert.spv", VkShaderStage.VERTEX_BIT) +// shaderStages[1].loadShader("$assetPath/shaders/particlefire/particle.frag.spv", VkShaderStage.FRAGMENT_BIT) +// +// // Vertex input state +// val vertexInputBinding = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, particleSize, VkVertexInputRate.VERTEX) +// +// val vertexInputAttributes = vk.VertexInputAttributeDescription( +// VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32A32_SFLOAT, 0, // Location 0: Position +// VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32A32_SFLOAT, Vec4.size, // Location 1: Color +// VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32_SFLOAT, Vec4.size * 2, // Location 2: Alpha +// VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32_SFLOAT, Vec4.size * 2 + Float.BYTES, // Location 3: Size +// VERTEX_BUFFER_BIND_ID, 4, VkFormat.R32_SFLOAT, Vec4.size * 2 + Float.BYTES * 2, // Location 4: Rotation +// VERTEX_BUFFER_BIND_ID, 5, VkFormat.R32_SINT, Vec4.size * 2 + Float.BYTES * 3) // Location 5: Particle type +// +// val vertexInputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertexInputBinding +// vertexAttributeDescriptions = vertexInputAttributes +// } +// pipelineCreateInfo.vertexInputState = vertexInputState +// +// // Dont' write to depth buffer +// depthStencilState.depthWriteEnable = false +// +// // Premulitplied alpha +// blendAttachmentState.apply { +// blendEnable = true +// srcColorBlendFactor = VkBlendFactor.ONE +// dstColorBlendFactor = VkBlendFactor.ONE_MINUS_SRC_ALPHA +// colorBlendOp = VkBlendOp.ADD +// srcAlphaBlendFactor = VkBlendFactor.ONE +// dstAlphaBlendFactor = VkBlendFactor.ZERO +// alphaBlendOp = VkBlendOp.ADD +// colorWriteMask = VkColorComponent.R_BIT or VkColorComponent.G_BIT or VkColorComponent.B_BIT or VkColorComponent.A_BIT +// } +// pipelines.particles = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// +// // Environment rendering pipeline (normal mapped) +// run { +// // Shaders +// shaderStages[0].loadShader("$assetPath/shaders/particlefire/normalmap.vert.spv", VkShaderStage.VERTEX_BIT) +// shaderStages[1].loadShader("$assetPath/shaders/particlefire/normalmap.frag.spv", VkShaderStage.FRAGMENT_BIT) +// +// // Vertex input state +// val vertexInputBinding = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, vertexLayout.stride, VkVertexInputRate.VERTEX) +// +// val vertexInputAttributes = vk.VertexInputAttributeDescription( +// VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, 0, // Location 0: Position +// VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32_SFLOAT, Vec3.size, // Location 1: UV +// VERTEX_BUFFER_BIND_ID, 2, VkFormat.R32G32B32_SFLOAT, Vec3.size + Vec2.size, // Location 2: Normal +// VERTEX_BUFFER_BIND_ID, 3, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2 + Vec2.size, // Location 3: Tangent +// VERTEX_BUFFER_BIND_ID, 4, VkFormat.R32G32B32_SFLOAT, Vec3.size * 3 + Vec2.size) // Location 4: Bitangen +// +// val vertexInputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertexInputBinding +// vertexAttributeDescriptions = vertexInputAttributes +// } +// pipelineCreateInfo.vertexInputState = vertexInputState +// +// blendAttachmentState.blendEnable = false +// depthStencilState.depthWriteEnable = true +// inputAssemblyState.topology = VkPrimitiveTopology.TRIANGLE_LIST +// +// pipelines.environment = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// } +// +// /** Prepare and initialize uniform buffer containing shader uniforms */ +// fun prepareUniformBuffers() { +// // Vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBuffers.fire, +// VkDeviceSize(uboVS.size.L)) +// +// // Vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBuffers.environment, +// VkDeviceSize(uboEnv.size.L)) +// +// // Map persistent +// uniformBuffers.fire.map() +// uniformBuffers.environment.map() +// +// updateUniformBuffers() +// } +// +// fun updateUniformBufferLight() { +// // Environment +// uboEnv.lightPos.x = sin(timer * 2f * glm.PIf) * 1.5f +// uboEnv.lightPos.y = 0f +// uboEnv.lightPos.z = cos(timer * 2f * glm.PIf) * 1.5f +// uboEnv to uniformBuffers.environment.mapped +// } +// +// fun updateUniformBuffers() { +// // Vertex shader +// uboVS.projection = glm.perspective(60f.rad, size.aspect, 0.001f, 256f) +// val viewMatrix = glm.translate(Mat4(), 0f, 0f, zoom) +// +// uboVS.model = viewMatrix * glm.translate(uboVS.model, 0f, 15f, 0f) +// .rotateAssign(rotation.x.rad, 1f, 0f, 0f) +// .rotateAssign(rotation.y.rad, 0f, 1f, 0f) +// .rotateAssign(rotation.z.rad, 0f, 0f, 1f) +// +// uboVS.viewportDim put size +// uboVS to uniformBuffers.fire.mapped +// +// // Environment +// uboEnv.projection = uboVS.projection +// uboEnv.model = uboVS.model +//// uboEnv.normal = glm.inverseTranspose(uboEnv.model) +// uboEnv.normal = uboEnv.model.inverse().transposeAssign() +// uboEnv.cameraPos = Vec4(0f, 0f, zoom, 0f) +// uboEnv to uniformBuffers.environment.mapped +// } +// +// fun draw() { +// +// super.prepareFrame() +// +// // Command buffer to be sumitted to the queue +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// +// // Submit to queue +// queue submit submitInfo +// +// super.submitFrame() +// } +// +// override fun prepare() { +// super.prepare() +// loadAssets() +// prepareParticles() +// prepareUniformBuffers() +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSets() +// buildCommandBuffers() +// prepared = true +// window.show() +// } +// +// override fun render() { +// if (!prepared) +// return +// draw() +// if (!paused) { +// updateUniformBufferLight() +// updateParticles() +// } +// } +// +// override fun viewChanged() = updateUniformBuffers() +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/basics/15 Stencil Buffer.kt b/src/main/kotlin/vulkan/basics/15 Stencil Buffer.kt index b1d41d2..666dbb4 100644 --- a/src/main/kotlin/vulkan/basics/15 Stencil Buffer.kt +++ b/src/main/kotlin/vulkan/basics/15 Stencil Buffer.kt @@ -1,304 +1,303 @@ -package vulkan.basics - -import glm_.L -import glm_.mat4x4.Mat4 -import glm_.vec3.Vec3 -import glm_.vec4.Vec4 -import org.lwjgl.system.MemoryUtil.NULL -import org.lwjgl.system.MemoryUtil.memCopy -import vkk.* -import vulkan.assetPath -import vulkan.base.* - -/* -* Vulkan Example - Rendering outlines using the stencil buffer -* -* Copyright (C) 2016-2017 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -fun main(args: Array) { - StencilBuffer().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - -private class StencilBuffer : VulkanExampleBase() { - - // Vertex layout for the models - val vertexLayout = VertexLayout( - VertexComponent.POSITION, - VertexComponent.COLOR, - VertexComponent.NORMAL) - - val model = Model() - - object uboVS : Bufferizable() { - var projection = Mat4() - var model = Mat4() - val lightPos = Vec4(0f, -2f, 1f, 0f) - // Vertex shader extrudes model by this value along normals for outlining - var outlineWidth = 0.05f - } - - val uniformBufferVS = Buffer() - - object pipelines { - var stencil: VkPipeline = NULL - var outline: VkPipeline = NULL - } - - var pipelineLayout: VkPipelineLayout = NULL - var descriptorSet: VkDescriptorSet = NULL - var descriptorSetLayout: VkDescriptorSetLayout = NULL - - init { - title = "Stencil buffer outlines" - timerSpeed *= 0.25f - camera.type = Camera.CameraType.lookAt - camera.setPerspective(60f, size.aspect, 0.1f, 512f) - camera.setRotation(Vec3(2.5f, -35f, 0f)) - camera.setTranslation(Vec3(0.08f, 3.6f, -8.4f)) -// settings.overlay = true - } - - override fun destroy() { - super.destroy() - - device.apply { - destroyPipeline(pipelines.stencil) - destroyPipeline(pipelines.outline) - - destroyPipelineLayout(pipelineLayout) - - destroyDescriptorSetLayout(descriptorSetLayout) - } - model.destroy() - uniformBufferVS.destroy() - } - - override fun buildCommandBuffers() { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(defaultClearColor) - it[1].depthStencil(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@StencilBuffer.renderPass - renderArea.offset(0) - renderArea.extent(size) - this.clearValues = clearValues - } - for (i in drawCmdBuffers.indices) { - - renderPassBeginInfo.framebuffer(frameBuffers[i]) // bug - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - setViewport(size) - setScissor(size) - - bindVertexBuffers(model.vertices.buffer) - bindIndexBuffer(model.indices.buffer, 0, VkIndexType.UINT32) - - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) - - // First pass renders object (toon shaded) and fills stencil buffer - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.stencil) - drawIndexed(model.indexCount, 1, 0, 0, 0) - - // Second pass renders scaled object only where stencil was not set by first pass - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.outline) - drawIndexed(model.indexCount, 1, 0, 0, 0) - - endRenderPass() - - end() - } - } - } - - fun loadAssets() { - model.loadFromFile("$assetPath/models/venus.fbx", vertexLayout, 0.3f, vulkanDevice, queue) - } - - fun setupDescriptorPool() { - - val poolSize = vk.DescriptorPoolSize(VkDescriptorType.UNIFORM_BUFFER, 1) - - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSize, 1) - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - - val setLayoutBinding = vk.DescriptorSetLayoutBinding( - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0) - - val descriptorLayoutInfo = vk.DescriptorSetLayoutCreateInfo(setLayoutBinding) - descriptorSetLayout = device createDescriptorSetLayout descriptorLayoutInfo - - val pipelineLayoutInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) - pipelineLayout = device createPipelineLayout pipelineLayoutInfo - } - - fun setupDescriptorSet() { - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) - descriptorSet = device allocateDescriptorSets allocInfo - val modelWriteDescriptorSets = vk.WriteDescriptorSet( - descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBufferVS.descriptor) - device updateDescriptorSets modelWriteDescriptorSets - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.FRONT_BIT.i, VkFrontFace.CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - val shaderStages = vk.PipelineShaderStageCreateInfo(2) - - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass) - - // Vertex bindings an attributes - val vertexInputBinding = vk.VertexInputBindingDescription(0, vertexLayout.stride, VkVertexInputRate.VERTEX) - - val vertexInputAttributes = vk.VertexInputAttributeDescription( - 0, 0, VkFormat.R32G32B32_SFLOAT, 0, // Location 0: Position - 0, 1, VkFormat.R32G32B32_SFLOAT, Vec3.size, // Location 1: Color - 0, 2, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2) // Location 2: Normal - - val vertexInputState = vk.PipelineVertexInputStateCreateInfo().apply { - vertexBindingDescription = vertexInputBinding - vertexAttributeDescriptions = vertexInputAttributes - } - pipelineCreateInfo.also { - it.vertexInputState = vertexInputState - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - } - // Toon render and stencil fill pass - shaderStages[0].loadShader("$assetPath/shaders/stencilbuffer/toon.vert.spv", VkShaderStage.VERTEX_BIT) - shaderStages[1].loadShader("$assetPath/shaders/stencilbuffer/toon.frag.spv", VkShaderStage.FRAGMENT_BIT) - - rasterizationState.cullMode = VkCullMode.NONE.i - - depthStencilState.apply { - stencilTestEnable = true - - back.apply { - compareOp = VkCompareOp.ALWAYS - failOp = VkStencilOp.REPLACE - depthFailOp = VkStencilOp.REPLACE - passOp = VkStencilOp.REPLACE - compareMask = 0xff - writeMask = 0xff - reference = 1 - } - front = back - } - pipelines.stencil = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - - // Outline pass - depthStencilState.apply { - back.apply { - compareOp = VkCompareOp.NOT_EQUAL - failOp = VkStencilOp.KEEP - depthFailOp = VkStencilOp.KEEP - passOp = VkStencilOp.REPLACE - } - front = back - depthTestEnable = false - } - shaderStages[0].loadShader("$assetPath/shaders/stencilbuffer/outline.vert.spv", VkShaderStage.VERTEX_BIT) - shaderStages[1].loadShader("$assetPath/shaders/stencilbuffer/outline.frag.spv", VkShaderStage.FRAGMENT_BIT) - pipelines . outline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - // Prepare and initialize uniform buffer containing shader uniforms - fun prepareUniformBuffers() { - // Mesh vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBufferVS, - uboVS.size.L) - - // Map persistent - uniformBufferVS.map() - - updateUniformBuffers() - } - - fun updateUniformBuffers() { - uboVS.projection = camera.matrices.perspective - uboVS.model = camera.matrices.view - uboVS to uniformBufferVS.mapped - } - - fun draw() { - - super.prepareFrame() - - submitInfo.commandBuffer = drawCmdBuffers [currentBuffer] - queue submit submitInfo - - super.submitFrame() - } - - override fun prepare() { - super.prepare() - loadAssets() - prepareUniformBuffers() - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSet() - buildCommandBuffers() - prepared = true - } - - override fun render() { - if (!prepared) - return - draw() - } - - override fun viewChanged() = updateUniformBuffers() - -// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { -// if (overlay->header("Settings")) -// if (overlay->inputFloat("Outline width", &uboVS.outlineWidth, 0.05f, 2)) +//package vulkan.basics +// +//import glm_.L +//import glm_.mat4x4.Mat4 +//import glm_.vec3.Vec3 +//import glm_.vec4.Vec4 +//import org.lwjgl.system.MemoryUtil.NULL +//import vkk.* +//import vulkan.assetPath +//import vulkan.base.* +// +///* +//* Vulkan Example - Rendering outlines using the stencil buffer +//* +//* Copyright (C) 2016-2017 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +//fun main(args: Array) { +// StencilBuffer().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +//private class StencilBuffer : VulkanExampleBase() { +// +// // Vertex layout for the models +// val vertexLayout = VertexLayout( +// VertexComponent.POSITION, +// VertexComponent.COLOR, +// VertexComponent.NORMAL) +// +// val model = Model() +// +// object uboVS : Bufferizable() { +// var projection = Mat4() +// var model = Mat4() +// val lightPos = Vec4(0f, -2f, 1f, 0f) +// // Vertex shader extrudes model by this value along normals for outlining +// var outlineWidth = 0.05f +// } +// +// val uniformBufferVS = Buffer() +// +// object pipelines { +// var stencil = VkPipeline(NULL) +// var outline = VkPipeline(NULL) +// } +// +// var pipelineLayout = VkPipelineLayout(NULL) +// var descriptorSet = VkDescriptorSet(NULL) +// var descriptorSetLayout = VkDescriptorSetLayout(NULL) +// +// init { +// title = "Stencil buffer outlines" +// timerSpeed *= 0.25f +// camera.type = Camera.CameraType.lookAt +// camera.setPerspective(60f, size.aspect, 0.1f, 512f) +// camera.setRotation(Vec3(2.5f, -35f, 0f)) +// camera.setTranslation(Vec3(0.08f, 3.6f, -8.4f)) +//// settings.overlay = true +// } +// +// override fun destroy() { +// super.destroy() +// +// device.apply { +// destroyPipeline(pipelines.stencil) +// destroyPipeline(pipelines.outline) +// +// destroyPipelineLayout(pipelineLayout) +// +// destroyDescriptorSetLayout(descriptorSetLayout) +// } +// model.destroy() +// uniformBufferVS.destroy() +// } +// +// override fun buildCommandBuffers() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(defaultClearColor) +// it[1].depthStencil(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@StencilBuffer.renderPass +// renderArea.offset(0) +// renderArea.extent(size) +// this.clearValues = clearValues +// } +// for (i in drawCmdBuffers.indices) { +// +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) // bug +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// setViewport(size) +// setScissor(size) +// +// bindVertexBuffers(model.vertices.buffer) +// bindIndexBuffer(model.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) +// +// // First pass renders object (toon shaded) and fills stencil buffer +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.stencil) +// drawIndexed(model.indexCount, 1, 0, 0, 0) +// +// // Second pass renders scaled object only where stencil was not set by first pass +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipelines.outline) +// drawIndexed(model.indexCount, 1, 0, 0, 0) +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// fun loadAssets() { +// model.loadFromFile("$assetPath/models/venus.fbx", vertexLayout, 0.3f, vulkanDevice, queue) +// } +// +// fun setupDescriptorPool() { +// +// val poolSize = vk.DescriptorPoolSize(VkDescriptorType.UNIFORM_BUFFER, 1) +// +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSize, 1) +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// +// val setLayoutBinding = vk.DescriptorSetLayoutBinding( +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0) +// +// val descriptorLayoutInfo = vk.DescriptorSetLayoutCreateInfo(setLayoutBinding) +// descriptorSetLayout = device createDescriptorSetLayout descriptorLayoutInfo +// +// val pipelineLayoutInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) +// pipelineLayout = device createPipelineLayout pipelineLayoutInfo +// } +// +// fun setupDescriptorSet() { +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) +// descriptorSet = device allocateDescriptorSets allocInfo +// val modelWriteDescriptorSets = vk.WriteDescriptorSet( +// descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBufferVS.descriptor) +// device updateDescriptorSets modelWriteDescriptorSets +// } +// +// fun preparePipelines() { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.FRONT_BIT.i, VkFrontFace.CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// val shaderStages = vk.PipelineShaderStageCreateInfo(2) +// +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass) +// +// // Vertex bindings an attributes +// val vertexInputBinding = vk.VertexInputBindingDescription(0, vertexLayout.stride, VkVertexInputRate.VERTEX) +// +// val vertexInputAttributes = vk.VertexInputAttributeDescription( +// 0, 0, VkFormat.R32G32B32_SFLOAT, 0, // Location 0: Position +// 0, 1, VkFormat.R32G32B32_SFLOAT, Vec3.size, // Location 1: Color +// 0, 2, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2) // Location 2: Normal +// +// val vertexInputState = vk.PipelineVertexInputStateCreateInfo().apply { +// vertexBindingDescription = vertexInputBinding +// vertexAttributeDescriptions = vertexInputAttributes +// } +// pipelineCreateInfo.also { +// it.vertexInputState = vertexInputState +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// } +// // Toon render and stencil fill pass +// shaderStages[0].loadShader("$assetPath/shaders/stencilbuffer/toon.vert.spv", VkShaderStage.VERTEX_BIT) +// shaderStages[1].loadShader("$assetPath/shaders/stencilbuffer/toon.frag.spv", VkShaderStage.FRAGMENT_BIT) +// +// rasterizationState.cullMode = VkCullMode.NONE.i +// +// depthStencilState.apply { +// stencilTestEnable = true +// +// back.apply { +// compareOp = VkCompareOp.ALWAYS +// failOp = VkStencilOp.REPLACE +// depthFailOp = VkStencilOp.REPLACE +// passOp = VkStencilOp.REPLACE +// compareMask = 0xff +// writeMask = 0xff +// reference = 1 +// } +// front = back +// } +// pipelines.stencil = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// +// // Outline pass +// depthStencilState.apply { +// back.apply { +// compareOp = VkCompareOp.NOT_EQUAL +// failOp = VkStencilOp.KEEP +// depthFailOp = VkStencilOp.KEEP +// passOp = VkStencilOp.REPLACE +// } +// front = back +// depthTestEnable = false +// } +// shaderStages[0].loadShader("$assetPath/shaders/stencilbuffer/outline.vert.spv", VkShaderStage.VERTEX_BIT) +// shaderStages[1].loadShader("$assetPath/shaders/stencilbuffer/outline.frag.spv", VkShaderStage.FRAGMENT_BIT) +// pipelines.outline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// +// // Prepare and initialize uniform buffer containing shader uniforms +// fun prepareUniformBuffers() { +// // Mesh vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBufferVS, +// VkDeviceSize(uboVS.size.L)) +// +// // Map persistent +// uniformBufferVS.map() +// // updateUniformBuffers() // } -} +// +// fun updateUniformBuffers() { +// uboVS.projection = camera.matrices.perspective +// uboVS.model = camera.matrices.view +// uboVS to uniformBufferVS.mapped +// } +// +// fun draw() { +// +// super.prepareFrame() +// +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// queue submit submitInfo +// +// super.submitFrame() +// } +// +// override fun prepare() { +// super.prepare() +// loadAssets() +// prepareUniformBuffers() +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSet() +// buildCommandBuffers() +// prepared = true +// } +// +// override fun render() { +// if (!prepared) +// return +// draw() +// } +// +// override fun viewChanged() = updateUniformBuffers() +// +//// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) { +//// if (overlay->header("Settings")) +//// if (overlay->inputFloat("Outline width", &uboVS.outlineWidth, 0.05f, 2)) +//// updateUniformBuffers() +//// } +//} diff --git a/src/main/kotlin/vulkan/computeShader/01 Image Processing.kt b/src/main/kotlin/vulkan/computeShader/01 Image Processing.kt index 667dbe8..7daf7b2 100644 --- a/src/main/kotlin/vulkan/computeShader/01 Image Processing.kt +++ b/src/main/kotlin/vulkan/computeShader/01 Image Processing.kt @@ -1,631 +1,632 @@ -/* -* Vulkan Example - Compute shader image processing -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -package vulkan.computeShader - -import ab.appBuffer -import glm_.L -import glm_.buffer.bufferBig -import glm_.f -import glm_.func.rad -import glm_.glm -import glm_.mat4x4.Mat4 -import glm_.vec2.Vec2 -import glm_.vec2.Vec2i -import glm_.vec3.Vec3 -import org.lwjgl.system.MemoryUtil.* -import org.lwjgl.vulkan.* -import uno.kotlin.buffers.capacity -import vkk.* -import vulkan.VERTEX_BUFFER_BIND_ID -import vulkan.assetPath -import vulkan.base.* -import vulkan.base.tools.VK_FLAGS_NONE - - -fun main(args: Array) { - ImageProcessing().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - -// Vertex layout for this example -private val Vertex = object { - // float pos[3]; -// float uv[2]; - val size = Vec3.size + Vec2.size - val offPos = 0 - val offUv = Vec3.size -} - -private class ImageProcessing : VulkanExampleBase() { - - val textureColorMap = Texture2D() - val textureComputeTarget = Texture2D() - - private val vertices = object { - lateinit var inputState: VkPipelineVertexInputStateCreateInfo - lateinit var bindingDescriptions: VkVertexInputBindingDescription - lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer - } - - /** Resources for the graphics part of the example */ - private val graphics = object { - var descriptorSetLayout: VkDescriptorSetLayout = NULL // Image display shader binding layout - var descriptorSetPreCompute: VkDescriptorSet = NULL // Image display shader bindings before compute shader image manipulation - var descriptorSetPostCompute: VkDescriptorSet = NULL // Image display shader bindings after compute shader image manipulation - var pipeline: VkPipeline = NULL // Image display pipeline - var pipelineLayout: VkPipelineLayout = NULL // Layout of the graphics pipeline - } - - /** Resources for the compute part of the example */ - private val compute = object { - lateinit var queue: VkQueue // Separate queue for compute commands (queue family may differ from the one used for graphics) - var commandPool: VkCommandPool = NULL // Use a separate command pool (queue family may differ from the one used for graphics) - lateinit var commandBuffer: VkCommandBuffer // Command buffer storing the dispatch commands and barriers - var fence: VkFence = NULL // Synchronization fence to avoid rewriting compute CB if still in use - var descriptorSetLayout: VkDescriptorSetLayout = NULL // Compute shader binding layout - var descriptorSet: VkDescriptorSet = NULL // Compute shader bindings - var pipelineLayout: VkPipelineLayout = NULL // Layout of the compute pipeline - val pipelines = ArrayList() // Compute pipelines for image filters - var pipelineIndex = 0 // Current image filtering compute pipeline index - var queueFamilyIndex = 0 // Family index of the graphics queue, used for barriers - } - - val vertexBuffer = Buffer() - var indexBuffer = Buffer() - var indexCount = 0 - - var uniformBufferVS = Buffer() - - private val uboVS = object { - var projection = Mat4() - var model = Mat4() - - fun pack() { - projection to buffer - model.to(buffer, Mat4.size) - } - - val size = Mat4.size * 2 - val buffer = bufferBig(size) - val address = memAddress(buffer) - } - - var vertexBufferSize = 0 - - val shaderNames = ArrayList() - - init { - zoom = -2.0f - title = "Compute shader image load/store" -// settings.overlay = true - } - - override fun destroy() { - device.apply { - // Graphics - destroyPipeline(graphics.pipeline) - destroyPipelineLayout(graphics.pipelineLayout) - destroyDescriptorSetLayout(graphics.descriptorSetLayout) - - // Compute - for (pipeline in compute.pipelines) - destroyPipeline(pipeline) - destroyPipelineLayout(compute.pipelineLayout) - destroyDescriptorSetLayout(compute.descriptorSetLayout) - destroyFence(compute.fence) - destroyCommandPool(compute.commandPool) - } - vertexBuffer.destroy() - indexBuffer.destroy() - uniformBufferVS.destroy() - - textureColorMap.destroy() - textureComputeTarget.destroy() - - super.destroy() - } - - /** Prepare a texture target that is used to store compute shader calculations */ - fun prepareTextureTarget(tex: Texture, size: Vec2i, format: VkFormat) { - - // Get device properties for the requested texture format - val formatProperties = physicalDevice getFormatProperties format - // Check if requested image format supports image storage operations - assert(formatProperties.optimalTilingFeatures has VkFormatFeature.STORAGE_IMAGE_BIT) - - // Prepare blit target texture - tex.size(size) - - val imageCreateInfo = vk.ImageCreateInfo { - imageType = VkImageType.`2D` - this.format = format - extent.set(size.x, size.y, 1) - mipLevels = 1 - arrayLayers = 1 - samples = VkSampleCount.`1_BIT` - tiling = VkImageTiling.OPTIMAL - // Image will be sampled in the fragment shader and used as storage target in the compute shader - usage = VkImageUsage.SAMPLED_BIT or VkImageUsage.STORAGE_BIT - flags = 0 - // Sharing mode exclusive means that ownership of the image does not need to be explicitly transferred between the compute and graphics queue - sharingMode = VkSharingMode.EXCLUSIVE - } - - tex.image = device createImage imageCreateInfo - - val memReqs = device getImageMemoryRequirements tex.image - val memAllocInfo = vk.MemoryAllocateInfo { - allocationSize = memReqs.size - memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) - } - tex.deviceMemory = device allocateMemory memAllocInfo - device.bindImageMemory(tex.image, tex.deviceMemory) - - val layoutCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) - - tex.imageLayout = VkImageLayout.GENERAL - tools.setImageLayout( - layoutCmd, tex.image, - VkImageAspect.COLOR_BIT.i, - VkImageLayout.UNDEFINED, - tex.imageLayout) - - super.flushCommandBuffer(layoutCmd, queue, true) - - // Create sampler - val sampler = vk.SamplerCreateInfo { - magFilter = VkFilter.LINEAR - minFilter = VkFilter.LINEAR - mipmapMode = VkSamplerMipmapMode.LINEAR - addressModeU = VkSamplerAddressMode.CLAMP_TO_BORDER - addressModeV = addressModeU - addressModeW = addressModeU - mipLodBias = 0f - maxAnisotropy = 1f - compareOp = VkCompareOp.NEVER - minLod = 0f - maxLod = tex.mipLevels.f - borderColor = VkBorderColor.FLOAT_OPAQUE_WHITE - } - tex.sampler = device createSampler sampler - - // Create image view - val view = vk.ImageViewCreateInfo { - image = NULL - viewType = VkImageViewType.`2D` - this.format = format - components(VkComponentSwizzle.R, VkComponentSwizzle.G, VkComponentSwizzle.B, VkComponentSwizzle.A) - subresourceRange.set(VkImageAspect.COLOR_BIT.i, 0, 1, 0, 1) - image = tex.image - } - tex.view = device createImageView view - - // Initialize a descriptor for later use - tex.descriptor.imageLayout = tex.imageLayout - tex.descriptor.imageView = tex.view - tex.descriptor.sampler = tex.sampler - tex.device = vulkanDevice - } - - fun loadAssets() { - textureColorMap.loadFromFile( - "$assetPath/textures/vulkan_11_rgba.ktx", - VkFormat.R8G8B8A8_UNORM, - vulkanDevice, queue, - VkImageUsage.SAMPLED_BIT or VkImageUsage.STORAGE_BIT, - VkImageLayout.GENERAL) - } - - override fun buildCommandBuffers() { - // Destroy command buffers if already present - if (!checkCommandBuffers()) { - destroyCommandBuffers() - createCommandBuffers() - } - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(defaultClearColor) - it[1].depthStencil.set(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@ImageProcessing.renderPass - renderArea.apply { - offset.set(0, 0) - extent.set(size.x, size.y) - } - this.clearValues = clearValues - } - for (i in drawCmdBuffers.indices) { - // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - // Image memory barrier to make sure that compute shader writes are finished before sampling from the texture - val imageMemoryBarrier = vk.ImageMemoryBarrier { - // We won't be changing the layout of the image - oldLayout = VkImageLayout.GENERAL - newLayout = VkImageLayout.GENERAL - image = textureComputeTarget.image - subresourceRange.set(VkImageAspect.COLOR_BIT.i, 0, 1, 0, 1) - srcAccessMask = VkAccess.SHADER_WRITE_BIT.i - dstAccessMask = VkAccess.SHADER_READ_BIT.i - } - pipelineBarrier( - VkPipelineStage.COMPUTE_SHADER_BIT.i, - VkPipelineStage.FRAGMENT_SHADER_BIT.i, - VK_FLAGS_NONE, - imageMemoryBarrier = imageMemoryBarrier) - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - val viewport = vk.Viewport(size.x * 0.5f, size.y.f) - setViewport(viewport) - - setScissor(size) - - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, vertexBuffer.buffer) - bindIndexBuffer(indexBuffer.buffer, 0, VkIndexType.UINT32) - - // Left (pre compute) - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, graphics.pipelineLayout, graphics.descriptorSetPreCompute) - bindPipeline(VkPipelineBindPoint.GRAPHICS, graphics.pipeline) - - drawIndexed(indexCount, 1, 0, 0, 0) - - // Right (post compute) - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, graphics.pipelineLayout, graphics.descriptorSetPostCompute) - bindPipeline(VkPipelineBindPoint.GRAPHICS, graphics.pipeline) - - viewport.x = size.x / 2f - setViewport(viewport) - drawIndexed(indexCount, 1, 0, 0, 0) - - endRenderPass() - - end() - } - } - } - - fun buildComputeCommandBuffer() { - // Flush the queue if we're rebuilding the command buffer after a pipeline change to ensure it's not currently in use - compute.queue.waitIdle() - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - compute.commandBuffer.apply { - - begin(cmdBufInfo) - - bindPipeline(VkPipelineBindPoint.COMPUTE, compute.pipelines[compute.pipelineIndex]) - bindDescriptorSets(VkPipelineBindPoint.COMPUTE, compute.pipelineLayout, compute.descriptorSet) - - compute.commandBuffer.dispatch(textureComputeTarget.size / 16, 1) - - end() - } - } - - /** Setup vertices for a single uv-mapped quad */ - fun generateQuad() { - // Setup vertices for a single uv-mapped quad made from two triangles - val vertices = appBuffer.floatBufferOf( - +1f, +1f, 0f, 1f, 1f, - -1f, +1f, 0f, 0f, 1f, - -1f, -1f, 0f, 0f, 0f, - +1f, -1f, 0f, 1f, 0f) - - // Setup indices - val indices = appBuffer.intBufferOf(0, 1, 2, 2, 3, 0) - indexCount = indices.capacity - - // Create buffers - // For the sake of simplicity we won't stage the vertex data to the gpu memory - // Vertex buffer - vulkanDevice.createBuffer( - VkBufferUsage.VERTEX_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - vertexBuffer, - vertices) - // Index buffer - vulkanDevice.createBuffer( - VkBufferUsage.INDEX_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - indexBuffer, - indices) - } - - fun setupVertexDescriptions() { - // Binding description - vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, Vertex.size, VkVertexInputRate.VERTEX) - - // Attribute descriptions - // Describes memory layout and shader positions - vertices.attributeDescriptions = vk.VertexInputAttributeDescription( - // Location 0: Position - VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, Vertex.offPos, - // Location 1: Texture coordinates - VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32_SFLOAT, Vertex.offUv) - - // Assign to vertex buffer - vertices.inputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertices.bindingDescriptions - vertexAttributeDescriptions = vertices.attributeDescriptions - } - } - - fun setupDescriptorPool() { - - val poolSizes = vk.DescriptorPoolSize( - // Graphics pipelines uniform buffers - VkDescriptorType.UNIFORM_BUFFER, 2, - // Graphics pipelines image samplers for displaying compute output image - VkDescriptorType.COMBINED_IMAGE_SAMPLER, 2, - // Compute pipelines uses a storage image for image reads and writes - VkDescriptorType.STORAGE_IMAGE, 2) - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 3) - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - // Binding 0: Vertex shader uniform buffer - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, - // Binding 1: Fragment shader input image - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - graphics.descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(graphics.descriptorSetLayout) - graphics.pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - } - - fun setupDescriptorSet() { - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, graphics.descriptorSetLayout) - - // Input image (before compute post processing) - graphics.descriptorSetPreCompute = device allocateDescriptorSets allocInfo - val baseImageWriteDescriptorSets = vk.WriteDescriptorSet( - graphics.descriptorSetPreCompute, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBufferVS.descriptor, - graphics.descriptorSetPreCompute, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textureColorMap.descriptor) - - device updateDescriptorSets baseImageWriteDescriptorSets - - // Final image (after compute shader processing) - graphics.descriptorSetPostCompute = device allocateDescriptorSets allocInfo - val writeDescriptorSets = vk.WriteDescriptorSet( - graphics.descriptorSetPostCompute, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBufferVS.descriptor, - graphics.descriptorSetPostCompute, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textureComputeTarget.descriptor) - - device updateDescriptorSets writeDescriptorSets - - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - // Rendering pipeline - // Load shaders - val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { - it[0].loadShader("$assetPath/shaders/computeshader/texture.vert.spv", VkShaderStage.VERTEX_BIT) - it[1].loadShader("$assetPath/shaders/computeshader/texture.frag.spv", VkShaderStage.FRAGMENT_BIT) - } - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(graphics.pipelineLayout, renderPass).also { - it.vertexInputState = vertices.inputState - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - it.renderPass = renderPass - } - graphics.pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - /** Find and create a compute capable device queue */ - fun getComputeQueue() { - - val queueFamilyProperties = physicalDevice.queueFamilyProperties - - // Some devices have dedicated compute queues, so we first try to find a queue that supports compute and not graphics - var computeQueueFound = false - for (i in queueFamilyProperties.indices) - if (queueFamilyProperties[i].queueFlags has VkQueueFlag.COMPUTE_BIT && queueFamilyProperties[i].queueFlags hasnt VkQueueFlag.GRAPHICS_BIT) { - compute.queueFamilyIndex = i - computeQueueFound = true - break - } - // If there is no dedicated compute queue, just find the first queue family that supports compute - if (!computeQueueFound) - for (i in queueFamilyProperties.indices) { - if (queueFamilyProperties[i].queueFlags has VkQueueFlag.COMPUTE_BIT) { - compute.queueFamilyIndex = i - computeQueueFound = true - break - } - } - - // Compute is mandatory in Vulkan, so there must be at least one queue family that supports compute - assert(computeQueueFound) - // Get a compute queue from the device - compute.queue = device getQueue compute.queueFamilyIndex - } - - fun prepareCompute() { - - getComputeQueue() - - // Create compute pipeline - // Compute pipelines are created separate from graphics pipelines even if they use the same queue - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - // Binding 0: Input image (read-only) - VkDescriptorType.STORAGE_IMAGE, VkShaderStage.COMPUTE_BIT.i, 0, - // Binding 1: Output image (write) - VkDescriptorType.STORAGE_IMAGE, VkShaderStage.COMPUTE_BIT.i, 1) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - compute.descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(compute.descriptorSetLayout) - - compute.pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, compute.descriptorSetLayout) - - compute.descriptorSet = device allocateDescriptorSets allocInfo - val computeWriteDescriptorSets = vk.WriteDescriptorSet( - compute.descriptorSet, VkDescriptorType.STORAGE_IMAGE, 0, textureColorMap.descriptor, - compute.descriptorSet, VkDescriptorType.STORAGE_IMAGE, 1, textureComputeTarget.descriptor) - - device updateDescriptorSets computeWriteDescriptorSets - - // Create compute shader pipelines - val computePipelineCreateInfo = vk.ComputePipelineCreateInfo(compute.pipelineLayout) - - // One pipeline for each effect - shaderNames += listOf("emboss", "edgedetect", "sharpen") - for (shaderName in shaderNames) { - val fileName = "$assetPath/shaders/computeshader/$shaderName.comp.spv" - computePipelineCreateInfo.stage.loadShader(fileName, VkShaderStage.COMPUTE_BIT) - val pipeline = device.createComputePipelines(pipelineCache, computePipelineCreateInfo) - compute.pipelines += pipeline - } - // Separate command pool as queue family for compute may be different than graphics - val cmdPoolInfo = vk.CommandPoolCreateInfo { - queueFamilyIndex = compute.queueFamilyIndex - flags = VkCommandPoolCreate.RESET_COMMAND_BUFFER_BIT.i - } - compute.commandPool = device createCommandPool cmdPoolInfo - - // Create a command buffer for compute operations - val cmdBufAllocateInfo = vk.CommandBufferAllocateInfo(compute.commandPool, VkCommandBufferLevel.PRIMARY, 1) - - compute.commandBuffer = device allocateCommandBuffer cmdBufAllocateInfo - - // Fence for compute CB sync - val fenceCreateInfo = vk.FenceCreateInfo(VkFenceCreate.SIGNALED_BIT.i) - compute.fence = device createFence fenceCreateInfo - - // Build a single command buffer containing the compute dispatch commands - buildComputeCommandBuffer() - } - - /** Prepare and initialize uniform buffer containing shader uniforms */ - fun prepareUniformBuffers() { - // Vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBufferVS, - uboVS.size.L) - - // Map persistent - uniformBufferVS.map() - - updateUniformBuffers() - } - - fun updateUniformBuffers() { - // Vertex shader uniform buffer block - uboVS.projection = glm.perspective(60f.rad, size.x * 0.5f / size.y, 0.1f, 256f) - val viewMatrix = glm.translate(Mat4(1f), 0f, 0f, zoom) - - uboVS.model = viewMatrix * glm.translate(Mat4(1f), cameraPos) - .rotateAssign(rotation.x.rad, 1f, 0f, 0f) - .rotateAssign(rotation.y.rad, 0f, 1f, 0f) - .rotateAssign(rotation.z.rad, 0f, 0f, 1f) - - uboVS.pack() - memCopy(uboVS.address, uniformBufferVS.mapped, uboVS.size.L) - } - - fun draw() { - - super.prepareFrame() - - submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] - queue submit submitInfo - - super.submitFrame() - - // Submit compute commands - // Use a fence to ensure that compute command buffer has finished executin before using it again - device.waitForFence(compute.fence, true, UINT64_MAX) - device.resetFence(compute.fence) - - val computeSubmitInfo = vk.SubmitInfo { commandBuffer = compute.commandBuffer } - compute.queue.submit(computeSubmitInfo, compute.fence) - } - - override fun prepare() { - super.prepare() - loadAssets() - generateQuad() - setupVertexDescriptions() - prepareUniformBuffers() - prepareTextureTarget(textureComputeTarget, textureColorMap.size, VkFormat.R8G8B8A8_UNORM) - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSet() - prepareCompute() - buildCommandBuffers() - prepared = true - window.show() - } - - override fun render() { - if (!prepared) - return - draw() - } - - override fun viewChanged() = updateUniformBuffers() - -// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) -// { -// if (overlay->header("Settings")) { -// if (overlay->comboBox("Shader", &compute.pipelineIndex, shaderNames)) { +///* +//* Vulkan Example - Compute shader image processing +//* +//* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +//package vulkan.computeShader +// +//import glm_.L +//import glm_.f +//import glm_.func.rad +//import glm_.glm +//import glm_.mat4x4.Mat4 +//import glm_.vec2.Vec2 +//import glm_.vec2.Vec2i +//import glm_.vec3.Vec3 +//import kool.bufferBig +//import kool.cap +//import kool.stak +//import org.lwjgl.system.MemoryUtil.* +//import org.lwjgl.vulkan.* +//import vkk.* +//import vulkan.UINT64_MAX +//import vulkan.VERTEX_BUFFER_BIND_ID +//import vulkan.assetPath +//import vulkan.base.* +//import vulkan.base.tools.VK_FLAGS_NONE +// +// +//fun main(args: Array) { +// ImageProcessing().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +//// Vertex layout for this example +//private val Vertex = object { +// // float pos[3]; +//// float uv[2]; +// val size = Vec3.size + Vec2.size +// val offPos = 0 +// val offUv = Vec3.size +//} +// +//private class ImageProcessing : VulkanExampleBase() { +// +// val textureColorMap = Texture2D() +// val textureComputeTarget = Texture2D() +// +// private val vertices = object { +// lateinit var inputState: VkPipelineVertexInputStateCreateInfo +// lateinit var bindingDescriptions: VkVertexInputBindingDescription +// lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer +// } +// +// /** Resources for the graphics part of the example */ +// private val graphics = object { +// var descriptorSetLayout = VkDescriptorSetLayout(NULL) // Image display shader binding layout +// var descriptorSetPreCompute = VkDescriptorSet(NULL) // Image display shader bindings before compute shader image manipulation +// var descriptorSetPostCompute = VkDescriptorSet(NULL) // Image display shader bindings after compute shader image manipulation +// var pipeline = VkPipeline(NULL) // Image display pipeline +// var pipelineLayout = VkPipelineLayout(NULL) // Layout of the graphics pipeline +// } +// +// /** Resources for the compute part of the example */ +// private val compute = object { +// lateinit var queue: VkQueue // Separate queue for compute commands (queue family may differ from the one used for graphics) +// var commandPool = VkCommandPool(NULL) // Use a separate command pool (queue family may differ from the one used for graphics) +// lateinit var commandBuffer: VkCommandBuffer // Command buffer storing the dispatch commands and barriers +// var fence = VkFence(NULL) // Synchronization fence to avoid rewriting compute CB if still in use +// var descriptorSetLayout = VkDescriptorSetLayout(NULL) // Compute shader binding layout +// var descriptorSet = VkDescriptorSet(NULL) // Compute shader bindings +// var pipelineLayout = VkPipelineLayout(NULL) // Layout of the compute pipeline +// val pipelines = ArrayList() // Compute pipelines for image filters +// var pipelineIndex = 0 // Current image filtering compute pipeline index +// var queueFamilyIndex = 0 // Family index of the graphics queue, used for barriers +// } +// +// val vertexBuffer = Buffer() +// var indexBuffer = Buffer() +// var indexCount = 0 +// +// var uniformBufferVS = Buffer() +// +// private val uboVS = object { +// var projection = Mat4() +// var model = Mat4() +// +// fun pack() { +// projection to buffer +// model.to(buffer, Mat4.size) +// } +// +// val size = Mat4.size * 2 +// val buffer = bufferBig(size) +// val address = memAddress(buffer) +// } +// +// var vertexBufferSize = 0 +// +// val shaderNames = ArrayList() +// +// init { +// zoom = -2.0f +// title = "Compute shader image load/store" +//// settings.overlay = true +// } +// +// override fun destroy() { +// device.apply { +// // Graphics +// destroyPipeline(graphics.pipeline) +// destroyPipelineLayout(graphics.pipelineLayout) +// destroyDescriptorSetLayout(graphics.descriptorSetLayout) +// +// // Compute +// for (pipeline in compute.pipelines) +// destroyPipeline(pipeline) +// destroyPipelineLayout(compute.pipelineLayout) +// destroyDescriptorSetLayout(compute.descriptorSetLayout) +// destroyFence(compute.fence) +// destroyCommandPool(compute.commandPool) +// } +// vertexBuffer.destroy() +// indexBuffer.destroy() +// uniformBufferVS.destroy() +// +// textureColorMap.destroy() +// textureComputeTarget.destroy() +// +// super.destroy() +// } +// +// /** Prepare a texture target that is used to store compute shader calculations */ +// fun prepareTextureTarget(tex: Texture, size: Vec2i, format: VkFormat) { +// +// // Get device properties for the requested texture format +// val formatProperties = physicalDevice getFormatProperties format +// // Check if requested image format supports image storage operations +// assert(formatProperties.optimalTilingFeatures has VkFormatFeature.STORAGE_IMAGE_BIT) +// +// // Prepare blit target texture +// tex.size(size) +// +// val imageCreateInfo = vk.ImageCreateInfo { +// imageType = VkImageType.`2D` +// this.format = format +// extent.set(size.x, size.y, 1) +// mipLevels = 1 +// arrayLayers = 1 +// samples = VkSampleCount.`1_BIT` +// tiling = VkImageTiling.OPTIMAL +// // Image will be sampled in the fragment shader and used as storage target in the compute shader +// usage = VkImageUsage.SAMPLED_BIT or VkImageUsage.STORAGE_BIT +// flags = 0 +// // Sharing mode exclusive means that ownership of the image does not need to be explicitly transferred between the compute and graphics queue +// sharingMode = VkSharingMode.EXCLUSIVE +// } +// +// tex.image = device createImage imageCreateInfo +// +// val memReqs = device getImageMemoryRequirements tex.image +// val memAllocInfo = vk.MemoryAllocateInfo { +// allocationSize = memReqs.size +// memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) +// } +// tex.deviceMemory = device allocateMemory memAllocInfo +// device.bindImageMemory(tex.image, tex.deviceMemory) +// +// val layoutCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) +// +// tex.imageLayout = VkImageLayout.GENERAL +// tools.setImageLayout( +// layoutCmd, tex.image, +// VkImageAspect.COLOR_BIT.i, +// VkImageLayout.UNDEFINED, +// tex.imageLayout) +// +// super.flushCommandBuffer(layoutCmd, queue, true) +// +// // Create sampler +// val sampler = vk.SamplerCreateInfo { +// magFilter = VkFilter.LINEAR +// minFilter = VkFilter.LINEAR +// mipmapMode = VkSamplerMipmapMode.LINEAR +// addressModeU = VkSamplerAddressMode.CLAMP_TO_BORDER +// addressModeV = addressModeU +// addressModeW = addressModeU +// mipLodBias = 0f +// maxAnisotropy = 1f +// compareOp = VkCompareOp.NEVER +// minLod = 0f +// maxLod = tex.mipLevels.f +// borderColor = VkBorderColor.FLOAT_OPAQUE_WHITE +// } +// tex.sampler = device createSampler sampler +// +// // Create image view +// val view = vk.ImageViewCreateInfo { +// image = VkImage(NULL) +// viewType = VkImageViewType.`2D` +// this.format = format +// components(VkComponentSwizzle.R, VkComponentSwizzle.G, VkComponentSwizzle.B, VkComponentSwizzle.A) +// subresourceRange.set(VkImageAspect.COLOR_BIT.i, 0, 1, 0, 1) +// image = tex.image +// } +// tex.view = device createImageView view +// +// // Initialize a descriptor for later use +// tex.descriptor.imageLayout = tex.imageLayout +// tex.descriptor.imageView = tex.view +// tex.descriptor.sampler = tex.sampler +// tex.device = vulkanDevice +// } +// +// fun loadAssets() { +// textureColorMap.loadFromFile( +// "$assetPath/textures/vulkan_11_rgba.ktx", +// VkFormat.R8G8B8A8_UNORM, +// vulkanDevice, queue, +// VkImageUsage.SAMPLED_BIT or VkImageUsage.STORAGE_BIT, +// VkImageLayout.GENERAL) +// } +// +// override fun buildCommandBuffers() { +// // Destroy command buffers if already present +// if (!checkCommandBuffers()) { +// destroyCommandBuffers() +// createCommandBuffers() +// } +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(defaultClearColor) +// it[1].depthStencil.set(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@ImageProcessing.renderPass +// renderArea.apply { +// offset.set(0, 0) +// extent.set(size.x, size.y) +// } +// this.clearValues = clearValues +// } +// for (i in drawCmdBuffers.indices) { +// // Set target frame buffer +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// // Image memory barrier to make sure that compute shader writes are finished before sampling from the texture +// val imageMemoryBarrier = vk.ImageMemoryBarrier { +// // We won't be changing the layout of the image +// oldLayout = VkImageLayout.GENERAL +// newLayout = VkImageLayout.GENERAL +// image = textureComputeTarget.image +// subresourceRange.set(VkImageAspect.COLOR_BIT.i, 0, 1, 0, 1) +// srcAccessMask = VkAccess.SHADER_WRITE_BIT.i +// dstAccessMask = VkAccess.SHADER_READ_BIT.i +// } +// pipelineBarrier( +// VkPipelineStage.COMPUTE_SHADER_BIT.i, +// VkPipelineStage.FRAGMENT_SHADER_BIT.i, +// VK_FLAGS_NONE, +// imageMemoryBarrier = imageMemoryBarrier) +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// val viewport = vk.Viewport(size.x * 0.5f, size.y.f) +// setViewport(viewport) +// +// setScissor(size) +// +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, vertexBuffer.buffer) +// bindIndexBuffer(indexBuffer.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// +// // Left (pre compute) +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, graphics.pipelineLayout, graphics.descriptorSetPreCompute) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, graphics.pipeline) +// +// drawIndexed(indexCount, 1, 0, 0, 0) +// +// // Right (post compute) +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, graphics.pipelineLayout, graphics.descriptorSetPostCompute) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, graphics.pipeline) +// +// viewport.x = size.x / 2f +// setViewport(viewport) +// drawIndexed(indexCount, 1, 0, 0, 0) +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// fun buildComputeCommandBuffer() { +// // Flush the queue if we're rebuilding the command buffer after a pipeline change to ensure it's not currently in use +// compute.queue.waitIdle() +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// compute.commandBuffer.apply { +// +// begin(cmdBufInfo) +// +// bindPipeline(VkPipelineBindPoint.COMPUTE, compute.pipelines[compute.pipelineIndex]) +// bindDescriptorSets(VkPipelineBindPoint.COMPUTE, compute.pipelineLayout, compute.descriptorSet) +// +// compute.commandBuffer.dispatch(textureComputeTarget.size / 16, 1) +// +// end() +// } +// } +// +// /** Setup vertices for a single uv-mapped quad */ +// fun generateQuad() = stak { +// // Setup vertices for a single uv-mapped quad made from two triangles +// val vertices = it.floats( +// +1f, +1f, 0f, 1f, 1f, +// -1f, +1f, 0f, 0f, 1f, +// -1f, -1f, 0f, 0f, 0f, +// +1f, -1f, 0f, 1f, 0f) +// +// // Setup indices +// val indices = it.ints(0, 1, 2, 2, 3, 0) +// indexCount = indices.cap +// +// // Create buffers +// // For the sake of simplicity we won't stage the vertex data to the gpu memory +// // Vertex buffer +// vulkanDevice.createBuffer( +// VkBufferUsage.VERTEX_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// vertexBuffer, +// vertices) +// // Index buffer +// vulkanDevice.createBuffer( +// VkBufferUsage.INDEX_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// indexBuffer, +// indices) +// } +// +// fun setupVertexDescriptions() { +// // Binding description +// vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, Vertex.size, VkVertexInputRate.VERTEX) +// +// // Attribute descriptions +// // Describes memory layout and shader positions +// vertices.attributeDescriptions = vk.VertexInputAttributeDescription( +// // Location 0: Position +// VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32_SFLOAT, Vertex.offPos, +// // Location 1: Texture coordinates +// VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32_SFLOAT, Vertex.offUv) +// +// // Assign to vertex buffer +// vertices.inputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertices.bindingDescriptions +// vertexAttributeDescriptions = vertices.attributeDescriptions +// } +// } +// +// fun setupDescriptorPool() { +// +// val poolSizes = vk.DescriptorPoolSize( +// // Graphics pipelines uniform buffers +// VkDescriptorType.UNIFORM_BUFFER, 2, +// // Graphics pipelines image samplers for displaying compute output image +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, 2, +// // Compute pipelines uses a storage image for image reads and writes +// VkDescriptorType.STORAGE_IMAGE, 2) +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 3) +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// // Binding 0: Vertex shader uniform buffer +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0, +// // Binding 1: Fragment shader input image +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// graphics.descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(graphics.descriptorSetLayout) +// graphics.pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// } +// +// fun setupDescriptorSet() { +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, graphics.descriptorSetLayout) +// +// // Input image (before compute post processing) +// graphics.descriptorSetPreCompute = device allocateDescriptorSets allocInfo +// val baseImageWriteDescriptorSets = vk.WriteDescriptorSet( +// graphics.descriptorSetPreCompute, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBufferVS.descriptor, +// graphics.descriptorSetPreCompute, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textureColorMap.descriptor) +// +// device updateDescriptorSets baseImageWriteDescriptorSets +// +// // Final image (after compute shader processing) +// graphics.descriptorSetPostCompute = device allocateDescriptorSets allocInfo +// val writeDescriptorSets = vk.WriteDescriptorSet( +// graphics.descriptorSetPostCompute, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBufferVS.descriptor, +// graphics.descriptorSetPostCompute, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textureComputeTarget.descriptor) +// +// device updateDescriptorSets writeDescriptorSets +// +// } +// +// fun preparePipelines() { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// // Rendering pipeline +// // Load shaders +// val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { +// it[0].loadShader("$assetPath/shaders/computeshader/texture.vert.spv", VkShaderStage.VERTEX_BIT) +// it[1].loadShader("$assetPath/shaders/computeshader/texture.frag.spv", VkShaderStage.FRAGMENT_BIT) +// } +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(graphics.pipelineLayout, renderPass).also { +// it.vertexInputState = vertices.inputState +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// it.renderPass = renderPass +// } +// graphics.pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// +// /** Find and create a compute capable device queue */ +// fun getComputeQueue() { +// +// val queueFamilyProperties = physicalDevice.queueFamilyProperties +// +// // Some devices have dedicated compute queues, so we first try to find a queue that supports compute and not graphics +// var computeQueueFound = false +// for (i in queueFamilyProperties.indices) +// if (queueFamilyProperties[i].queueFlags has VkQueueFlag.COMPUTE_BIT && queueFamilyProperties[i].queueFlags hasnt VkQueueFlag.GRAPHICS_BIT) { +// compute.queueFamilyIndex = i +// computeQueueFound = true +// break +// } +// // If there is no dedicated compute queue, just find the first queue family that supports compute +// if (!computeQueueFound) +// for (i in queueFamilyProperties.indices) { +// if (queueFamilyProperties[i].queueFlags has VkQueueFlag.COMPUTE_BIT) { +// compute.queueFamilyIndex = i +// computeQueueFound = true +// break +// } +// } +// +// // Compute is mandatory in Vulkan, so there must be at least one queue family that supports compute +// assert(computeQueueFound) +// // Get a compute queue from the device +// compute.queue = device getQueue compute.queueFamilyIndex +// } +// +// fun prepareCompute() { +// +// getComputeQueue() +// +// // Create compute pipeline +// // Compute pipelines are created separate from graphics pipelines even if they use the same queue +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// // Binding 0: Input image (read-only) +// VkDescriptorType.STORAGE_IMAGE, VkShaderStage.COMPUTE_BIT.i, 0, +// // Binding 1: Output image (write) +// VkDescriptorType.STORAGE_IMAGE, VkShaderStage.COMPUTE_BIT.i, 1) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// compute.descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(compute.descriptorSetLayout) +// +// compute.pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, compute.descriptorSetLayout) +// +// compute.descriptorSet = device allocateDescriptorSets allocInfo +// val computeWriteDescriptorSets = vk.WriteDescriptorSet( +// compute.descriptorSet, VkDescriptorType.STORAGE_IMAGE, 0, textureColorMap.descriptor, +// compute.descriptorSet, VkDescriptorType.STORAGE_IMAGE, 1, textureComputeTarget.descriptor) +// +// device updateDescriptorSets computeWriteDescriptorSets +// +// // Create compute shader pipelines +// val computePipelineCreateInfo = vk.ComputePipelineCreateInfo(compute.pipelineLayout) +// +// // One pipeline for each effect +// shaderNames += listOf("emboss", "edgedetect", "sharpen") +// for (shaderName in shaderNames) { +// val fileName = "$assetPath/shaders/computeshader/$shaderName.comp.spv" +// computePipelineCreateInfo.stage.loadShader(fileName, VkShaderStage.COMPUTE_BIT) +// val pipeline = device.createComputePipelines(pipelineCache, computePipelineCreateInfo) +// compute.pipelines += pipeline +// } +// // Separate command pool as queue family for compute may be different than graphics +// val cmdPoolInfo = vk.CommandPoolCreateInfo { +// queueFamilyIndex = compute.queueFamilyIndex +// flags = VkCommandPoolCreate.RESET_COMMAND_BUFFER_BIT.i +// } +// compute.commandPool = device createCommandPool cmdPoolInfo +// +// // Create a command buffer for compute operations +// val cmdBufAllocateInfo = vk.CommandBufferAllocateInfo(compute.commandPool, VkCommandBufferLevel.PRIMARY, 1) +// +// compute.commandBuffer = device allocateCommandBuffer cmdBufAllocateInfo +// +// // Fence for compute CB sync +// val fenceCreateInfo = vk.FenceCreateInfo(VkFenceCreate.SIGNALED_BIT.i) +// compute.fence = device createFence fenceCreateInfo +// +// // Build a single command buffer containing the compute dispatch commands // buildComputeCommandBuffer() // } +// +// /** Prepare and initialize uniform buffer containing shader uniforms */ +// fun prepareUniformBuffers() { +// // Vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBufferVS, +// VkDeviceSize(uboVS.size.L)) +// +// // Map persistent +// uniformBufferVS.map() +// +// updateUniformBuffers() +// } +// +// fun updateUniformBuffers() { +// // Vertex shader uniform buffer block +// uboVS.projection = glm.perspective(60f.rad, size.x * 0.5f / size.y, 0.1f, 256f) +// val viewMatrix = glm.translate(Mat4(1f), 0f, 0f, zoom) +// +// uboVS.model = viewMatrix * glm.translate(Mat4(1f), cameraPos) +// .rotateAssign(rotation.x.rad, 1f, 0f, 0f) +// .rotateAssign(rotation.y.rad, 0f, 1f, 0f) +// .rotateAssign(rotation.z.rad, 0f, 0f, 1f) +// +// uboVS.pack() +// memCopy(uboVS.address, uniformBufferVS.mapped, uboVS.size.L) +// } +// +// fun draw() { +// +// super.prepareFrame() +// +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// queue submit submitInfo +// +// super.submitFrame() +// +// // Submit compute commands +// // Use a fence to ensure that compute command buffer has finished executin before using it again +// device.waitForFence(compute.fence, true, UINT64_MAX) +// device.resetFence(compute.fence) +// +// val computeSubmitInfo = vk.SubmitInfo { commandBuffer = compute.commandBuffer } +// compute.queue.submit(computeSubmitInfo, compute.fence) +// } +// +// override fun prepare() { +// super.prepare() +// loadAssets() +// generateQuad() +// setupVertexDescriptions() +// prepareUniformBuffers() +// prepareTextureTarget(textureComputeTarget, textureColorMap.size, VkFormat.R8G8B8A8_UNORM) +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSet() +// prepareCompute() +// buildCommandBuffers() +// prepared = true +// window.show() // } +// +// override fun render() { +// if (!prepared) +// return +// draw() // } -} \ No newline at end of file +// +// override fun viewChanged() = updateUniformBuffers() +// +//// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) +//// { +//// if (overlay->header("Settings")) { +//// if (overlay->comboBox("Shader", &compute.pipelineIndex, shaderNames)) { +//// buildComputeCommandBuffer() +//// } +//// } +//// } +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/computeShader/02 Gpu Particle System.kt b/src/main/kotlin/vulkan/computeShader/02 Gpu Particle System.kt index f625047..121bdd0 100644 --- a/src/main/kotlin/vulkan/computeShader/02 Gpu Particle System.kt +++ b/src/main/kotlin/vulkan/computeShader/02 Gpu Particle System.kt @@ -1,561 +1,562 @@ -/* -* Vulkan Example - Attraction based compute shader particle system -* -* Updated compute shader by Lukas Bergdoll (https://github.com/Voultapher) -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -package vulkan.computeShader - -import glm_.BYTES -import glm_.L -import glm_.buffer.bufferBig -import glm_.buffer.free -import glm_.func.rad -import glm_.glm -import glm_.vec2.Vec2 -import glm_.vec4.Vec4 -import org.lwjgl.system.MemoryUtil.* -import org.lwjgl.vulkan.* -import vkk.* -import vulkan.PARTICLE_COUNT -import vulkan.VERTEX_BUFFER_BIND_ID -import vulkan.assetPath -import vulkan.base.Buffer -import vulkan.base.Texture2D -import vulkan.base.VulkanExampleBase -import vulkan.base.tools.VK_FLAGS_NONE -import java.nio.ByteBuffer -import kotlin.math.sin - - -fun main(args: Array) { - GpuParticleSystem().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - -class GpuParticleSystem : VulkanExampleBase() { - - var animStart = 20f - var animate = true // TODO fix mouse animation - - object textures { - val particle = Texture2D() - val gradient = Texture2D() - } - - object vertices { - lateinit var inputState: VkPipelineVertexInputStateCreateInfo - lateinit var bindingDescriptions: VkVertexInputBindingDescription - lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer - } - - /** Resources for the graphics part of the example */ - object graphics { - var descriptorSetLayout: VkDescriptorSetLayout = NULL // Particle system rendering shader binding layout - var descriptorSet: VkDescriptorSet = NULL // Particle system rendering shader bindings - var pipelineLayout: VkPipelineLayout = NULL // Layout of the graphics pipeline - var pipeline: VkPipeline = NULL // Particle rendering pipeline - } - - /** Resources for the compute part of the example */ - object compute { - - val storageBuffer = Buffer() // (Shader) storage buffer object containing the particles - val uniformBuffer = Buffer() // Uniform buffer object containing particle system parameters - lateinit var queue: VkQueue // Separate queue for compute commands (queue family may differ from the one used for graphics) - var commandPool: VkCommandPool = NULL // Use a separate command pool (queue family may differ from the one used for graphics) - lateinit var commandBuffer: VkCommandBuffer // Command buffer storing the dispatch commands and barriers - var fence: VkFence = NULL // Synchronization fence to avoid rewriting compute CB if still in use - var descriptorSetLayout: VkDescriptorSetLayout = NULL // Compute shader binding layout - var descriptorSet: VkDescriptorSet = NULL // Compute shader bindings - var pipelineLayout: VkPipelineLayout = NULL // Layout of the compute pipeline - var pipeline: VkPipeline = NULL // Compute pipeline for updating particle positions - - object ubo { // Compute shader uniform block object - var deltaT = 0f // Frame delta time - var dest = Vec2() // x position of the attractor - var particleCount = PARTICLE_COUNT - - fun pack() { - buffer.putFloat(0, deltaT) - dest.to(buffer, Float.BYTES) - buffer.putInt(Float.BYTES + Vec2.size, particleCount) - } - - val size = Float.BYTES + Vec2.size + Int.BYTES - val buffer = bufferBig(size) - val address = memAddress(buffer) - } - } - - // SSBO particle declaration - class Particle { - val pos = Vec2() // Particle position - val vel = Vec2() // Particle velocity - val gradientPos = Vec4() // Texture coordiantes for the gradient ramp map - - fun to(buffer: ByteBuffer, offset: Int) { - pos.to(buffer, offset) - vel.to(buffer, offset + Vec2.size) - gradientPos.to(buffer, offset + Vec2.size * 2) - } - - companion object { - val size = Vec2.size * 2 + Vec4.size - val ofsPos = 0 - val ofsVel = Vec2.size - val ofsGrd = Vec2.size * 2 - } - } - - init { - title = "Compute shader particle system" -// settings.overlay = true - } - - override fun destroy() { - - device.apply { - // Graphics - destroyPipeline(graphics.pipeline) - destroyPipelineLayout(graphics.pipelineLayout) - destroyDescriptorSetLayout(graphics.descriptorSetLayout) - - // Compute - compute.storageBuffer.destroy() - compute.uniformBuffer.destroy() - destroyPipelineLayout(compute.pipelineLayout) - destroyDescriptorSetLayout(compute.descriptorSetLayout) - destroyPipeline(compute.pipeline) - destroyFence(compute.fence) - destroyCommandPool(compute.commandPool) - } - textures.particle.destroy() - textures.gradient.destroy() - - super.destroy() - } - - fun loadAssets() { - textures.particle.loadFromFile("$assetPath/textures/particle01_rgba.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) - textures.gradient.loadFromFile("$assetPath/textures/particle_gradient_rgba.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) - } - - override fun buildCommandBuffers() { - // Destroy command buffers if already present - if (!checkCommandBuffers()) { - destroyCommandBuffers() - createCommandBuffers() - } - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(defaultClearColor) - it[1].depthStencil(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@GpuParticleSystem.renderPass - renderArea.offset(0) - renderArea.extent(size) - this.clearValues = clearValues - } - for (i in drawCmdBuffers.indices) { - // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - // Draw the particle system using the update vertex buffer - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - setViewport(size) - setScissor(size) - - bindPipeline(VkPipelineBindPoint.GRAPHICS, graphics.pipeline) - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, graphics.pipelineLayout, graphics.descriptorSet) - - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, compute.storageBuffer.buffer) - draw(PARTICLE_COUNT, 1, 0, 0) - - endRenderPass() - - end() - } - } - } - - fun buildComputeCommandBuffer() { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - compute.commandBuffer.apply { - - begin(cmdBufInfo) - - // Compute particle movement - - // Add memory barrier to ensure that the (graphics) vertex shader has fetched attributes before compute starts to write to the buffer - val bufferBarrier = vk.BufferMemoryBarrier { - buffer = compute.storageBuffer.buffer - size = compute.storageBuffer.descriptor.range - srcAccessMask = VkAccess.VERTEX_ATTRIBUTE_READ_BIT.i // Vertex shader invocations have finished reading from the buffer - dstAccessMask = VkAccess.SHADER_WRITE_BIT.i // Compute shader wants to write to the buffer - // Compute and graphics queue may have different queue families (see VulkanDevice::createLogicalDevice) - // For the barrier to work across different queues, we need to set their family indices - srcQueueFamilyIndex = vulkanDevice.queueFamilyIndices.graphics // Required as compute and graphics queue may have different families - dstQueueFamilyIndex = vulkanDevice.queueFamilyIndices.compute // Required as compute and graphics queue may have different families - } - compute.commandBuffer.pipelineBarrier( - VkPipelineStage.VERTEX_SHADER_BIT.i, - VkPipelineStage.COMPUTE_SHADER_BIT.i, - VK_FLAGS_NONE, - bufferMemoryBarrier = bufferBarrier) - - bindPipeline(VkPipelineBindPoint.COMPUTE, compute.pipeline) - bindDescriptorSets(VkPipelineBindPoint.COMPUTE, compute.pipelineLayout, compute.descriptorSet) - - // Dispatch the compute job - dispatch(PARTICLE_COUNT / 256, 1, 1) - - // Add memory barrier to ensure that compute shader has finished writing to the buffer - // Without this the (rendering) vertex shader may display incomplete results (partial data from last frame) - bufferBarrier.apply { - srcAccessMask = VkAccess.SHADER_WRITE_BIT.i // Compute shader has finished writes to the buffer - dstAccessMask = VkAccess.VERTEX_ATTRIBUTE_READ_BIT.i // Vertex shader invocations want to read from the buffer - buffer = compute.storageBuffer.buffer - size = compute.storageBuffer.descriptor.range - // Compute and graphics queue may have different queue families (see VulkanDevice::createLogicalDevice) - // For the barrier to work across different queues, we need to set their family indices - srcQueueFamilyIndex = vulkanDevice.queueFamilyIndices.compute // Required as compute and graphics queue may have different families - dstQueueFamilyIndex = vulkanDevice.queueFamilyIndices.graphics // Required as compute and graphics queue may have different families - } - compute.commandBuffer.pipelineBarrier( - VkPipelineStage.COMPUTE_SHADER_BIT.i, - VkPipelineStage.VERTEX_SHADER_BIT.i, - VK_FLAGS_NONE, - bufferMemoryBarrier = bufferBarrier) - - end() - } - } - - /** Setup and fill the compute shader storage buffers containing the particles */ - fun prepareStorageBuffers() { - - // Initial particle positions - val particlesBuffer = bufferBig(PARTICLE_COUNT * Particle.size) - for (i in 0 until PARTICLE_COUNT) { - val particle = Particle().apply { - pos(glm.linearRand(-1f, 1f), glm.linearRand(-1f, 1f)) - vel(0f) - gradientPos.x = pos.x / 2f - } - particle.to(particlesBuffer, i * Particle.size) - } - - - val storageBufferSize: VkDeviceSize = PARTICLE_COUNT * Particle.size.L - - // Staging - // SSBO won't be changed on the host after upload so copy to device local memory - - val stagingBuffer = Buffer() - - vulkanDevice.createBuffer( - VkBufferUsage.TRANSFER_SRC_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - stagingBuffer, - particlesBuffer) - - vulkanDevice.createBuffer( - // The SSBO will be used as a storage buffer for the compute pipeline and as a vertex buffer in the graphics pipeline - VkBufferUsage.VERTEX_BUFFER_BIT or VkBufferUsage.STORAGE_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT, - VkMemoryProperty.DEVICE_LOCAL_BIT.i, - compute.storageBuffer, - storageBufferSize) - - // Copy to staging buffer - val copyCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) - val copyRegion = vk.BufferCopy { size = storageBufferSize } - copyCmd.copyBuffer(stagingBuffer.buffer, compute.storageBuffer.buffer, copyRegion) - super.flushCommandBuffer(copyCmd, queue, true) - - stagingBuffer.destroy() - - // Binding description - vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, Particle.size, VkVertexInputRate.VERTEX) - - // Attribute descriptions - // Describes memory layout and shader positions - vertices.attributeDescriptions = vk.VertexInputAttributeDescription( - // Location 0 : Position - VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32_SFLOAT, Particle.ofsPos, - // Location 1 : Gradient position - VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32A32_SFLOAT, Particle.ofsGrd) - - // Assign to vertex buffer - vertices.inputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertices.bindingDescriptions - vertexAttributeDescriptions = vertices.attributeDescriptions - } - - particlesBuffer.free() - } - - fun setupDescriptorPool() { - - val poolSizes = vk.DescriptorPoolSize( - VkDescriptorType.UNIFORM_BUFFER, 1, - VkDescriptorType.STORAGE_BUFFER, 1, - VkDescriptorType.COMBINED_IMAGE_SAMPLER, 2) - - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) - - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - // Binding 0 : Particle color map - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 0, - // Binding 1 : Particle gradient ramp - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - - graphics.descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(graphics.descriptorSetLayout) - - graphics.pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - } - - fun setupDescriptorSet() { - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, graphics.descriptorSetLayout) - - graphics.descriptorSet = device allocateDescriptorSets allocInfo - - val writeDescriptorSets = vk.WriteDescriptorSet( - // Binding 0 : Particle color map - graphics.descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 0, textures.particle.descriptor, - // Binding 1 : Particle gradient ramp - graphics.descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textures.gradient.descriptor) - - device updateDescriptorSets writeDescriptorSets - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.POINT_LIST, 0, false) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.COUNTER_CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(false, false, VkCompareOp.ALWAYS) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - // Rendering pipeline - // Load shaders - val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { - it[0].loadShader("$assetPath/shaders/computeparticles/particle.vert.spv", VkShaderStage.VERTEX_BIT) - it[1].loadShader("$assetPath/shaders/computeparticles/particle.frag.spv", VkShaderStage.FRAGMENT_BIT) - } - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(graphics.pipelineLayout, renderPass).also { - it.vertexInputState = vertices.inputState - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - it.renderPass = renderPass - } - // Additive blending - blendAttachmentState.apply { - colorWriteMask = 0xF - blendEnable = true - colorBlendOp = VkBlendOp.ADD - srcColorBlendFactor = VkBlendFactor.ONE - dstColorBlendFactor = VkBlendFactor.ONE - alphaBlendOp = VkBlendOp.ADD - srcAlphaBlendFactor = VkBlendFactor.SRC_ALPHA - dstAlphaBlendFactor = VkBlendFactor.DST_ALPHA - } - graphics.pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - fun prepareCompute() { - /* Create a compute capable device queue - The VulkanDevice::createLogicalDevice functions finds a compute capable queue and prefers queue families - that only support compute - Depending on the implementation this may result in different queue family indices for graphics and computes, - requiring proper synchronization (see the memory barriers in buildComputeCommandBuffer) */ - compute.queue = device getQueue vulkanDevice.queueFamilyIndices.compute - - // Create compute pipeline - // Compute pipelines are created separate from graphics pipelines even if they use the same queue (family index) - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - // Binding 0 : Particle position storage buffer - VkDescriptorType.STORAGE_BUFFER, VkShaderStage.COMPUTE_BIT.i, 0, - // Binding 1 : Uniform buffer - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.COMPUTE_BIT.i, 1) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - - compute.descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(compute.descriptorSetLayout) - - compute.pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, compute.descriptorSetLayout) - - compute.descriptorSet = device allocateDescriptorSets allocInfo - - val computeWriteDescriptorSets = vk.WriteDescriptorSet( - // Binding 0 : Particle position storage buffer - compute.descriptorSet, VkDescriptorType.STORAGE_BUFFER, 0, compute.storageBuffer.descriptor, - // Binding 1 : Uniform buffer - compute.descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 1, compute.uniformBuffer.descriptor) - - device updateDescriptorSets computeWriteDescriptorSets - - // Create pipeline - val computePipelineCreateInfo = vk.ComputePipelineCreateInfo(compute.pipelineLayout).apply { - stage.loadShader("$assetPath/shaders/computeparticles/particle.comp.spv", VkShaderStage.COMPUTE_BIT) - } - compute.pipeline = device.createComputePipelines(pipelineCache, computePipelineCreateInfo) - - // Separate command pool as queue family for compute may be different than graphics - val cmdPoolInfo = vk.CommandPoolCreateInfo { - queueFamilyIndex = vulkanDevice.queueFamilyIndices.compute - flags = VkCommandPoolCreate.RESET_COMMAND_BUFFER_BIT.i - } - compute.commandPool = device createCommandPool cmdPoolInfo - - // Create a command buffer for compute operations - val cmdBufAllocateInfo = vk.CommandBufferAllocateInfo(compute.commandPool, VkCommandBufferLevel.PRIMARY, 1) - - compute.commandBuffer = device allocateCommandBuffer cmdBufAllocateInfo - - // Fence for compute CB sync - val fenceCreateInfo = vk.FenceCreateInfo(VkFenceCreate.SIGNALED_BIT.i) - compute.fence = device createFence fenceCreateInfo - - // Build a single command buffer containing the compute dispatch commands - buildComputeCommandBuffer() - } - - /** Prepare and initialize uniform buffer containing shader uniforms */ - fun prepareUniformBuffers() { - // Compute shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - compute.uniformBuffer, - compute.ubo.size.L) - - // Map for host access - compute.uniformBuffer.map() - - updateUniformBuffers() - } - - fun updateUniformBuffers() { - - compute.ubo.deltaT = frameTimer * 2.5f - if (animate) - compute.ubo.dest(sin((timer * 360f).rad) * 0.75f, 0f) - else { - val normalizedM = (mousePos - (size / 2)) / (size / 2) - compute.ubo.dest(normalizedM) - } - - compute.ubo.pack() - memCopy(compute.ubo.address, compute.uniformBuffer.mapped, compute.ubo.size.L) - } - - fun draw() { - - val computeSubmitInfo = vk.SubmitInfo { commandBuffer = compute.commandBuffer } - compute.queue.submit(computeSubmitInfo, compute.fence) - - // Submit graphics commands - super.prepareFrame() - - submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] - queue submit submitInfo - - super.submitFrame() - - // Submit compute commands - device.waitForFence(compute.fence, true, UINT64_MAX) - device resetFence compute.fence - } - - override fun prepare() { - super.prepare() - loadAssets() - prepareStorageBuffers() - prepareUniformBuffers() - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSet() - prepareCompute() - buildCommandBuffers() - prepared = true - window.show() - } - - override fun render() { - if (!prepared) - return - draw() - - if (animate) - if (animStart > 0f) - animStart -= frameTimer * 5f - else if (animStart <= 0f) { - timer += frameTimer * 0.04f - if (timer > 1f) - timer = 0f - } - - updateUniformBuffers() - } - -// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) -// { -// if (overlay->header("Settings")) { overlay -> -// checkBox("Moving attractor", & animate) +///* +//* Vulkan Example - Attraction based compute shader particle system +//* +//* Updated compute shader by Lukas Bergdoll (https://github.com/Voultapher) +//* +//* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +//package vulkan.computeShader +// +//import glm_.BYTES +//import glm_.L +//import glm_.func.rad +//import glm_.glm +//import glm_.vec2.Vec2 +//import glm_.vec4.Vec4 +//import kool.bufferBig +//import kool.free +//import org.lwjgl.system.MemoryUtil.* +//import org.lwjgl.vulkan.* +//import vkk.* +//import vulkan.PARTICLE_COUNT +//import vulkan.UINT64_MAX +//import vulkan.VERTEX_BUFFER_BIND_ID +//import vulkan.assetPath +//import vulkan.base.Buffer +//import vulkan.base.Texture2D +//import vulkan.base.VulkanExampleBase +//import vulkan.base.tools.VK_FLAGS_NONE +//import java.nio.ByteBuffer +//import kotlin.math.sin +// +// +//fun main(args: Array) { +// GpuParticleSystem().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() // } +//} +// +//class GpuParticleSystem : VulkanExampleBase() { +// +// var animStart = 20f +// var animate = true // TODO fix mouse animation +// +// object textures { +// val particle = Texture2D() +// val gradient = Texture2D() // } -} \ No newline at end of file +// +// object vertices { +// lateinit var inputState: VkPipelineVertexInputStateCreateInfo +// lateinit var bindingDescriptions: VkVertexInputBindingDescription +// lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer +// } +// +// /** Resources for the graphics part of the example */ +// object graphics { +// var descriptorSetLayout = VkDescriptorSetLayout(NULL) // Particle system rendering shader binding layout +// var descriptorSet = VkDescriptorSet(NULL) // Particle system rendering shader bindings +// var pipelineLayout = VkPipelineLayout(NULL) // Layout of the graphics pipeline +// var pipeline = VkPipeline(NULL) // Particle rendering pipeline +// } +// +// /** Resources for the compute part of the example */ +// object compute { +// +// val storageBuffer = Buffer() // (Shader) storage buffer object containing the particles +// val uniformBuffer = Buffer() // Uniform buffer object containing particle system parameters +// lateinit var queue: VkQueue // Separate queue for compute commands (queue family may differ from the one used for graphics) +// var commandPool = VkCommandPool(NULL) // Use a separate command pool (queue family may differ from the one used for graphics) +// lateinit var commandBuffer: VkCommandBuffer // Command buffer storing the dispatch commands and barriers +// var fence = VkFence(NULL) // Synchronization fence to avoid rewriting compute CB if still in use +// var descriptorSetLayout = VkDescriptorSetLayout(NULL) // Compute shader binding layout +// var descriptorSet = VkDescriptorSet(NULL) // Compute shader bindings +// var pipelineLayout = VkPipelineLayout(NULL) // Layout of the compute pipeline +// var pipeline = VkPipeline(NULL) // Compute pipeline for updating particle positions +// +// object ubo { // Compute shader uniform block object +// var deltaT = 0f // Frame delta time +// var dest = Vec2() // x position of the attractor +// var particleCount = PARTICLE_COUNT +// +// fun pack() { +// buffer.putFloat(0, deltaT) +// dest.to(buffer, Float.BYTES) +// buffer.putInt(Float.BYTES + Vec2.size, particleCount) +// } +// +// val size = Float.BYTES + Vec2.size + Int.BYTES +// val buffer = bufferBig(size) +// val address = memAddress(buffer) +// } +// } +// +// // SSBO particle declaration +// class Particle { +// val pos = Vec2() // Particle position +// val vel = Vec2() // Particle velocity +// val gradientPos = Vec4() // Texture coordiantes for the gradient ramp map +// +// fun to(buffer: ByteBuffer, offset: Int) { +// pos.to(buffer, offset) +// vel.to(buffer, offset + Vec2.size) +// gradientPos.to(buffer, offset + Vec2.size * 2) +// } +// +// companion object { +// val size = Vec2.size * 2 + Vec4.size +// val ofsPos = 0 +// val ofsVel = Vec2.size +// val ofsGrd = Vec2.size * 2 +// } +// } +// +// init { +// title = "Compute shader particle system" +//// settings.overlay = true +// } +// +// override fun destroy() { +// +// device.apply { +// // Graphics +// destroyPipeline(graphics.pipeline) +// destroyPipelineLayout(graphics.pipelineLayout) +// destroyDescriptorSetLayout(graphics.descriptorSetLayout) +// +// // Compute +// compute.storageBuffer.destroy() +// compute.uniformBuffer.destroy() +// destroyPipelineLayout(compute.pipelineLayout) +// destroyDescriptorSetLayout(compute.descriptorSetLayout) +// destroyPipeline(compute.pipeline) +// destroyFence(compute.fence) +// destroyCommandPool(compute.commandPool) +// } +// textures.particle.destroy() +// textures.gradient.destroy() +// +// super.destroy() +// } +// +// fun loadAssets() { +// textures.particle.loadFromFile("$assetPath/textures/particle01_rgba.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) +// textures.gradient.loadFromFile("$assetPath/textures/particle_gradient_rgba.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) +// } +// +// override fun buildCommandBuffers() { +// // Destroy command buffers if already present +// if (!checkCommandBuffers()) { +// destroyCommandBuffers() +// createCommandBuffers() +// } +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(defaultClearColor) +// it[1].depthStencil(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@GpuParticleSystem.renderPass +// renderArea.offset(0) +// renderArea.extent(size) +// this.clearValues = clearValues +// } +// for (i in drawCmdBuffers.indices) { +// // Set target frame buffer +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// // Draw the particle system using the update vertex buffer +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// setViewport(size) +// setScissor(size) +// +// bindPipeline(VkPipelineBindPoint.GRAPHICS, graphics.pipeline) +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, graphics.pipelineLayout, graphics.descriptorSet) +// +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, compute.storageBuffer.buffer) +// draw(PARTICLE_COUNT, 1, 0, 0) +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// fun buildComputeCommandBuffer() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// compute.commandBuffer.apply { +// +// begin(cmdBufInfo) +// +// // Compute particle movement +// +// // Add memory barrier to ensure that the (graphics) vertex shader has fetched attributes before compute starts to write to the buffer +// val bufferBarrier = vk.BufferMemoryBarrier { +// buffer = compute.storageBuffer.buffer +// size = compute.storageBuffer.descriptor.range +// srcAccessMask = VkAccess.VERTEX_ATTRIBUTE_READ_BIT.i // Vertex shader invocations have finished reading from the buffer +// dstAccessMask = VkAccess.SHADER_WRITE_BIT.i // Compute shader wants to write to the buffer +// // Compute and graphics queue may have different queue families (see VulkanDevice::createLogicalDevice) +// // For the barrier to work across different queues, we need to set their family indices +// srcQueueFamilyIndex = vulkanDevice.queueFamilyIndices.graphics // Required as compute and graphics queue may have different families +// dstQueueFamilyIndex = vulkanDevice.queueFamilyIndices.compute // Required as compute and graphics queue may have different families +// } +// compute.commandBuffer.pipelineBarrier( +// VkPipelineStage.VERTEX_SHADER_BIT.i, +// VkPipelineStage.COMPUTE_SHADER_BIT.i, +// VK_FLAGS_NONE, +// bufferMemoryBarrier = bufferBarrier) +// +// bindPipeline(VkPipelineBindPoint.COMPUTE, compute.pipeline) +// bindDescriptorSets(VkPipelineBindPoint.COMPUTE, compute.pipelineLayout, compute.descriptorSet) +// +// // Dispatch the compute job +// dispatch(PARTICLE_COUNT / 256, 1, 1) +// +// // Add memory barrier to ensure that compute shader has finished writing to the buffer +// // Without this the (rendering) vertex shader may display incomplete results (partial data from last frame) +// bufferBarrier.apply { +// srcAccessMask = VkAccess.SHADER_WRITE_BIT.i // Compute shader has finished writes to the buffer +// dstAccessMask = VkAccess.VERTEX_ATTRIBUTE_READ_BIT.i // Vertex shader invocations want to read from the buffer +// buffer = compute.storageBuffer.buffer +// size = compute.storageBuffer.descriptor.range +// // Compute and graphics queue may have different queue families (see VulkanDevice::createLogicalDevice) +// // For the barrier to work across different queues, we need to set their family indices +// srcQueueFamilyIndex = vulkanDevice.queueFamilyIndices.compute // Required as compute and graphics queue may have different families +// dstQueueFamilyIndex = vulkanDevice.queueFamilyIndices.graphics // Required as compute and graphics queue may have different families +// } +// compute.commandBuffer.pipelineBarrier( +// VkPipelineStage.COMPUTE_SHADER_BIT.i, +// VkPipelineStage.VERTEX_SHADER_BIT.i, +// VK_FLAGS_NONE, +// bufferMemoryBarrier = bufferBarrier) +// +// end() +// } +// } +// +// /** Setup and fill the compute shader storage buffers containing the particles */ +// fun prepareStorageBuffers() { +// +// // Initial particle positions +// val particlesBuffer = bufferBig(PARTICLE_COUNT * Particle.size) +// for (i in 0 until PARTICLE_COUNT) { +// val particle = Particle().apply { +// pos(glm.linearRand(-1f, 1f), glm.linearRand(-1f, 1f)) +// vel(0f) +// gradientPos.x = pos.x / 2f +// } +// particle.to(particlesBuffer, i * Particle.size) +// } +// +// +// val storageBufferSize = VkDeviceSize(PARTICLE_COUNT * Particle.size.L) +// +// // Staging +// // SSBO won't be changed on the host after upload so copy to device local memory +// +// val stagingBuffer = Buffer() +// +// vulkanDevice.createBuffer( +// VkBufferUsage.TRANSFER_SRC_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// stagingBuffer, +// particlesBuffer) +// +// vulkanDevice.createBuffer( +// // The SSBO will be used as a storage buffer for the compute pipeline and as a vertex buffer in the graphics pipeline +// VkBufferUsage.VERTEX_BUFFER_BIT or VkBufferUsage.STORAGE_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT, +// VkMemoryProperty.DEVICE_LOCAL_BIT.i, +// compute.storageBuffer, +// storageBufferSize) +// +// // Copy to staging buffer +// val copyCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) +// val copyRegion = vk.BufferCopy { size = storageBufferSize } +// copyCmd.copyBuffer(stagingBuffer.buffer, compute.storageBuffer.buffer, copyRegion) +// super.flushCommandBuffer(copyCmd, queue, true) +// +// stagingBuffer.destroy() +// +// // Binding description +// vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, Particle.size, VkVertexInputRate.VERTEX) +// +// // Attribute descriptions +// // Describes memory layout and shader positions +// vertices.attributeDescriptions = vk.VertexInputAttributeDescription( +// // Location 0 : Position +// VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32_SFLOAT, Particle.ofsPos, +// // Location 1 : Gradient position +// VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32A32_SFLOAT, Particle.ofsGrd) +// +// // Assign to vertex buffer +// vertices.inputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertices.bindingDescriptions +// vertexAttributeDescriptions = vertices.attributeDescriptions +// } +// +// particlesBuffer.free() +// } +// +// fun setupDescriptorPool() { +// +// val poolSizes = vk.DescriptorPoolSize( +// VkDescriptorType.UNIFORM_BUFFER, 1, +// VkDescriptorType.STORAGE_BUFFER, 1, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, 2) +// +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) +// +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// // Binding 0 : Particle color map +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 0, +// // Binding 1 : Particle gradient ramp +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// +// graphics.descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(graphics.descriptorSetLayout) +// +// graphics.pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// } +// +// fun setupDescriptorSet() { +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, graphics.descriptorSetLayout) +// +// graphics.descriptorSet = device allocateDescriptorSets allocInfo +// +// val writeDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0 : Particle color map +// graphics.descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 0, textures.particle.descriptor, +// // Binding 1 : Particle gradient ramp +// graphics.descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textures.gradient.descriptor) +// +// device updateDescriptorSets writeDescriptorSets +// } +// +// fun preparePipelines() { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.POINT_LIST, 0, false) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.COUNTER_CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(false, false, VkCompareOp.ALWAYS) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// // Rendering pipeline +// // Load shaders +// val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { +// it[0].loadShader("$assetPath/shaders/computeparticles/particle.vert.spv", VkShaderStage.VERTEX_BIT) +// it[1].loadShader("$assetPath/shaders/computeparticles/particle.frag.spv", VkShaderStage.FRAGMENT_BIT) +// } +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(graphics.pipelineLayout, renderPass).also { +// it.vertexInputState = vertices.inputState +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// it.renderPass = renderPass +// } +// // Additive blending +// blendAttachmentState.apply { +// colorWriteMask = 0xF +// blendEnable = true +// colorBlendOp = VkBlendOp.ADD +// srcColorBlendFactor = VkBlendFactor.ONE +// dstColorBlendFactor = VkBlendFactor.ONE +// alphaBlendOp = VkBlendOp.ADD +// srcAlphaBlendFactor = VkBlendFactor.SRC_ALPHA +// dstAlphaBlendFactor = VkBlendFactor.DST_ALPHA +// } +// graphics.pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// +// fun prepareCompute() { +// /* Create a compute capable device queue +// The VulkanDevice::createLogicalDevice functions finds a compute capable queue and prefers queue families +// that only support compute +// Depending on the implementation this may result in different queue family indices for graphics and computes, +// requiring proper synchronization (see the memory barriers in buildComputeCommandBuffer) */ +// compute.queue = device getQueue vulkanDevice.queueFamilyIndices.compute +// +// // Create compute pipeline +// // Compute pipelines are created separate from graphics pipelines even if they use the same queue (family index) +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// // Binding 0 : Particle position storage buffer +// VkDescriptorType.STORAGE_BUFFER, VkShaderStage.COMPUTE_BIT.i, 0, +// // Binding 1 : Uniform buffer +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.COMPUTE_BIT.i, 1) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// +// compute.descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(compute.descriptorSetLayout) +// +// compute.pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, compute.descriptorSetLayout) +// +// compute.descriptorSet = device allocateDescriptorSets allocInfo +// +// val computeWriteDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0 : Particle position storage buffer +// compute.descriptorSet, VkDescriptorType.STORAGE_BUFFER, 0, compute.storageBuffer.descriptor, +// // Binding 1 : Uniform buffer +// compute.descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 1, compute.uniformBuffer.descriptor) +// +// device updateDescriptorSets computeWriteDescriptorSets +// +// // Create pipeline +// val computePipelineCreateInfo = vk.ComputePipelineCreateInfo(compute.pipelineLayout).apply { +// stage.loadShader("$assetPath/shaders/computeparticles/particle.comp.spv", VkShaderStage.COMPUTE_BIT) +// } +// compute.pipeline = device.createComputePipelines(pipelineCache, computePipelineCreateInfo) +// +// // Separate command pool as queue family for compute may be different than graphics +// val cmdPoolInfo = vk.CommandPoolCreateInfo { +// queueFamilyIndex = vulkanDevice.queueFamilyIndices.compute +// flags = VkCommandPoolCreate.RESET_COMMAND_BUFFER_BIT.i +// } +// compute.commandPool = device createCommandPool cmdPoolInfo +// +// // Create a command buffer for compute operations +// val cmdBufAllocateInfo = vk.CommandBufferAllocateInfo(compute.commandPool, VkCommandBufferLevel.PRIMARY, 1) +// +// compute.commandBuffer = device allocateCommandBuffer cmdBufAllocateInfo +// +// // Fence for compute CB sync +// val fenceCreateInfo = vk.FenceCreateInfo(VkFenceCreate.SIGNALED_BIT.i) +// compute.fence = device createFence fenceCreateInfo +// +// // Build a single command buffer containing the compute dispatch commands +// buildComputeCommandBuffer() +// } +// +// /** Prepare and initialize uniform buffer containing shader uniforms */ +// fun prepareUniformBuffers() { +// // Compute shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// compute.uniformBuffer, +// VkDeviceSize(compute.ubo.size.L)) +// +// // Map for host access +// compute.uniformBuffer.map() +// +// updateUniformBuffers() +// } +// +// fun updateUniformBuffers() { +// +// compute.ubo.deltaT = frameTimer * 2.5f +// if (animate) +// compute.ubo.dest(sin((timer * 360f).rad) * 0.75f, 0f) +// else { +// val normalizedM = (mousePos - (size / 2)) / (size / 2) +// compute.ubo.dest(normalizedM) +// } +// +// compute.ubo.pack() +// memCopy(compute.ubo.address, compute.uniformBuffer.mapped, compute.ubo.size.L) +// } +// +// fun draw() { +// +// val computeSubmitInfo = vk.SubmitInfo { commandBuffer = compute.commandBuffer } +// compute.queue.submit(computeSubmitInfo, compute.fence) +// +// // Submit graphics commands +// super.prepareFrame() +// +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// queue submit submitInfo +// +// super.submitFrame() +// +// // Submit compute commands +// device.waitForFence(compute.fence, true, UINT64_MAX) +// device resetFence compute.fence +// } +// +// override fun prepare() { +// super.prepare() +// loadAssets() +// prepareStorageBuffers() +// prepareUniformBuffers() +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSet() +// prepareCompute() +// buildCommandBuffers() +// prepared = true +// window.show() +// } +// +// override fun render() { +// if (!prepared) +// return +// draw() +// +// if (animate) +// if (animStart > 0f) +// animStart -= frameTimer * 5f +// else if (animStart <= 0f) { +// timer += frameTimer * 0.04f +// if (timer > 1f) +// timer = 0f +// } +// +// updateUniformBuffers() +// } +// +//// virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay) +//// { +//// if (overlay->header("Settings")) { overlay -> +//// checkBox("Moving attractor", & animate) +//// } +//// } +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/computeShader/03 N-Body Simulation.kt b/src/main/kotlin/vulkan/computeShader/03 N-Body Simulation.kt index 9a88ee3..5cf1e19 100644 --- a/src/main/kotlin/vulkan/computeShader/03 N-Body Simulation.kt +++ b/src/main/kotlin/vulkan/computeShader/03 N-Body Simulation.kt @@ -1,682 +1,683 @@ -/* -* Vulkan Example - Compute shader N-body simulation using two passes and shared compute shader memory -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -package vulkan.computeShader - -import glm_.* -import glm_.buffer.bufferBig -import glm_.func.rad -import glm_.mat4x4.Mat4 -import glm_.vec2.Vec2 -import glm_.vec3.Vec3 -import glm_.vec4.Vec4 -import org.lwjgl.system.MemoryUtil.* -import org.lwjgl.vulkan.* -import org.lwjgl.vulkan.VK10.VK_QUEUE_FAMILY_IGNORED -import vkk.* -import vulkan.PARTICLES_PER_ATTRACTOR -import vulkan.VERTEX_BUFFER_BIND_ID -import vulkan.assetPath -import vulkan.base.* -import vulkan.base.tools.VK_FLAGS_NONE -import java.nio.ByteBuffer -import kotlin.math.sin - - -fun main(args: Array) { - NBodySimulation().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - - -private class NBodySimulation : VulkanExampleBase() { - - var numParticles = 0 - - object textures { - val particle = Texture2D() - val gradient = Texture2D() - } - - object vertices { - lateinit var inputState: VkPipelineVertexInputStateCreateInfo - lateinit var bindingDescriptions: VkVertexInputBindingDescription - lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer - } - - /** Resources for the graphics part of the example */ - object graphics { - val uniformBuffer = Buffer() // Contains scene matrices - var descriptorSetLayout: VkDescriptorSetLayout = NULL // Particle system rendering shader binding layout - var descriptorSet: VkDescriptorSet = NULL // Particle system rendering shader bindings - var pipelineLayout: VkPipelineLayout = NULL // Layout of the graphics pipeline - var pipeline: VkPipeline = NULL // Particle rendering pipeline - - object ubo { - var projection = Mat4() - var view = Mat4() - var screenDim = Vec2() - - fun pack() { - projection.to(buffer, 0) - view.to(buffer, Mat4.size) - screenDim.to(buffer, Mat4.size * 2) - } - - val size = Mat4.size * 2 + Vec2.size - val buffer = bufferBig(size) - val address = memAddress(buffer) - } - } - - /** Resources for the compute part of the example */ - object compute { - val storageBuffer = Buffer() // (Shader) storage buffer object containing the particles - val uniformBuffer = Buffer() // Uniform buffer object containing particle system parameters - lateinit var queue: VkQueue // Separate queue for compute commands (queue family may differ from the one used for graphics) - var commandPool: VkCommandPool = NULL // Use a separate command pool (queue family may differ from the one used for graphics) - lateinit var commandBuffer: VkCommandBuffer // Command buffer storing the dispatch commands and barriers - var fence: VkFence = NULL // Synchronization fence to avoid rewriting compute CB if still in use - var descriptorSetLayout: VkDescriptorSetLayout = NULL // Compute shader binding layout - var descriptorSet: VkDescriptorSet = NULL // Compute shader bindings - var pipelineLayout: VkPipelineLayout = NULL // Layout of the compute pipeline - var pipelineCalculate: VkPipeline = NULL // Compute pipeline for N-Body velocity calculation (1st pass) - var pipelineIntegrate: VkPipeline = NULL // Compute pipeline for euler integration (2nd pass) - var blur: VkPipeline = NULL - var pipelineLayoutBlur: VkPipelineLayout = NULL - var descriptorSetLayoutBlur: VkDescriptorSetLayout = NULL - var descriptorSetBlur: VkDescriptorSet = NULL - - object ubo { - // Compute shader uniform block object - var deltaT = 0f // Frame delta time - var dest = Vec2() // x position of the attractor - var particleCount = 0 - - fun pack() { - buffer.putFloat(0, deltaT) - dest.to(buffer, Float.BYTES) - buffer.putInt(Float.BYTES + Vec2.size, particleCount) - } - - val size = Float.BYTES + Vec2.size + Int.BYTES - val buffer = bufferBig(size) - val address = memAddress(buffer) - } - } - - // SSBO particle declaration - class Particle { - var pos = Vec4() // xyz = position, w = mass - var vel = Vec4() // xyz = velocity, w = gradient texture position - - fun to(buffer: ByteBuffer, offset: Int) { - pos.to(buffer, offset) - vel.to(buffer, offset + Vec4.size) - } - - companion object { - val size = Vec4.size * 2 - val ofsPos = 0 - val ofsVel = Vec4.size - } - } - - init { - title = "Compute shader N-body system" -// settings.overlay = true - camera.type = Camera.CameraType.lookAt - camera.setPerspective(60f, size.aspect, 0.1f, 512f) - camera.setRotation(Vec3(-26f, 75f, 0f)) - camera.setTranslation(Vec3(0f, 0f, -14f)) - camera.movementSpeed = 2.5f - } - - override fun destroy() { - - device.apply { - // Graphics - graphics.uniformBuffer.destroy() - destroyPipeline(graphics.pipeline) - destroyPipelineLayout(graphics.pipelineLayout) - destroyDescriptorSetLayout(graphics.descriptorSetLayout) - - // Compute - compute.storageBuffer.destroy() - compute.uniformBuffer.destroy() - destroyPipelineLayout(compute.pipelineLayout) - destroyDescriptorSetLayout(compute.descriptorSetLayout) - destroyPipeline(compute.pipelineCalculate) - destroyPipeline(compute.pipelineIntegrate) - destroyFence(compute.fence) - destroyCommandPool(compute.commandPool) - } - textures.particle.destroy() - textures.gradient.destroy() - - super.destroy() - } - - fun loadAssets() { - textures.particle.loadFromFile("$assetPath/textures/particle01_rgba.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) - textures.gradient.loadFromFile("$assetPath/textures/particle_gradient_rgba.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) - } - - override fun buildCommandBuffers() { - // Destroy command buffers if already present - if (!checkCommandBuffers()) { - destroyCommandBuffers() - createCommandBuffers() - } - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(0f, 0f, 0f, 1f) - it[1].depthStencil.set(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@NBodySimulation.renderPass - renderArea.offset.set(0, 0) - renderArea.extent.set(size.x, size.y) - this.clearValues = clearValues - } - for (i in drawCmdBuffers.indices) { - // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - // Draw the particle system using the update vertex buffer - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - setViewport(size) - setScissor(size) - - bindPipeline(VkPipelineBindPoint.GRAPHICS, graphics.pipeline) - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, graphics.pipelineLayout, graphics.descriptorSet) - - bindVertexBuffers(VERTEX_BUFFER_BIND_ID, compute.storageBuffer.buffer) - draw(numParticles, 1, 0, 0) - - endRenderPass() - - end() - } - } - } - - fun buildComputeCommandBuffer() { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - compute.commandBuffer.apply { - - begin(cmdBufInfo) - - // Compute particle movement - - // Add memory barrier to ensure that the (graphics) vertex shader has fetched attributes before compute starts to write to the buffer - val bufferBarrier = vk.BufferMemoryBarrier { - buffer = compute.storageBuffer.buffer - size = compute.storageBuffer.descriptor.range - srcAccessMask = VkAccess.VERTEX_ATTRIBUTE_READ_BIT.i // Vertex shader invocations have finished reading from the buffer - dstAccessMask = VkAccess.SHADER_WRITE_BIT.i // Compute shader wants to write to the buffer - // Transfer ownership if compute and graphics queue familiy indices differ - srcQueueFamilyIndex = vulkanDevice.queueFamilyIndices.graphics - dstQueueFamilyIndex = vulkanDevice.queueFamilyIndices.compute - } - pipelineBarrier( - VkPipelineStage.VERTEX_SHADER_BIT.i, - VkPipelineStage.COMPUTE_SHADER_BIT.i, - tools.VK_FLAGS_NONE, - bufferMemoryBarrier = bufferBarrier) - - bindPipeline(VkPipelineBindPoint.COMPUTE, compute.pipelineCalculate) - bindDescriptorSets(VkPipelineBindPoint.COMPUTE, compute.pipelineLayout, compute.descriptorSet) - - // First pass: Calculate particle movement - // ------------------------------------------------------------------------------------------------------- - dispatch(numParticles / 256, 1, 1) - - // Add memory barrier to ensure that compute shader has finished writing to the buffer - bufferBarrier.apply { - srcAccessMask = VkAccess.SHADER_WRITE_BIT.i // Compute shader has finished writes to the buffer - dstAccessMask = VkAccess.SHADER_READ_BIT.i - buffer = compute.storageBuffer.buffer - size = compute.storageBuffer.descriptor.range - // No ownership transfer necessary - srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED - dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED - } - pipelineBarrier( - VkPipelineStage.COMPUTE_SHADER_BIT.i, - VkPipelineStage.COMPUTE_SHADER_BIT.i, - VK_FLAGS_NONE, - bufferMemoryBarrier = bufferBarrier) - - // Second pass: Integrate particles - // ------------------------------------------------------------------------------------------------------- - bindPipeline(VkPipelineBindPoint.COMPUTE, compute.pipelineIntegrate) - dispatch(numParticles / 256, 1, 1) - - // Add memory barrier to ensure that compute shader has finished writing to the buffer - // Without this the (rendering) vertex shader may display incomplete results (partial data from last frame) - bufferBarrier.apply { - srcAccessMask = VkAccess.SHADER_WRITE_BIT.i // Compute shader has finished writes to the buffer - dstAccessMask = VkAccess.VERTEX_ATTRIBUTE_READ_BIT.i // Vertex shader invocations want to read from the buffer - buffer = compute.storageBuffer.buffer - size = compute.storageBuffer.descriptor.range - // Transfer ownership if compute and graphics queue familiy indices differ - srcQueueFamilyIndex = vulkanDevice.queueFamilyIndices.compute - dstQueueFamilyIndex = vulkanDevice.queueFamilyIndices.graphics - } - pipelineBarrier( - VkPipelineStage.COMPUTE_SHADER_BIT.i, - VkPipelineStage.VERTEX_SHADER_BIT.i, - VK_FLAGS_NONE, - bufferMemoryBarrier = bufferBarrier) - - end() - } - } - - /** Setup and fill the compute shader storage buffers containing the particles */ - fun prepareStorageBuffers() { - +///* +//* Vulkan Example - Compute shader N-body simulation using two passes and shared compute shader memory +//* +//* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +//package vulkan.computeShader +// +//import glm_.* +//import glm_.func.rad +//import glm_.mat4x4.Mat4 +//import glm_.vec2.Vec2 +//import glm_.vec3.Vec3 +//import glm_.vec4.Vec4 +//import kool.bufferBig +//import org.lwjgl.system.MemoryUtil.* +//import org.lwjgl.vulkan.* +//import org.lwjgl.vulkan.VK10.VK_QUEUE_FAMILY_IGNORED +//import vkk.* +//import vulkan.PARTICLES_PER_ATTRACTOR +//import vulkan.UINT64_MAX +//import vulkan.VERTEX_BUFFER_BIND_ID +//import vulkan.assetPath +//import vulkan.base.* +//import vulkan.base.tools.VK_FLAGS_NONE +//import java.nio.ByteBuffer +//import kotlin.math.sin +// +// +//fun main(args: Array) { +// NBodySimulation().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +// +//private class NBodySimulation : VulkanExampleBase() { +// +// var numParticles = 0 +// +// object textures { +// val particle = Texture2D() +// val gradient = Texture2D() +// } +// +// object vertices { +// lateinit var inputState: VkPipelineVertexInputStateCreateInfo +// lateinit var bindingDescriptions: VkVertexInputBindingDescription +// lateinit var attributeDescriptions: VkVertexInputAttributeDescription.Buffer +// } +// +// /** Resources for the graphics part of the example */ +// object graphics { +// val uniformBuffer = Buffer() // Contains scene matrices +// var descriptorSetLayout= VkDescriptorSetLayout (NULL) // Particle system rendering shader binding layout +// var descriptorSet= VkDescriptorSet (NULL) // Particle system rendering shader bindings +// var pipelineLayout= VkPipelineLayout (NULL) // Layout of the graphics pipeline +// var pipeline= VkPipeline(NULL) // Particle rendering pipeline +// +// object ubo { +// var projection = Mat4() +// var view = Mat4() +// var screenDim = Vec2() +// +// fun pack() { +// projection.to(buffer, 0) +// view.to(buffer, Mat4.size) +// screenDim.to(buffer, Mat4.size * 2) +// } +// +// val size = Mat4.size * 2 + Vec2.size +// val buffer = bufferBig(size) +// val address = memAddress(buffer) +// } +// } +// +// /** Resources for the compute part of the example */ +// object compute { +// val storageBuffer = Buffer() // (Shader) storage buffer object containing the particles +// val uniformBuffer = Buffer() // Uniform buffer object containing particle system parameters +// lateinit var queue: VkQueue // Separate queue for compute commands (queue family may differ from the one used for graphics) +// var commandPool= VkCommandPool (NULL) // Use a separate command pool (queue family may differ from the one used for graphics) +// lateinit var commandBuffer: VkCommandBuffer // Command buffer storing the dispatch commands and barriers +// var fence= VkFence (NULL) // Synchronization fence to avoid rewriting compute CB if still in use +// var descriptorSetLayout= VkDescriptorSetLayout (NULL) // Compute shader binding layout +// var descriptorSet= VkDescriptorSet (NULL) // Compute shader bindings +// var pipelineLayout= VkPipelineLayout (NULL) // Layout of the compute pipeline +// var pipelineCalculate= VkPipeline (NULL) // Compute pipeline for N-Body velocity calculation (1st pass) +// var pipelineIntegrate= VkPipeline (NULL) // Compute pipeline for euler integration (2nd pass) +// var blur= VkPipeline (NULL) +// var pipelineLayoutBlur= VkPipelineLayout (NULL) +// var descriptorSetLayoutBlur= VkDescriptorSetLayout (NULL) +// var descriptorSetBlur= VkDescriptorSet (NULL) +// +// object ubo { +// // Compute shader uniform block object +// var deltaT = 0f // Frame delta time +// var dest = Vec2() // x position of the attractor +// var particleCount = 0 +// +// fun pack() { +// buffer.putFloat(0, deltaT) +// dest.to(buffer, Float.BYTES) +// buffer.putInt(Float.BYTES + Vec2.size, particleCount) +// } +// +// val size = Float.BYTES + Vec2.size + Int.BYTES +// val buffer = bufferBig(size) +// val address = memAddress(buffer) +// } +// } +// +// // SSBO particle declaration +// class Particle { +// var pos = Vec4() // xyz = position, w = mass +// var vel = Vec4() // xyz = velocity, w = gradient texture position +// +// fun to(buffer: ByteBuffer, offset: Int) { +// pos.to(buffer, offset) +// vel.to(buffer, offset + Vec4.size) +// } +// +// companion object { +// val size = Vec4.size * 2 +// val ofsPos = 0 +// val ofsVel = Vec4.size +// } +// } +// +// init { +// title = "Compute shader N-body system" +//// settings.overlay = true +// camera.type = Camera.CameraType.lookAt +// camera.setPerspective(60f, size.aspect, 0.1f, 512f) +// camera.setRotation(Vec3(-26f, 75f, 0f)) +// camera.setTranslation(Vec3(0f, 0f, -14f)) +// camera.movementSpeed = 2.5f +// } +// +// override fun destroy() { +// +// device.apply { +// // Graphics +// graphics.uniformBuffer.destroy() +// destroyPipeline(graphics.pipeline) +// destroyPipelineLayout(graphics.pipelineLayout) +// destroyDescriptorSetLayout(graphics.descriptorSetLayout) +// +// // Compute +// compute.storageBuffer.destroy() +// compute.uniformBuffer.destroy() +// destroyPipelineLayout(compute.pipelineLayout) +// destroyDescriptorSetLayout(compute.descriptorSetLayout) +// destroyPipeline(compute.pipelineCalculate) +// destroyPipeline(compute.pipelineIntegrate) +// destroyFence(compute.fence) +// destroyCommandPool(compute.commandPool) +// } +// textures.particle.destroy() +// textures.gradient.destroy() +// +// super.destroy() +// } +// +// fun loadAssets() { +// textures.particle.loadFromFile("$assetPath/textures/particle01_rgba.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) +// textures.gradient.loadFromFile("$assetPath/textures/particle_gradient_rgba.ktx", VkFormat.R8G8B8A8_UNORM, vulkanDevice, queue) +// } +// +// override fun buildCommandBuffers() { +// // Destroy command buffers if already present +// if (!checkCommandBuffers()) { +// destroyCommandBuffers() +// createCommandBuffers() +// } +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(0f, 0f, 0f, 1f) +// it[1].depthStencil.set(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@NBodySimulation.renderPass +// renderArea.offset.set(0, 0) +// renderArea.extent.set(size.x, size.y) +// this.clearValues = clearValues +// } +// for (i in drawCmdBuffers.indices) { +// // Set target frame buffer +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// // Draw the particle system using the update vertex buffer +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// setViewport(size) +// setScissor(size) +// +// bindPipeline(VkPipelineBindPoint.GRAPHICS, graphics.pipeline) +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, graphics.pipelineLayout, graphics.descriptorSet) +// +// bindVertexBuffers(VERTEX_BUFFER_BIND_ID, compute.storageBuffer.buffer) +// draw(numParticles, 1, 0, 0) +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// fun buildComputeCommandBuffer() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// compute.commandBuffer.apply { +// +// begin(cmdBufInfo) +// +// // Compute particle movement +// +// // Add memory barrier to ensure that the (graphics) vertex shader has fetched attributes before compute starts to write to the buffer +// val bufferBarrier = vk.BufferMemoryBarrier { +// buffer = compute.storageBuffer.buffer +// size = compute.storageBuffer.descriptor.range +// srcAccessMask = VkAccess.VERTEX_ATTRIBUTE_READ_BIT.i // Vertex shader invocations have finished reading from the buffer +// dstAccessMask = VkAccess.SHADER_WRITE_BIT.i // Compute shader wants to write to the buffer +// // Transfer ownership if compute and graphics queue familiy indices differ +// srcQueueFamilyIndex = vulkanDevice.queueFamilyIndices.graphics +// dstQueueFamilyIndex = vulkanDevice.queueFamilyIndices.compute +// } +// pipelineBarrier( +// VkPipelineStage.VERTEX_SHADER_BIT.i, +// VkPipelineStage.COMPUTE_SHADER_BIT.i, +// tools.VK_FLAGS_NONE, +// bufferMemoryBarrier = bufferBarrier) +// +// bindPipeline(VkPipelineBindPoint.COMPUTE, compute.pipelineCalculate) +// bindDescriptorSets(VkPipelineBindPoint.COMPUTE, compute.pipelineLayout, compute.descriptorSet) +// +// // First pass: Calculate particle movement +// // ------------------------------------------------------------------------------------------------------- +// dispatch(numParticles / 256, 1, 1) +// +// // Add memory barrier to ensure that compute shader has finished writing to the buffer +// bufferBarrier.apply { +// srcAccessMask = VkAccess.SHADER_WRITE_BIT.i // Compute shader has finished writes to the buffer +// dstAccessMask = VkAccess.SHADER_READ_BIT.i +// buffer = compute.storageBuffer.buffer +// size = compute.storageBuffer.descriptor.range +// // No ownership transfer necessary +// srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED +// dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED +// } +// pipelineBarrier( +// VkPipelineStage.COMPUTE_SHADER_BIT.i, +// VkPipelineStage.COMPUTE_SHADER_BIT.i, +// VK_FLAGS_NONE, +// bufferMemoryBarrier = bufferBarrier) +// +// // Second pass: Integrate particles +// // ------------------------------------------------------------------------------------------------------- +// bindPipeline(VkPipelineBindPoint.COMPUTE, compute.pipelineIntegrate) +// dispatch(numParticles / 256, 1, 1) +// +// // Add memory barrier to ensure that compute shader has finished writing to the buffer +// // Without this the (rendering) vertex shader may display incomplete results (partial data from last frame) +// bufferBarrier.apply { +// srcAccessMask = VkAccess.SHADER_WRITE_BIT.i // Compute shader has finished writes to the buffer +// dstAccessMask = VkAccess.VERTEX_ATTRIBUTE_READ_BIT.i // Vertex shader invocations want to read from the buffer +// buffer = compute.storageBuffer.buffer +// size = compute.storageBuffer.descriptor.range +// // Transfer ownership if compute and graphics queue familiy indices differ +// srcQueueFamilyIndex = vulkanDevice.queueFamilyIndices.compute +// dstQueueFamilyIndex = vulkanDevice.queueFamilyIndices.graphics +// } +// pipelineBarrier( +// VkPipelineStage.COMPUTE_SHADER_BIT.i, +// VkPipelineStage.VERTEX_SHADER_BIT.i, +// VK_FLAGS_NONE, +// bufferMemoryBarrier = bufferBarrier) +// +// end() +// } +// } +// +// /** Setup and fill the compute shader storage buffers containing the particles */ +// fun prepareStorageBuffers() { +// +//// val attractors = listOf( +//// Vec3(2.5f, 1.5f, 0f), +//// Vec3(-2.5f, -1.5f, 0f)) // val attractors = listOf( -// Vec3(2.5f, 1.5f, 0f), -// Vec3(-2.5f, -1.5f, 0f)) - val attractors = listOf( - Vec3(5f, 0f, 0f), - Vec3(-5f, 0f, 0f), - Vec3(0f, 0f, 5f), - Vec3(0f, 0f, -5f), - Vec3(0f, 4f, 0f), - Vec3(0f, -8f, 0f)) - - numParticles = attractors.size * PARTICLES_PER_ATTRACTOR - - // Initial particle positions - val particleBuffer = bufferBig(numParticles * Particle.size) - - fun next() = glm.linearRand(0f, 1f) - - for (i in attractors.indices) - for (j in 0 until PARTICLES_PER_ATTRACTOR) { - - val particle = Particle() - - // First particle in group as heavy center of gravity - if (j == 0) { - particle.pos(attractors[i] * 1.5f, 90000f) - particle.vel(0f) - } else { - // Position - val position = attractors[i] + Vec3 { next() } * 0.75f - val len = (position - attractors[i]).normalizeAssign().length() - position.y *= 2f - len * len - - // Velocity - val angular = Vec3(0.5f, 1.5f, 0.5f) * if ((i % 2) == 0) 1f else -1f - val velocity = ((position - attractors[i]) cross angular) + Vec3(next(), next(), next() * 0.025f) - - val mass = (next() * 0.5f + 0.5f) * 75f - particle.pos(position, mass) - particle.vel(velocity, 0f) - } - - // Color gradient offset - particle.vel.w = i * 1f / attractors.size - - particle.to(particleBuffer, (i * PARTICLES_PER_ATTRACTOR + j) * Particle.size) - } - - compute.ubo.particleCount = numParticles - - val storageBufferSize: VkDeviceSize = particleBuffer.size.L - - // Staging - // SSBO won't be changed on the host after upload so copy to device local memory - - val stagingBuffer = Buffer() - - vulkanDevice.createBuffer( - VkBufferUsage.TRANSFER_SRC_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - stagingBuffer, - particleBuffer) - - vulkanDevice.createBuffer( - // The SSBO will be used as a storage buffer for the compute pipeline and as a vertex buffer in the graphics pipeline - VkBufferUsage.VERTEX_BUFFER_BIT or VkBufferUsage.STORAGE_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT, - VkMemoryProperty.DEVICE_LOCAL_BIT.i, - compute.storageBuffer, - storageBufferSize) - - // Copy to staging buffer - val copyCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) - val copyRegion = vk.BufferCopy { size = storageBufferSize } - copyCmd.copyBuffer(stagingBuffer.buffer, compute.storageBuffer.buffer, copyRegion) - super.flushCommandBuffer(copyCmd, queue, true) - - stagingBuffer.destroy() - - // Binding description - vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, Particle.size, VkVertexInputRate.VERTEX) - - // Attribute descriptions - // Describes memory layout and shader positions - vertices.attributeDescriptions = vk.VertexInputAttributeDescription( - // Location 0 : Position - VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32A32_SFLOAT, Particle.ofsPos, - // Location 1 : Velocity (used for gradient lookup) - VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32A32_SFLOAT, Particle.ofsVel) - - // Assign to vertex buffer - vertices.inputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertices.bindingDescriptions - vertexAttributeDescriptions = vertices.attributeDescriptions - } - } - - fun setupDescriptorPool() { - - val poolSizes = vk.DescriptorPoolSize( - VkDescriptorType.UNIFORM_BUFFER, 2, - VkDescriptorType.STORAGE_BUFFER, 1, - VkDescriptorType.COMBINED_IMAGE_SAMPLER, 2) - - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) - - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 0, - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1, - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 2) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - - graphics.descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(graphics.descriptorSetLayout) - - graphics.pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - } - - fun setupDescriptorSet() { - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, graphics.descriptorSetLayout) - - graphics.descriptorSet = device allocateDescriptorSets allocInfo - - val writeDescriptorSets = vk.WriteDescriptorSet( - graphics.descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 0, textures.particle.descriptor, - graphics.descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textures.gradient.descriptor, - graphics.descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 2, graphics.uniformBuffer.descriptor) - - device updateDescriptorSets writeDescriptorSets - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.POINT_LIST, 0, false) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.COUNTER_CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(false, false, VkCompareOp.ALWAYS) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - // Rendering pipeline - // Load shaders - val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { - it[0].loadShader("$assetPath/shaders/computenbody/particle.vert.spv", VkShaderStage.VERTEX_BIT) - it[1].loadShader("$assetPath/shaders/computenbody/particle.frag.spv", VkShaderStage.FRAGMENT_BIT) - } - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(graphics.pipelineLayout, renderPass).also { - it.vertexInputState = vertices.inputState - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - it.renderPass = renderPass - } - // Additive blending - blendAttachmentState.apply { - colorWriteMask = 0xF - blendEnable = true - colorBlendOp = VkBlendOp.ADD - srcColorBlendFactor = VkBlendFactor.ONE - dstColorBlendFactor = VkBlendFactor.ONE - alphaBlendOp = VkBlendOp.ADD - srcAlphaBlendFactor = VkBlendFactor.SRC_ALPHA - dstAlphaBlendFactor = VkBlendFactor.DST_ALPHA - } - graphics.pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - // Set shader parameters via specialization constants - object specializationData { - var sharedDataSize = 0 - var gravity = 0f - var power = 0f - var soften = 0f - - fun toBuffer() = bufferBig(size).apply { - putInt(offset.sharedDataSize, sharedDataSize) - putFloat(offset.gravity, gravity) - putFloat(offset.power, power) - putFloat(offset.soften, soften) - } - - val size = Int.BYTES + Float.BYTES * 3 - - object offset { - val sharedDataSize = 0 - val gravity = Int.BYTES - val power = gravity + Float.BYTES - val soften = power + Float.BYTES - } - } - - fun prepareCompute() { - /* Create a compute capable device queue - The VulkanDevice::createLogicalDevice functions finds a compute capable queue and prefers queue families - that only support compute - Depending on the implementation this may result in different queue family indices for graphics and computes, - requiring proper synchronization (see the memory barriers in buildComputeCommandBuffer) */ - val queueCreateInfo = vk.DeviceQueueCreateInfo { - queueFamilyIndex = vulkanDevice.queueFamilyIndices.compute - } - compute.queue = device getQueue vulkanDevice.queueFamilyIndices.compute - - // Create compute pipeline - // Compute pipelines are created separate from graphics pipelines even if they use the same queue (family index) - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - // Binding 0 : Particle position storage buffer - VkDescriptorType.STORAGE_BUFFER, VkShaderStage.COMPUTE_BIT.i, 0, - // Binding 1 : Uniform buffer - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.COMPUTE_BIT.i, 1) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - - compute.descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(compute.descriptorSetLayout) - - compute.pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, compute.descriptorSetLayout) - - compute.descriptorSet = device allocateDescriptorSets allocInfo - - val computeWriteDescriptorSets = vk.WriteDescriptorSet( - // Binding 0 : Particle position storage buffer - compute.descriptorSet, VkDescriptorType.STORAGE_BUFFER, 0, compute.storageBuffer.descriptor, - // Binding 1 : Uniform buffer - compute.descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 1, compute.uniformBuffer.descriptor) - - device updateDescriptorSets computeWriteDescriptorSets - - // Create pipelines - val computePipelineCreateInfo = vk.ComputePipelineCreateInfo(compute.pipelineLayout).apply { - // 1st pass - stage.loadShader("$assetPath/shaders/computenbody/particle_calculate.comp.spv", VkShaderStage.COMPUTE_BIT) - } - - val specializationMapEntries = vk.SpecializationMapEntry( - 0, specializationData.offset.sharedDataSize, Int.BYTES, - 1, specializationData.offset.gravity, Float.BYTES, - 2, specializationData.offset.power, Float.BYTES, - 3, specializationData.offset.soften, Float.BYTES) - - specializationData.apply { - sharedDataSize = 1024 min (vulkanDevice.properties.limits.maxComputeSharedMemorySize / Vec4.size) - gravity = 0.002f - power = 0.75f - soften = 0.05f - } - val specializationInfo = vk.SpecializationInfo(specializationMapEntries, specializationData.toBuffer()) - computePipelineCreateInfo.stage.specializationInfo = specializationInfo - - compute.pipelineCalculate = device.createComputePipelines(pipelineCache, computePipelineCreateInfo) - - // 2nd pass - computePipelineCreateInfo.stage.loadShader("$assetPath/shaders/computenbody/particle_integrate.comp.spv", VkShaderStage.COMPUTE_BIT) - compute.pipelineIntegrate = device.createComputePipelines(pipelineCache, computePipelineCreateInfo) - - // Separate command pool as queue family for compute may be different than graphics - val cmdPoolInfo = vk.CommandPoolCreateInfo { - queueFamilyIndex = vulkanDevice.queueFamilyIndices.compute - flags = VkCommandPoolCreate.RESET_COMMAND_BUFFER_BIT.i - } - compute.commandPool = device createCommandPool cmdPoolInfo - - // Create a command buffer for compute operations - val cmdBufAllocateInfo = vk.CommandBufferAllocateInfo(compute.commandPool, VkCommandBufferLevel.PRIMARY, 1) - - compute.commandBuffer = device allocateCommandBuffer cmdBufAllocateInfo - - // Fence for compute CB sync - val fenceCreateInfo = vk.FenceCreateInfo(VkFenceCreate.SIGNALED_BIT.i) - compute.fence = device createFence fenceCreateInfo - - // Build a single command buffer containing the compute dispatch commands - buildComputeCommandBuffer() - } - - /** Prepare and initialize uniform buffer containing shader uniforms */ - fun prepareUniformBuffers() { - // Compute shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - compute.uniformBuffer, - compute.ubo.size.L) - - // Map for host access - compute.uniformBuffer.map() - - // Vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - graphics.uniformBuffer, - graphics.ubo.size.L) - - // Map for host access - graphics.uniformBuffer.map() - - updateGraphicsUniformBuffers() - } - - fun updateUniformBuffers() { - compute.ubo.deltaT = if (paused) 0f else frameTimer * 0.05f - compute.ubo.dest(sin((timer * 360f).rad) * 0.75f, 0f) - compute.ubo.pack() - memCopy(compute.ubo.address, compute.uniformBuffer.mapped, compute.ubo.size.L) - } - - fun updateGraphicsUniformBuffers() { - graphics.ubo.projection put camera.matrices.perspective - graphics.ubo.view put camera.matrices.view - graphics.ubo.screenDim(size) - compute.ubo.pack() - memCopy(graphics.ubo.address, graphics.uniformBuffer.mapped, graphics.ubo.size.L) - } - - fun draw() { - // Submit graphics commands - super.prepareFrame() - - submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] - queue submit submitInfo - - super.submitFrame() - - // Submit compute commands - device.waitForFence(compute.fence, true, UINT64_MAX) - device resetFence compute.fence - - val computeSubmitInfo = vk.SubmitInfo { commandBuffer = compute.commandBuffer } - - compute.queue.submit(computeSubmitInfo, compute.fence) - } - - override fun prepare() { - super.prepare() - loadAssets() - prepareStorageBuffers() - prepareUniformBuffers() - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSet() - prepareCompute() - buildCommandBuffers() - prepared = true - window.show() - } - - override fun render() { - if (!prepared) - return - draw() - updateUniformBuffers() - } - - override fun viewChanged() = updateGraphicsUniformBuffers() -} \ No newline at end of file +// Vec3(5f, 0f, 0f), +// Vec3(-5f, 0f, 0f), +// Vec3(0f, 0f, 5f), +// Vec3(0f, 0f, -5f), +// Vec3(0f, 4f, 0f), +// Vec3(0f, -8f, 0f)) +// +// numParticles = attractors.size * PARTICLES_PER_ATTRACTOR +// +// // Initial particle positions +// val particleBuffer = bufferBig(numParticles * Particle.size) +// +// fun next() = glm.linearRand(0f, 1f) +// +// for (i in attractors.indices) +// for (j in 0 until PARTICLES_PER_ATTRACTOR) { +// +// val particle = Particle() +// +// // First particle in group as heavy center of gravity +// if (j == 0) { +// particle.pos(attractors[i] * 1.5f, 90000f) +// particle.vel(0f) +// } else { +// // Position +// val position = attractors[i] + Vec3 { next() } * 0.75f +// val len = (position - attractors[i]).normalizeAssign().length() +// position.y *= 2f - len * len +// +// // Velocity +// val angular = Vec3(0.5f, 1.5f, 0.5f) * if ((i % 2) == 0) 1f else -1f +// val velocity = ((position - attractors[i]) cross angular) + Vec3(next(), next(), next() * 0.025f) +// +// val mass = (next() * 0.5f + 0.5f) * 75f +// particle.pos(position, mass) +// particle.vel(velocity, 0f) +// } +// +// // Color gradient offset +// particle.vel.w = i * 1f / attractors.size +// +// particle.to(particleBuffer, (i * PARTICLES_PER_ATTRACTOR + j) * Particle.size) +// } +// +// compute.ubo.particleCount = numParticles +// +// val storageBufferSize = VkDeviceSize(particleBuffer.size.L) +// +// // Staging +// // SSBO won't be changed on the host after upload so copy to device local memory +// +// val stagingBuffer = Buffer() +// +// vulkanDevice.createBuffer( +// VkBufferUsage.TRANSFER_SRC_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// stagingBuffer, +// particleBuffer) +// +// vulkanDevice.createBuffer( +// // The SSBO will be used as a storage buffer for the compute pipeline and as a vertex buffer in the graphics pipeline +// VkBufferUsage.VERTEX_BUFFER_BIT or VkBufferUsage.STORAGE_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT, +// VkMemoryProperty.DEVICE_LOCAL_BIT.i, +// compute.storageBuffer, +// storageBufferSize) +// +// // Copy to staging buffer +// val copyCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) +// val copyRegion = vk.BufferCopy { size = storageBufferSize } +// copyCmd.copyBuffer(stagingBuffer.buffer, compute.storageBuffer.buffer, copyRegion) +// super.flushCommandBuffer(copyCmd, queue, true) +// +// stagingBuffer.destroy() +// +// // Binding description +// vertices.bindingDescriptions = vk.VertexInputBindingDescription(VERTEX_BUFFER_BIND_ID, Particle.size, VkVertexInputRate.VERTEX) +// +// // Attribute descriptions +// // Describes memory layout and shader positions +// vertices.attributeDescriptions = vk.VertexInputAttributeDescription( +// // Location 0 : Position +// VERTEX_BUFFER_BIND_ID, 0, VkFormat.R32G32B32A32_SFLOAT, Particle.ofsPos, +// // Location 1 : Velocity (used for gradient lookup) +// VERTEX_BUFFER_BIND_ID, 1, VkFormat.R32G32B32A32_SFLOAT, Particle.ofsVel) +// +// // Assign to vertex buffer +// vertices.inputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertices.bindingDescriptions +// vertexAttributeDescriptions = vertices.attributeDescriptions +// } +// } +// +// fun setupDescriptorPool() { +// +// val poolSizes = vk.DescriptorPoolSize( +// VkDescriptorType.UNIFORM_BUFFER, 2, +// VkDescriptorType.STORAGE_BUFFER, 1, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, 2) +// +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) +// +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 0, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 1, +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 2) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// +// graphics.descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(graphics.descriptorSetLayout) +// +// graphics.pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// } +// +// fun setupDescriptorSet() { +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, graphics.descriptorSetLayout) +// +// graphics.descriptorSet = device allocateDescriptorSets allocInfo +// +// val writeDescriptorSets = vk.WriteDescriptorSet( +// graphics.descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 0, textures.particle.descriptor, +// graphics.descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1, textures.gradient.descriptor, +// graphics.descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 2, graphics.uniformBuffer.descriptor) +// +// device updateDescriptorSets writeDescriptorSets +// } +// +// fun preparePipelines() { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.POINT_LIST, 0, false) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.COUNTER_CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(false, false, VkCompareOp.ALWAYS) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// // Rendering pipeline +// // Load shaders +// val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { +// it[0].loadShader("$assetPath/shaders/computenbody/particle.vert.spv", VkShaderStage.VERTEX_BIT) +// it[1].loadShader("$assetPath/shaders/computenbody/particle.frag.spv", VkShaderStage.FRAGMENT_BIT) +// } +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(graphics.pipelineLayout, renderPass).also { +// it.vertexInputState = vertices.inputState +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// it.renderPass = renderPass +// } +// // Additive blending +// blendAttachmentState.apply { +// colorWriteMask = 0xF +// blendEnable = true +// colorBlendOp = VkBlendOp.ADD +// srcColorBlendFactor = VkBlendFactor.ONE +// dstColorBlendFactor = VkBlendFactor.ONE +// alphaBlendOp = VkBlendOp.ADD +// srcAlphaBlendFactor = VkBlendFactor.SRC_ALPHA +// dstAlphaBlendFactor = VkBlendFactor.DST_ALPHA +// } +// graphics.pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// +// // Set shader parameters via specialization constants +// object specializationData { +// var sharedDataSize = 0 +// var gravity = 0f +// var power = 0f +// var soften = 0f +// +// fun toBuffer() = bufferBig(size).apply { +// putInt(offset.sharedDataSize, sharedDataSize) +// putFloat(offset.gravity, gravity) +// putFloat(offset.power, power) +// putFloat(offset.soften, soften) +// } +// +// val size = Int.BYTES + Float.BYTES * 3 +// +// object offset { +// val sharedDataSize = 0 +// val gravity = Int.BYTES +// val power = gravity + Float.BYTES +// val soften = power + Float.BYTES +// } +// } +// +// fun prepareCompute() { +// /* Create a compute capable device queue +// The VulkanDevice::createLogicalDevice functions finds a compute capable queue and prefers queue families +// that only support compute +// Depending on the implementation this may result in different queue family indices for graphics and computes, +// requiring proper synchronization (see the memory barriers in buildComputeCommandBuffer) */ +// val queueCreateInfo = vk.DeviceQueueCreateInfo { +// queueFamilyIndex = vulkanDevice.queueFamilyIndices.compute +// } +// compute.queue = device getQueue vulkanDevice.queueFamilyIndices.compute +// +// // Create compute pipeline +// // Compute pipelines are created separate from graphics pipelines even if they use the same queue (family index) +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// // Binding 0 : Particle position storage buffer +// VkDescriptorType.STORAGE_BUFFER, VkShaderStage.COMPUTE_BIT.i, 0, +// // Binding 1 : Uniform buffer +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.COMPUTE_BIT.i, 1) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// +// compute.descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(compute.descriptorSetLayout) +// +// compute.pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, compute.descriptorSetLayout) +// +// compute.descriptorSet = device allocateDescriptorSets allocInfo +// +// val computeWriteDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0 : Particle position storage buffer +// compute.descriptorSet, VkDescriptorType.STORAGE_BUFFER, 0, compute.storageBuffer.descriptor, +// // Binding 1 : Uniform buffer +// compute.descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 1, compute.uniformBuffer.descriptor) +// +// device updateDescriptorSets computeWriteDescriptorSets +// +// // Create pipelines +// val computePipelineCreateInfo = vk.ComputePipelineCreateInfo(compute.pipelineLayout).apply { +// // 1st pass +// stage.loadShader("$assetPath/shaders/computenbody/particle_calculate.comp.spv", VkShaderStage.COMPUTE_BIT) +// } +// +// val specializationMapEntries = vk.SpecializationMapEntry( +// 0, specializationData.offset.sharedDataSize, Int.BYTES, +// 1, specializationData.offset.gravity, Float.BYTES, +// 2, specializationData.offset.power, Float.BYTES, +// 3, specializationData.offset.soften, Float.BYTES) +// +// specializationData.apply { +// sharedDataSize = 1024 min (vulkanDevice.properties.limits.maxComputeSharedMemorySize / Vec4.size) +// gravity = 0.002f +// power = 0.75f +// soften = 0.05f +// } +// val specializationInfo = vk.SpecializationInfo(specializationMapEntries, specializationData.toBuffer()) +// computePipelineCreateInfo.stage.specializationInfo = specializationInfo +// +// compute.pipelineCalculate = device.createComputePipelines(pipelineCache, computePipelineCreateInfo) +// +// // 2nd pass +// computePipelineCreateInfo.stage.loadShader("$assetPath/shaders/computenbody/particle_integrate.comp.spv", VkShaderStage.COMPUTE_BIT) +// compute.pipelineIntegrate = device.createComputePipelines(pipelineCache, computePipelineCreateInfo) +// +// // Separate command pool as queue family for compute may be different than graphics +// val cmdPoolInfo = vk.CommandPoolCreateInfo { +// queueFamilyIndex = vulkanDevice.queueFamilyIndices.compute +// flags = VkCommandPoolCreate.RESET_COMMAND_BUFFER_BIT.i +// } +// compute.commandPool = device createCommandPool cmdPoolInfo +// +// // Create a command buffer for compute operations +// val cmdBufAllocateInfo = vk.CommandBufferAllocateInfo(compute.commandPool, VkCommandBufferLevel.PRIMARY, 1) +// +// compute.commandBuffer = device allocateCommandBuffer cmdBufAllocateInfo +// +// // Fence for compute CB sync +// val fenceCreateInfo = vk.FenceCreateInfo(VkFenceCreate.SIGNALED_BIT.i) +// compute.fence = device createFence fenceCreateInfo +// +// // Build a single command buffer containing the compute dispatch commands +// buildComputeCommandBuffer() +// } +// +// /** Prepare and initialize uniform buffer containing shader uniforms */ +// fun prepareUniformBuffers() { +// // Compute shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// compute.uniformBuffer, +// VkDeviceSize( compute.ubo.size.L)) +// +// // Map for host access +// compute.uniformBuffer.map() +// +// // Vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// graphics.uniformBuffer, +// VkDeviceSize(graphics.ubo.size.L)) +// +// // Map for host access +// graphics.uniformBuffer.map() +// +// updateGraphicsUniformBuffers() +// } +// +// fun updateUniformBuffers() { +// compute.ubo.deltaT = if (paused) 0f else frameTimer * 0.05f +// compute.ubo.dest(sin((timer * 360f).rad) * 0.75f, 0f) +// compute.ubo.pack() +// memCopy(compute.ubo.address, compute.uniformBuffer.mapped, compute.ubo.size.L) +// } +// +// fun updateGraphicsUniformBuffers() { +// graphics.ubo.projection put camera.matrices.perspective +// graphics.ubo.view put camera.matrices.view +// graphics.ubo.screenDim(size) +// compute.ubo.pack() +// memCopy(graphics.ubo.address, graphics.uniformBuffer.mapped, graphics.ubo.size.L) +// } +// +// fun draw() { +// // Submit graphics commands +// super.prepareFrame() +// +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// queue submit submitInfo +// +// super.submitFrame() +// +// // Submit compute commands +// device.waitForFence(compute.fence, true, UINT64_MAX) +// device resetFence compute.fence +// +// val computeSubmitInfo = vk.SubmitInfo { commandBuffer = compute.commandBuffer } +// +// compute.queue.submit(computeSubmitInfo, compute.fence) +// } +// +// override fun prepare() { +// super.prepare() +// loadAssets() +// prepareStorageBuffers() +// prepareUniformBuffers() +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSet() +// prepareCompute() +// buildCommandBuffers() +// prepared = true +// window.show() +// } +// +// override fun render() { +// if (!prepared) +// return +// draw() +// updateUniformBuffers() +// } +// +// override fun viewChanged() = updateGraphicsUniformBuffers() +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/computeShader/04 Ray Tracing.kt b/src/main/kotlin/vulkan/computeShader/04 Ray Tracing.kt index da88eea..e95dcbc 100644 --- a/src/main/kotlin/vulkan/computeShader/04 Ray Tracing.kt +++ b/src/main/kotlin/vulkan/computeShader/04 Ray Tracing.kt @@ -1,622 +1,622 @@ -/* -* Vulkan Example - Compute shader ray tracing -* -* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -package vulkan.computeShader - -import glm_.BYTES -import glm_.L -import glm_.buffer.bufferBig -import glm_.func.rad -import glm_.size -import glm_.vec2.Vec2i -import glm_.vec3.Vec3 -import glm_.vec3.Vec3i -import glm_.vec4.Vec4 -import org.lwjgl.system.MemoryUtil.* -import org.lwjgl.vulkan.VK10.VK_WHOLE_SIZE -import org.lwjgl.vulkan.VkCommandBuffer -import org.lwjgl.vulkan.VkQueue -import vkk.* -import vulkan.TEX_DIM -import vulkan.assetPath -import vulkan.base.* -import vulkan.base.tools.VK_FLAGS_NONE -import kotlin.math.cos -import kotlin.math.sin - - -fun main(args: Array) { - RayTracing().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - -class RayTracing : VulkanExampleBase() { - - val textureComputeTarget = Texture() - - /** Resources for the graphics part of the example */ - object graphics { - var descriptorSetLayout: VkDescriptorSetLayout = NULL // Raytraced image display shader binding layout - var descriptorSetPreCompute: VkDescriptorSet = NULL // Raytraced image display shader bindings before compute shader image manipulation - var descriptorSet: VkDescriptorSet = NULL // Raytraced image display shader bindings after compute shader image manipulation - var pipeline: VkPipeline = NULL // Raytraced image display pipeline - var pipelineLayout: VkPipelineLayout = NULL // Layout of the graphics pipeline - } - - /** Resources for the compute part of the example */ - object compute { - object storageBuffers { - val spheres = Buffer() // (Shader) storage buffer object with scene spheres - val planes = Buffer() // (Shader) storage buffer object with scene planes - } - - val uniformBuffer = Buffer() // Uniform buffer object containing scene data - lateinit var queue: VkQueue // Separate queue for compute commands (queue family may differ from the one used for graphics) - var commandPool: VkCommandPool = NULL // Use a separate command pool (queue family may differ from the one used for graphics) - lateinit var commandBuffer: VkCommandBuffer // Command buffer storing the dispatch commands and barriers - var fence: VkFence = NULL // Synchronization fence to avoid rewriting compute CB if still in use - var descriptorSetLayout: VkDescriptorSetLayout = NULL // Compute shader binding layout - var descriptorSet: VkDescriptorSet = NULL // Compute shader bindings - var pipelineLayout: VkPipelineLayout = NULL // Layout of the compute pipeline - var pipeline: VkPipeline = NULL // Compute raytracing pipeline - - object ubo { - // Compute shader uniform block object - var lightPos = Vec3() - var aspectRatio = 0f // Aspect ratio of the viewport - var fogColor = Vec4(0f) - - object camera { - var pos = Vec3(0f, 0f, 4f) - var lookat = Vec3(0f, 0.5f, 0f) - var fov = 10f - } - - fun pack() { - lightPos to buffer - buffer.putFloat(Vec3.size, aspectRatio) - fogColor.to(buffer, Vec4.size) - camera.pos.to(buffer, Vec4.size * 2) - camera.lookat.to(buffer, Vec4.size * 2 + Vec3.size) - buffer.putFloat(Vec4.size + Vec3.size * 2, camera.fov) - } - - val size = Vec4.size * 2 + Vec3.size * 2 + 2 * Float.BYTES - val buffer = bufferBig(size) - val address = memAddress(buffer) - } - } - - // SSBO sphere declaration - class Sphere( // Shader uses std140 layout (so we only use vec4 instead of vec3) - val pos: Vec3, - val radius: Float, - val diffuse: Vec3, - val specular: Float, - /** Id used to identify sphere for raytracing */ - val id: Int) : Bufferizable() { - - lateinit var _pad: Vec3i - - override var fieldOrder = arrayOf("pos", "radius", "diffuse", "specular", "id") - - companion object { - val size = Vec4.size * 3 - } - } - - // SSBO plane declaration - class Plane( - val normal: Vec3, - var distance: Float, - val diffuse: Vec3, - val specular: Float, - val id: Int) : Bufferizable() { - - lateinit var _pad: Vec3i - - override var fieldOrder = arrayOf("normal", "distance", "diffuse", "specular", "id") - } - - init { - title = "Compute shader ray tracing" -// settings.overlay = true - compute.ubo.aspectRatio = size.aspect - timerSpeed *= 0.25f - - camera.type = Camera.CameraType.lookAt - camera.setPerspective(60f, size.aspect, 0.1f, 512f) - camera.setRotation(Vec3()) - camera.setTranslation(Vec3(0f, 0f, -4f)) - camera.rotationSpeed = 0f - camera.movementSpeed = 2.5f - } - - override fun destroy() { - - device.apply { - // Graphics - destroyPipeline(graphics.pipeline) - destroyPipelineLayout(graphics.pipelineLayout) - destroyDescriptorSetLayout(graphics.descriptorSetLayout) - - // Compute - destroyPipeline(compute.pipeline) - destroyPipelineLayout(compute.pipelineLayout) - destroyDescriptorSetLayout(compute.descriptorSetLayout) - destroyFence(compute.fence) - destroyCommandPool(compute.commandPool) - } - compute.uniformBuffer.destroy() - compute.storageBuffers.spheres.destroy() - compute.storageBuffers.planes.destroy() - textureComputeTarget.destroy() - - super.destroy() - } - - /** Prepare a texture target that is used to store compute shader calculations */ - fun prepareTextureTarget(tex: Texture, size: Vec2i, format: VkFormat) { - // Get device properties for the requested texture format - val formatProperties = physicalDevice getFormatProperties format - // Check if requested image format supports image storage operations - assert(formatProperties.optimalTilingFeatures has VkFormatFeature.STORAGE_IMAGE_BIT) - - // Prepare blit target texture - tex.size(size) - - val imageCreateInfo = vk.ImageCreateInfo { - imageType = VkImageType.`2D` - this.format = format - extent.set(size.x, size.y, 1) - mipLevels = 1 - arrayLayers = 1 - samples = VkSampleCount.`1_BIT` - tiling = VkImageTiling.OPTIMAL - initialLayout = VkImageLayout.UNDEFINED - // Image will be sampled in the fragment shader and used as storage target in the compute shader - usage = VkImageUsage.SAMPLED_BIT or VkImageUsage.STORAGE_BIT - flags = 0 - } - - tex.image = device createImage imageCreateInfo - val memReqs = device.getImageMemoryRequirements(tex.image) - val memAllocInfo = vk.MemoryAllocateInfo { - allocationSize = memReqs.size - memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) - } - tex.deviceMemory = device allocateMemory memAllocInfo - device.bindImageMemory(tex.image, tex.deviceMemory) - - val layoutCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) - - tex.imageLayout = VkImageLayout.GENERAL - tools.setImageLayout( - layoutCmd, - tex.image, - VkImageAspect.COLOR_BIT.i, - VkImageLayout.UNDEFINED, - tex.imageLayout) - - super.flushCommandBuffer(layoutCmd, queue, true) - - // Create sampler - val sampler = vk.SamplerCreateInfo { - magFilter = VkFilter.LINEAR - minFilter = VkFilter.LINEAR - mipmapMode = VkSamplerMipmapMode.LINEAR - addressModeU = VkSamplerAddressMode.CLAMP_TO_BORDER - addressModeV = addressModeU - addressModeW = addressModeU - mipLodBias = 0f - maxAnisotropy = 1f - compareOp = VkCompareOp.NEVER - minLod = 0f - maxLod = 0f - borderColor = VkBorderColor.FLOAT_OPAQUE_WHITE - } - tex.sampler = device createSampler sampler - - // Create image view - val view = vk.ImageViewCreateInfo { - viewType = VkImageViewType.`2D` - this.format = format - components(VkComponentSwizzle.R, VkComponentSwizzle.G, VkComponentSwizzle.B, VkComponentSwizzle.A) - subresourceRange.set(VkImageAspect.COLOR_BIT.i, 0, 1, 0, 1) - image = tex.image - } - tex.view = device createImageView view - - // Initialize a descriptor for later use - tex.descriptor.imageLayout = tex.imageLayout - tex.descriptor.imageView = tex.view - tex.descriptor.sampler = tex.sampler - tex.device = vulkanDevice - } - - override fun buildCommandBuffers() { - // Destroy command buffers if already present - if (!checkCommandBuffers()) { - destroyCommandBuffers() - createCommandBuffers() - } - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(defaultClearColor) - it[1].depthStencil.set(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@RayTracing.renderPass - renderArea.apply { - offset.set(0, 0) - extent.set(size.x, size.y) - } - this.clearValues = clearValues - } - for (i in drawCmdBuffers.indices) { - // Set target frame buffer - renderPassBeginInfo.framebuffer(frameBuffers[i]) - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - // Image memory barrier to make sure that compute shader writes are finished before sampling from the texture - val imageMemoryBarrier = vk.ImageMemoryBarrier { - oldLayout = VkImageLayout.GENERAL - newLayout = VkImageLayout.GENERAL - image = textureComputeTarget.image - subresourceRange.set(VkImageAspect.COLOR_BIT.i, 0, 1, 0, 1) - srcAccessMask = VkAccess.SHADER_WRITE_BIT.i - dstAccessMask = VkAccess.SHADER_READ_BIT.i - } - pipelineBarrier( - VkPipelineStage.COMPUTE_SHADER_BIT.i, - VkPipelineStage.FRAGMENT_SHADER_BIT.i, - VK_FLAGS_NONE, - imageMemoryBarrier = imageMemoryBarrier) - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - setViewport(size) - setScissor(size) - - // Display ray traced image generated by compute shader as a full screen quad - // Quad vertices are generated in the vertex shader - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, graphics.pipelineLayout, graphics.descriptorSet) - bindPipeline(VkPipelineBindPoint.GRAPHICS, graphics.pipeline) - draw(3, 1, 0, 0) - - endRenderPass() - - end() - } - } - } - - fun buildComputeCommandBuffer() { - - compute.commandBuffer.apply { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - begin(cmdBufInfo) - - bindPipeline(VkPipelineBindPoint.COMPUTE, compute.pipeline) - bindDescriptorSets(VkPipelineBindPoint.COMPUTE, compute.pipelineLayout, compute.descriptorSet) - - dispatch(textureComputeTarget.size / 16, 1) - - end() - } - } - - /** Id used to identify objects by the ray tracing shader */ - var currentId = 0 - - /** Setup and fill the compute shader storage buffers containing primitives for the raytraced scene */ - fun prepareStorageBuffers() { - - // Spheres - val spheres = bufferOf( - Sphere(Vec3(1.75f, -0.5f, 0.0f), 1f, Vec3(0f, 1f, 0f), 32f, currentId++), - Sphere(Vec3(0f, 1f, -0.5f), 1f, Vec3(0.65f, 0.77f, 0.97f), 32f, currentId++), - Sphere(Vec3(-1.75f, -0.75f, -0.5f), 1.25f, Vec3(0.9f, 0.76f, 0.46f), 32f, currentId++)) - var storageBufferSize: VkDeviceSize = spheres.size.L - - // Stage - val stagingBuffer = Buffer() - - vulkanDevice.createBuffer( - VkBufferUsage.TRANSFER_SRC_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - stagingBuffer, - spheres) - - vulkanDevice.createBuffer( - // The SSBO will be used as a storage buffer for the compute pipeline and as a vertex buffer in the graphics pipeline - VkBufferUsage.VERTEX_BUFFER_BIT or VkBufferUsage.STORAGE_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT, - VkMemoryProperty.DEVICE_LOCAL_BIT.i, - compute.storageBuffers.spheres, - storageBufferSize) - - // Copy to staging buffer - var copyCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) - val copyRegion = vk.BufferCopy { size = storageBufferSize } - copyCmd.copyBuffer(stagingBuffer.buffer, compute.storageBuffers.spheres.buffer, copyRegion) - super.flushCommandBuffer(copyCmd, queue, true) - - stagingBuffer.destroy() - - // Planes - val roomDim = 4f - val planes = bufferOf( - Plane(Vec3(0f, 1f, 0f), roomDim, Vec3(1f), 32f, currentId++), - Plane(Vec3(0f, -1f, 0f), roomDim, Vec3(1f), 32f, currentId++), - Plane(Vec3(0f, 0f, 1f), roomDim, Vec3(1f), 32f, currentId++), - Plane(Vec3(0f, 0f, -1f), roomDim, Vec3(0f), 32f, currentId++), - Plane(Vec3(-1f, 0f, 0f), roomDim, Vec3(1f, 0f, 0f), 32f, currentId++), - Plane(Vec3(1f, 0f, 0f), roomDim, Vec3(0f, 1f, 0f), 32f, currentId++)) - storageBufferSize = planes.size.L - - // Stage - vulkanDevice.createBuffer( - VkBufferUsage.TRANSFER_SRC_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - stagingBuffer, - planes) - - vulkanDevice.createBuffer( - // The SSBO will be used as a storage buffer for the compute pipeline and as a vertex buffer in the graphics pipeline - VkBufferUsage.VERTEX_BUFFER_BIT or VkBufferUsage.STORAGE_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT, - VkMemoryProperty.DEVICE_LOCAL_BIT.i, - compute.storageBuffers.planes, - storageBufferSize) - - // Copy to staging buffer - copyCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) - copyRegion.size = storageBufferSize - copyCmd.copyBuffer(stagingBuffer.buffer, compute.storageBuffers.planes.buffer, copyRegion) - super.flushCommandBuffer(copyCmd, queue, true) - - stagingBuffer.destroy() - } - - fun setupDescriptorPool() { - - val poolSizes = vk.DescriptorPoolSize( - VkDescriptorType.UNIFORM_BUFFER, 2, // Compute UBO - VkDescriptorType.COMBINED_IMAGE_SAMPLER, 4, // Graphics image samplers - VkDescriptorType.STORAGE_IMAGE, 1, // Storage image for ray traced image output - VkDescriptorType.STORAGE_BUFFER, 2) // Storage buffer for the scene primitives - - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 3) - - descriptorPool = device createDescriptorPool descriptorPoolInfo - } - - fun setupDescriptorSetLayout() { - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - // Binding 0 : Fragment shader image sampler - VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 0) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - - graphics.descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(graphics.descriptorSetLayout) - - graphics.pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - } - - fun setupDescriptorSet() { - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, graphics.descriptorSetLayout) - - graphics.descriptorSet = device allocateDescriptorSets allocInfo - - val writeDescriptorSets = vk.WriteDescriptorSet( - // Binding 0 : Fragment shader texture sampler - graphics.descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 0, textureComputeTarget.descriptor) - - device updateDescriptorSets writeDescriptorSets - } - - fun preparePipelines() { - - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.FRONT_BIT.i, VkFrontFace.COUNTER_CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(false, false, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - // Display pipeline - val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { - it[0].loadShader("$assetPath/shaders/raytracing/texture.vert.spv", VkShaderStage.VERTEX_BIT) - it[1].loadShader("$assetPath/shaders/raytracing/texture.frag.spv", VkShaderStage.FRAGMENT_BIT) - } - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(graphics.pipelineLayout, renderPass) - - val emptyInputState = vk.PipelineVertexInputStateCreateInfo { - vertexAttributeDescriptions = null - vertexBindingDescriptions = null - } - pipelineCreateInfo.also { - it.vertexInputState = emptyInputState - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - it.renderPass = renderPass - } - graphics.pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - /** Prepare the compute pipeline that generates the ray traced image */ - fun prepareCompute() { - /* Create a compute capable device queue - The VulkanDevice::createLogicalDevice functions finds a compute capable queue and prefers queue families - that only support compute - Depending on the implementation this may result in different queue family indices for graphics and computes, - requiring proper synchronization (see the memory barriers in buildComputeCommandBuffer) */ - val queueCreateInfo = vk.DeviceQueueCreateInfo { queueFamilyIndex = vulkanDevice.queueFamilyIndices.compute } - compute.queue = device getQueue vulkanDevice.queueFamilyIndices.compute - - val setLayoutBindings = vk.DescriptorSetLayoutBinding( - // Binding 0: Storage image (raytraced output) - VkDescriptorType.STORAGE_IMAGE, VkShaderStage.COMPUTE_BIT.i, 0, - // Binding 1: Uniform buffer block - VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.COMPUTE_BIT.i, 1, - // Binding 1: Shader storage buffer for the spheres - VkDescriptorType.STORAGE_BUFFER, VkShaderStage.COMPUTE_BIT.i, 2, - // Binding 1: Shader storage buffer for the planes - VkDescriptorType.STORAGE_BUFFER, VkShaderStage.COMPUTE_BIT.i, 3) - - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - - compute.descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(compute.descriptorSetLayout) - - compute.pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, compute.descriptorSetLayout) - - compute.descriptorSet = device allocateDescriptorSets allocInfo - - val computeWriteDescriptorSets = vk.WriteDescriptorSet( - // Binding 0: Output storage image - compute.descriptorSet, VkDescriptorType.STORAGE_IMAGE, 0, textureComputeTarget.descriptor, - // Binding 1: Uniform buffer block - compute.descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 1, compute.uniformBuffer.descriptor, - // Binding 2: Shader storage buffer for the spheres - compute.descriptorSet, VkDescriptorType.STORAGE_BUFFER, 2, compute.storageBuffers.spheres.descriptor, - // Binding 2: Shader storage buffer for the planes - compute.descriptorSet, VkDescriptorType.STORAGE_BUFFER, 3, compute.storageBuffers.planes.descriptor) - - device updateDescriptorSets computeWriteDescriptorSets - - // Create compute shader pipelines - val computePipelineCreateInfo = vk.ComputePipelineCreateInfo(compute.pipelineLayout).apply { - stage.loadShader("$assetPath/shaders/raytracing/raytracing.comp.spv", VkShaderStage.COMPUTE_BIT) - } - compute.pipeline = device.createComputePipelines(pipelineCache, computePipelineCreateInfo) - - // Separate command pool as queue family for compute may be different than graphics - val cmdPoolInfo = vk.CommandPoolCreateInfo { - queueFamilyIndex = vulkanDevice.queueFamilyIndices.compute - flags = VkCommandPoolCreate.RESET_COMMAND_BUFFER_BIT.i - } - compute.commandPool = device createCommandPool cmdPoolInfo - - // Create a command buffer for compute operations - val cmdBufAllocateInfo = vk.CommandBufferAllocateInfo(compute.commandPool, VkCommandBufferLevel.PRIMARY, 1) - - compute.commandBuffer = device allocateCommandBuffer cmdBufAllocateInfo - - // Fence for compute CB sync - val fenceCreateInfo = vk.FenceCreateInfo(VkFenceCreate.SIGNALED_BIT.i) - compute.fence = device createFence fenceCreateInfo - - // Build a single command buffer containing the compute dispatch commands - buildComputeCommandBuffer() - } - - /** Prepare and initialize uniform buffer containing shader uniforms */ - fun prepareUniformBuffers() { - // Compute shader parameter uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - compute.uniformBuffer, - compute.ubo.size.L) - - updateUniformBuffers() - } - - fun updateUniformBuffers() { - compute.ubo.lightPos.put( - sin((timer * 360f).rad) * cos((timer * 360f).rad) * 2f, - sin((timer * 360f).rad) * 2f, - cos((timer * 360f).rad) * 2f) - compute.ubo.camera.pos = -camera.position - compute.uniformBuffer.mapping { data -> - memCopy(compute.ubo.address, data, compute.ubo.size.L) - } - } - - fun draw() { - - super.prepareFrame() - - // Command buffer to be sumitted to the queue - submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] - queue submit submitInfo - - super.submitFrame() - - // Submit compute commands - // Use a fence to ensure that compute command buffer has finished executing before using it again - device.waitForFence(compute.fence, true, UINT64_MAX) - device resetFence compute.fence - - val computeSubmitInfo = vk.SubmitInfo { commandBuffer = compute.commandBuffer } - compute.queue.submit(computeSubmitInfo, compute.fence) - } - - override fun prepare() { - super.prepare() - prepareStorageBuffers() - prepareUniformBuffers() - prepareTextureTarget(textureComputeTarget, TEX_DIM, VkFormat.R8G8B8A8_UNORM) - setupDescriptorSetLayout() - preparePipelines() - setupDescriptorPool() - setupDescriptorSet() - prepareCompute() - buildCommandBuffers() - prepared = true - window.show() - } - - override fun render() { - if (!prepared) - return - draw() - if (!paused) - updateUniformBuffers() - } - - override fun viewChanged() { - compute.ubo.aspectRatio = size.aspect - updateUniformBuffers() - } -} \ No newline at end of file +///* +//* Vulkan Example - Compute shader ray tracing +//* +//* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +//package vulkan.computeShader +// +//import glm_.BYTES +//import glm_.L +//import glm_.func.rad +//import glm_.size +//import glm_.vec2.Vec2i +//import glm_.vec3.Vec3 +//import glm_.vec3.Vec3i +//import glm_.vec4.Vec4 +//import kool.bufferBig +//import org.lwjgl.system.MemoryUtil.* +//import org.lwjgl.vulkan.VkCommandBuffer +//import org.lwjgl.vulkan.VkQueue +//import vkk.* +//import vulkan.TEX_DIM +//import vulkan.UINT64_MAX +//import vulkan.assetPath +//import vulkan.base.* +//import vulkan.base.tools.VK_FLAGS_NONE +//import kotlin.math.cos +//import kotlin.math.sin +// +// +//fun main(args: Array) { +// RayTracing().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() +// } +//} +// +//class RayTracing : VulkanExampleBase() { +// +// val textureComputeTarget = Texture() +// +// /** Resources for the graphics part of the example */ +// object graphics { +// var descriptorSetLayout = VkDescriptorSetLayout (NULL) // Raytraced image display shader binding layout +// var descriptorSetPreCompute = VkDescriptorSet (NULL) // Raytraced image display shader bindings before compute shader image manipulation +// var descriptorSet = VkDescriptorSet (NULL) // Raytraced image display shader bindings after compute shader image manipulation +// var pipeline = VkPipeline (NULL) // Raytraced image display pipeline +// var pipelineLayout = VkPipelineLayout (NULL) // Layout of the graphics pipeline +// } +// +// /** Resources for the compute part of the example */ +// object compute { +// object storageBuffers { +// val spheres = Buffer() // (Shader) storage buffer object with scene spheres +// val planes = Buffer() // (Shader) storage buffer object with scene planes +// } +// +// val uniformBuffer = Buffer() // Uniform buffer object containing scene data +// lateinit var queue: VkQueue // Separate queue for compute commands (queue family may differ from the one used for graphics) +// var commandPool = VkCommandPool (NULL) // Use a separate command pool (queue family may differ from the one used for graphics) +// lateinit var commandBuffer: VkCommandBuffer // Command buffer storing the dispatch commands and barriers +// var fence = VkFence (NULL) // Synchronization fence to avoid rewriting compute CB if still in use +// var descriptorSetLayout = VkDescriptorSetLayout (NULL) // Compute shader binding layout +// var descriptorSet = VkDescriptorSet (NULL) // Compute shader bindings +// var pipelineLayout = VkPipelineLayout (NULL) // Layout of the compute pipeline +// var pipeline = VkPipeline (NULL) // Compute raytracing pipeline +// +// object ubo { +// // Compute shader uniform block object +// var lightPos = Vec3() +// var aspectRatio = 0f // Aspect ratio of the viewport +// var fogColor = Vec4(0f) +// +// object camera { +// var pos = Vec3(0f, 0f, 4f) +// var lookat = Vec3(0f, 0.5f, 0f) +// var fov = 10f +// } +// +// fun pack() { +// lightPos to buffer +// buffer.putFloat(Vec3.size, aspectRatio) +// fogColor.to(buffer, Vec4.size) +// camera.pos.to(buffer, Vec4.size * 2) +// camera.lookat.to(buffer, Vec4.size * 2 + Vec3.size) +// buffer.putFloat(Vec4.size + Vec3.size * 2, camera.fov) +// } +// +// val size = Vec4.size * 2 + Vec3.size * 2 + 2 * Float.BYTES +// val buffer = bufferBig(size) +// val address = memAddress(buffer) +// } +// } +// +// // SSBO sphere declaration +// class Sphere( // Shader uses std140 layout (so we only use vec4 instead of vec3) +// val pos: Vec3, +// val radius: Float, +// val diffuse: Vec3, +// val specular: Float, +// /** Id used to identify sphere for raytracing */ +// val id: Int) : Bufferizable() { +// +// lateinit var _pad: Vec3i +// +// override var fieldOrder = arrayOf("pos", "radius", "diffuse", "specular", "id") +// +// companion object { +// val size = Vec4.size * 3 +// } +// } +// +// // SSBO plane declaration +// class Plane( +// val normal: Vec3, +// var distance: Float, +// val diffuse: Vec3, +// val specular: Float, +// val id: Int) : Bufferizable() { +// +// lateinit var _pad: Vec3i +// +// override var fieldOrder = arrayOf("normal", "distance", "diffuse", "specular", "id") +// } +// +// init { +// title = "Compute shader ray tracing" +//// settings.overlay = true +// compute.ubo.aspectRatio = size.aspect +// timerSpeed *= 0.25f +// +// camera.type = Camera.CameraType.lookAt +// camera.setPerspective(60f, size.aspect, 0.1f, 512f) +// camera.setRotation(Vec3()) +// camera.setTranslation(Vec3(0f, 0f, -4f)) +// camera.rotationSpeed = 0f +// camera.movementSpeed = 2.5f +// } +// +// override fun destroy() { +// +// device.apply { +// // Graphics +// destroyPipeline(graphics.pipeline) +// destroyPipelineLayout(graphics.pipelineLayout) +// destroyDescriptorSetLayout(graphics.descriptorSetLayout) +// +// // Compute +// destroyPipeline(compute.pipeline) +// destroyPipelineLayout(compute.pipelineLayout) +// destroyDescriptorSetLayout(compute.descriptorSetLayout) +// destroyFence(compute.fence) +// destroyCommandPool(compute.commandPool) +// } +// compute.uniformBuffer.destroy() +// compute.storageBuffers.spheres.destroy() +// compute.storageBuffers.planes.destroy() +// textureComputeTarget.destroy() +// +// super.destroy() +// } +// +// /** Prepare a texture target that is used to store compute shader calculations */ +// fun prepareTextureTarget(tex: Texture, size: Vec2i, format: VkFormat) { +// // Get device properties for the requested texture format +// val formatProperties = physicalDevice getFormatProperties format +// // Check if requested image format supports image storage operations +// assert(formatProperties.optimalTilingFeatures has VkFormatFeature.STORAGE_IMAGE_BIT) +// +// // Prepare blit target texture +// tex.size(size) +// +// val imageCreateInfo = vk.ImageCreateInfo { +// imageType = VkImageType.`2D` +// this.format = format +// extent.set(size.x, size.y, 1) +// mipLevels = 1 +// arrayLayers = 1 +// samples = VkSampleCount.`1_BIT` +// tiling = VkImageTiling.OPTIMAL +// initialLayout = VkImageLayout.UNDEFINED +// // Image will be sampled in the fragment shader and used as storage target in the compute shader +// usage = VkImageUsage.SAMPLED_BIT or VkImageUsage.STORAGE_BIT +// flags = 0 +// } +// +// tex.image = device createImage imageCreateInfo +// val memReqs = device.getImageMemoryRequirements(tex.image) +// val memAllocInfo = vk.MemoryAllocateInfo { +// allocationSize = memReqs.size +// memoryTypeIndex = vulkanDevice.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) +// } +// tex.deviceMemory = device allocateMemory memAllocInfo +// device.bindImageMemory(tex.image, tex.deviceMemory) +// +// val layoutCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) +// +// tex.imageLayout = VkImageLayout.GENERAL +// tools.setImageLayout( +// layoutCmd, +// tex.image, +// VkImageAspect.COLOR_BIT.i, +// VkImageLayout.UNDEFINED, +// tex.imageLayout) +// +// super.flushCommandBuffer(layoutCmd, queue, true) +// +// // Create sampler +// val sampler = vk.SamplerCreateInfo { +// magFilter = VkFilter.LINEAR +// minFilter = VkFilter.LINEAR +// mipmapMode = VkSamplerMipmapMode.LINEAR +// addressModeU = VkSamplerAddressMode.CLAMP_TO_BORDER +// addressModeV = addressModeU +// addressModeW = addressModeU +// mipLodBias = 0f +// maxAnisotropy = 1f +// compareOp = VkCompareOp.NEVER +// minLod = 0f +// maxLod = 0f +// borderColor = VkBorderColor.FLOAT_OPAQUE_WHITE +// } +// tex.sampler = device createSampler sampler +// +// // Create image view +// val view = vk.ImageViewCreateInfo { +// viewType = VkImageViewType.`2D` +// this.format = format +// components(VkComponentSwizzle.R, VkComponentSwizzle.G, VkComponentSwizzle.B, VkComponentSwizzle.A) +// subresourceRange.set(VkImageAspect.COLOR_BIT.i, 0, 1, 0, 1) +// image = tex.image +// } +// tex.view = device createImageView view +// +// // Initialize a descriptor for later use +// tex.descriptor.imageLayout = tex.imageLayout +// tex.descriptor.imageView = tex.view +// tex.descriptor.sampler = tex.sampler +// tex.device = vulkanDevice +// } +// +// override fun buildCommandBuffers() { +// // Destroy command buffers if already present +// if (!checkCommandBuffers()) { +// destroyCommandBuffers() +// createCommandBuffers() +// } +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(defaultClearColor) +// it[1].depthStencil.set(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@RayTracing.renderPass +// renderArea.apply { +// offset.set(0, 0) +// extent.set(size.x, size.y) +// } +// this.clearValues = clearValues +// } +// for (i in drawCmdBuffers.indices) { +// // Set target frame buffer +// renderPassBeginInfo.framebuffer(frameBuffers[i].L) +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// // Image memory barrier to make sure that compute shader writes are finished before sampling from the texture +// val imageMemoryBarrier = vk.ImageMemoryBarrier { +// oldLayout = VkImageLayout.GENERAL +// newLayout = VkImageLayout.GENERAL +// image = textureComputeTarget.image +// subresourceRange.set(VkImageAspect.COLOR_BIT.i, 0, 1, 0, 1) +// srcAccessMask = VkAccess.SHADER_WRITE_BIT.i +// dstAccessMask = VkAccess.SHADER_READ_BIT.i +// } +// pipelineBarrier( +// VkPipelineStage.COMPUTE_SHADER_BIT.i, +// VkPipelineStage.FRAGMENT_SHADER_BIT.i, +// VK_FLAGS_NONE, +// imageMemoryBarrier = imageMemoryBarrier) +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// setViewport(size) +// setScissor(size) +// +// // Display ray traced image generated by compute shader as a full screen quad +// // Quad vertices are generated in the vertex shader +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, graphics.pipelineLayout, graphics.descriptorSet) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, graphics.pipeline) +// draw(3, 1, 0, 0) +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// fun buildComputeCommandBuffer() { +// +// compute.commandBuffer.apply { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// begin(cmdBufInfo) +// +// bindPipeline(VkPipelineBindPoint.COMPUTE, compute.pipeline) +// bindDescriptorSets(VkPipelineBindPoint.COMPUTE, compute.pipelineLayout, compute.descriptorSet) +// +// dispatch(textureComputeTarget.size / 16, 1) +// +// end() +// } +// } +// +// /** Id used to identify objects by the ray tracing shader */ +// var currentId = 0 +// +// /** Setup and fill the compute shader storage buffers containing primitives for the raytraced scene */ +// fun prepareStorageBuffers() { +// +// // Spheres +// val spheres = bufferOf( +// Sphere(Vec3(1.75f, -0.5f, 0.0f), 1f, Vec3(0f, 1f, 0f), 32f, currentId++), +// Sphere(Vec3(0f, 1f, -0.5f), 1f, Vec3(0.65f, 0.77f, 0.97f), 32f, currentId++), +// Sphere(Vec3(-1.75f, -0.75f, -0.5f), 1.25f, Vec3(0.9f, 0.76f, 0.46f), 32f, currentId++)) +// var storageBufferSize = VkDeviceSize (spheres.size.L) +// +// // Stage +// val stagingBuffer = Buffer() +// +// vulkanDevice.createBuffer( +// VkBufferUsage.TRANSFER_SRC_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// stagingBuffer, +// spheres) +// +// vulkanDevice.createBuffer( +// // The SSBO will be used as a storage buffer for the compute pipeline and as a vertex buffer in the graphics pipeline +// VkBufferUsage.VERTEX_BUFFER_BIT or VkBufferUsage.STORAGE_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT, +// VkMemoryProperty.DEVICE_LOCAL_BIT.i, +// compute.storageBuffers.spheres, +// storageBufferSize) +// +// // Copy to staging buffer +// var copyCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) +// val copyRegion = vk.BufferCopy { size = storageBufferSize } +// copyCmd.copyBuffer(stagingBuffer.buffer, compute.storageBuffers.spheres.buffer, copyRegion) +// super.flushCommandBuffer(copyCmd, queue, true) +// +// stagingBuffer.destroy() +// +// // Planes +// val roomDim = 4f +// val planes = bufferOf( +// Plane(Vec3(0f, 1f, 0f), roomDim, Vec3(1f), 32f, currentId++), +// Plane(Vec3(0f, -1f, 0f), roomDim, Vec3(1f), 32f, currentId++), +// Plane(Vec3(0f, 0f, 1f), roomDim, Vec3(1f), 32f, currentId++), +// Plane(Vec3(0f, 0f, -1f), roomDim, Vec3(0f), 32f, currentId++), +// Plane(Vec3(-1f, 0f, 0f), roomDim, Vec3(1f, 0f, 0f), 32f, currentId++), +// Plane(Vec3(1f, 0f, 0f), roomDim, Vec3(0f, 1f, 0f), 32f, currentId++)) +// storageBufferSize = VkDeviceSize(planes.size.L) +// +// // Stage +// vulkanDevice.createBuffer( +// VkBufferUsage.TRANSFER_SRC_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// stagingBuffer, +// planes) +// +// vulkanDevice.createBuffer( +// // The SSBO will be used as a storage buffer for the compute pipeline and as a vertex buffer in the graphics pipeline +// VkBufferUsage.VERTEX_BUFFER_BIT or VkBufferUsage.STORAGE_BUFFER_BIT or VkBufferUsage.TRANSFER_DST_BIT, +// VkMemoryProperty.DEVICE_LOCAL_BIT.i, +// compute.storageBuffers.planes, +// storageBufferSize) +// +// // Copy to staging buffer +// copyCmd = super.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) +// copyRegion.size = storageBufferSize +// copyCmd.copyBuffer(stagingBuffer.buffer, compute.storageBuffers.planes.buffer, copyRegion) +// super.flushCommandBuffer(copyCmd, queue, true) +// +// stagingBuffer.destroy() +// } +// +// fun setupDescriptorPool() { +// +// val poolSizes = vk.DescriptorPoolSize( +// VkDescriptorType.UNIFORM_BUFFER, 2, // Compute UBO +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, 4, // Graphics image samplers +// VkDescriptorType.STORAGE_IMAGE, 1, // Storage image for ray traced image output +// VkDescriptorType.STORAGE_BUFFER, 2) // Storage buffer for the scene primitives +// +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 3) +// +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// } +// +// fun setupDescriptorSetLayout() { +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// // Binding 0 : Fragment shader image sampler +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 0) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// +// graphics.descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(graphics.descriptorSetLayout) +// +// graphics.pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// } +// +// fun setupDescriptorSet() { +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, graphics.descriptorSetLayout) +// +// graphics.descriptorSet = device allocateDescriptorSets allocInfo +// +// val writeDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0 : Fragment shader texture sampler +// graphics.descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 0, textureComputeTarget.descriptor) +// +// device updateDescriptorSets writeDescriptorSets +// } +// +// fun preparePipelines() { +// +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST, 0, false) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.FRONT_BIT.i, VkFrontFace.COUNTER_CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(false, false, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// // Display pipeline +// val shaderStages = vk.PipelineShaderStageCreateInfo(2).also { +// it[0].loadShader("$assetPath/shaders/raytracing/texture.vert.spv", VkShaderStage.VERTEX_BIT) +// it[1].loadShader("$assetPath/shaders/raytracing/texture.frag.spv", VkShaderStage.FRAGMENT_BIT) +// } +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(graphics.pipelineLayout, renderPass) +// +// val emptyInputState = vk.PipelineVertexInputStateCreateInfo { +// vertexAttributeDescriptions = null +// vertexBindingDescriptions = null +// } +// pipelineCreateInfo.also { +// it.vertexInputState = emptyInputState +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// it.renderPass = renderPass +// } +// graphics.pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// +// /** Prepare the compute pipeline that generates the ray traced image */ +// fun prepareCompute() { +// /* Create a compute capable device queue +// The VulkanDevice::createLogicalDevice functions finds a compute capable queue and prefers queue families +// that only support compute +// Depending on the implementation this may result in different queue family indices for graphics and computes, +// requiring proper synchronization (see the memory barriers in buildComputeCommandBuffer) */ +// val queueCreateInfo = vk.DeviceQueueCreateInfo { queueFamilyIndex = vulkanDevice.queueFamilyIndices.compute } +// compute.queue = device getQueue vulkanDevice.queueFamilyIndices.compute +// +// val setLayoutBindings = vk.DescriptorSetLayoutBinding( +// // Binding 0: Storage image (raytraced output) +// VkDescriptorType.STORAGE_IMAGE, VkShaderStage.COMPUTE_BIT.i, 0, +// // Binding 1: Uniform buffer block +// VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.COMPUTE_BIT.i, 1, +// // Binding 1: Shader storage buffer for the spheres +// VkDescriptorType.STORAGE_BUFFER, VkShaderStage.COMPUTE_BIT.i, 2, +// // Binding 1: Shader storage buffer for the planes +// VkDescriptorType.STORAGE_BUFFER, VkShaderStage.COMPUTE_BIT.i, 3) +// +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// +// compute.descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(compute.descriptorSetLayout) +// +// compute.pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, compute.descriptorSetLayout) +// +// compute.descriptorSet = device allocateDescriptorSets allocInfo +// +// val computeWriteDescriptorSets = vk.WriteDescriptorSet( +// // Binding 0: Output storage image +// compute.descriptorSet, VkDescriptorType.STORAGE_IMAGE, 0, textureComputeTarget.descriptor, +// // Binding 1: Uniform buffer block +// compute.descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 1, compute.uniformBuffer.descriptor, +// // Binding 2: Shader storage buffer for the spheres +// compute.descriptorSet, VkDescriptorType.STORAGE_BUFFER, 2, compute.storageBuffers.spheres.descriptor, +// // Binding 2: Shader storage buffer for the planes +// compute.descriptorSet, VkDescriptorType.STORAGE_BUFFER, 3, compute.storageBuffers.planes.descriptor) +// +// device updateDescriptorSets computeWriteDescriptorSets +// +// // Create compute shader pipelines +// val computePipelineCreateInfo = vk.ComputePipelineCreateInfo(compute.pipelineLayout).apply { +// stage.loadShader("$assetPath/shaders/raytracing/raytracing.comp.spv", VkShaderStage.COMPUTE_BIT) +// } +// compute.pipeline = device.createComputePipelines(pipelineCache, computePipelineCreateInfo) +// +// // Separate command pool as queue family for compute may be different than graphics +// val cmdPoolInfo = vk.CommandPoolCreateInfo { +// queueFamilyIndex = vulkanDevice.queueFamilyIndices.compute +// flags = VkCommandPoolCreate.RESET_COMMAND_BUFFER_BIT.i +// } +// compute.commandPool = device createCommandPool cmdPoolInfo +// +// // Create a command buffer for compute operations +// val cmdBufAllocateInfo = vk.CommandBufferAllocateInfo(compute.commandPool, VkCommandBufferLevel.PRIMARY, 1) +// +// compute.commandBuffer = device allocateCommandBuffer cmdBufAllocateInfo +// +// // Fence for compute CB sync +// val fenceCreateInfo = vk.FenceCreateInfo(VkFenceCreate.SIGNALED_BIT.i) +// compute.fence = device createFence fenceCreateInfo +// +// // Build a single command buffer containing the compute dispatch commands +// buildComputeCommandBuffer() +// } +// +// /** Prepare and initialize uniform buffer containing shader uniforms */ +// fun prepareUniformBuffers() { +// // Compute shader parameter uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// compute.uniformBuffer, +// VkDeviceSize(compute.ubo.size.L)) +// +// updateUniformBuffers() +// } +// +// fun updateUniformBuffers() { +// compute.ubo.lightPos.put( +// sin((timer * 360f).rad) * cos((timer * 360f).rad) * 2f, +// sin((timer * 360f).rad) * 2f, +// cos((timer * 360f).rad) * 2f) +// compute.ubo.camera.pos = -camera.position +// compute.uniformBuffer.mapping { data -> +// memCopy(compute.ubo.address, data, compute.ubo.size.L) +// } +// } +// +// fun draw() { +// +// super.prepareFrame() +// +// // Command buffer to be sumitted to the queue +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// queue submit submitInfo +// +// super.submitFrame() +// +// // Submit compute commands +// // Use a fence to ensure that compute command buffer has finished executing before using it again +// device.waitForFence(compute.fence, true, UINT64_MAX) +// device resetFence compute.fence +// +// val computeSubmitInfo = vk.SubmitInfo { commandBuffer = compute.commandBuffer } +// compute.queue.submit(computeSubmitInfo, compute.fence) +// } +// +// override fun prepare() { +// super.prepare() +// prepareStorageBuffers() +// prepareUniformBuffers() +// prepareTextureTarget(textureComputeTarget, TEX_DIM, VkFormat.R8G8B8A8_UNORM) +// setupDescriptorSetLayout() +// preparePipelines() +// setupDescriptorPool() +// setupDescriptorSet() +// prepareCompute() +// buildCommandBuffers() +// prepared = true +// window.show() +// } +// +// override fun render() { +// if (!prepared) +// return +// draw() +// if (!paused) +// updateUniformBuffers() +// } +// +// override fun viewChanged() { +// compute.ubo.aspectRatio = size.aspect +// updateUniformBuffers() +// } +//} \ No newline at end of file diff --git a/src/main/kotlin/vulkan/settings.kt b/src/main/kotlin/vulkan/settings.kt index 9838154..39d28d2 100644 --- a/src/main/kotlin/vulkan/settings.kt +++ b/src/main/kotlin/vulkan/settings.kt @@ -1,6 +1,8 @@ package vulkan import glm_.vec2.Vec2i +import org.lwjgl.vulkan.VK10 +import vkk.VkDeviceSize import java.nio.file.Paths @@ -26,4 +28,10 @@ val TEX_DIM = Vec2i(2048) val NUM_LIGHTS = 64 -fun FloatArray.last(last: Float) = set(lastIndex, last) \ No newline at end of file +fun FloatArray.last(last: Float) = set(lastIndex, last) + + +val VK_WHOLE_SIZE = VkDeviceSize(VK10.VK_WHOLE_SIZE) + +const val UINT32_MAX = 0.inv() +const val UINT64_MAX = 0L.inv() \ No newline at end of file diff --git a/src/main/kotlin/vulkan/userInterface/imgui.kt b/src/main/kotlin/vulkan/userInterface/imgui.kt index fea7759..92b4c62 100644 --- a/src/main/kotlin/vulkan/userInterface/imgui.kt +++ b/src/main/kotlin/vulkan/userInterface/imgui.kt @@ -1,779 +1,777 @@ -/* -* Vulkan Example - imGui (https://github.com/ocornut/imgui) -* -* Copyright (C) 2017 by Sascha Willems - www.saschawillems.de -* -* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -*/ - -package vulkan.userInterface - -import glm_.BYTES -import glm_.L -import glm_.buffer.adr -import glm_.buffer.bufferBig -import glm_.func.cos -import glm_.func.rad -import glm_.func.sin -import glm_.i -import glm_.mat4x4.Mat4 -import glm_.max -import glm_.vec2.Vec2 -import glm_.vec2.Vec2i -import glm_.vec2.operators.div -import glm_.vec3.Vec3 -import glm_.vec4.Vec4 -import glm_.vec4.Vec4b -import imgui.* -import imgui.ImGui.checkbox -import imgui.ImGui.inputVec3 -import imgui.ImGui.plotLines -import imgui.ImGui.setNextWindowPos -import imgui.ImGui.setNextWindowSize -import imgui.ImGui.sliderFloat -import imgui.ImGui.text -import imgui.ImGui.textUnformatted -import imgui.functionalProgramming.withWindow -import org.lwjgl.glfw.GLFW -import org.lwjgl.glfw.GLFW.* -import org.lwjgl.system.MemoryUtil.* -import org.lwjgl.vulkan.VkCommandBuffer -import org.lwjgl.vulkan.VkQueue -import vkk.* -import vulkan.assetPath -import vulkan.base.* -import vulkan.last - - -fun main(args: Array) { - Imgui().apply { - setupWindow() - initVulkan() - prepare() - renderLoop() - destroy() - } -} - -// Options and values to display/toggle from the UI -object uiSettings { - var displayModels = true - var displayLogos = true - var displayBackground = true - var animateLight = false - var lightSpeed = 0.25f - val frameTimes = FloatArray(50) - var frameTimeMin = 9999f - var frameTimeMax = 0f - var lightTimer = 0f -} - -// ---------------------------------------------------------------------------- -// ImGUI class -// ---------------------------------------------------------------------------- -class ImGUI(val example: VulkanExampleBase) { - - // Vulkan resources for rendering the UI - var sampler: VkSampler = NULL - val vertexBuffer = Buffer() - val indexBuffer = Buffer() - var vertexCount = 0 - var indexCount = 0 - var fontMemory: VkDeviceMemory = NULL - var fontImage: VkImage = NULL - var fontView: VkImageView = NULL - var pipelineCache: VkPipelineCache = NULL - var pipelineLayout: VkPipelineLayout = NULL - var pipeline: VkPipeline = NULL - var descriptorPool: VkDescriptorPool = NULL - var descriptorSetLayout: VkDescriptorSetLayout = NULL - var descriptorSet: VkDescriptorSet = NULL - val device: VulkanDevice = example.vulkanDevice - - // UI params are set via push constants - object pushConstBlock { - val scale = Vec2() - val translate = Vec2() - fun pack() { - scale to buffer - translate.to(buffer, Vec2.size) - } - - val size = Vec2.size * 2 - val buffer = bufferBig(size) - } - - fun destroy() { - // Release all Vulkan resources required for rendering imGui - vertexBuffer.destroy() - indexBuffer.destroy() - device.logicalDevice!!.apply { - destroyImage(fontImage) - destroyImageView(fontView) - freeMemory(fontMemory) - destroySampler(sampler) - destroyPipelineCache(pipelineCache) - destroyPipeline(pipeline) - destroyPipelineLayout(pipelineLayout) - destroyDescriptorPool(descriptorPool) - destroyDescriptorSetLayout(descriptorSetLayout) - } - } - - /** Initialize styles, keys, etc. */ - fun init(size: Vec2i) { - // Color scheme - ImGui.style.colors.also { - it[Col.TitleBg] = Vec4(1f, 0f, 0f, 0.6f) - it[Col.TitleBgActive] = Vec4(1f, 0f, 0f, 0.8f) - it[Col.MenuBarBg] = Vec4(1f, 0f, 0f, 0.4f) - it[Col.Header] = Vec4(1f, 0f, 0f, 0.4f) - it[Col.CheckMark] = Vec4(0f, 1f, 0f, 1f) - } - // Dimensions - ImGui.io.apply { - displaySize put size - displayFramebufferScale put 1f - } - } - - /** Initialize all Vulkan resources used by the ui */ - fun initResources(renderPass: VkRenderPass, copyQueue: VkQueue) { - - val io = ImGui.io - - // Create font texture - val (fontData, texSize, _) = io.fonts.getTexDataAsRGBA32() - val uploadSize: VkDeviceSize = texSize.x * texSize.y * Vec4b.size.L - - // Create target image for copy - val imageInfo = vk.ImageCreateInfo { - imageType = VkImageType.`2D` - format = VkFormat.R8G8B8A8_UNORM - extent(texSize, 1) - mipLevels = 1 - arrayLayers = 1 - samples = VkSampleCount.`1_BIT` - tiling = VkImageTiling.OPTIMAL - usage = VkImageUsage.SAMPLED_BIT or VkImageUsage.TRANSFER_DST_BIT - sharingMode = VkSharingMode.EXCLUSIVE - initialLayout = VkImageLayout.UNDEFINED - } - val dev = device.logicalDevice!! - fontImage = dev createImage imageInfo - val memReqs = dev getImageMemoryRequirements fontImage - val memAllocInfo = vk.MemoryAllocateInfo { } - memAllocInfo.allocationSize = memReqs.size - memAllocInfo.memoryTypeIndex = device.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) - fontMemory = dev allocateMemory memAllocInfo - dev.bindImageMemory(fontImage, fontMemory) - - // Image view - val viewInfo = vk.ImageViewCreateInfo { - image = fontImage - viewType = VkImageViewType.`2D` - format = VkFormat.R8G8B8A8_UNORM - subresourceRange.apply { - aspectMask = VkImageAspect.COLOR_BIT.i - levelCount = 1 - layerCount = 1 - } - } - fontView = dev createImageView viewInfo - - // Staging buffers for font data upload - val stagingBuffer = Buffer() - - device.createBuffer( - VkBufferUsage.TRANSFER_SRC_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - stagingBuffer, - uploadSize) - - stagingBuffer.mapping { - memCopy(fontData.adr, stagingBuffer.mapped, uploadSize) - } - // Copy buffer data to font image - val copyCmd = device.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) - - // Prepare for transfer - tools.setImageLayout( - copyCmd, - fontImage, - VkImageAspect.COLOR_BIT.i, - VkImageLayout.UNDEFINED, - VkImageLayout.TRANSFER_DST_OPTIMAL, - VkPipelineStage.HOST_BIT.i, - VkPipelineStage.TRANSFER_BIT.i) - - // Copy - val bufferCopyRegion = vk.BufferImageCopy { - imageSubresource.apply { - aspectMask = VkImageAspect.COLOR_BIT.i - layerCount = 1 - } - imageExtent(texSize, 1) - } - copyCmd.copyBufferToImage( - stagingBuffer.buffer, - fontImage, - VkImageLayout.TRANSFER_DST_OPTIMAL, - bufferCopyRegion) - - // Prepare for shader read - tools.setImageLayout( - copyCmd, - fontImage, - VkImageAspect.COLOR_BIT.i, - VkImageLayout.TRANSFER_DST_OPTIMAL, - VkImageLayout.SHADER_READ_ONLY_OPTIMAL, - VkPipelineStage.TRANSFER_BIT.i, - VkPipelineStage.FRAGMENT_SHADER_BIT.i) - - device.flushCommandBuffer(copyCmd, copyQueue, true) - - stagingBuffer.destroy() - - // Font texture Sampler - val samplerInfo = vk.SamplerCreateInfo { - magFilter = VkFilter.LINEAR - minFilter = VkFilter.LINEAR - mipmapMode = VkSamplerMipmapMode.LINEAR - addressMode = VkSamplerAddressMode.CLAMP_TO_EDGE - borderColor = VkBorderColor.FLOAT_OPAQUE_WHITE - } - sampler = dev createSampler samplerInfo - - // Descriptor pool - val poolSizes = vk.DescriptorPoolSize(VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1) - - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) - descriptorPool = dev createDescriptorPool descriptorPoolInfo - - // Descriptor set layout - val setLayoutBindings = vk.DescriptorSetLayoutBinding(VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 0) - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - descriptorSetLayout = dev createDescriptorSetLayout descriptorLayout - - // Descriptor set - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) - descriptorSet = dev allocateDescriptorSets allocInfo - val fontDescriptor = vk.DescriptorImageInfo( - sampler, - fontView, - VkImageLayout.SHADER_READ_ONLY_OPTIMAL) - val writeDescriptorSets = vk.WriteDescriptorSet(descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 0, fontDescriptor) - dev.updateDescriptorSets(writeDescriptorSets) - - // Pipeline cache - pipelineCache = dev createPipelineCache vk.PipelineCacheCreateInfo() - - // Pipeline layout - // Push constants for UI rendering parameters - val pushConstantRange = vk.PushConstantRange(VkShaderStage.VERTEX_BIT, pushConstBlock.size) - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout).also { - it.pushConstantRange = pushConstantRange - } - pipelineLayout = dev createPipelineLayout pipelineLayoutCreateInfo - - // Setup graphics pipeline for UI rendering - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.COUNTER_CLOCKWISE) - - // Enable blending - val blendAttachmentState = vk.PipelineColorBlendAttachmentState { - blendEnable = true - colorWriteMask = VkColorComponent.R_BIT or VkColorComponent.G_BIT or VkColorComponent.B_BIT.i or VkColorComponent.A_BIT.i - srcColorBlendFactor = VkBlendFactor.SRC_ALPHA - dstColorBlendFactor = VkBlendFactor.ONE_MINUS_SRC_ALPHA - colorBlendOp = VkBlendOp.ADD - srcAlphaBlendFactor = VkBlendFactor.ONE_MINUS_SRC_ALPHA - dstAlphaBlendFactor = VkBlendFactor.ZERO - alphaBlendOp = VkBlendOp.ADD - } - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(false, false, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - val shaderStages = vk.PipelineShaderStageCreateInfo(2) - - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - } - // Vertex bindings an attributes based on ImGui vertex definition - val vertexInputBindings = vk.VertexInputBindingDescription(0, DrawVert.size, VkVertexInputRate.VERTEX) - - val vertexInputAttributes = vk.VertexInputAttributeDescription( - 0, 0, VkFormat.R32G32_SFLOAT, 0, // Location 0: Position - 0, 1, VkFormat.R32G32_SFLOAT, Vec2.size, // Location 1: UV - 0, 2, VkFormat.R8G8B8A8_UNORM, Vec2.size * 2) // Location 0: Color - val vertexInputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertexInputBindings - vertexAttributeDescriptions = vertexInputAttributes - } - pipelineCreateInfo.vertexInputState = vertexInputState - - example.apply { - shaderStages[0].loadShader("$assetPath/shaders/imgui/ui.vert.spv", VkShaderStage.VERTEX_BIT) - shaderStages[1].loadShader("$assetPath/shaders/imgui/ui.frag.spv", VkShaderStage.FRAGMENT_BIT) - } - pipeline = dev.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - var f = 0f - - /** Starts a new imGui frame and sets up windows and ui elements */ - fun newFrame(updateFrameGraph: Boolean) { - - ImGui.newFrame() - - // Init imGui windows and elements - - val clearColor = Color(114, 144, 154) - textUnformatted(example.title) - textUnformatted(device.properties.deviceName) - - // Update frame time display - if (updateFrameGraph) { - for (i in uiSettings.frameTimes.indices) - uiSettings.frameTimes[i] = uiSettings.frameTimes.getOrElse(i) { uiSettings.frameTimes.last() } - val frameTime = 1000f / (example.frameTimer * 1000f) - uiSettings.frameTimes.last(frameTime) - if (frameTime < uiSettings.frameTimeMin) - uiSettings.frameTimeMin = frameTime - if (frameTime > uiSettings.frameTimeMax) - uiSettings.frameTimeMax = frameTime - } - - plotLines("Frame Times", uiSettings.frameTimes, 0, "", uiSettings.frameTimeMin, uiSettings.frameTimeMax, Vec2(0, 80)) - - text("Camera") - inputVec3("position", example.camera.position, "%f") - inputVec3("rotation", example.camera.rotation, "%f") - - setNextWindowSize(Vec2(200), Cond.FirstUseEver) - withWindow("Example settings") { - checkbox("Render models", uiSettings::displayModels) - checkbox("Display logos", uiSettings::displayLogos) - checkbox("Display background", uiSettings::displayBackground) - checkbox("Animate light", uiSettings::animateLight) - sliderFloat("Light speed", uiSettings::lightSpeed, 0.1f, 1f) - } - - setNextWindowPos(Vec2(650, 20), Cond.FirstUseEver) -// showTestWindow() - - // Render to generate draw buffers - ImGui.render() - } - - /** Update vertex and index buffer containing the imGui elements when required */ - fun updateBuffers() { - - val drawData = ImGui.drawData!! - - // Note: Alignment is done inside buffer creation - val vertexBufferSize: VkDeviceSize = drawData.totalVtxCount * DrawVert.size.L - val indexBufferSize: VkDeviceSize = drawData.totalIdxCount * DrawIdx.BYTES.L - - // Update buffers only if vertex or index count has been changed compared to current buffer size - - // Vertex buffer - if (vertexBuffer.buffer == NULL || vertexCount != drawData.totalVtxCount) { - vertexBuffer.unmap() - vertexBuffer.destroy() - device.createBuffer(VkBufferUsage.VERTEX_BUFFER_BIT.i, VkMemoryProperty.HOST_VISIBLE_BIT.i, vertexBuffer, vertexBufferSize) - vertexCount = drawData.totalVtxCount - vertexBuffer.unmap() - vertexBuffer.map() - } - - // Index buffer - val indexSize: VkDeviceSize = drawData.totalIdxCount * DrawIdx.BYTES.L - if (indexBuffer.buffer == NULL || indexCount < drawData.totalIdxCount) { - indexBuffer.unmap() - indexBuffer.destroy() - device.createBuffer(VkBufferUsage.INDEX_BUFFER_BIT.i, VkMemoryProperty.HOST_VISIBLE_BIT.i, indexBuffer, indexBufferSize) - indexCount = drawData.totalIdxCount - indexBuffer.map() - } - - // Upload data - var vtxDst = vertexBuffer.mapped - var idxDst = indexBuffer.mapped - - for (cmdList in drawData.cmdLists) { - var k = 0 - for (v in cmdList.vtxBuffer) { - val ofs = vtxDst + DrawVert.size * k++ - memPutFloat(ofs, v.pos.x) - memPutFloat(ofs + Float.BYTES, v.pos.y) - memPutFloat(ofs + Vec2.size, v.uv.x) - memPutFloat(ofs + Vec2.size + Float.BYTES, v.uv.y) - memPutInt(ofs + Vec2.size * 2, v.col) - } - k = 0 - for (i in cmdList.idxBuffer) - memPutInt(idxDst + DrawIdx.BYTES * k++, i) - vtxDst += cmdList.vtxBuffer.size - idxDst += cmdList.idxBuffer.size - } - - // Flush to make writes visible to GPU - vertexBuffer.flush() - indexBuffer.flush() - } - - /** Draw current imGui frame into a command buffer */ - fun drawFrame(commandBuffer: VkCommandBuffer) { - - val io = ImGui.io - - commandBuffer.apply { - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipeline) - - // Bind vertex and index buffer - bindVertexBuffers(vertexBuffer.buffer) - bindIndexBuffer(indexBuffer.buffer, 0, VkIndexType.UINT16) - - setViewport(vk.Viewport(io.displaySize)) - - // UI scale and translate via push constants - pushConstBlock.scale put 2f / io.displaySize - pushConstBlock.translate put -1f - pushConstBlock.pack() - pushConstants(pipelineLayout, VkShaderStage.VERTEX_BIT.i, pushConstBlock.size, pushConstBlock.buffer) - - // Render commands - val drawData = ImGui.drawData!! - var vertexOffset = 0 - var indexOffset = 0 - for (cmdList in drawData.cmdLists) { - for (cmd in cmdList.cmdBuffer) { - val scissorRect = vk.Rect2D( - offsetX = cmd.clipRect.x.i max 0, - offsetY = cmd.clipRect.y.i max 0, - width = (cmd.clipRect.z - cmd.clipRect.x).i, - height = (cmd.clipRect.w - cmd.clipRect.y).i) - setScissor(scissorRect) - drawIndexed(cmd.elemCount, 1, indexOffset, vertexOffset, 0) - indexOffset += cmd.elemCount - } - vertexOffset += cmdList.vtxBuffer.size - } - } - } - -} - -// ---------------------------------------------------------------------------- -// VulkanExample -// ---------------------------------------------------------------------------- - -private class Imgui : VulkanExampleBase() { - - lateinit var imGui: ImGUI - - // Vertex layout for the models - val vertexLayout = VertexLayout( - VertexComponent.POSITION, - VertexComponent.NORMAL, - VertexComponent.COLOR) - - object models { - val models = Model() - val logos = Model() - val background = Model() - } - - val uniformBufferVS = Buffer() - - object uboVS { - var projection = Mat4() - var modelview = Mat4() - var lightPos = Vec4() - fun pack() { - projection to buffer - modelview.to(buffer, Mat4.size) - lightPos.to(buffer, Mat4.size * 2) - } - - val size = Mat4.size * 2 + Vec4.size - val buffer = bufferBig(size) - } - - var pipelineLayout: VkPipelineLayout = NULL - var pipeline: VkPipeline = NULL - var descriptorSetLayout: VkDescriptorSetLayout = NULL - var descriptorSet: VkDescriptorSet = NULL - - init { - title = "Vulkan Example - ImGui" - camera.type = Camera.CameraType.lookAt - camera.setPosition(Vec3(0f, 1.4f, -4.8f)) - camera.setRotation(Vec3(4.5f, -380f, 0f)) - camera.setPerspective(45f, size.aspect, 0.1f, 256f) - } - - override fun destroy() { - super.destroy() - - device.apply { - destroyPipeline(pipeline) - destroyPipelineLayout(pipelineLayout) - destroyDescriptorSetLayout(descriptorSetLayout) - } - models.apply { - models.destroy() - background.destroy() - logos.destroy() - } - uniformBufferVS.destroy() - - imGui.destroy() - } - - override fun buildCommandBuffers() { - - val cmdBufInfo = vk.CommandBufferBeginInfo() - - val clearValues = vk.ClearValue(2).also { - it[0].color(0.2f, 0.2f, 0.2f, 1f) - it[1].depthStencil(1f, 0) - } - val renderPassBeginInfo = vk.RenderPassBeginInfo { - renderPass = this@Imgui.renderPass - renderArea.apply { - offset(0) - extent(size) - } - this.clearValues = clearValues - } - imGui.newFrame(frameCounter == 0) - - imGui.updateBuffers() - - for (i in drawCmdBuffers.indices) { - // Set target frame buffer - renderPassBeginInfo.framebuffer = frameBuffers[i] - - drawCmdBuffers[i].apply { - - begin(cmdBufInfo) - - beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) - - setViewport(vk.Viewport(size)) - - setScissor(vk.Rect2D(size)) - - // Render scene - bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) - bindPipeline(VkPipelineBindPoint.GRAPHICS, pipeline) - - if (uiSettings.displayBackground) { - bindVertexBuffers(models.background.vertices.buffer) - bindIndexBuffer(models.background.indices.buffer, 0, VkIndexType.UINT32) - drawIndexed(models.background.indexCount, 1, 0, 0, 0) - } - - if (uiSettings.displayModels) { - bindVertexBuffers(models.models.vertices.buffer) - bindIndexBuffer(models.models.indices.buffer, 0, VkIndexType.UINT32) - drawIndexed(models.models.indexCount, 1, 0, 0, 0) - } - - if (uiSettings.displayLogos) { - bindVertexBuffers(models.logos.vertices.buffer) - bindIndexBuffer(models.logos.indices.buffer, 0, VkIndexType.UINT32) - drawIndexed(models.logos.indexCount, 1, 0, 0, 0) - } - - // Render imGui - imGui.drawFrame(this) - - endRenderPass() - - end() - } - } - } - - fun setupLayoutsAndDescriptors() { - // descriptor pool - val poolSizes = vk.DescriptorPoolSize( - VkDescriptorType.UNIFORM_BUFFER, 2, - VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1) - val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) - descriptorPool = device createDescriptorPool descriptorPoolInfo - - // Set layout - val setLayoutBindings = vk.DescriptorSetLayoutBinding(VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0) - val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) - descriptorSetLayout = device createDescriptorSetLayout descriptorLayout - - // Pipeline layout - val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) - pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo - - // Descriptor set - val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) - descriptorSet = device allocateDescriptorSets allocInfo - val writeDescriptorSets = vk.WriteDescriptorSet(descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBufferVS.descriptor) - - device updateDescriptorSets writeDescriptorSets - } - - fun preparePipelines() { - // Rendering - val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST) - - val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.FRONT_BIT.i, VkFrontFace.COUNTER_CLOCKWISE) - - val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) - - val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) - - val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) - - val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) - - val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) - - val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) - val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) - - // Load shaders - val shaderStages = vk.PipelineShaderStageCreateInfo(2) - - val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { - it.inputAssemblyState = inputAssemblyState - it.rasterizationState = rasterizationState - it.colorBlendState = colorBlendState - it.multisampleState = multisampleState - it.viewportState = viewportState - it.depthStencilState = depthStencilState - it.dynamicState = dynamicState - it.stages = shaderStages - } - val vertexInputBindings = vk.VertexInputBindingDescription(0, vertexLayout.stride, VkVertexInputRate.VERTEX) - - val vertexInputAttributes = vk.VertexInputAttributeDescription( - 0, 0, VkFormat.R32G32B32_SFLOAT, 0, // Location 0: Position - 0, 1, VkFormat.R32G32B32_SFLOAT, Vec3.size, // Location 1: Normal - 0, 2, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2) // Location 2: Color - - val vertexInputState = vk.PipelineVertexInputStateCreateInfo { - vertexBindingDescription = vertexInputBindings - vertexAttributeDescriptions = vertexInputAttributes - } - pipelineCreateInfo.vertexInputState = vertexInputState - - shaderStages[0].loadShader("$assetPath/shaders/imgui/scene.vert.spv", VkShaderStage.VERTEX_BIT) - shaderStages[1].loadShader("$assetPath/shaders/imgui/scene.frag.spv", VkShaderStage.FRAGMENT_BIT) - pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) - } - - /** Prepare and initialize uniform buffer containing shader uniforms */ - fun prepareUniformBuffers() { - // Vertex shader uniform buffer block - vulkanDevice.createBuffer( - VkBufferUsage.UNIFORM_BUFFER_BIT.i, - VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, - uniformBufferVS, - uboVS.size.L, - uboVS.buffer.adr) - - updateUniformBuffers() - } - - fun updateUniformBuffers() { - // Vertex shader - uboVS.projection = camera.matrices.perspective - uboVS.modelview = camera.matrices.view - - // Light source - if (uiSettings.animateLight) { - uiSettings.lightTimer += frameTimer * uiSettings.lightSpeed - uboVS.lightPos.x = (uiSettings.lightTimer * 360f).rad.sin * 15f - uboVS.lightPos.z = (uiSettings.lightTimer * 360f).rad.cos * 15f - } - - uniformBufferVS.mapping { - memCopy(uboVS.buffer.adr, uniformBufferVS.mapped, uboVS.size.L) - } - } - - fun draw() { - super.prepareFrame() - buildCommandBuffers() - submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] - queue submit submitInfo - super.submitFrame() - } - - fun loadAssets() { - models.models.loadFromFile("$assetPath/models/vulkanscenemodels.dae", vertexLayout, 1f, vulkanDevice, queue) - models.background.loadFromFile("$assetPath/models/vulkanscenebackground.dae", vertexLayout, 1f, vulkanDevice, queue) - models.logos.loadFromFile("$assetPath/models/vulkanscenelogos.dae", vertexLayout, 1f, vulkanDevice, queue) - } - - fun prepareImGui() { - imGui = ImGUI(this) - imGui.init(size) - imGui.initResources(renderPass, queue) - } - - override fun prepare() { - super.prepare() - loadAssets() - prepareUniformBuffers() - setupLayoutsAndDescriptors() - preparePipelines() - prepareImGui() - buildCommandBuffers() - prepared = true - } - - override fun render() { - - if (!prepared) return - - // Update imGui - ImGui.io.apply { - displaySize(size) - deltaTime = frameTimer - - mousePos(this@Imgui.mousePos) - mouseDown[0] = window.mouseButton(GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS - mouseDown[0] = window.mouseButton(GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS - } - draw() - - if (uiSettings.animateLight) - updateUniformBuffers() - } - - override fun viewChanged() = updateUniformBuffers() - -// override fun mouseMoved(double x, double y, bool & handled) { -// ImGuiIO& io = ImGui::GetIO() -// handled = io.WantCaptureMouse +///* +//* Vulkan Example - imGui (https://github.com/ocornut/imgui) +//* +//* Copyright (C) 2017 by Sascha Willems - www.saschawillems.de +//* +//* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +//*/ +// +//package vulkan.userInterface +// +//import glm_.BYTES +//import glm_.L +//import glm_.func.cos +//import glm_.func.rad +//import glm_.func.sin +//import glm_.i +//import glm_.mat4x4.Mat4 +//import glm_.max +//import glm_.vec2.Vec2 +//import glm_.vec2.Vec2i +//import glm_.vec2.operators.div +//import glm_.vec3.Vec3 +//import glm_.vec4.Vec4 +//import glm_.vec4.Vec4b +//import imgui.* +//import imgui.ImGui.checkbox +//import imgui.ImGui.inputVec3 +//import imgui.ImGui.plotLines +//import imgui.ImGui.setNextWindowPos +//import imgui.ImGui.setNextWindowSize +//import imgui.ImGui.sliderFloat +//import imgui.ImGui.text +//import imgui.ImGui.textUnformatted +//import imgui.functionalProgramming.withWindow +//import kool.adr +//import kool.bufferBig +//import org.lwjgl.glfw.GLFW.* +//import org.lwjgl.system.MemoryUtil.* +//import org.lwjgl.vulkan.VkCommandBuffer +//import org.lwjgl.vulkan.VkQueue +//import vkk.* +//import vulkan.assetPath +//import vulkan.base.* +//import vulkan.last +// +// +//fun main(args: Array) { +// Imgui().apply { +// setupWindow() +// initVulkan() +// prepare() +// renderLoop() +// destroy() // } -} \ No newline at end of file +//} +// +//// Options and values to display/toggle from the UI +//object uiSettings { +// var displayModels = true +// var displayLogos = true +// var displayBackground = true +// var animateLight = false +// var lightSpeed = 0.25f +// val frameTimes = FloatArray(50) +// var frameTimeMin = 9999f +// var frameTimeMax = 0f +// var lightTimer = 0f +//} +// +//// ---------------------------------------------------------------------------- +//// ImGUI class +//// ---------------------------------------------------------------------------- +//class ImGUI(val example: VulkanExampleBase) { +// +// // Vulkan resources for rendering the UI +// var sampler = VkSampler(NULL) +// val vertexBuffer = Buffer() +// val indexBuffer = Buffer() +// var vertexCount = 0 +// var indexCount = 0 +// var fontMemory = VkDeviceMemory(NULL) +// var fontImage = VkImage(NULL) +// var fontView = VkImageView(NULL) +// var pipelineCache = VkPipelineCache(NULL) +// var pipelineLayout = VkPipelineLayout(NULL) +// var pipeline = VkPipeline(NULL) +// var descriptorPool = VkDescriptorPool(NULL) +// var descriptorSetLayout = VkDescriptorSetLayout(NULL) +// var descriptorSet = VkDescriptorSet(NULL) +// val device: VulkanDevice = example.vulkanDevice +// +// // UI params are set via push constants +// object pushConstBlock { +// val scale = Vec2() +// val translate = Vec2() +// fun pack() { +// scale to buffer +// translate.to(buffer, Vec2.size) +// } +// +// val size = Vec2.size * 2 +// val buffer = bufferBig(size) +// } +// +// fun destroy() { +// // Release all Vulkan resources required for rendering imGui +// vertexBuffer.destroy() +// indexBuffer.destroy() +// device.logicalDevice!!.apply { +// destroyImage(fontImage) +// destroyImageView(fontView) +// freeMemory(fontMemory) +// destroySampler(sampler) +// destroyPipelineCache(pipelineCache) +// destroyPipeline(pipeline) +// destroyPipelineLayout(pipelineLayout) +// destroyDescriptorPool(descriptorPool) +// destroyDescriptorSetLayout(descriptorSetLayout) +// } +// } +// +// /** Initialize styles, keys, etc. */ +// fun init(size: Vec2i) { +// // Color scheme +// ImGui.style.colors.also { +// it[Col.TitleBg] = Vec4(1f, 0f, 0f, 0.6f) +// it[Col.TitleBgActive] = Vec4(1f, 0f, 0f, 0.8f) +// it[Col.MenuBarBg] = Vec4(1f, 0f, 0f, 0.4f) +// it[Col.Header] = Vec4(1f, 0f, 0f, 0.4f) +// it[Col.CheckMark] = Vec4(0f, 1f, 0f, 1f) +// } +// // Dimensions +// ImGui.io.apply { +// displaySize put size +// displayFramebufferScale put 1f +// } +// } +// +// /** Initialize all Vulkan resources used by the ui */ +// fun initResources(renderPass: VkRenderPass, copyQueue: VkQueue) { +// +// val io = ImGui.io +// +// // Create font texture +// val (fontData, texSize, _) = io.fonts.getTexDataAsRGBA32() +// val uploadSize = VkDeviceSize(texSize.x * texSize.y * Vec4b.size.L) +// +// // Create target image for copy +// val imageInfo = vk.ImageCreateInfo { +// imageType = VkImageType.`2D` +// format = VkFormat.R8G8B8A8_UNORM +// extent(texSize, 1) +// mipLevels = 1 +// arrayLayers = 1 +// samples = VkSampleCount.`1_BIT` +// tiling = VkImageTiling.OPTIMAL +// usage = VkImageUsage.SAMPLED_BIT or VkImageUsage.TRANSFER_DST_BIT +// sharingMode = VkSharingMode.EXCLUSIVE +// initialLayout = VkImageLayout.UNDEFINED +// } +// val dev = device.logicalDevice!! +// fontImage = dev createImage imageInfo +// val memReqs = dev getImageMemoryRequirements fontImage +// val memAllocInfo = vk.MemoryAllocateInfo { } +// memAllocInfo.allocationSize = memReqs.size +// memAllocInfo.memoryTypeIndex = device.getMemoryType(memReqs.memoryTypeBits, VkMemoryProperty.DEVICE_LOCAL_BIT) +// fontMemory = dev allocateMemory memAllocInfo +// dev.bindImageMemory(fontImage, fontMemory) +// +// // Image view +// val viewInfo = vk.ImageViewCreateInfo { +// image = fontImage +// viewType = VkImageViewType.`2D` +// format = VkFormat.R8G8B8A8_UNORM +// subresourceRange.apply { +// aspectMask = VkImageAspect.COLOR_BIT.i +// levelCount = 1 +// layerCount = 1 +// } +// } +// fontView = dev createImageView viewInfo +// +// // Staging buffers for font data upload +// val stagingBuffer = Buffer() +// +// device.createBuffer( +// VkBufferUsage.TRANSFER_SRC_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// stagingBuffer, +// uploadSize) +// +// stagingBuffer.mapping { +// memCopy(fontData.adr, stagingBuffer.mapped, uploadSize) +// } +// // Copy buffer data to font image +// val copyCmd = device.createCommandBuffer(VkCommandBufferLevel.PRIMARY, true) +// +// // Prepare for transfer +// tools.setImageLayout( +// copyCmd, +// fontImage, +// VkImageAspect.COLOR_BIT.i, +// VkImageLayout.UNDEFINED, +// VkImageLayout.TRANSFER_DST_OPTIMAL, +// VkPipelineStage.HOST_BIT.i, +// VkPipelineStage.TRANSFER_BIT.i) +// +// // Copy +// val bufferCopyRegion = vk.BufferImageCopy { +// imageSubresource.apply { +// aspectMask = VkImageAspect.COLOR_BIT.i +// layerCount = 1 +// } +// imageExtent(texSize, 1) +// } +// copyCmd.copyBufferToImage( +// stagingBuffer.buffer, +// fontImage, +// VkImageLayout.TRANSFER_DST_OPTIMAL, +// bufferCopyRegion) +// +// // Prepare for shader read +// tools.setImageLayout( +// copyCmd, +// fontImage, +// VkImageAspect.COLOR_BIT.i, +// VkImageLayout.TRANSFER_DST_OPTIMAL, +// VkImageLayout.SHADER_READ_ONLY_OPTIMAL, +// VkPipelineStage.TRANSFER_BIT.i, +// VkPipelineStage.FRAGMENT_SHADER_BIT.i) +// +// device.flushCommandBuffer(copyCmd, copyQueue, true) +// +// stagingBuffer.destroy() +// +// // Font texture Sampler +// val samplerInfo = vk.SamplerCreateInfo { +// magFilter = VkFilter.LINEAR +// minFilter = VkFilter.LINEAR +// mipmapMode = VkSamplerMipmapMode.LINEAR +// addressMode = VkSamplerAddressMode.CLAMP_TO_EDGE +// borderColor = VkBorderColor.FLOAT_OPAQUE_WHITE +// } +// sampler = dev createSampler samplerInfo +// +// // Descriptor pool +// val poolSizes = vk.DescriptorPoolSize(VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1) +// +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) +// descriptorPool = dev createDescriptorPool descriptorPoolInfo +// +// // Descriptor set layout +// val setLayoutBindings = vk.DescriptorSetLayoutBinding(VkDescriptorType.COMBINED_IMAGE_SAMPLER, VkShaderStage.FRAGMENT_BIT.i, 0) +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// descriptorSetLayout = dev createDescriptorSetLayout descriptorLayout +// +// // Descriptor set +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) +// descriptorSet = dev allocateDescriptorSets allocInfo +// val fontDescriptor = vk.DescriptorImageInfo( +// sampler, +// fontView, +// VkImageLayout.SHADER_READ_ONLY_OPTIMAL) +// val writeDescriptorSets = vk.WriteDescriptorSet(descriptorSet, VkDescriptorType.COMBINED_IMAGE_SAMPLER, 0, fontDescriptor) +// dev.updateDescriptorSets(writeDescriptorSets) +// +// // Pipeline cache +// pipelineCache = dev createPipelineCache vk.PipelineCacheCreateInfo() +// +// // Pipeline layout +// // Push constants for UI rendering parameters +// val pushConstantRange = vk.PushConstantRange(VkShaderStage.VERTEX_BIT, pushConstBlock.size) +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout).also { +// it.pushConstantRange = pushConstantRange +// } +// pipelineLayout = dev createPipelineLayout pipelineLayoutCreateInfo +// +// // Setup graphics pipeline for UI rendering +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.NONE.i, VkFrontFace.COUNTER_CLOCKWISE) +// +// // Enable blending +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState { +// blendEnable = true +// colorWriteMask = VkColorComponent.R_BIT or VkColorComponent.G_BIT or VkColorComponent.B_BIT.i or VkColorComponent.A_BIT.i +// srcColorBlendFactor = VkBlendFactor.SRC_ALPHA +// dstColorBlendFactor = VkBlendFactor.ONE_MINUS_SRC_ALPHA +// colorBlendOp = VkBlendOp.ADD +// srcAlphaBlendFactor = VkBlendFactor.ONE_MINUS_SRC_ALPHA +// dstAlphaBlendFactor = VkBlendFactor.ZERO +// alphaBlendOp = VkBlendOp.ADD +// } +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(false, false, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// val shaderStages = vk.PipelineShaderStageCreateInfo(2) +// +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// } +// // Vertex bindings an attributes based on ImGui vertex definition +// val vertexInputBindings = vk.VertexInputBindingDescription(0, DrawVert.size, VkVertexInputRate.VERTEX) +// +// val vertexInputAttributes = vk.VertexInputAttributeDescription( +// 0, 0, VkFormat.R32G32_SFLOAT, 0, // Location 0: Position +// 0, 1, VkFormat.R32G32_SFLOAT, Vec2.size, // Location 1: UV +// 0, 2, VkFormat.R8G8B8A8_UNORM, Vec2.size * 2) // Location 0: Color +// val vertexInputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertexInputBindings +// vertexAttributeDescriptions = vertexInputAttributes +// } +// pipelineCreateInfo.vertexInputState = vertexInputState +// +// example.apply { +// shaderStages[0].loadShader("$assetPath/shaders/imgui/ui.vert.spv", VkShaderStage.VERTEX_BIT) +// shaderStages[1].loadShader("$assetPath/shaders/imgui/ui.frag.spv", VkShaderStage.FRAGMENT_BIT) +// } +// pipeline = dev.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// +// var f = 0f +// +// /** Starts a new imGui frame and sets up windows and ui elements */ +// fun newFrame(updateFrameGraph: Boolean) { +// +// ImGui.newFrame() +// +// // Init imGui windows and elements +// +// val clearColor = Color(114, 144, 154) +// textUnformatted(example.title) +// textUnformatted(device.properties.deviceName) +// +// // Update frame time display +// if (updateFrameGraph) { +// for (i in uiSettings.frameTimes.indices) +// uiSettings.frameTimes[i] = uiSettings.frameTimes.getOrElse(i) { uiSettings.frameTimes.last() } +// val frameTime = 1000f / (example.frameTimer * 1000f) +// uiSettings.frameTimes.last(frameTime) +// if (frameTime < uiSettings.frameTimeMin) +// uiSettings.frameTimeMin = frameTime +// if (frameTime > uiSettings.frameTimeMax) +// uiSettings.frameTimeMax = frameTime +// } +// +// plotLines("Frame Times", uiSettings.frameTimes, 0, "", uiSettings.frameTimeMin, uiSettings.frameTimeMax, Vec2(0, 80)) +// +// text("Camera") +// inputVec3("position", example.camera.position, "%f") +// inputVec3("rotation", example.camera.rotation, "%f") +// +// setNextWindowSize(Vec2(200), Cond.FirstUseEver) +// withWindow("Example settings") { +// checkbox("Render models", uiSettings::displayModels) +// checkbox("Display logos", uiSettings::displayLogos) +// checkbox("Display background", uiSettings::displayBackground) +// checkbox("Animate light", uiSettings::animateLight) +// sliderFloat("Light speed", uiSettings::lightSpeed, 0.1f, 1f) +// } +// +// setNextWindowPos(Vec2(650, 20), Cond.FirstUseEver) +//// showTestWindow() +// +// // Render to generate draw buffers +// ImGui.render() +// } +// +// /** Update vertex and index buffer containing the imGui elements when required */ +// fun updateBuffers() { +// +// val drawData = ImGui.drawData!! +// +// // Note: Alignment is done inside buffer creation +// val vertexBufferSize = VkDeviceSize (drawData.totalVtxCount * DrawVert.size.L) +// val indexBufferSize = VkDeviceSize (drawData.totalIdxCount * DrawIdx.BYTES.L) +// +// // Update buffers only if vertex or index count has been changed compared to current buffer size +// +// // Vertex buffer +// if (vertexBuffer.buffer.isInvalid() || vertexCount != drawData.totalVtxCount) { +// vertexBuffer.unmap() +// vertexBuffer.destroy() +// device.createBuffer(VkBufferUsage.VERTEX_BUFFER_BIT.i, VkMemoryProperty.HOST_VISIBLE_BIT.i, vertexBuffer, vertexBufferSize) +// vertexCount = drawData.totalVtxCount +// vertexBuffer.unmap() +// vertexBuffer.map() +// } +// +// // Index buffer +// if (indexBuffer.buffer.isInvalid() || indexCount < drawData.totalIdxCount) { +// indexBuffer.unmap() +// indexBuffer.destroy() +// device.createBuffer(VkBufferUsage.INDEX_BUFFER_BIT.i, VkMemoryProperty.HOST_VISIBLE_BIT.i, indexBuffer, indexBufferSize) +// indexCount = drawData.totalIdxCount +// indexBuffer.map() +// } +// +// // Upload data +// var vtxDst = vertexBuffer.mapped +// var idxDst = indexBuffer.mapped +// +// for (cmdList in drawData.cmdLists) { +// var k = 0 +// for (v in cmdList.vtxBuffer) { +// val ofs = vtxDst + DrawVert.size * k++ +// memPutFloat(ofs, v.pos.x) +// memPutFloat(ofs + Float.BYTES, v.pos.y) +// memPutFloat(ofs + Vec2.size, v.uv.x) +// memPutFloat(ofs + Vec2.size + Float.BYTES, v.uv.y) +// memPutInt(ofs + Vec2.size * 2, v.col) +// } +// k = 0 +// for (i in cmdList.idxBuffer) +// memPutInt(idxDst + DrawIdx.BYTES * k++, i) +// vtxDst += cmdList.vtxBuffer.size +// idxDst += cmdList.idxBuffer.size +// } +// +// // Flush to make writes visible to GPU +// vertexBuffer.flush() +// indexBuffer.flush() +// } +// +// /** Draw current imGui frame into a command buffer */ +// fun drawFrame(commandBuffer: VkCommandBuffer) { +// +// val io = ImGui.io +// +// commandBuffer.apply { +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipeline) +// +// // Bind vertex and index buffer +// bindVertexBuffers(vertexBuffer.buffer) +// bindIndexBuffer(indexBuffer.buffer, VkDeviceSize(0), VkIndexType.UINT16) +// +// setViewport(vk.Viewport(io.displaySize)) +// +// // UI scale and translate via push constants +// pushConstBlock.scale put 2f / io.displaySize +// pushConstBlock.translate put -1f +// pushConstBlock.pack() +// pushConstants(pipelineLayout, VkShaderStage.VERTEX_BIT.i, pushConstBlock.size, pushConstBlock.buffer) +// +// // Render commands +// val drawData = ImGui.drawData!! +// var vertexOffset = 0 +// var indexOffset = 0 +// for (cmdList in drawData.cmdLists) { +// for (cmd in cmdList.cmdBuffer) { +// val scissorRect = vk.Rect2D( +// offsetX = cmd.clipRect.x.i max 0, +// offsetY = cmd.clipRect.y.i max 0, +// width = (cmd.clipRect.z - cmd.clipRect.x).i, +// height = (cmd.clipRect.w - cmd.clipRect.y).i) +// setScissor(scissorRect) +// drawIndexed(cmd.elemCount, 1, indexOffset, vertexOffset, 0) +// indexOffset += cmd.elemCount +// } +// vertexOffset += cmdList.vtxBuffer.size +// } +// } +// } +// +//} +// +//// ---------------------------------------------------------------------------- +//// VulkanExample +//// ---------------------------------------------------------------------------- +// +//private class Imgui : VulkanExampleBase() { +// +// lateinit var imGui: ImGUI +// +// // Vertex layout for the models +// val vertexLayout = VertexLayout( +// VertexComponent.POSITION, +// VertexComponent.NORMAL, +// VertexComponent.COLOR) +// +// object models { +// val models = Model() +// val logos = Model() +// val background = Model() +// } +// +// val uniformBufferVS = Buffer() +// +// object uboVS { +// var projection = Mat4() +// var modelview = Mat4() +// var lightPos = Vec4() +// fun pack() { +// projection to buffer +// modelview.to(buffer, Mat4.size) +// lightPos.to(buffer, Mat4.size * 2) +// } +// +// val size = Mat4.size * 2 + Vec4.size +// val buffer = bufferBig(size) +// } +// +// var pipelineLayout = VkPipelineLayout (NULL) +// var pipeline = VkPipeline (NULL) +// var descriptorSetLayout = VkDescriptorSetLayout (NULL) +// var descriptorSet = VkDescriptorSet (NULL) +// +// init { +// title = "Vulkan Example - ImGui" +// camera.type = Camera.CameraType.lookAt +// camera.setPosition(Vec3(0f, 1.4f, -4.8f)) +// camera.setRotation(Vec3(4.5f, -380f, 0f)) +// camera.setPerspective(45f, size.aspect, 0.1f, 256f) +// } +// +// override fun destroy() { +// super.destroy() +// +// device.apply { +// destroyPipeline(pipeline) +// destroyPipelineLayout(pipelineLayout) +// destroyDescriptorSetLayout(descriptorSetLayout) +// } +// models.apply { +// models.destroy() +// background.destroy() +// logos.destroy() +// } +// uniformBufferVS.destroy() +// +// imGui.destroy() +// } +// +// override fun buildCommandBuffers() { +// +// val cmdBufInfo = vk.CommandBufferBeginInfo() +// +// val clearValues = vk.ClearValue(2).also { +// it[0].color(0.2f, 0.2f, 0.2f, 1f) +// it[1].depthStencil(1f, 0) +// } +// val renderPassBeginInfo = vk.RenderPassBeginInfo { +// renderPass = this@Imgui.renderPass +// renderArea.apply { +// offset(0) +// extent(size) +// } +// this.clearValues = clearValues +// } +// imGui.newFrame(frameCounter == 0) +// +// imGui.updateBuffers() +// +// for (i in drawCmdBuffers.indices) { +// // Set target frame buffer +// renderPassBeginInfo.framebuffer = frameBuffers[i] +// +// drawCmdBuffers[i].apply { +// +// begin(cmdBufInfo) +// +// beginRenderPass(renderPassBeginInfo, VkSubpassContents.INLINE) +// +// setViewport(vk.Viewport(size)) +// +// setScissor(vk.Rect2D(size)) +// +// // Render scene +// bindDescriptorSets(VkPipelineBindPoint.GRAPHICS, pipelineLayout, descriptorSet) +// bindPipeline(VkPipelineBindPoint.GRAPHICS, pipeline) +// +// if (uiSettings.displayBackground) { +// bindVertexBuffers(models.background.vertices.buffer) +// bindIndexBuffer(models.background.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// drawIndexed(models.background.indexCount, 1, 0, 0, 0) +// } +// +// if (uiSettings.displayModels) { +// bindVertexBuffers(models.models.vertices.buffer) +// bindIndexBuffer(models.models.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// drawIndexed(models.models.indexCount, 1, 0, 0, 0) +// } +// +// if (uiSettings.displayLogos) { +// bindVertexBuffers(models.logos.vertices.buffer) +// bindIndexBuffer(models.logos.indices.buffer, VkDeviceSize(0), VkIndexType.UINT32) +// drawIndexed(models.logos.indexCount, 1, 0, 0, 0) +// } +// +// // Render imGui +// imGui.drawFrame(this) +// +// endRenderPass() +// +// end() +// } +// } +// } +// +// fun setupLayoutsAndDescriptors() { +// // descriptor pool +// val poolSizes = vk.DescriptorPoolSize( +// VkDescriptorType.UNIFORM_BUFFER, 2, +// VkDescriptorType.COMBINED_IMAGE_SAMPLER, 1) +// val descriptorPoolInfo = vk.DescriptorPoolCreateInfo(poolSizes, 2) +// descriptorPool = device createDescriptorPool descriptorPoolInfo +// +// // Set layout +// val setLayoutBindings = vk.DescriptorSetLayoutBinding(VkDescriptorType.UNIFORM_BUFFER, VkShaderStage.VERTEX_BIT.i, 0) +// val descriptorLayout = vk.DescriptorSetLayoutCreateInfo(setLayoutBindings) +// descriptorSetLayout = device createDescriptorSetLayout descriptorLayout +// +// // Pipeline layout +// val pipelineLayoutCreateInfo = vk.PipelineLayoutCreateInfo(descriptorSetLayout) +// pipelineLayout = device createPipelineLayout pipelineLayoutCreateInfo +// +// // Descriptor set +// val allocInfo = vk.DescriptorSetAllocateInfo(descriptorPool, descriptorSetLayout) +// descriptorSet = device allocateDescriptorSets allocInfo +// val writeDescriptorSets = vk.WriteDescriptorSet(descriptorSet, VkDescriptorType.UNIFORM_BUFFER, 0, uniformBufferVS.descriptor) +// +// device updateDescriptorSets writeDescriptorSets +// } +// +// fun preparePipelines() { +// // Rendering +// val inputAssemblyState = vk.PipelineInputAssemblyStateCreateInfo(VkPrimitiveTopology.TRIANGLE_LIST) +// +// val rasterizationState = vk.PipelineRasterizationStateCreateInfo(VkPolygonMode.FILL, VkCullMode.FRONT_BIT.i, VkFrontFace.COUNTER_CLOCKWISE) +// +// val blendAttachmentState = vk.PipelineColorBlendAttachmentState(0xf, false) +// +// val colorBlendState = vk.PipelineColorBlendStateCreateInfo(blendAttachmentState) +// +// val depthStencilState = vk.PipelineDepthStencilStateCreateInfo(true, true, VkCompareOp.LESS_OR_EQUAL) +// +// val viewportState = vk.PipelineViewportStateCreateInfo(1, 1) +// +// val multisampleState = vk.PipelineMultisampleStateCreateInfo(VkSampleCount.`1_BIT`) +// +// val dynamicStateEnables = listOf(VkDynamicState.VIEWPORT, VkDynamicState.SCISSOR) +// val dynamicState = vk.PipelineDynamicStateCreateInfo(dynamicStateEnables) +// +// // Load shaders +// val shaderStages = vk.PipelineShaderStageCreateInfo(2) +// +// val pipelineCreateInfo = vk.GraphicsPipelineCreateInfo(pipelineLayout, renderPass).also { +// it.inputAssemblyState = inputAssemblyState +// it.rasterizationState = rasterizationState +// it.colorBlendState = colorBlendState +// it.multisampleState = multisampleState +// it.viewportState = viewportState +// it.depthStencilState = depthStencilState +// it.dynamicState = dynamicState +// it.stages = shaderStages +// } +// val vertexInputBindings = vk.VertexInputBindingDescription(0, vertexLayout.stride, VkVertexInputRate.VERTEX) +// +// val vertexInputAttributes = vk.VertexInputAttributeDescription( +// 0, 0, VkFormat.R32G32B32_SFLOAT, 0, // Location 0: Position +// 0, 1, VkFormat.R32G32B32_SFLOAT, Vec3.size, // Location 1: Normal +// 0, 2, VkFormat.R32G32B32_SFLOAT, Vec3.size * 2) // Location 2: Color +// +// val vertexInputState = vk.PipelineVertexInputStateCreateInfo { +// vertexBindingDescription = vertexInputBindings +// vertexAttributeDescriptions = vertexInputAttributes +// } +// pipelineCreateInfo.vertexInputState = vertexInputState +// +// shaderStages[0].loadShader("$assetPath/shaders/imgui/scene.vert.spv", VkShaderStage.VERTEX_BIT) +// shaderStages[1].loadShader("$assetPath/shaders/imgui/scene.frag.spv", VkShaderStage.FRAGMENT_BIT) +// pipeline = device.createGraphicsPipelines(pipelineCache, pipelineCreateInfo) +// } +// +// /** Prepare and initialize uniform buffer containing shader uniforms */ +// fun prepareUniformBuffers() { +// // Vertex shader uniform buffer block +// vulkanDevice.createBuffer( +// VkBufferUsage.UNIFORM_BUFFER_BIT.i, +// VkMemoryProperty.HOST_VISIBLE_BIT or VkMemoryProperty.HOST_COHERENT_BIT, +// uniformBufferVS, +// VkDeviceSize(uboVS.size.L), +// uboVS.buffer.adr) +// +// updateUniformBuffers() +// } +// +// fun updateUniformBuffers() { +// // Vertex shader +// uboVS.projection = camera.matrices.perspective +// uboVS.modelview = camera.matrices.view +// +// // Light source +// if (uiSettings.animateLight) { +// uiSettings.lightTimer += frameTimer * uiSettings.lightSpeed +// uboVS.lightPos.x = (uiSettings.lightTimer * 360f).rad.sin * 15f +// uboVS.lightPos.z = (uiSettings.lightTimer * 360f).rad.cos * 15f +// } +// +// uniformBufferVS.mapping { +// memCopy(uboVS.buffer.adr, uniformBufferVS.mapped, uboVS.size.L) +// } +// } +// +// fun draw() { +// super.prepareFrame() +// buildCommandBuffers() +// submitInfo.commandBuffer = drawCmdBuffers[currentBuffer] +// queue submit submitInfo +// super.submitFrame() +// } +// +// fun loadAssets() { +// models.models.loadFromFile("$assetPath/models/vulkanscenemodels.dae", vertexLayout, 1f, vulkanDevice, queue) +// models.background.loadFromFile("$assetPath/models/vulkanscenebackground.dae", vertexLayout, 1f, vulkanDevice, queue) +// models.logos.loadFromFile("$assetPath/models/vulkanscenelogos.dae", vertexLayout, 1f, vulkanDevice, queue) +// } +// +// fun prepareImGui() { +// imGui = ImGUI(this) +// imGui.init(size) +// imGui.initResources(renderPass, queue) +// } +// +// override fun prepare() { +// super.prepare() +// loadAssets() +// prepareUniformBuffers() +// setupLayoutsAndDescriptors() +// preparePipelines() +// prepareImGui() +// buildCommandBuffers() +// prepared = true +// } +// +// override fun render() { +// +// if (!prepared) return +// +// // Update imGui +// ImGui.io.apply { +// displaySize(size) +// deltaTime = frameTimer +// +// mousePos(this@Imgui.mousePos) +// mouseDown[0] = window.mouseButton(GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS +// mouseDown[0] = window.mouseButton(GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS +// } +// draw() +// +// if (uiSettings.animateLight) +// updateUniformBuffers() +// } +// +// override fun viewChanged() = updateUniformBuffers() +// +//// override fun mouseMoved(double x, double y, bool & handled) { +//// ImGuiIO& io = ImGui::GetIO() +//// handled = io.WantCaptureMouse +//// } +//} \ No newline at end of file