merge vulkan library into dlib

This commit is contained in:
Matthew 2026-05-11 06:34:32 +10:00
parent 2c81e42008
commit 3a4518beb4
11 changed files with 23163 additions and 107 deletions

View File

@ -16,18 +16,6 @@ fi
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
build="$1" build="$1"
if [ -n "$wasm" ]; then
ext_path="${script_dir}/external"
cpp_compiler="clang++"
c_compiler="clang"
flags="-target wasm32 -nostdlib -c -static -mbulk-memory -mbulk-memory-opt -matomics -msimd128 -mno-gc"
files="${ext_path}/tinyalloc/tinyalloc.c"
includes="-I${ext_path}/tinyalloc"
out="-obuild/dlibincludes.wasm"
$c_compiler $flags $includes $files $out
else
if [ -x "$(command -v g++)" ]; then cpp_compiler="g++"; c_compiler="gcc"; if [ -x "$(command -v g++)" ]; then cpp_compiler="g++"; c_compiler="gcc";
elif [ -x "$(command -v clang++)" ]; then cpp_compiler="clang++"; c_compiler="clang"; elif [ -x "$(command -v clang++)" ]; then cpp_compiler="clang++"; c_compiler="clang";
else echo "Unable to find c++ cpp_compiler"; exit -1; fi; else echo "Unable to find c++ cpp_compiler"; exit -1; fi;
@ -56,18 +44,6 @@ else
rm $obj rm $obj
fi fi
# M3D
#src="${script_dir}/external/m3d/m3d.c"
#flags="-std=c99 -Wno-everything -Iexternal/m3d -c -static"
#obj="${build}/m3d.o"
#lib="${build}/libm3d.a"
#
#if ! [ -f "${build}/libm3d.a" ]; then
# $c_compiler $flags $src $out $obj
# ar rcs $lib $obj
# rm $obj
#fi
# CGLTF # CGLTF
src="${script_dir}/external/cgltf/cgltf.c" src="${script_dir}/external/cgltf/cgltf.c"
flags="-std=c99 -Iexternal/cgltf $shared_flags" flags="-std=c99 -Iexternal/cgltf $shared_flags"
@ -80,17 +56,27 @@ else
rm $obj rm $obj
fi fi
# Build VMA
src="${script_dir}/external/vma/vma.cpp"
flags="-std=c++20 -D_USE_MATH_DEFINES -Iexternal/vma -c -Wno-everything -static"
out="-o"
obj="${build}/vma.o"
lib="${build}/libvma.a"
# XXHASH if ! [ -f $lib ]; then
#src="${script_dir}/external/xxhash/xxhash.c" $cpp_compiler $flags $src $out $obj
#flags="-std=c99 -Iexternal/xxhash $shared_flags" ar rcs $lib $obj
#obj="${build}/xxhash.o" rm $obj
#lib="${build}/libxxhash.a"
#if ! [ -f $lib ]; then
# $c_compiler $flags $src $out $obj
# ar rcs $lib $obj
# rm $obj
#fi
fi fi
# Convert Shader
shader="${script_dir}/vulkan/convert.comp.glsl"
shader_compiler="glslc"
shader_flags="-std=460 -O --target-env=vulkan1.2"
shader_out="-o${build}/"
shader_stage="-fshader-stage=comp"
base_name=$(basename -- "$shader" .glsl)
$shader_compiler $shader_flags $shader_stage $shader "${shader_out}${base_name}.spv"

View File

