aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2025-10-13 18:57:01 +0200
committerAndre Weissflog <floooh@gmail.com>2025-10-13 18:57:01 +0200
commita154d98439d468bbdab1cc53e5c8edb15e72607c (patch)
tree108c26f32f85f3cedd7e4ef22e03d57a04dd78ef
parent9222b395e2701e92bcf728f9d8bf501e31f33a9d (diff)
sokol_gfx.h vk: _sg_vk_init_caps
-rw-r--r--sokol_app.h21
-rw-r--r--sokol_gfx.h98
-rw-r--r--sokol_glue.h2
3 files changed, 109 insertions, 12 deletions
diff --git a/sokol_app.h b/sokol_app.h
index 0f99d46b..8d556ec5 100644
--- a/sokol_app.h
+++ b/sokol_app.h
@@ -1865,7 +1865,9 @@ typedef struct sapp_wgpu_environment {
} sapp_wgpu_environment;
typedef struct sapp_vulkan_environment {
+ const void* physical_device;
const void* device;
+ const void* queue;
} sapp_vulkan_environment;
typedef struct sapp_environment {
@@ -2739,7 +2741,7 @@ typedef struct {
VkPhysicalDevice physical_device;
uint32_t queue_family_index;
VkDevice device;
- VkQueue present_queue;
+ VkQueue queue;
VkSwapchainKHR swapchain;
uint32_t num_swapchain_images;
uint32_t cur_swapchain_image_index;
@@ -4427,19 +4429,17 @@ _SOKOL_PRIVATE void _sapp_vk_create_device(void) {
_SAPP_PANIC(VULKAN_CREATE_DEVICE_FAILED);
}
SOKOL_ASSERT(_sapp.vk.device);
-}
-_SOKOL_PRIVATE void _sapp_vk_get_present_queue(void) {
- SOKOL_ASSERT(_sapp.vk.device);
- SOKOL_ASSERT(0 == _sapp.vk.present_queue);
- vkGetDeviceQueue(_sapp.vk.device, _sapp.vk.queue_family_index, 0, &_sapp.vk.present_queue);
- SOKOL_ASSERT(_sapp.vk.present_queue);
+ SOKOL_ASSERT(0 == _sapp.vk.queue);
+ vkGetDeviceQueue(_sapp.vk.device, _sapp.vk.queue_family_index, 0, &_sapp.vk.queue);
+ SOKOL_ASSERT(_sapp.vk.queue);
}
_SOKOL_PRIVATE void _sapp_vk_destroy_device(void) {
SOKOL_ASSERT(_sapp.vk.device);
vkDestroyDevice(_sapp.vk.device, 0);
_sapp.vk.device = 0;
+ _sapp.vk.queue = 0;
}
_SOKOL_PRIVATE void _sapp_vk_create_surface(void) {
@@ -4608,7 +4608,6 @@ _SOKOL_PRIVATE void _sapp_vk_init(void) {
_sapp_vk_create_surface();
_sapp_vk_pick_physical_device();
_sapp_vk_create_device();
- _sapp_vk_get_present_queue();
_sapp_vk_create_sync_objects();
_sapp_vk_create_swapchain();
}
@@ -4639,7 +4638,7 @@ _SOKOL_PRIVATE void _sapp_vk_swapchain_next(void) {
}
_SOKOL_PRIVATE void _sapp_vk_present(void) {
- SOKOL_ASSERT(_sapp.vk.present_queue);
+ SOKOL_ASSERT(_sapp.vk.queue);
VkPresentInfoKHR present_info;
_sapp_clear(&present_info, sizeof(present_info));
present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
@@ -4648,7 +4647,7 @@ _SOKOL_PRIVATE void _sapp_vk_present(void) {
present_info.swapchainCount = 1;
present_info.pSwapchains = &_sapp.vk.swapchain;
present_info.pImageIndices = &_sapp.vk.cur_swapchain_image_index;
- VkResult res = vkQueuePresentKHR(_sapp.vk.present_queue, &present_info);
+ VkResult res = vkQueuePresentKHR(_sapp.vk.queue, &present_info);
if ((res != VK_SUCCESS) || (res != VK_SUBOPTIMAL_KHR)) {
_SAPP_WARN(VULKAN_QUEUE_PRESENT_FAILED);
}
@@ -13553,7 +13552,9 @@ SOKOL_API_IMPL sapp_environment sapp_get_environment(void) {
res.wgpu.device = (const void*) _sapp.wgpu.device;
#endif
#if defined(SOKOL_VULKAN)
+ res.vulkan.physical_device = (const void*) _sapp.vk.physical_device;
res.vulkan.device = (const void*) _sapp.vk.device;
+ res.vulkan.queue = (const void*) _sapp.vk.queue;
#endif
return res;
}
diff --git a/sokol_gfx.h b/sokol_gfx.h
index 573a6d95..b22de072 100644
--- a/sokol_gfx.h
+++ b/sokol_gfx.h
@@ -4821,7 +4821,9 @@ typedef struct sg_wgpu_environment {
} sg_wgpu_environment;
typedef struct sg_vulkan_environment {
+ const void* physical_device;
const void* device;
+ const void* queue;
} sg_vulkan_environment;
typedef struct sg_environment {
@@ -6767,7 +6769,9 @@ typedef _sg_vk_view_t _sg_view_t;
typedef struct {
bool valid;
+ VkPhysicalDevice phys_dev;
VkDevice dev;
+ VkQueue queue;
} _sg_vk_backend_t;
#endif // SOKOL_VULKAN
@@ -17222,7 +17226,6 @@ _SOKOL_PRIVATE void _sg_wgpu_setup_backend(const sg_desc* desc) {
SOKOL_ASSERT(desc);
SOKOL_ASSERT(desc->environment.wgpu.device);
SOKOL_ASSERT(desc->uniform_buffer_size > 0);
- _sg.backend = SG_BACKEND_WGPU;
_sg.wgpu.valid = true;
_sg.wgpu.dev = (WGPUDevice) desc->environment.wgpu.device;
_sg.wgpu.queue = wgpuDeviceGetQueue(_sg.wgpu.dev);
@@ -18216,13 +18219,104 @@ _SOKOL_PRIVATE void _sg_wgpu_update_image(_sg_image_t* img, const sg_image_data*
// >>vk
#elif defined(SOKOL_VULKAN)
+_SOKOL_PRIVATE void _sg_vk_init_caps(void) {
+ _sg.backend = SG_BACKEND_VULKAN;
+ _sg.features.origin_top_left = true;
+ _sg.features.image_clamp_to_border = false; // FIXME?
+ _sg.features.mrt_independent_blend_state = true;
+ _sg.features.mrt_independent_write_mask = true;
+ _sg.features.compute = true;
+ _sg.features.msaa_texture_bindings = true;
+ _sg.features.draw_base_vertex = true;
+ _sg.features.draw_base_instance = true;
+
+ SOKOL_ASSERT(_sg.vk.phys_dev);
+ VkPhysicalDeviceProperties props;
+ _sg_clear(&props, sizeof(props));
+ vkGetPhysicalDeviceProperties(_sg.vk.phys_dev, &props);
+ _sg.limits.max_image_size_2d = (int)props.limits.maxImageDimension2D;
+ _sg.limits.max_image_size_cube = (int)props.limits.maxImageDimensionCube;
+ _sg.limits.max_image_size_3d = (int)props.limits.maxImageDimension3D;
+ _sg.limits.max_image_size_array = _sg.limits.max_image_size_2d;
+ _sg.limits.max_image_array_layers = (int)props.limits.maxImageArrayLayers;
+ _sg.limits.max_vertex_attrs = _sg_min((int)props.limits.maxVertexInputAttributes, SG_MAX_VERTEX_ATTRIBUTES);
+ _sg.limits.max_color_attachments = _sg_min((int)props.limits.maxFragmentOutputAttachments, SG_MAX_COLOR_ATTACHMENTS);
+ _sg.limits.max_texture_bindings_per_stage = _sg_min((int)props.limits.maxPerStageDescriptorSampledImages, SG_MAX_VIEW_BINDSLOTS);
+ _sg.limits.max_storage_buffer_bindings_per_stage = _sg_min((int)props.limits.maxPerStageDescriptorStorageBuffers, SG_MAX_VIEW_BINDSLOTS);
+ _sg.limits.max_storage_image_bindings_per_stage = _sg_min((int)props.limits.maxPerStageDescriptorStorageImages, SG_MAX_VIEW_BINDSLOTS);
+
+ // FIXME: currently these are the same as in the WebGPU backend
+ // FIXME: compressed formats
+ _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_R8]);
+ _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG8]);
+ _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA8]);
+ _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_SRGB8A8]);
+ _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_BGRA8]);
+ _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_R16F]);
+ _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RG16F]);
+ _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGBA16F]);
+ _sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_RGB10A2]);
+
+ _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_R8SN]);
+ _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RG8SN]);
+ _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RGBA8SN]);
+
+ _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RG11B10F]);
+
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R8UI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R8SI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RG8UI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RG8SI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RGBA8UI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RGBA8SI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R16UI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R16SI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RG16UI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RG16SI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RGBA16UI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RGBA16SI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R32UI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_R32SI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RG32UI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RG32SI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RGBA32UI]);
+ _sg_pixelformat_sr(&_sg.formats[SG_PIXELFORMAT_RGBA32SI]);
+
+ _sg_pixelformat_srmd(&_sg.formats[SG_PIXELFORMAT_DEPTH]);
+ _sg_pixelformat_srmd(&_sg.formats[SG_PIXELFORMAT_DEPTH_STENCIL]);
+
+ _sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_RGB9E5]);
+
+ _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8]);
+ _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8SN]);
+ _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8UI]);
+ _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA8SI]);
+ _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16UI]);
+ _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16SI]);
+ _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA16F]);
+ _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R32UI]);
+ _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R32SI]);
+ _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_R32F]);
+ _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG32UI]);
+ _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG32SI]);
+ _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RG32F]);
+ _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA32UI]);
+ _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA32SI]);
+ _sg_pixelformat_compute_all(&_sg.formats[SG_PIXELFORMAT_RGBA32F]);
+}
+
_SOKOL_PRIVATE void _sg_vk_setup_backend(const sg_desc* desc) {
SOKOL_ASSERT(desc);
+ SOKOL_ASSERT(desc->environment.vulkan.physical_device);
SOKOL_ASSERT(desc->environment.vulkan.device);
+ SOKOL_ASSERT(desc->environment.vulkan.queue);
SOKOL_ASSERT(desc->uniform_buffer_size > 0);
- _sg.backend = SG_BACKEND_VULKAN;
_sg.vk.valid = true;
+ _sg.vk.phys_dev = (VkPhysicalDevice) desc->environment.vulkan.physical_device;
_sg.vk.dev = (VkDevice) desc->environment.vulkan.device;
+ _sg.vk.queue = (VkQueue) desc->environment.vulkan.queue;
+
+ _sg_vk_init_caps();
}
_SOKOL_PRIVATE void _sg_vk_discard_backend(void) {
diff --git a/sokol_glue.h b/sokol_glue.h
index 2645d618..0f17a5c5 100644
--- a/sokol_glue.h
+++ b/sokol_glue.h
@@ -165,7 +165,9 @@ SOKOL_API_IMPL sg_environment sglue_environment(void) {
res.d3d11.device = env.d3d11.device;
res.d3d11.device_context = env.d3d11.device_context;
res.wgpu.device = env.wgpu.device;
+ res.vulkan.physical_device = env.vulkan.physical_device;
res.vulkan.device = env.vulkan.device;
+ res.vulkan.queue = env.vulkan.queue;
return res;
}