@ -1,6 +1,7 @@
//#pragma attribute(push, nogc, nothrow) #pragma attribute(push, nogc, nothrow)
#ifdef __linux__ #ifdef __linux__
# define VK_USE_PLATFORM_XLIB_KHR
# define XLIB_ILLEGAL_ACCESS # define XLIB_ILLEGAL_ACCESS
# include <X11/Xlib.h> # include <X11/Xlib.h>
# include <X11/XKBlib.h> # include <X11/XKBlib.h>
@ -17,6 +18,11 @@
# include FT_GLYPH_H # include FT_GLYPH_H
#endif #endif
#ifdef _WIN32
# include <windows.h>
# define VK_USE_PLATFORM_WIN32_KHR
#endif
#if !defined(NO_STBI) && !defined(BUILD_WASM) #if !defined(NO_STBI) && !defined(BUILD_WASM)
# include "../external/stb/stb_image.h" # include "../external/stb/stb_image.h"
# include "../external/stb/stb_image_write.h" # include "../external/stb/stb_image_write.h"
@ -26,10 +32,6 @@
# include "../external/tinyalloc/tinyalloc.c" # include "../external/tinyalloc/tinyalloc.c"
#endif #endif
#ifndef NO_STBI
// # include "../external/stb/stb_truetype.h"
#endif
#ifdef DLIB_INCLUDE_VULKAN #ifdef DLIB_INCLUDE_VULKAN
# include "../../VulkanRenderer/vulkan_includes.c" # include "../../VulkanRenderer/vulkan_includes.c"
#endif #endif
@ -37,3 +39,17 @@
#ifndef BUILD_WASM #ifndef BUILD_WASM
# include "../external/cgltf/cgltf.h" # include "../external/cgltf/cgltf.h"
#endif #endif
#ifdef BUILD_VULKAN
# define VK_NO_PROTOTYPES
# include <vulkan/vulkan.h>
# define VMA_STATIC_VULKAN_FUNCTIONS 0
# define VMA_DYNAMIC_VULKAN_FUNCTIONS 1
# define VMA_VULKAN_VERSION 1002000
# include "../external/vma/vk_mem_alloc.h"
#endif

View File

@ -142,7 +142,9 @@ struct SlugBuffer
struct FontAtlas struct FontAtlas
{ {
Glyph[128] glyphs; Glyph[128] glyphs;
f32 ascent = 0.0; // All unscaled u32 pixel_size;
f32 baseline = 0.0; // All unscaled
f32 ascent = 0.0;
f32 descent = 0.0; f32 descent = 0.0;
f32 line_gap = 0.0; f32 line_gap = 0.0;
f32 line_height = 0.0; f32 line_height = 0.0;
@ -219,7 +221,14 @@ GenerateMSDF(string file_path)()
static T GetJSONValue(T)(JSONValue jsonv, string name) static T GetJSONValue(T)(JSONValue jsonv, string name)
{ {
T result = Select!(is(T == string), null, cast(T)0); static if(is(T == string))
{
T result = null;
}
else
{
T result = cast(T)0;
}
if(const(JSONValue)* value = name in jsonv) if(const(JSONValue)* value = name in jsonv)
{ {
@ -286,6 +295,11 @@ GenerateMSDF(string file_path)()
MSDFGlyph[] glyphs = new MSDFGlyph[128]; MSDFGlyph[] glyphs = new MSDFGlyph[128];
foreach(i; 0 .. glyphs.length)
{
glyphs[i].glyph = cast(dchar)i;
}
JSONValue[] glyph_json = jsonv["glyphs"].array; JSONValue[] glyph_json = jsonv["glyphs"].array;
foreach(i; 0 .. glyph_json.length) foreach(i; 0 .. glyph_json.length)
@ -346,13 +360,15 @@ TextSize(f32 s)
} }
FontAtlas FontAtlas
PopulateAtlasGlyphInfo(Arena* arena, FontFace* font, MSDFInfo* msdf_info) PopulateAtlasGlyphInfo(FontFace* font, u32 pixel_size, const MSDFInfo* msdf_info)
{ {
FontAtlas atlas; FontAtlas atlas;
// TODO: proper packing algorithm // TODO: proper packing algorithm
if(font != null) if(font != null)
{ {
f32 scale = stbtt_ScaleForPixelHeight(font, cast(f32)pixel_size);
i32 ascent, descent, line_gap; i32 ascent, descent, line_gap;
stbtt_GetFontVMetrics(font, &ascent, &descent, &line_gap); stbtt_GetFontVMetrics(font, &ascent, &descent, &line_gap);
@ -373,27 +389,33 @@ PopulateAtlasGlyphInfo(Arena* arena, FontFace* font, MSDFInfo* msdf_info)
{ {
if(msdf_info.glyphs[j].glyph == ch) if(msdf_info.glyphs[j].glyph == ch)
{ {
msdfg = msdf_info.glyphs.ptr + j; msdfg = cast(MSDFGlyph*)msdf_info.glyphs.ptr + j;
break; break;
} }
} }
Glyph* g = atlas.glyphs.ptr + ch; Glyph* g = atlas.glyphs.ptr + ch;
g.ch = ch;
g.advance = cast(f32)advance * scale;
g.atlas = msdfg.atlas; g.atlas = msdfg.atlas;
g.plane.left = cast(f32)x0 * scale;
g.plane.left = cast(f32)x0; g.plane.top = cast(f32)y0 * scale;
g.plane.top = cast(f32)y0; g.plane.right = cast(f32)x1 * scale;
g.plane.right = cast(f32)x1; g.plane.bottom = cast(f32)y1 * scale;
g.plane.bottom = cast(f32)y1;
} }
} }
atlas.ascent = cast(f32)ascent; i32 x0, y0, x1, y1;
atlas.descent = cast(f32)descent; stbtt_GetFontBoundingBox(font, &x0, &y0, &x1, &y1);
atlas.line_height = cast(f32)(ascent - descent); // Maybe add line gap?
atlas.line_gap = cast(f32)line_gap; atlas.pixel_size = pixel_size;
atlas.max_advance = cast(f32)max_advance; atlas.ascent = cast(f32)ascent * scale;
atlas.descent = cast(f32)descent * scale;
atlas.baseline = cast(f32)-y0 * scale;
atlas.line_height = cast(f32)(y1 - y0) * scale; // Maybe add line gap?
atlas.line_gap = cast(f32)line_gap * scale;
atlas.max_advance = cast(f32)max_advance * scale;
} }
return atlas; return atlas;
@ -902,3 +924,4 @@ SlugLoadFontVertex(u8 ch, IVec2 pos, SlugFont* font, SlugBuffer* buffer)
pos.x += cast(i32)(cast(f32)(glyph.advance) * font.scale); pos.x += cast(i32)(cast(f32)(glyph.advance) * font.scale);
} }
} }

View File

@ -1972,10 +1972,10 @@ version(DLIB_TEST) unittest
u8[] data_valid, data_test; u8[] data_valid, data_test;
File f = File("dlib/platform.d", "rb"); File f = File("../dlib/platform.d", "rb");
data_valid = f.rawRead(new u8[f.size()]); data_valid = f.rawRead(new u8[f.size()]);
data_test = LoadFile(&arena, "dlib/platform.d"); data_test = LoadFile(&arena, "../dlib/platform.d");
assert(data_valid == data_test); assert(data_valid == data_test);
} }

19112
external/vma/vk_mem_alloc.h vendored Normal file

File diff suppressed because it is too large Load Diff

15
external/vma/vma.cpp vendored Normal file
View File

@ -0,0 +1,15 @@
#define VMA_IMPLEMENTATION
#define VMA_STATIC_VULKAN_FUNCTIONS 0
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1
#define VMA_VULKAN_VERSION 1002000
#ifdef __linux__
# define XLIB_ILLEGAL_ACCESS
# define VK_USE_PLATFORM_XLIB_KHR
#elif _WIN32
# define VK_USE_PLATFORM_WIN32_KHR
#else
# error not yet implemented
#endif
#include "vk_mem_alloc.h"

87
test.sh
View File

@ -1,29 +1,86 @@
#!/bin/bash #!/bin/bash
name="Test_Runner" mkdir -p build
shared_src="dlib/package.d dlib/platform.d dlib/fonts.d dlib/aliases.d dlib/math.d dlib/util.d dlib/alloc.d dlib/assets.d dlib/externdecl.d stb_truetype.d" declare -a shared_src=(
dlib/package.d
dlib/platform.d
dlib/fonts.d
dlib/aliases.d
dlib/math.d
dlib/util.d
dlib/alloc.d
dlib/assets.d
dlib/externdecl.d
stb_truetype.d
)
if [ "$1" == "wasm" ]; then if [ "$1" == "wasm" ]; then
flags="-vgc -betterC -mtriple=wasm32-unknown-unknown-wasm -d-version=DLIB_TEST -fvisibility=hidden --unittest -Iwasm/runtime -i=core -i=std -i=. --real-precision=double --of=build/dlibmain.wasm --d-version=inline_concat -verrors=90 --of=build/dlib.wasm -gcc=clang" out="build/dlib.wasm"
wasm_src="wasm/runtime/object.d stb_truetype.d" declare -a flags=(
-vgc
-betterC
-mtriple=wasm32-unknown-unknown-wasm
-d-version=DLIB_TEST
-fvisibility=hidden
--unittest
-Iwasm/runtime
-i=core
-i=std
-i=.
--real-precision=double
-gcc=clang
"--of=$out"
)
declare -a wasm_src=(wasm/runtime/object.d)
#/bin/bash ./build.sh build wasm ldc2 "${flags[@]}" "${shared_src[@]}" "${wasm_src[@]}"
ldc2 $flags $shared_src $wasm_src cp $out wasm/dlib.wasm
#wasm-ld build/dlibmain.wasm build/dlibincludes.wasm --export=RunTests --error-limit=0 --export-memory -obuild/dlib.wasm
cp build/dlib.wasm wasm/dlib.wasm
else else
flags="-P-I/usr/include/freetype2 -Idlib -L-lfreetype --main --unittest -g --of=$name" out="build/Test_Runner"
declare -a native_src=(
build/libcgltf.a
)
declare -a flags=(
-P-I/usr/include/freetype2
-L-lfreetype
-Idlib
--main
--unittest
-g
-d-version=DLIB_TEST
-verrors=50
"--of=$out"
)
/bin/bash ./build.sh build /bin/bash ./build.sh build
ldc2 $flags $shared_src build/libxxhash.a -d-version=DLIB_TEST -verrors=50 # Test for success
ldc2 "${flags[@]}" "${shared_src[@]}" "${native_src[@]}"
rm $name.o rm "./${out}.o"
./$name "./${out}"
rm $name rm $out
native_src+=(
vulkan/vulkan.d
vulkan/vulkan_funcs.d
build/libvma.a
)
flags+=(
-L-lvulkan
-L-lstdc++
-Jbuild
-d-version=VULKAN_RENDERER_TEST
-Xcc=-DBUILD_VULKAN
)
# Test for compilation
ldc2 "${flags[@]}" "${shared_src[@]}" "${native_src[@]}"
rm "./${out}.o"
"./${out}"
rm $out
fi fi

56
vulkan/convert.comp.glsl Normal file
View File

@ -0,0 +1,56 @@
#version 460
#extension GL_EXT_shader_8bit_storage : require
layout (constant_id = 0) const int CHANNELS = 3;
layout (local_size_x = 32, local_size_y = 32) in;
layout (push_constant) uniform Constants {
uint x;
uint y;
} PC;
layout (set = 1, binding = 0, rgba32f) uniform image2D dst;
layout (set = 1, binding = 1) buffer input_array
{
uint8_t src[];
};
void main()
{
uint x = gl_GlobalInvocationID.x;
uint y = gl_GlobalInvocationID.y;
if(x > PC.x || y > PC.y)
{
return;
}
if(CHANNELS == 1)
{
uint index = x + y * PC.x;
vec4 col = vec4(vec3(uint(src[index]) / 255.0), 1.0);
imageStore(dst, ivec2(x, y), col);
}
else if(CHANNELS == 2)
{
uint index = (x + y * PC.x) * 2;
float f = uint(src[index]) / 255.0;
float a = uint(src[index+1]) / 255.0;
vec4 col = vec4(f, f, f, a);
imageStore(dst, ivec2(x, y), col);
}
else if(CHANNELS == 3)
{
uint index = (x + y * PC.x) * 3;
vec4 col = vec4(uint(src[index]) / 255.0, uint(src[index+1]) / 255.0, uint(src[index+2]) / 255.0, 1.0);
imageStore(dst, ivec2(x, y), col);
}
}

3519
vulkan/vulkan.d Normal file

File diff suppressed because it is too large Load Diff

272
vulkan/vulkan_funcs.d Normal file
View File

@ -0,0 +1,272 @@
import vulkan;
import dlibincludes;
// Global Functions
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
PFN_vkCreateInstance vkCreateInstance;
PFN_vkEnumerateInstanceLayerProperties vkEnumerateInstanceLayerProperties;
// Instance Functions
PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices;
PFN_vkCreateDevice vkCreateDevice;
PFN_vkGetPhysicalDeviceQueueFamilyProperties vkGetPhysicalDeviceQueueFamilyProperties;
PFN_vkGetPhysicalDeviceSurfaceSupportKHR vkGetPhysicalDeviceSurfaceSupportKHR;
PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties;
PFN_vkGetPhysicalDeviceFeatures2 vkGetPhysicalDeviceFeatures2;
PFN_vkEnumerateDeviceExtensionProperties vkEnumerateDeviceExtensionProperties;
PFN_vkGetPhysicalDeviceSurfacePresentModesKHR vkGetPhysicalDeviceSurfacePresentModesKHR;
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR vkGetPhysicalDeviceSurfaceFormatsKHR;
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR vkGetPhysicalDeviceSurfaceCapabilitiesKHR;
PFN_vkGetPhysicalDeviceImageFormatProperties vkGetPhysicalDeviceImageFormatProperties;
PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
PFN_vkDestroyInstance vkDestroyInstance;
PFN_vkDestroySurfaceKHR vkDestroySurfaceKHR;
version(VULKAN_DEBUG)
{
PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT;
PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT;
}
// Platform Functions
version(linux)
{
PFN_vkCreateXlibSurfaceKHR vkCreateXlibSurfaceKHR;
}
version(Windows)
{
PFN_vkCreateWin32SurfaceKHR vkCreateWin32SurfaceKHR;
}
version(AMD_GPU) version(VULKAN_DEBUG)
{
PFN_vkGetShaderInfoAMD vkGetShaderInfoAMD;
}
// Device Functions
PFN_vkCreateSwapchainKHR vkCreateSwapchainKHR;
PFN_vkCmdBeginRenderPass vkCmdBeginRenderPass;
PFN_vkCmdEndRenderPass vkCmdEndRenderPass;
PFN_vkCreateFramebuffer vkCreateFramebuffer;
PFN_vkDestroyFramebuffer vkDestroyFramebuffer;
PFN_vkCreateRenderPass vkCreateRenderPass;
PFN_vkDestroyRenderPass vkDestroyRenderPass;
PFN_vkCreateImage vkCreateImage;
PFN_vkCreateImageView vkCreateImageView;
PFN_vkCreateBufferView vkCreateBufferView;
PFN_vkGetSwapchainImagesKHR vkGetSwapchainImagesKHR;
PFN_vkGetDeviceQueue vkGetDeviceQueue;
PFN_vkCreateSemaphore vkCreateSemaphore;
PFN_vkAllocateCommandBuffers vkAllocateCommandBuffers;
PFN_vkCreateCommandPool vkCreateCommandPool;
PFN_vkCreateFence vkCreateFence;
PFN_vkCreateDescriptorPool vkCreateDescriptorPool;
PFN_vkCreateDescriptorSetLayout vkCreateDescriptorSetLayout;
PFN_vkAllocateDescriptorSets vkAllocateDescriptorSets;
PFN_vkCreatePipelineLayout vkCreatePipelineLayout;
PFN_vkResetDescriptorPool vkResetDescriptorPool;
PFN_vkCreateShaderModule vkCreateShaderModule;
PFN_vkCreateGraphicsPipelines vkCreateGraphicsPipelines;
PFN_vkCreateComputePipelines vkCreateComputePipelines;
PFN_vkUpdateDescriptorSets vkUpdateDescriptorSets;
PFN_vkDestroyDevice vkDestroyDevice;
PFN_vkDestroyDescriptorPool vkDestroyDescriptorPool;
PFN_vkDestroySwapchainKHR vkDestroySwapchainKHR;
PFN_vkDestroyBufferView vkDestroyBufferView;
PFN_vkQueueSubmit2KHR vkQueueSubmit2KHR;
PFN_vkDestroyImage vkDestroyImage;
PFN_vkCmdBlitImage vkCmdBlitImage;
PFN_vkDestroyImageView vkDestroyImageView;
PFN_vkDestroyCommandPool vkDestroyCommandPool;
PFN_vkDestroySemaphore vkDestroySemaphore;
PFN_vkDestroyFence vkDestroyFence;
PFN_vkDestroyPipelineLayout vkDestroyPipelineLayout;
PFN_vkCmdPipelineBarrier vkCmdPipelineBarrier;
PFN_vkCmdPipelineBarrier2KHR vkCmdPipelineBarrier2KHR;
PFN_vkDestroyPipeline vkDestroyPipeline;
PFN_vkWaitForFences vkWaitForFences;
PFN_vkBeginCommandBuffer vkBeginCommandBuffer;
PFN_vkEndCommandBuffer vkEndCommandBuffer;
PFN_vkAcquireNextImageKHR vkAcquireNextImageKHR;
PFN_vkCmdBindPipeline vkCmdBindPipeline;
PFN_vkCmdBindDescriptorSets vkCmdBindDescriptorSets;
PFN_vkCmdDispatch vkCmdDispatch;
PFN_vkCmdSetViewport vkCmdSetViewport;
PFN_vkCmdSetScissor vkCmdSetScissor;
PFN_vkCmdPushConstants vkCmdPushConstants;
PFN_vkCmdBindIndexBuffer vkCmdBindIndexBuffer;
PFN_vkCmdBindVertexBuffers vkCmdBindVertexBuffers;
PFN_vkCmdDrawIndexed vkCmdDrawIndexed;
PFN_vkCmdCopyBufferToImage vkCmdCopyBufferToImage;
PFN_vkCmdCopyBuffer vkCmdCopyBuffer;
PFN_vkResetFences vkResetFences;
PFN_vkResetCommandBuffer vkResetCommandBuffer;
PFN_vkFreeCommandBuffers vkFreeCommandBuffers;
PFN_vkDestroyDescriptorSetLayout vkDestroyDescriptorSetLayout;
PFN_vkDestroyShaderModule vkDestroyShaderModule;
PFN_vkQueuePresentKHR vkQueuePresentKHR;
PFN_vkCmdDraw vkCmdDraw;
PFN_vkDeviceWaitIdle vkDeviceWaitIdle;
PFN_vkCmdClearColorImage vkCmdClearColorImage;
PFN_vkCreateSampler vkCreateSampler;
PFN_vkDestroySampler vkDestroySampler;
PFN_vkGetBufferDeviceAddress vkGetBufferDeviceAddress;
PFN_vkWaitSemaphores vkWaitSemaphores;
PFN_vkQueueWaitIdle vkQueueWaitIdle;
PFN_vkCmdSetStencilTestEnableEXT vkCmdSetStencilTestEnableEXT;
PFN_vkCmdSetStencilOpEXT vkCmdSetStencilOpEXT;
PFN_vkCmdSetStencilReference vkCmdSetStencilReference;
PFN_vkCmdSetStencilCompareMask vkCmdSetStencilCompareMask;
PFN_vkCmdSetStencilWriteMask vkCmdSetStencilWriteMask;
alias vkQueueSubmit2 = vkQueueSubmit2KHR;
alias vkCmdPipelineBarrier2 = vkCmdPipelineBarrier2KHR;
alias vkCmdSetStencilTestEnable = vkCmdSetStencilTestEnableEXT;
alias vkCmdSetStencilOp = vkCmdSetStencilOpEXT;
static string
LoadDeviceFunc(alias fn)()
{
import std.format : format;
import std.string : chompPrefix;
enum string fn_str = __traits(identifier, fn);
enum string vk_str = __traits(identifier, g_vk);
return format("%s = cast(typeof(%s))vkGetDeviceProcAddr(%s.device, \"%s\"); assert(%s != null, \"Function pointer %s is null\");", fn_str, fn_str, vk_str, fn_str, fn_str, fn_str);
}
static string
LoadInstanceFunc(alias fn)()
{
import std.format : format;
import std.string : chompPrefix;
enum string fn_str = __traits(identifier, fn);
enum string vk_str = __traits(identifier, g_vk);
return format("%s = cast(typeof(%s))vkGetInstanceProcAddr(%s.instance, \"%s\"); assert(%s != null, \"Function pointer %s is null\");", fn_str, fn_str, vk_str, fn_str, fn_str, fn_str);
}
void
LoadDeviceFunctions()
{
mixin(LoadDeviceFunc!(vkCreateSwapchainKHR));
mixin(LoadDeviceFunc!(vkCmdBeginRenderPass));
mixin(LoadDeviceFunc!(vkCmdEndRenderPass));
mixin(LoadDeviceFunc!(vkCreateFramebuffer));
mixin(LoadDeviceFunc!(vkDestroyFramebuffer));
mixin(LoadDeviceFunc!(vkCreateRenderPass));
mixin(LoadDeviceFunc!(vkDestroyRenderPass));
mixin(LoadDeviceFunc!(vkCreateImage));
mixin(LoadDeviceFunc!(vkCreateImageView));
mixin(LoadDeviceFunc!(vkQueueSubmit2));
mixin(LoadDeviceFunc!(vkCreateBufferView));
mixin(LoadDeviceFunc!(vkGetSwapchainImagesKHR));
mixin(LoadDeviceFunc!(vkGetDeviceQueue));
mixin(LoadDeviceFunc!(vkCreateSemaphore));
mixin(LoadDeviceFunc!(vkAllocateCommandBuffers));
mixin(LoadDeviceFunc!(vkCreateCommandPool));
mixin(LoadDeviceFunc!(vkCmdPipelineBarrier));
mixin(LoadDeviceFunc!(vkCmdPipelineBarrier2));
mixin(LoadDeviceFunc!(vkCreateFence));
mixin(LoadDeviceFunc!(vkCreateDescriptorPool));
mixin(LoadDeviceFunc!(vkCreateDescriptorSetLayout));
mixin(LoadDeviceFunc!(vkAllocateDescriptorSets));
mixin(LoadDeviceFunc!(vkCreatePipelineLayout));
mixin(LoadDeviceFunc!(vkResetDescriptorPool));
mixin(LoadDeviceFunc!(vkCreateShaderModule));
mixin(LoadDeviceFunc!(vkCreateGraphicsPipelines));
mixin(LoadDeviceFunc!(vkCreateComputePipelines));
mixin(LoadDeviceFunc!(vkUpdateDescriptorSets));
mixin(LoadDeviceFunc!(vkDestroyDevice));
mixin(LoadDeviceFunc!(vkDestroyDescriptorPool));
mixin(LoadDeviceFunc!(vkDestroySwapchainKHR));
mixin(LoadDeviceFunc!(vkDestroyBufferView));
mixin(LoadDeviceFunc!(vkDestroyImage));
mixin(LoadDeviceFunc!(vkDestroyImageView));
mixin(LoadDeviceFunc!(vkDestroyCommandPool));
mixin(LoadDeviceFunc!(vkDestroySemaphore));
mixin(LoadDeviceFunc!(vkDestroyFence));
mixin(LoadDeviceFunc!(vkDestroyPipelineLayout));
mixin(LoadDeviceFunc!(vkDestroyPipeline));
mixin(LoadDeviceFunc!(vkWaitForFences));
mixin(LoadDeviceFunc!(vkBeginCommandBuffer));
mixin(LoadDeviceFunc!(vkEndCommandBuffer));
mixin(LoadDeviceFunc!(vkAcquireNextImageKHR));
mixin(LoadDeviceFunc!(vkCmdBindPipeline));
mixin(LoadDeviceFunc!(vkCmdBindDescriptorSets));
mixin(LoadDeviceFunc!(vkCmdDispatch));
mixin(LoadDeviceFunc!(vkCmdSetViewport));
mixin(LoadDeviceFunc!(vkCmdSetScissor));
mixin(LoadDeviceFunc!(vkCmdPushConstants));
mixin(LoadDeviceFunc!(vkCmdBindIndexBuffer));
mixin(LoadDeviceFunc!(vkCmdBindVertexBuffers));
mixin(LoadDeviceFunc!(vkCmdDrawIndexed));
mixin(LoadDeviceFunc!(vkCmdBlitImage));
mixin(LoadDeviceFunc!(vkCmdCopyBufferToImage));
mixin(LoadDeviceFunc!(vkCmdCopyBuffer));
mixin(LoadDeviceFunc!(vkResetFences));
mixin(LoadDeviceFunc!(vkResetCommandBuffer));
mixin(LoadDeviceFunc!(vkFreeCommandBuffers));
mixin(LoadDeviceFunc!(vkDestroyDescriptorSetLayout));
mixin(LoadDeviceFunc!(vkDestroyShaderModule));
mixin(LoadDeviceFunc!(vkQueuePresentKHR));
mixin(LoadDeviceFunc!(vkCmdDraw));
mixin(LoadDeviceFunc!(vkDeviceWaitIdle));
mixin(LoadDeviceFunc!(vkCmdClearColorImage));
mixin(LoadDeviceFunc!(vkCreateSampler));
mixin(LoadDeviceFunc!(vkDestroySampler));
mixin(LoadDeviceFunc!(vkGetBufferDeviceAddress));
mixin(LoadDeviceFunc!(vkWaitSemaphores));
mixin(LoadDeviceFunc!(vkQueueWaitIdle));
mixin(LoadDeviceFunc!(vkCmdSetStencilTestEnableEXT));
mixin(LoadDeviceFunc!(vkCmdSetStencilOpEXT));
mixin(LoadDeviceFunc!(vkCmdSetStencilReference));
mixin(LoadDeviceFunc!(vkCmdSetStencilCompareMask));
mixin(LoadDeviceFunc!(vkCmdSetStencilWriteMask));
version(AMD_GPU) version(VULKAN_DEBUG)
{
mixin(LoadDeviceFunc!(vkGetShaderInfoAMD));
}
}
void
LoadInstanceFunctions()
{
mixin(LoadInstanceFunc!(vkEnumeratePhysicalDevices));
mixin(LoadInstanceFunc!(vkDestroySurfaceKHR));
mixin(LoadInstanceFunc!(vkDestroyInstance));
mixin(LoadInstanceFunc!(vkCreateDevice));
mixin(LoadInstanceFunc!(vkGetPhysicalDeviceQueueFamilyProperties));
mixin(LoadInstanceFunc!(vkGetPhysicalDeviceSurfaceSupportKHR));
mixin(LoadInstanceFunc!(vkGetPhysicalDeviceProperties));
mixin(LoadInstanceFunc!(vkGetPhysicalDeviceFeatures2));
mixin(LoadInstanceFunc!(vkEnumerateDeviceExtensionProperties));
mixin(LoadInstanceFunc!(vkGetPhysicalDeviceSurfacePresentModesKHR));
mixin(LoadInstanceFunc!(vkGetPhysicalDeviceSurfaceFormatsKHR));
mixin(LoadInstanceFunc!(vkGetPhysicalDeviceSurfaceCapabilitiesKHR));
mixin(LoadInstanceFunc!(vkGetPhysicalDeviceImageFormatProperties));
mixin(LoadInstanceFunc!(vkGetDeviceProcAddr));
version(linux)
{
mixin(LoadInstanceFunc!(vkCreateXlibSurfaceKHR));
}
version(Windows)
{
mixin(LoadInstanceFunc!(vkCreateWin32SurfaceKHR));
}
version(VULKAN_DEBUG)
{
mixin(LoadInstanceFunc!(vkCreateDebugUtilsMessengerEXT));
mixin(LoadInstanceFunc!(vkDestroyDebugUtilsMessengerEXT));
}
}

Binary file not shown.