From 141175b0806001be673c1657b04de377cce1ae0a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Thu, 28 Feb 2019 09:23:04 +0100 Subject: [PATCH] deffered resolve funcs, comments, some warnings resolves --- CMakeLists.txt | 8 +- CMakeLists.txt.user.4.8-pre1 | 667 +++++++++++++++++++++++++++++++++++ include/vkvg.h | 6 +- shaders/wired.frag | 12 +- src/shaders.h | 168 +++++---- src/vectors.c | 42 ++- src/vectors.h | 4 +- src/vkvg_context.c | 154 ++++---- src/vkvg_context_internal.c | 28 +- src/vkvg_context_internal.h | 6 +- src/vkvg_device.c | 35 +- src/vkvg_device_internal.c | 55 ++- src/vkvg_device_internal.h | 66 ++-- src/vkvg_fonts.c | 29 +- src/vkvg_fonts.h | 92 ++--- src/vkvg_internal.h | 9 + src/vkvg_surface.c | 41 +++ tests/test1.c | 78 +++- tests/vkengine.c | 17 +- vkh | 2 +- 20 files changed, 1229 insertions(+), 290 deletions(-) create mode 100644 CMakeLists.txt.user.4.8-pre1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 832f977..4e5e45c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,8 +13,10 @@ ENDIF() if (CMAKE_BUILD_TYPE STREQUAL "Debug") ADD_DEFINITIONS (-DDEBUG) OPTION(ENABLE_VALIDATION "enable vulkan validation layer" ON) + OPTION(ENABLE_WIRED_FILL "enable wired polygon draw to check vertices and primitives" OFF) ELSE() - OPTION(ENABLE_VALIDATION "enable vulkan validation layer" OFF) + UNSET(ENABLE_VALIDATION CACHE) + UNSET(ENABLE_WIRED_FILL CACHE) ENDIF() OPTION(VKVG_TILING_OPTIMAL "use VK_IMAGE_TILING_OPTIMAL for surface backend texture" OFF) @@ -40,7 +42,9 @@ endif() IF (ENABLE_VALIDATION) ADD_DEFINITIONS (-DVKVG_USE_VALIDATION) ENDIF () - +IF (ENABLE_WIRED_FILL) + ADD_DEFINITIONS (-DVKVG_WIRED_DEBUG) +ENDIF () #be aware that system libraries have priority on SDK in the finding. FIND_PACKAGE(Vulkan REQUIRED) diff --git a/CMakeLists.txt.user.4.8-pre1 b/CMakeLists.txt.user.4.8-pre1 new file mode 100644 index 0000000..f37959b --- /dev/null +++ b/CMakeLists.txt.user.4.8-pre1 @@ -0,0 +1,667 @@ + + + + + + EnvironmentId + {961cb273-e1a2-4675-b40c-c0bceac9bf63} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 1 + true + true + 0 + 8 + true + 1 + true + true + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + + + + ProjectExplorer.Project.Target.0 + + Imported Kit + Imported Kit + {f19ccac4-98ac-4fd0-a51d-b683584e99fb} + 0 + 0 + 4 + + + CMAKE_BUILD_TYPE:STRING=Release + CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++ + CMAKE_C_COMPILER:FILEPATH=/usr/bin/cc + CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} + ENABLE_VALIDATION:BOOL=OFF + QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} + VKVG_TILING_OPTIMAL:BOOL=OFF + + /mnt/devel/gts/vkvg/build + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + 0 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Compilation + Compilation + CMakeProjectManager.CMakeBuildConfiguration + + 1 + + + 0 + Déploiement + + ProjectExplorer.BuildSteps.Deploy + + 1 + Configuration de déploiement + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + + + 2 + + vkvg_test + + CMakeProjectManager.CMakeRunConfiguration.vkvg_test + 3768 + false + true + false + false + true + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + + + 2 + + vkvg_test1 + + CMakeProjectManager.CMakeRunConfiguration.vkvg_test1 + 3768 + false + true + false + false + true + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + + + 2 + + vkvg_test_curves + + CMakeProjectManager.CMakeRunConfiguration.vkvg_test_curves + 3768 + false + true + false + false + true + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + + + 2 + + vkvg_perf_test_0 + + CMakeProjectManager.CMakeRunConfiguration.vkvg_perf_test_0 + 3768 + false + true + false + false + true + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + + /mnt/devel/gts/vkvg/build + 2 + + vkvg_test + vkvg_test2 + CMakeProjectManager.CMakeRunConfiguration.vkvg_test +/mnt/devel/gts/vkvg/ + 3768 + false + true + false + false + true + + 5 + + + + ProjectExplorer.Project.Target.1 + + Desktop + Desktop + {81275d56-2237-4c29-a364-8221c7c7c53e} + 0 + 0 + 0 + + + /mnt/devel/gts/build-vkvg-Desktop-Du00e9faut + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + 0 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Défaut + Défaut + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Debug + + /mnt/devel/gts/build-vkvg-Desktop-Debug + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + 0 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Release + + /mnt/devel/gts/build-vkvg-Desktop-Release + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + 0 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=RelWithDebInfo + + /mnt/devel/gts/build-vkvg-Desktop-Release with Debug Information + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + 0 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release with Debug Information + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=MinSizeRel + + /mnt/devel/gts/build-vkvg-Desktop-Minimum Size Release + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + 0 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Minimum Size Release + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 5 + + + 0 + Déploiement + + ProjectExplorer.BuildSteps.Deploy + + 1 + Configuration de déploiement + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + + + 2 + + vkvg_test + + CMakeProjectManager.CMakeRunConfiguration.vkvg_test + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 2 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/include/vkvg.h b/include/vkvg.h index 550b90c..108461e 100644 --- a/include/vkvg.h +++ b/include/vkvg.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Jean-Philippe Bruyère + * Copyright (c) 2018-2019 Jean-Philippe Bruyère * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -28,6 +28,7 @@ extern "C" { #include #include +#include #ifdef VKVG_TILING_OPTIMAL #define VKVG_TILING VK_IMAGE_TILING_OPTIMAL @@ -160,7 +161,7 @@ typedef struct _vkvg_device_t* VkvgDevice; typedef struct _vkvg_pattern_t* VkvgPattern; VkvgDevice vkvg_device_create (VkInstance inst, VkPhysicalDevice phy, VkDevice vkdev, uint32_t qFamIdx, uint32_t qIndex); -VkvgDevice vkvg_device_create_multisample (VkInstance inst, VkPhysicalDevice phy, VkDevice vkdev, uint32_t qFamIdx, uint32_t qIndex, VkSampleCountFlags samples); +VkvgDevice vkvg_device_create_multisample (VkInstance inst, VkPhysicalDevice phy, VkDevice vkdev, uint32_t qFamIdx, uint32_t qIndex, VkSampleCountFlags samples, bool deferredResolve); void vkvg_device_destroy (VkvgDevice dev); VkvgDevice vkvg_device_reference (VkvgDevice dev); uint32_t vkvg_device_get_reference_count (VkvgDevice dev); @@ -180,6 +181,7 @@ uint32_t vkvg_surface_get_width (VkvgSurface surf); uint32_t vkvg_surface_get_height (VkvgSurface surf); VkImage vkvg_surface_get_vkh_image (VkvgSurface surf); void vkvg_surface_write_to_png (VkvgSurface surf, const char* path); +void vkvg_multisample_surface_resolve (VkvgSurface surf); //mimic from cairo, to facilitate usage of vkvg as cairo vulkan backend typedef enum _vkvg_operator { diff --git a/shaders/wired.frag b/shaders/wired.frag index 5bd59cc..f5cd701 100644 --- a/shaders/wired.frag +++ b/shaders/wired.frag @@ -5,9 +5,15 @@ layout (set=0, binding = 0) uniform sampler2DArray fontMap; layout (set=1, binding = 0) uniform sampler2D source; +layout (set=2, binding = 0) uniform _uboGrad { + vec4 cp[3]; + vec4 colors[16]; + vec4 stops[16]; + uint count; +}uboGrad; -layout (location = 0) in vec3 inFontUV; //if it is a text drawing, inFontUV.z hold fontMap layer -layout (location = 1) in vec4 inColor; //source rgba +layout (location = 0) in vec3 inFontUV; //if it is a text drawing, inFontUV.z hold fontMap layer +layout (location = 1) in vec4 inSrc; //source bounds or color layout (location = 2) in flat int inPatType; layout (location = 3) in mat3x2 inMat; @@ -17,5 +23,5 @@ layout (constant_id = 0) const int NUM_SAMPLES = 8; void main() { - outFragColor = inColor; + outFragColor = vec4(1,1,1,1);//inSrc; } diff --git a/src/shaders.h b/src/shaders.h index 43948ae..909c604 100644 --- a/src/shaders.h +++ b/src/shaders.h @@ -1234,14 +1234,14 @@ unsigned char vkvg_main_vert_spv[] = { unsigned int vkvg_main_vert_spv_len = 2680; unsigned char wired_frag_spv[] = { 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x0d, 0x00, - 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, + 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0a, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0xc2, 0x01, 0x00, 0x00, 0x04, 0x00, 0x09, 0x00, 0x47, 0x4c, 0x5f, 0x41, 0x52, 0x42, 0x5f, 0x73, 0x65, 0x70, 0x61, 0x72, @@ -1259,73 +1259,111 @@ unsigned char wired_frag_spv[] = { 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x09, 0x00, 0x00, 0x00, 0x6f, 0x75, 0x74, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x43, 0x6f, - 0x6c, 0x6f, 0x72, 0x00, 0x05, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x6e, 0x74, 0x4d, 0x61, 0x70, 0x00, 0x05, 0x00, 0x04, 0x00, - 0x14, 0x00, 0x00, 0x00, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x00, 0x00, - 0x05, 0x00, 0x05, 0x00, 0x17, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x46, 0x6f, - 0x6e, 0x74, 0x55, 0x56, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, - 0x1a, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x50, 0x61, 0x74, 0x54, 0x79, 0x70, - 0x65, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x1e, 0x00, 0x00, 0x00, - 0x69, 0x6e, 0x4d, 0x61, 0x74, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, - 0x1f, 0x00, 0x00, 0x00, 0x4e, 0x55, 0x4d, 0x5f, 0x53, 0x41, 0x4d, 0x50, - 0x4c, 0x45, 0x53, 0x00, 0x47, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, - 0x0b, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x47, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x04, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x66, 0x6f, 0x6e, 0x74, + 0x4d, 0x61, 0x70, 0x00, 0x05, 0x00, 0x04, 0x00, 0x13, 0x00, 0x00, 0x00, + 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, + 0x1a, 0x00, 0x00, 0x00, 0x5f, 0x75, 0x62, 0x6f, 0x47, 0x72, 0x61, 0x64, + 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x04, 0x00, 0x1a, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x63, 0x70, 0x00, 0x00, 0x06, 0x00, 0x05, 0x00, + 0x1a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6c, 0x6f, + 0x72, 0x73, 0x00, 0x00, 0x06, 0x00, 0x05, 0x00, 0x1a, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x73, 0x74, 0x6f, 0x70, 0x73, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x05, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x75, 0x62, 0x6f, 0x47, 0x72, 0x61, 0x64, 0x00, + 0x05, 0x00, 0x05, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x46, 0x6f, + 0x6e, 0x74, 0x55, 0x56, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, + 0x21, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x53, 0x72, 0x63, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x05, 0x00, 0x24, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x50, 0x61, + 0x74, 0x54, 0x79, 0x70, 0x65, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, + 0x28, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x4d, 0x61, 0x74, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x05, 0x00, 0x29, 0x00, 0x00, 0x00, 0x4e, 0x55, 0x4d, 0x5f, + 0x53, 0x41, 0x4d, 0x50, 0x4c, 0x45, 0x53, 0x00, 0x47, 0x00, 0x04, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x47, 0x00, 0x04, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, - 0x14, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x47, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x17, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, - 0x1a, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, - 0x1a, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x47, 0x00, 0x04, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x1f, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, - 0x3b, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x0a, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, - 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x19, 0x00, 0x09, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x13, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x47, 0x00, 0x04, 0x00, 0x13, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x16, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x47, 0x00, 0x04, 0x00, 0x19, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x1a, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x48, 0x00, 0x05, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x23, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, + 0x1a, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, + 0x30, 0x01, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x1a, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x30, 0x02, 0x00, 0x00, + 0x47, 0x00, 0x03, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x47, 0x00, 0x04, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, + 0x1f, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x47, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, + 0x28, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x47, 0x00, 0x04, 0x00, 0x29, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x17, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x3f, 0x2c, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x19, 0x00, 0x09, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x1b, 0x00, 0x03, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x04, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x0e, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x0f, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x00, 0x09, 0x00, - 0x11, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x03, 0x00, - 0x12, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, - 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, - 0x3b, 0x00, 0x04, 0x00, 0x13, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x15, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, - 0x16, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, - 0x3b, 0x00, 0x04, 0x00, 0x16, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x0d, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, + 0x3b, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x19, 0x00, 0x09, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x03, 0x00, 0x11, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x12, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, + 0x12, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x15, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x15, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, + 0x2b, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, 0x00, + 0x19, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, + 0x1e, 0x00, 0x06, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x04, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x1a, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x1b, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, + 0x1d, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x04, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x1d, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x1e, 0x00, 0x00, 0x00, + 0x1f, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x3b, 0x00, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, - 0x19, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, - 0x3b, 0x00, 0x04, 0x00, 0x19, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x1b, 0x00, 0x00, 0x00, + 0x23, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, + 0x3b, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x18, 0x00, 0x04, 0x00, - 0x1c, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x04, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x1d, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x32, 0x00, 0x04, 0x00, - 0x18, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x26, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x26, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x32, 0x00, 0x04, 0x00, + 0x22, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, - 0x05, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, - 0x38, 0x00, 0x01, 0x00 + 0x05, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x09, 0x00, 0x00, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00 }; -unsigned int wired_frag_spv_len = 1120; +unsigned int wired_frag_spv_len = 1584; diff --git a/src/vectors.c b/src/vectors.c index 236ce45..5f7374c 100644 --- a/src/vectors.c +++ b/src/vectors.c @@ -22,12 +22,21 @@ #include "vectors.h" -#define ROUNDF(f, c) (((float)((int)((f) * (c))) / (c))) - +// init float vector inline vec2 vec2_create (float x, float y) { vec2 v = {x,y}; return v; } +// compute normal direction vector from line defined by 2 points in double precision +vec2d vec2d_line_norm(vec2d a, vec2d b) +{ + vec2d d = {b.x - a.x, b.y - a.y}; + double md = sqrt (d.x*d.x + d.y*d.y); + d.x/=md; + d.y/=md; + return d; +} +// compute normal direction vector from line defined by 2 points vec2 vec2_line_norm(vec2 a, vec2 b) { vec2 d = {b.x - a.x, b.y - a.y}; @@ -36,74 +45,81 @@ vec2 vec2_line_norm(vec2 a, vec2 b) d.y/=md; return d; } +// compute length of double vector 2d double vec2d_length(vec2d v){ return sqrt (v.x*v.x + v.y*v.y); } +// compute length of float vector 2d float vec2_length(vec2 v){ return sqrt (v.x*v.x + v.y*v.y); } +// normalize float vector vec2 vec2_norm(vec2 a) { float m = sqrt (a.x*a.x + a.y*a.y); vec2 d = {a.x/m, a.y/m}; return d; } +// normalize double vector vec2d vec2d_norm(vec2d a) { double m = sqrt (a.x*a.x + a.y*a.y); vec2d d = {a.x/m, a.y/m}; return d; } +// multiply 2d vector by scalar vec2d vec2d_mult(vec2d a, double m){ vec2d r = {a.x*m,a.y*m}; return r; } +// multiply 2d vector by scalar vec2 vec2_mult(vec2 a, float m){ vec2 r = {a.x*m,a.y*m}; return r; } - -vec2d vec2d_line_norm(vec2d a, vec2d b) -{ - vec2d d = {b.x - a.x, b.y - a.y}; - double md = sqrt (d.x*d.x + d.y*d.y); - d.x/=md; - d.y/=md; - return d; -} +// compute perpendicular vector vec2d vec2d_perp (vec2d a){ vec2d vp = {a.y, -a.x}; return vp; } +// compute perpendicular vector vec2 vec2_perp (vec2 a){ vec2 vp = {a.y, -a.x}; return vp; } +// convert double precision vector to single precision vec2 vec2d_to_vec2(vec2d vd){ vec2 v = {vd.x,vd.y}; return v; } +// compute sum of two single precision vectors vec2 vec2_add (vec2 a, vec2 b){ vec2 r = {a.x + b.x, a.y + b.y}; return r; } +// compute sum of two double precision vectors vec2d vec2d_add (vec2d a, vec2d b){ vec2d r = {a.x + b.x, a.y + b.y}; return r; } +// compute subbstraction of two single precision vectors vec2 vec2_sub (vec2 a, vec2 b){ vec2 r = {a.x - b.x, a.y - b.y}; return r; } +// compute subbstraction of two double precision vectors vec2d vec2d_sub (vec2d a, vec2d b){ vec2d r = {a.x - b.x, a.y - b.y}; return r; } +// test equality of two single precision vectors bool vec2_equ (vec2 a, vec2 b){ - if ((ROUNDF(a.x,10000) == ROUNDF(b.x,10000)) && (ROUNDF(a.y,10000) == ROUNDF(b.y,10000))) + /*if ((ROUNDF(a.x,10000) == ROUNDF(b.x,10000)) && (ROUNDF(a.y,10000) == ROUNDF(b.y,10000))) return true; - return false; + return false;*/ + return (EQUF(a.x,b.x)&EQUF(a.y,b.y)); } +// compute opposite of single precision vector void vec2_inv (vec2* v){ v->x = -v->x; v->y = -v->y; diff --git a/src/vectors.h b/src/vectors.h index db569aa..dbd37bb 100644 --- a/src/vectors.h +++ b/src/vectors.h @@ -22,9 +22,7 @@ #ifndef VKVG_VECTORS_H #define VKVG_VECTORS_H -#include -#include -#include +#include "vkvg_internal.h" typedef struct { float x; diff --git a/src/vkvg_context.c b/src/vkvg_context.c index 8020651..755d9ba 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -31,6 +31,11 @@ static vec2 debugLinePoints[1000]; static uint32_t dlpCount = 0; #endif +/** + * @brief create new context for surface + * @param drawing operation output surface + * @return newly created context pointer + */ VkvgContext vkvg_create(VkvgSurface surf) { LOG(LOG_INFO, "CREATE Context: surf = %lu\n", (ulong)surf); @@ -38,8 +43,10 @@ VkvgContext vkvg_create(VkvgSurface surf) VkvgDevice dev = surf->dev; VkvgContext ctx = (vkvg_context*)calloc(1, sizeof(vkvg_context)); - if (ctx==NULL) + if (ctx==NULL) { + dev->status = VKVG_STATUS_NO_MEMORY; return NULL; + } ctx->sizePoints = VKVG_PTS_SIZE; ctx->sizeVertices = VKVG_VBO_SIZE; @@ -95,8 +102,11 @@ VkvgContext vkvg_create(VkvgSurface surf) ctx->status = VKVG_STATUS_SUCCESS; return ctx; } +/** + * @brief explicitly flush pending drawing operations on context + * @param context pointer to flush + */ void vkvg_flush (VkvgContext ctx){ - ctx->status = VKVG_STATUS_SUCCESS; _flush_cmd_buff(ctx); _init_cmd_buff(ctx); /* @@ -123,6 +133,10 @@ void vkvg_flush (VkvgContext ctx){ */ } +/** + * @brief decrement reference count on context and release ressources if reference equal 0. + * @param context to destroy + */ void vkvg_destroy (VkvgContext ctx) { ctx->references--; @@ -165,6 +179,7 @@ void vkvg_destroy (VkvgContext ctx) vkvg_pattern_destroy (cur->pattern); } + //remove context from double linked list of context in device if (ctx->pSurf->dev->lastCtx == ctx){ ctx->pSurf->dev->lastCtx = ctx->pPrev; if (ctx->pPrev != NULL) @@ -179,28 +194,46 @@ void vkvg_destroy (VkvgContext ctx) free(ctx); } +/** + * @brief increment reference count on context + * @param context pointer + * @return + */ VkvgContext vkvg_reference (VkvgContext ctx) { ctx->references++; return ctx; } +/** + * @brief get current reference count for context + * @param context pointer + * @return + */ uint32_t vkvg_get_reference_count (VkvgContext ctx) { return ctx->references; } - +/** + * @brief Start new sub path, no current point is defined + * @param context pointer + */ void vkvg_new_sub_path (VkvgContext ctx){ - ctx->status = VKVG_STATUS_SUCCESS; _finish_path(ctx); } +/** + * @brief clear current context path without drawing anything + * @param context pointer + */ void vkvg_new_path (VkvgContext ctx){ - ctx->status = VKVG_STATUS_SUCCESS; _clear_path(ctx); } //path closing is done by setting the endpoint of the path to the same index //as the start point. //I'll test if closing by adding a new point with the same x,y as the start point //would not make more sense. +/** + * @brief Close current path if at least 3 points are present + * @param context pointer + */ void vkvg_close_path (VkvgContext ctx){ - ctx->status = VKVG_STATUS_SUCCESS; if (_current_path_is_empty(ctx)){ ctx->status = VKVG_STATUS_NO_CURRENT_POINT; return; @@ -217,8 +250,13 @@ void vkvg_close_path (VkvgContext ctx){ }else _finish_path(ctx); } +/** + * @brief draw line with second point coordinates relative to current point + * @param context pointer + * @param delta x + * @param delta y + */ void vkvg_rel_line_to (VkvgContext ctx, float x, float y){ - ctx->status = VKVG_STATUS_SUCCESS; if (_current_path_is_empty(ctx)){ ctx->status = VKVG_STATUS_NO_CURRENT_POINT; return; @@ -226,9 +264,14 @@ void vkvg_rel_line_to (VkvgContext ctx, float x, float y){ vec2 cp = _get_current_position(ctx); vkvg_line_to(ctx, cp.x + x, cp.y + y); } +/** + * @brief Draw line from current point, if no current point is defined, only a move to will be executed. + * @param context pointer + * @param absolute x coordinate of second point + * @param aboslute y coordinate of second point + */ void vkvg_line_to (VkvgContext ctx, float x, float y) { - ctx->status = VKVG_STATUS_SUCCESS; vec2 p = {x,y}; if (_current_path_is_empty(ctx)){ vkvg_move_to(ctx, x,y); @@ -238,15 +281,25 @@ void vkvg_line_to (VkvgContext ctx, float x, float y) _add_point(ctx,x,y); } - +/** + * @brief Draw arc + * @param context pointer + * @param center x coordinate + * @param center y coordinate + * @param radius + * @param start angle of arc + * @param end angle of arc + */ void vkvg_arc (VkvgContext ctx, float xc, float yc, float radius, float a1, float a2){ - ctx->status = VKVG_STATUS_SUCCESS; - while (a2 < a1) - a2 += 2*M_PI; + while (a2 < a1)//positive arc must have a1 2.f * M_PIF) //limit arc to 2PI + a2 = a1 + 2.f * M_PIF; - vec2 v = {cos(a1)*radius + xc, sin(a1)*radius + yc}; + vec2 v = {cosf(a1)*radius + xc, sinf(a1)*radius + yc}; - float step = M_PI/radius; + float step = M_PIF/radius*1.5f; float a = a1; if (_current_path_is_empty(ctx)) @@ -256,31 +309,33 @@ void vkvg_arc (VkvgContext ctx, float xc, float yc, float radius, float a1, floa a+=step; - if (a2 == a1) + if (EQUF(a2, a1)) return; while(a < a2){ - v.x = cos(a)*radius + xc; - v.y = sin(a)*radius + yc; + v.x = cosf(a)*radius + xc; + v.y = sinf(a)*radius + yc; _add_point (ctx, v.x, v.y); a+=step; } - + if (EQUF(a2-a1,M_PIF*2.f))//if arc is complete circle, last point is the same as the first one + return; a = a2; vec2 lastP = v; - v.x = cos(a)*radius + xc; - v.y = sin(a)*radius + yc; + v.x = cosf(a)*radius + xc; + v.y = sinf(a)*radius + yc; //if (!vec2_equ (v,lastP))//this test should not be required _add_point (ctx, v.x, v.y); } void vkvg_arc_negative (VkvgContext ctx, float xc, float yc, float radius, float a1, float a2) { - ctx->status = VKVG_STATUS_SUCCESS; while (a2 > a1) - a2 -= 2*M_PI; + a2 -= 2.f*M_PIF; + if (a1 - a2 > a1 + 2.f * M_PIF) //limit arc to 2PI + a2 = a1 - 2.f * M_PIF; - vec2 v = {cos(a1)*radius + xc, sin(a1)*radius + yc}; + vec2 v = {cosf(a1)*radius + xc, sinf(a1)*radius + yc}; - float step = M_PI/radius; + float step = M_PIF/radius*1.5f; float a = a1; if (_current_path_is_empty(ctx)) @@ -291,26 +346,28 @@ void vkvg_arc_negative (VkvgContext ctx, float xc, float yc, float radius, float a-=step; - if (a2 == a1)//double check if this test should not be in the previous if + if (EQUF(a2, a1)) return; while(a > a2){ - v.x = cos(a)*radius + xc; - v.y = sin(a)*radius + yc; + v.x = cosf(a)*radius + xc; + v.y = sinf(a)*radius + yc; _add_point (ctx,v.x,v.y); a-=step; } + if (EQUF(a1-a2,M_PIF*2.f))//if arc is complete circle, last point is the same as the first one + return; + a = a2; vec2 lastP = v; - v.x = cos(a)*radius + xc; - v.y = sin(a)*radius + yc; + v.x = cosf(a)*radius + xc; + v.y = sinf(a)*radius + yc; //if (!vec2_equ (v,lastP)) _add_point (ctx, v.x, v.y); } void vkvg_rel_move_to (VkvgContext ctx, float x, float y) { - ctx->status = VKVG_STATUS_SUCCESS; if (_current_path_is_empty(ctx)){ ctx->status = VKVG_STATUS_NO_CURRENT_POINT; return; @@ -320,12 +377,10 @@ void vkvg_rel_move_to (VkvgContext ctx, float x, float y) } void vkvg_move_to (VkvgContext ctx, float x, float y) { - ctx->status = VKVG_STATUS_SUCCESS; _finish_path(ctx); _start_sub_path(ctx, x, y); } void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3) { - ctx->status = VKVG_STATUS_SUCCESS; if (_current_path_is_empty(ctx)) vkvg_move_to(ctx, x1, y1); @@ -337,7 +392,6 @@ void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, flo _add_point(ctx,x3,y3); } void vkvg_rel_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3) { - ctx->status = VKVG_STATUS_SUCCESS; if (_current_path_is_empty(ctx)){ ctx->status = VKVG_STATUS_NO_CURRENT_POINT; return; @@ -347,7 +401,6 @@ void vkvg_rel_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, } void vkvg_rectangle (VkvgContext ctx, float x, float y, float w, float h){ - ctx->status = VKVG_STATUS_SUCCESS; _finish_path (ctx); _start_sub_path(ctx, x, y); @@ -357,16 +410,14 @@ void vkvg_rectangle (VkvgContext ctx, float x, float y, float w, float h){ vkvg_close_path (ctx); } -const VkClearAttachment clearStencil = {VK_IMAGE_ASPECT_STENCIL_BIT, 1, {0}}; -const VkClearAttachment clearColorAttach = {VK_IMAGE_ASPECT_COLOR_BIT, 0, {0}}; +static const VkClearAttachment clearStencil = {VK_IMAGE_ASPECT_STENCIL_BIT, 1, {0}}; +static const VkClearAttachment clearColorAttach = {VK_IMAGE_ASPECT_COLOR_BIT, 0, {0}}; void vkvg_reset_clip (VkvgContext ctx){ - ctx->status = VKVG_STATUS_SUCCESS; _check_cmd_buff_state (ctx); vkCmdClearAttachments(ctx->cmd, 1, &clearStencil, 1, &ctx->clearRect); } void vkvg_clear (VkvgContext ctx){ - ctx->status = VKVG_STATUS_SUCCESS; _check_cmd_buff_state (ctx); VkClearAttachment ca[2] = {clearColorAttach, clearStencil}; vkCmdClearAttachments(ctx->cmd, 2, ca, 1, &ctx->clearRect); @@ -414,7 +465,6 @@ void _poly_fill (VkvgContext ctx){ } } void vkvg_clip_preserve (VkvgContext ctx){ - ctx->status = VKVG_STATUS_SUCCESS; if (ctx->pathPtr == 0) //nothing to fill return; _finish_path(ctx); @@ -433,7 +483,6 @@ void vkvg_clip_preserve (VkvgContext ctx){ CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT); } void vkvg_fill_preserve (VkvgContext ctx){ - ctx->status = VKVG_STATUS_SUCCESS; if (ctx->pathPtr == 0) //nothing to fill return; _finish_path(ctx); @@ -453,7 +502,6 @@ void vkvg_fill_preserve (VkvgContext ctx){ } void vkvg_stroke_preserve (VkvgContext ctx) { - ctx->status = VKVG_STATUS_SUCCESS; if (ctx->pathPtr == 0)//nothing to stroke return; _finish_path(ctx); @@ -584,45 +632,36 @@ void vkvg_stroke_preserve (VkvgContext ctx) _record_draw_cmd(ctx); } void vkvg_paint (VkvgContext ctx){ - ctx->status = VKVG_STATUS_SUCCESS; _check_cmd_buff_state(ctx); CmdDrawIndexed (ctx->cmd,6,1,0,0,0); } inline void vkvg_set_source_rgb (VkvgContext ctx, float r, float g, float b) { - ctx->status = VKVG_STATUS_SUCCESS; vkvg_set_source_rgba (ctx, r, g, b, 1); } void vkvg_set_source_rgba (VkvgContext ctx, float r, float g, float b, float a) { - ctx->status = VKVG_STATUS_SUCCESS; _update_cur_pattern (ctx, vkvg_pattern_create_rgba (r,g,b,a)); } void vkvg_set_source_surface(VkvgContext ctx, VkvgSurface surf, float x, float y){ - ctx->status = VKVG_STATUS_SUCCESS; _update_cur_pattern (ctx, vkvg_pattern_create_for_surface(surf)); ctx->pushConsts.source.x = x; ctx->pushConsts.source.y = y; ctx->pushCstDirty = true; } void vkvg_set_source (VkvgContext ctx, VkvgPattern pat){ - ctx->status = VKVG_STATUS_SUCCESS; _update_cur_pattern (ctx, pat); vkvg_pattern_reference (pat); } void vkvg_set_line_width (VkvgContext ctx, float width){ - ctx->status = VKVG_STATUS_SUCCESS; ctx->lineWidth = width; } void vkvg_set_line_cap (VkvgContext ctx, vkvg_line_cap_t cap){ - ctx->status = VKVG_STATUS_SUCCESS; ctx->lineCap = cap; } void vkvg_set_line_join (VkvgContext ctx, vkvg_line_join_t join){ - ctx->status = VKVG_STATUS_SUCCESS; ctx->lineJoin = join; } void vkvg_set_operator (VkvgContext ctx, vkvg_operator_t op){ - ctx->status = VKVG_STATUS_SUCCESS; ctx->curOperator = op; _bind_draw_pipeline (ctx); } @@ -644,27 +683,23 @@ VkvgPattern vkvg_get_source (VkvgContext ctx){ } void vkvg_select_font_face (VkvgContext ctx, const char* name){ - ctx->status = VKVG_STATUS_SUCCESS; _select_font_face (ctx, name); } void vkvg_set_font_size (VkvgContext ctx, uint32_t size){ - ctx->status = VKVG_STATUS_SUCCESS; _set_font_size (ctx,size); } void vkvg_set_text_direction (vkvg_context* ctx, vkvg_direction_t direction){ - ctx->status = VKVG_STATUS_SUCCESS; + } void vkvg_show_text (VkvgContext ctx, const char* text){ - ctx->status = VKVG_STATUS_SUCCESS; _check_cmd_buff_state(ctx); _show_text (ctx, text); _record_draw_cmd (ctx); } VkvgText vkvg_text_run_create (VkvgContext ctx, const char* text) { - ctx->status = VKVG_STATUS_SUCCESS; VkvgText tr = (vkvg_text_run_t*)calloc(1, sizeof(vkvg_text_run_t)); _create_text_run(ctx, text, tr); return tr; @@ -674,7 +709,6 @@ void vkvg_text_run_destroy (VkvgText textRun) { free (textRun); } void vkvg_show_text_run (VkvgContext ctx, VkvgText textRun) { - ctx->status = VKVG_STATUS_SUCCESS; _show_text_run(ctx, textRun); } vkvg_text_extents_t* vkvg_text_run_get_extents (VkvgText textRun) { @@ -689,7 +723,6 @@ void vkvg_font_extents (VkvgContext ctx, vkvg_font_extents_t* extents) { } void vkvg_save (VkvgContext ctx){ - ctx->status = VKVG_STATUS_SUCCESS; LOG(LOG_INFO, "SAVE CONTEXT: ctx = %lu\n", (ulong)ctx); _flush_cmd_buff(ctx); @@ -761,7 +794,6 @@ void vkvg_save (VkvgContext ctx){ _init_cmd_buff (ctx); } void vkvg_restore (VkvgContext ctx){ - ctx->status = VKVG_STATUS_SUCCESS; if (ctx->pSavedCtxs == NULL){ ctx->status = VKVG_STATUS_INVALID_RESTORE; return; @@ -833,35 +865,29 @@ void vkvg_restore (VkvgContext ctx){ } void vkvg_translate (VkvgContext ctx, float dx, float dy){ - ctx->status = VKVG_STATUS_SUCCESS; vkvg_matrix_translate (&ctx->pushConsts.mat, dx, dy); _set_mat_inv_and_vkCmdPush (ctx); } void vkvg_scale (VkvgContext ctx, float sx, float sy){ - ctx->status = VKVG_STATUS_SUCCESS; vkvg_matrix_scale (&ctx->pushConsts.mat, sx, sy); _set_mat_inv_and_vkCmdPush (ctx); } void vkvg_rotate (VkvgContext ctx, float radians){ - ctx->status = VKVG_STATUS_SUCCESS; vkvg_matrix_rotate (&ctx->pushConsts.mat, radians); _set_mat_inv_and_vkCmdPush (ctx); } void vkvg_transform (VkvgContext ctx, const vkvg_matrix_t* matrix) { - ctx->status = VKVG_STATUS_SUCCESS; vkvg_matrix_t res; vkvg_matrix_multiply (&res, &ctx->pushConsts.mat, matrix); ctx->pushConsts.mat = res; _set_mat_inv_and_vkCmdPush (ctx); } void vkvg_identity_matrix (VkvgContext ctx) { - ctx->status = VKVG_STATUS_SUCCESS; vkvg_matrix_t im = VKVG_IDENTITY_MATRIX; ctx->pushConsts.mat = im; _set_mat_inv_and_vkCmdPush (ctx); } void vkvg_set_matrix (VkvgContext ctx, const vkvg_matrix_t* matrix){ - ctx->status = VKVG_STATUS_SUCCESS; ctx->pushConsts.mat = (*matrix); _set_mat_inv_and_vkCmdPush (ctx); } diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index 081ba97..2ffe7b3 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -102,9 +102,9 @@ void _add_point_vec2(VkvgContext ctx, vec2 v){ } float _normalizeAngle(float a) { - float res = ROUND_DOWN(fmod(a,2.0f*M_PI),100); + float res = ROUND_DOWN(fmod(a,2.0f*M_PIF),100); if (res < 0.0f) - return res + 2.0f*M_PI; + return res + 2.0f*M_PIF; else return res; } @@ -184,11 +184,11 @@ void _record_draw_cmd (VkvgContext ctx){ _check_cmd_buff_state(ctx); CmdDrawIndexed(ctx->cmd, ctx->indCount - ctx->curIndStart, 1, ctx->curIndStart, 0, 1); - //DEBUG - /*CmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelineWired); +#ifdef VKVG_WIRED_DEBUG + CmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelineWired); CmdDrawIndexed(ctx->cmd, ctx->indCount - ctx->curIndStart, 1, ctx->curIndStart, 0, 1); - CmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipe_OVER);*/ - ////////// + CmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipe_OVER); +#endif ctx->curIndStart = ctx->indCount; } @@ -211,7 +211,7 @@ inline void _submit_wait_and_reset_cmd (VkvgContext ctx){ _submit_ctx_cmd(ctx); _wait_and_reset_ctx_cmd(ctx); } -void _explicit_ms_resolve (VkvgContext ctx){//should init cmd before calling this (unused, using automatic resolve by renderpass) +/*void _explicit_ms_resolve (VkvgContext ctx){//should init cmd before calling this (unused, using automatic resolve by renderpass) vkh_image_set_layout (ctx->cmd, ctx->pSurf->imgMS, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); @@ -232,7 +232,7 @@ void _explicit_ms_resolve (VkvgContext ctx){//should init cmd before calling thi vkh_image_set_layout (ctx->cmd, ctx->pSurf->imgMS, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL , VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); -} +}*/ void _end_render_pass (VkvgContext ctx) { LOG(LOG_INFO, "FLUSH Context: ctx = %lu; vert cpt = %d; ind cpt = %d\n", ctx, ctx->vertCount -4, ctx->indCount - 6); @@ -560,13 +560,13 @@ void _build_vb_step (vkvg_context* ctx, Vertex v, float hw, uint32_t iL, uint32_ _add_triangle_indices(ctx, idx+2, idx+3, idx+1); _add_triangle_indices(ctx, idx+1, idx+3, idx+4); }else if (ctx->lineJoin == VKVG_LINE_JOIN_ROUND){ - float step = M_PI / hw; + float step = M_PIF / hw; float a = acos(vp.x); if (vp.y < 0) a = -a; if (cross<0){ - a+=M_PI; + a+=M_PIF; float a1 = a + alpha*2; a-=step; while (a > a1){ @@ -700,8 +700,8 @@ void _recursive_bezier (VkvgContext ctx, float a23 = atan2(y3 - y2, x3 - x2); da1 = fabs(a23 - atan2(y2 - y1, x2 - x1)); da2 = fabs(atan2(y4 - y3, x4 - x3) - a23); - if(da1 >= M_PI) da1 = M_2_PI - da1; - if(da2 >= M_PI) da2 = M_2_PI - da2; + if(da1 >= M_PIF) da1 = M_2_PI - da1; + if(da2 >= M_PIF) da2 = M_2_PI - da2; if(da1 + da2 < m_angle_tolerance) { @@ -742,7 +742,7 @@ void _recursive_bezier (VkvgContext ctx, // Angle Condition //---------------------- da1 = fabs(atan2(y3 - y2, x3 - x2) - atan2(y2 - y1, x2 - x1)); - if(da1 >= M_PI) da1 = M_2_PI - da1; + if(da1 >= M_PIF) da1 = M_2_PI - da1; if(da1 < m_angle_tolerance) { @@ -774,7 +774,7 @@ void _recursive_bezier (VkvgContext ctx, // Angle Condition //---------------------- da1 = fabs(atan2(y4 - y3, x4 - x3) - atan2(y3 - y2, x3 - x2)); - if(da1 >= M_PI) da1 = M_2_PI - da1; + if(da1 >= M_PIF) da1 = M_2_PI - da1; if(da1 < m_angle_tolerance) { diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h index a282c47..5614923 100644 --- a/src/vkvg_context_internal.h +++ b/src/vkvg_context_internal.h @@ -28,14 +28,12 @@ #include "vkh.h" #include "vkvg_fonts.h" -#define VKVG_PTS_SIZE 16384 +#define VKVG_PTS_SIZE 10000 #define VKVG_VBO_SIZE VKVG_PTS_SIZE * 2 #define VKVG_IBO_SIZE VKVG_VBO_SIZE * 2 -#define VKVG_PATHES_SIZE 256 +#define VKVG_PATHES_SIZE 16 #define VKVG_ARRAY_THRESHOLD 4 -#define ROUND_DOWN(v,p) (floorf(v * p) / p) - typedef struct{ vec2 pos; vec3 uv; diff --git a/src/vkvg_device.c b/src/vkvg_device.c index f0b1458..1ea7e79 100644 --- a/src/vkvg_device.c +++ b/src/vkvg_device.c @@ -24,12 +24,33 @@ #include "vkh_queue.h" #include "vkh_phyinfo.h" #include "vk_mem_alloc.h" - +/** + * @brief Create VkvgDevice with default multisampling configuration + * @param Vulkan instance, usefull to retrieve function pointers + * @param Vulkan physical device + * @param Vulkan Device + * @param Queue familly index + * @param Queue index in selected familly + * @return + */ VkvgDevice vkvg_device_create(VkInstance inst, VkPhysicalDevice phy, VkDevice vkdev, uint32_t qFamIdx, uint32_t qIndex) { - return vkvg_device_create_multisample (inst,phy,vkdev,qFamIdx,qIndex, VK_SAMPLE_COUNT_4_BIT); + return vkvg_device_create_multisample (inst,phy,vkdev,qFamIdx,qIndex, VK_SAMPLE_COUNT_4_BIT, false); } -VkvgDevice vkvg_device_create_multisample(VkInstance inst, VkPhysicalDevice phy, VkDevice vkdev, uint32_t qFamIdx, uint32_t qIndex, VkSampleCountFlags samples) +/** + * @brief Create VkvgDevice with default multisampling configuration + * @param Vulkan instance, usefull to retrieve function pointers + * @param Vulkan physical device + * @param Vulkan Device + * @param Queue familly index + * @param Queue index in selected familly + * @param multisample count + * @param When set to false, surface is resolve after each renderpasses on resolve attachment of surface. + * If set to true, multisample surface image is resolve with vkvg_multisample_surface_resolve. This function + * is called automatically when surface's VkImage is querried with vkvg_surface_get_vk_image. + * @return + */ +VkvgDevice vkvg_device_create_multisample(VkInstance inst, VkPhysicalDevice phy, VkDevice vkdev, uint32_t qFamIdx, uint32_t qIndex, VkSampleCountFlags samples, bool deferredResolve) { LOG(LOG_INFO, "CREATE Device: qFam = %d; qIdx = %d\n", qFamIdx, qIndex); @@ -39,6 +60,7 @@ VkvgDevice vkvg_device_create_multisample(VkInstance inst, VkPhysicalDevice phy, dev->hdpi = 72; dev->vdpi = 72; dev->samples= samples; + dev->deferredResolve = deferredResolve; dev->vkDev = vkdev; dev->phy = phy; @@ -66,7 +88,10 @@ VkvgDevice vkvg_device_create_multisample(VkInstance inst, VkPhysicalDevice phy, _create_pipeline_cache (dev); _init_fonts_cache (dev); - _setupRenderPass (dev); + if (dev->deferredResolve) + _setupRenderPassDeferredResolve(dev); + else + _setupRenderPass (dev); _createDescriptorSetLayout (dev); _setupPipelines (dev); @@ -98,7 +123,7 @@ void vkvg_device_destroy (VkvgDevice dev) vkDestroyPipeline (dev->vkDev, dev->pipe_SUB, NULL); vkDestroyPipeline (dev->vkDev, dev->pipe_CLEAR, NULL); -#if DEBUG +#ifdef VKVG_WIRED_DEBUG vkDestroyPipeline (dev->vkDev, dev->pipelineWired, NULL); vkDestroyPipeline (dev->vkDev, dev->pipelineLineList, NULL); #endif diff --git a/src/vkvg_device_internal.c b/src/vkvg_device_internal.c index 5d30911..23d6572 100644 --- a/src/vkvg_device_internal.c +++ b/src/vkvg_device_internal.c @@ -45,6 +45,59 @@ void _create_pipeline_cache(VkvgDevice dev){ VkPipelineCacheCreateInfo pipelineCacheCreateInfo = {.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO}; VK_CHECK_RESULT(vkCreatePipelineCache(dev->vkDev, &pipelineCacheCreateInfo, NULL, &dev->pipelineCache)); } +void _setupRenderPassDeferredResolve(VkvgDevice dev) +{ + VkAttachmentDescription attColor = { + .format = FB_COLOR_FORMAT, + .samples = dev->samples, + .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD, + .storeOp = VK_ATTACHMENT_STORE_OP_STORE, + .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE, + .stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE, + .initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + .finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL }; + VkAttachmentDescription attDS = { + .format = VK_FORMAT_S8_UINT, + .samples = dev->samples, + .loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE, + .storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE, + .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD, + .stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE, + .initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, + .finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL }; + + VkAttachmentDescription attachments[] = {attColor,attDS}; + VkAttachmentReference colorRef = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}; + VkAttachmentReference dsRef = {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL}; + + VkSubpassDescription subpassDescription = { .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS, + .colorAttachmentCount = 1, + .pColorAttachments = &colorRef, + .pDepthStencilAttachment= &dsRef}; + + VkSubpassDependency dependencies[] = + { + { VK_SUBPASS_EXTERNAL, 0, + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, + VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, + VK_DEPENDENCY_BY_REGION_BIT}, + { 0, VK_SUBPASS_EXTERNAL, + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, + VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT, + VK_DEPENDENCY_BY_REGION_BIT}, + }; + + VkRenderPassCreateInfo renderPassInfo = { .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, + .attachmentCount = 2, + .pAttachments = attachments, + .subpassCount = 1, + .pSubpasses = &subpassDescription, + .dependencyCount = 2, + .pDependencies = dependencies + }; + + VK_CHECK_RESULT(vkCreateRenderPass(dev->vkDev, &renderPassInfo, NULL, &dev->renderPass)); +} void _setupRenderPass(VkvgDevice dev) { VkAttachmentDescription attColor = { @@ -259,7 +312,7 @@ void _setupPipelines(VkvgDevice dev) VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipe_CLEAR)); -#if DEBUG +#ifdef VKVG_WIRED_DEBUG rasterizationState.polygonMode = VK_POLYGON_MODE_FILL; inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST; shaderStages[1].pName = "main"; diff --git a/src/vkvg_device_internal.h b/src/vkvg_device_internal.h index e736683..c888fed 100644 --- a/src/vkvg_device_internal.h +++ b/src/vkvg_device_internal.h @@ -49,50 +49,49 @@ PFN_vkCmdPushDescriptorSetKHR CmdPushDescriptorSet; typedef struct _vkvg_device_t{ - VkDevice vkDev; - VkPhysicalDeviceMemoryProperties phyMemProps; - VkPhysicalDevice phy; - VmaAllocator allocator; - - VkhQueue gQueue; - MUTEX gQMutex;//queue submission has to be externally syncronized - VkRenderPass renderPass; - - uint32_t references; - VkCommandPool cmdPool; - VkCommandBuffer cmd; - //this fence is kept signaled when idle, wait and reset are called before each recording. - VkFence fence; - - VkPipeline pipe_OVER; //default operator + VkDevice vkDev; /**< Vulkan Logical Device */ + VkPhysicalDeviceMemoryProperties phyMemProps; /**< Vulkan Physical device memory properties */ + VkPhysicalDevice phy; /**< Vulkan Physical device */ + VmaAllocator allocator; /**< Vulkan Memory allocator */ + VkInstance instance; /**< Vulkan instance */ + + VkhQueue gQueue; /**< Vulkan Queue with Graphic flag */ + MUTEX gQMutex; /**< queue submission has to be externally syncronized */ + VkRenderPass renderPass; /**< Vulkan render pass, common for all surfaces */ + + uint32_t references; /**< Reference count, prevent destroying device if still in use */ + VkCommandPool cmdPool; /**< Global command pool for processing on surfaces without context */ + VkCommandBuffer cmd; /**< Global command buffer */ + VkFence fence; /**< this fence is kept signaled when idle, wait and reset are called before each recording. */ + + VkPipeline pipe_OVER; /**< default operator */ VkPipeline pipe_SUB; - VkPipeline pipe_CLEAR; //clear operator + VkPipeline pipe_CLEAR; /**< clear operator */ - VkPipeline pipelinePolyFill; // - VkPipeline pipelineClipping; //to update clip + VkPipeline pipelinePolyFill; /**< even-odd polygon filling first step */ + VkPipeline pipelineClipping; /**< draw on stencil to update clipping regions */ -#if DEBUG +#ifdef VKVG_WIRED_DEBUG VkPipeline pipelineWired; VkPipeline pipelineLineList; #endif - VkPipelineCache pipelineCache; - VkPipelineLayout pipelineLayout; - VkDescriptorPool descriptorPool; - VkDescriptorSetLayout dslFont; - VkDescriptorSetLayout dslSrc; - VkDescriptorSetLayout dslGrad; + VkPipelineCache pipelineCache; /**< speed up startup by caching configured pipelines on disk */ + VkPipelineLayout pipelineLayout; /**< layout common to all pipelines */ + VkDescriptorSetLayout dslFont; /**< font cache descriptors layout */ + VkDescriptorSetLayout dslSrc; /**< context source surface descriptors layout */ + VkDescriptorSetLayout dslGrad; /**< context gradient descriptors layout */ - int hdpi, + int hdpi, /**< only used for FreeType fonts */ vdpi; - VkInstance instance; - VkhImage emptyImg;//prevent unbound descriptor to trigger Validation error 61 - VkSampleCountFlags samples;//samples count for all surfaces - vkvg_status_t status; + VkhImage emptyImg; /**< prevent unbound descriptor to trigger Validation error 61 */ + VkSampleCountFlags samples; /**< samples count common to all surfaces */ + bool deferredResolve; /**< if true, resolve only on context destruction and set as source */ + vkvg_status_t status; /**< Current status of device, affected by last operation */ - _font_cache_t* fontCache; - VkvgContext lastCtx; //double linked list last elmt + _font_cache_t* fontCache; /**< Store everything relative to common font caching system */ + VkvgContext lastCtx; /**< last element of double linked list of context, used to trigger font caching system update on all contexts*/ }vkvg_device; void _init_function_pointers (VkvgDevice dev); @@ -100,6 +99,7 @@ void _create_empty_texture (VkvgDevice dev); void _check_image_format_properties (VkvgDevice dev); void _create_pipeline_cache (VkvgDevice dev); void _setupRenderPass (VkvgDevice dev); +void _setupRenderPassDeferredResolve (VkvgDevice dev); void _setupPipelines (VkvgDevice dev); void _createDescriptorSetLayout (VkvgDevice dev); void _flush_all_contexes (VkvgDevice dev); diff --git a/src/vkvg_fonts.c b/src/vkvg_fonts.c index 3215fa0..79bf493 100644 --- a/src/vkvg_fonts.c +++ b/src/vkvg_fonts.c @@ -27,7 +27,7 @@ #include "vkh.h" -int defaultFontCharSize = 12<<6; +static int defaultFontCharSize = 12<<6; void _init_fonts_cache (VkvgDevice dev){ _font_cache_t* cache = (_font_cache_t*)calloc(1, sizeof(_font_cache_t)); @@ -59,6 +59,7 @@ void _init_fonts_cache (VkvgDevice dev){ dev->fontCache = cache; } +///increase layer count of 2d texture array used as font cache. void _increase_font_tex_array (VkvgDevice dev){ _font_cache_t* cache = dev->fontCache; @@ -118,6 +119,7 @@ void _increase_font_tex_array (VkvgDevice dev){ _init_all_contexes (dev); } +///Start a new line in font cache, increase texture layer count if needed. void _init_next_line_in_tex_cache (VkvgDevice dev, _vkvg_font_t* f){ _font_cache_t* cache = dev->fontCache; int i; @@ -169,6 +171,8 @@ void _destroy_font_cache (VkvgDevice dev){ } +#ifdef DEBUG +//helper function void _dump_glyphs (FT_Face face){ FT_GlyphSlot slot; char gname[256]; @@ -185,7 +189,8 @@ void _dump_glyphs (FT_Face face){ face->size->metrics.max_advance/64); } } - +#endif +//flush font stagging buffer to cache texture array void _flush_chars_to_tex (VkvgDevice dev, _vkvg_font_t* f) { _font_cache_t* cache = dev->fontCache; if (cache->stagingX == 0) @@ -225,7 +230,7 @@ void _flush_chars_to_tex (VkvgDevice dev, _vkvg_font_t* f) { cache->stagingX = 0; memset(cache->hostBuff, 0, FONT_PAGE_SIZE * FONT_PAGE_SIZE); } - +//create a new char entry and put glyph in stagging buffer, ready for upload. _char_ref* _prepare_char (VkvgDevice dev, _vkvg_font_t* f, FT_UInt gindex){ FT_CHECK_RESULT(FT_Load_Glyph(f->face, gindex, FT_LOAD_RENDER)); @@ -253,18 +258,19 @@ _char_ref* _prepare_char (VkvgDevice dev, _vkvg_font_t* f, FT_UInt gindex){ bmp.rows}; cr->bounds = uvBounds; cr->pageIdx = f->curLine.pageIdx; - cr->bmpDiff.x = slot->bitmap_left; - cr->bmpDiff.y = slot->bitmap_top; + cr->bmpDiff.x = (int16_t)slot->bitmap_left; + cr->bmpDiff.y = (int16_t)slot->bitmap_top; f->charLookup[gindex] = cr; dev->fontCache->stagingX += bmp.width; return cr; } - +//set current font size for context void _set_font_size (VkvgContext ctx, uint32_t size){ ctx->selectedFont.charSize = size << 6; ctx->currentFont = NULL; } +//select current font for context void _select_font_face (VkvgContext ctx, const char* name){ _font_cache_t* cache = (_font_cache_t*)ctx->pSurf->dev->fontCache; @@ -289,7 +295,7 @@ void _select_font_face (VkvgContext ctx, const char* name){ ctx->currentFont = NULL; } - +//try to find font in cache with same font file path and font size as selected in context. _vkvg_font_t* _tryFindVkvgFont (VkvgContext ctx){ _font_cache_t* cache = (_font_cache_t*)ctx->pSurf->dev->fontCache; for (int i = 0; i < cache->fontsCount; ++i) { @@ -298,7 +304,7 @@ _vkvg_font_t* _tryFindVkvgFont (VkvgContext ctx){ } return NULL; } - +//try to find corresponding font in cache (defined by context selectedFont) and create a new font entry if not found. void _update_current_font (VkvgContext ctx) { VkvgDevice dev = ctx->pSurf->dev; if (ctx->currentFont == NULL){ @@ -336,7 +342,7 @@ void _update_current_font (VkvgContext ctx) { } } } - +//Get harfBuzz buffer for provided text. hb_buffer_t * _get_hb_buffer (VkvgContext ctx, const char* text) { hb_buffer_t *buf = hb_buffer_create(); @@ -353,6 +359,7 @@ hb_buffer_t * _get_hb_buffer (VkvgContext ctx, const char* text) { hb_shape (ctx->currentFont->hb_font, buf, NULL, 0); return buf; } +//retrieve global font extends of context's current font as defined by FreeType void _font_extents (VkvgContext ctx, vkvg_font_extents_t *extents) { _update_current_font (ctx); @@ -365,7 +372,7 @@ void _font_extents (VkvgContext ctx, vkvg_font_extents_t *extents) { extents->max_x_advance = bbox->xMax >> 6; extents->max_y_advance = bbox->yMax >> 6; } - +//compute text extends for provided string. void _text_extents (VkvgContext ctx, const char* text, vkvg_text_extents_t *extents) { _update_current_font (ctx); @@ -470,7 +477,7 @@ void _show_text (VkvgContext ctx, const char* text){ //_show_texture(ctx); return; } -#if DEBUG +#ifdef DEBUG void _show_texture (vkvg_context* ctx){ Vertex vs[] = { {{0,0}, {0,0,1}}, diff --git a/src/vkvg_fonts.h b/src/vkvg_fonts.h index ac5ad8c..0c4be3b 100644 --- a/src/vkvg_fonts.h +++ b/src/vkvg_fonts.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Jean-Philippe Bruyère + * Copyright (c) 2018-2019 Jean-Philippe Bruyère * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -48,71 +48,79 @@ #include "vkvg.h" #include "vkvg_buff.h" #include "vkh.h" -//#include "vkh_image.h" - -///texture coords of one char +//texture coordinates of one character in font cache array texture. typedef struct { - vec4 bounds; - vec2i16 bmpDiff; - uint8_t pageIdx; + vec4 bounds; /* normalized float bounds of character bitmap in font cache texture. */ + vec2i16 bmpDiff; /* Difference in pixel between char bitmap top left corner and char glyph*/ + uint8_t pageIdx; /* Page index in font cache texture array */ }_char_ref; -//chars texture atlas reference +// Current location in font cache texture array for new character addition. Each font holds such structure to locate +// where to upload new chars. typedef struct { - uint8_t pageIdx; - int penX; - int penY; - int height; + uint8_t pageIdx; /* Current page number in font cache */ + int penX; /* Current X in cache for next char addition */ + int penY; /* Current Y in cache for next char addition */ + int height; /* Height of current line pointed by this structure */ }_tex_ref_t; - +// Loaded font structure, holds informations for glyphes upload in cache and the lookup table of characters. typedef struct { - char* fontFile; - FT_F26Dot6 charSize; - hb_font_t* hb_font; - FT_Face face; - _char_ref** charLookup; + char* fontFile; /* Font file full path*/ + FT_F26Dot6 charSize; /* Font size*/ + hb_font_t* hb_font; /* HarfBuzz font instance*/ + FT_Face face; /* FreeType face*/ + _char_ref** charLookup; /* Lookup table of characteres in cache, if not found, upload is queued*/ - _tex_ref_t curLine; //tex coord where to add new char bmp's + _tex_ref_t curLine; /* tex coord where to add new char bmp's */ }_vkvg_font_t; - +// Font cache global structure, entry point for all font related operations. typedef struct { - FT_Library library; - FcConfig* config; + FT_Library library; /* FreeType library*/ + FcConfig* config; /* Font config, used to find font files by font names*/ - int stagingX; //x pen in host buffer - uint8_t* hostBuff; //host mem where bitmaps are first loaded + int stagingX; /* x pen in host buffer */ + uint8_t* hostBuff; /* host memory where bitmaps are first loaded */ - VkCommandBuffer cmd; //upload cmd buff - vkvg_buff buff; //stagin buffer - VkhImage cacheTex; //tex 2d array - uint8_t cacheTexLength; //tex array length - int* pensY; //y pen pos in each texture of array - VkFence uploadFence; + VkCommandBuffer cmd; /* vulkan command buffer for font textures upload */ + vkvg_buff buff; /* stagin buffer */ + VkhImage cacheTex; /* 2d array texture used by contexts to draw characteres */ + uint8_t cacheTexLength; /* layer count of 2d array texture, starts with FONT_CACHE_INIT_LAYERS count and increased when needed */ + int* pensY; /* array of current y pen positions for each texture in cache 2d array */ + VkFence uploadFence; /* Signaled when upload is finished */ - _vkvg_font_t* fonts; - uint8_t fontsCount; + _vkvg_font_t* fonts; /* Loaded fonts structure array */ + uint8_t fontsCount; /* Loaded fonts array count*/ }_font_cache_t; - +// Precompute everything necessary to draw one line of text, usefull to draw the same text multiple times. typedef struct _vkvg_text_run_t { - hb_buffer_t* hbBuf; - _vkvg_font_t* font; - VkvgDevice dev; - vkvg_text_extents_t extents; - const char* text; - unsigned int glyph_count; - hb_glyph_position_t *glyph_pos; + hb_buffer_t* hbBuf; /* HarfBuzz buffer of text */ + _vkvg_font_t* font; /* vkvg font structure pointer */ + VkvgDevice dev; /* vkvg device associated with this text run */ + vkvg_text_extents_t extents; /* store computed text extends */ + const char* text; /* utf8 char array of text*/ + unsigned int glyph_count;/* Total glyph count */ + hb_glyph_position_t *glyph_pos; /* HarfBuzz computed glyph positions array */ } vkvg_text_run_t; - +//Create font cache. void _init_fonts_cache (VkvgDevice dev); +//Release all ressources of font cache. void _destroy_font_cache (VkvgDevice dev); +//Select current font for context from font name, create new font entry in cache if required void _select_font_face (VkvgContext ctx, const char* name); +//Set current font size for context void _set_font_size (VkvgContext ctx, uint32_t size); +//Draw text void _show_text (VkvgContext ctx, const char* text); +//Get text dimmensions void _text_extents (VkvgContext ctx, const char* text, vkvg_text_extents_t *extents); +//Get font global dimmensions void _font_extents (VkvgContext ctx, vkvg_font_extents_t* extents); - +//Create text object that could be drawn multiple times minimizing harfbuzz and compute processing. void _create_text_run (VkvgContext ctx, const char* text, VkvgText textRun); +//Release ressources held by a text run. void _destroy_text_run (VkvgText textRun); +//Draw text run void _show_text_run (VkvgContext ctx, VkvgText tr); +//Trigger stagging buffer to be uploaded in font cache. Groupping upload improve performances. void _flush_chars_to_tex (VkvgDevice dev, _vkvg_font_t* f); #endif diff --git a/src/vkvg_internal.h b/src/vkvg_internal.h index e1bced2..9801167 100644 --- a/src/vkvg_internal.h +++ b/src/vkvg_internal.h @@ -27,6 +27,15 @@ #include #include #include +#include +#include + +# define M_PIF 3.14159265358979323846f /* float pi */ + +#define ROUNDF(f, c) (((float)((int)((f) * (c))) / (c))) +#define ROUND_DOWN(v,p) (floorf(v * p) / p) +#define EQUF(a, b) (fabsf(a-b)<=FLT_EPSILON) + #include "vectors.h" #include "cross_mutex.h" diff --git a/src/vkvg_surface.c b/src/vkvg_surface.c index d904f36..0dd14aa 100644 --- a/src/vkvg_surface.c +++ b/src/vkvg_surface.c @@ -29,6 +29,38 @@ #include "stb_image_write.h" #include "vkh_image.h" +void _explicit_ms_resolve (VkvgSurface surf){ + VkvgDevice dev = surf->dev; + VkCommandBuffer cmd = dev->cmd; + + _wait_and_reset_device_fence (dev); + + vkh_cmd_begin (cmd, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT); + vkh_image_set_layout (cmd, surf->imgMS, VK_IMAGE_ASPECT_COLOR_BIT, + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); + vkh_image_set_layout (cmd, surf->img, VK_IMAGE_ASPECT_COLOR_BIT, + VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); + + VkImageResolve re = { + .extent = {surf->width, surf->height,1}, + .srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT,0,0,1}, + .dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT,0,0,1} + }; + + vkCmdResolveImage(cmd, + vkh_image_get_vkimage (surf->imgMS), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + vkh_image_get_vkimage (surf->img) ,VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + 1,&re); + vkh_image_set_layout (cmd, surf->imgMS, VK_IMAGE_ASPECT_COLOR_BIT, + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL , + VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); + vkh_cmd_end (cmd); + + _submit_cmd (dev, &cmd, dev->fence); +} + void _clear_surface (VkvgSurface surf, VkImageAspectFlags aspect) { VkvgDevice dev = surf->dev; @@ -99,6 +131,10 @@ void _create_framebuffer (VkvgSurface surf) { .width = surf->width, .height = surf->height, .layers = 1 }; + if (surf->dev->deferredResolve) { + attachments[1] = attachments[2]; + frameBufferCreateInfo.attachmentCount = 2; + } VK_CHECK_RESULT(vkCreateFramebuffer(surf->dev->vkDev, &frameBufferCreateInfo, NULL, &surf->fb)); } void _init_surface (VkvgSurface surf) { @@ -292,8 +328,13 @@ uint32_t vkvg_surface_get_reference_count (VkvgSurface surf) { VkImage vkvg_surface_get_vk_image(VkvgSurface surf) { + if (surf->dev->deferredResolve) + _explicit_ms_resolve(surf); return vkh_image_get_vkimage (surf->img); } +void vkvg_multisample_surface_resolve (VkvgSurface surf){ + _explicit_ms_resolve(surf); +} VkFormat vkvg_surface_get_vk_format(VkvgSurface surf) { return surf->format; diff --git a/tests/test1.c b/tests/test1.c index 32fac3c..82aa694 100644 --- a/tests/test1.c +++ b/tests/test1.c @@ -90,6 +90,13 @@ VkvgDevice device; VkvgSurface surf = NULL; +static float panX = 0.f; +static float panY = 0.f; +static float lastX = 0.f; +static float lastY = 0.f; +static float zoom = 1.0f; +static bool mouseDown = false; + static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { if (action != GLFW_PRESS) return; @@ -100,8 +107,28 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action, } } static void char_callback (GLFWwindow* window, uint32_t c){} -static void mouse_move_callback(GLFWwindow* window, double x, double y){} -static void mouse_button_callback(GLFWwindow* window, int but, int state, int modif){} +static void mouse_move_callback(GLFWwindow* window, double x, double y){ + if (mouseDown) { + panX += ((float)x-lastX); + panY += ((float)y-lastY); + } + lastX = (float)x; + lastY = (float)y; +} +static void scroll_callback(GLFWwindow* window, double x, double y){ + if (y<0.f) + zoom *= 0.5f; + else + zoom *= 2.0f; +} +static void mouse_button_callback(GLFWwindow* window, int but, int state, int modif){ + if (but != GLFW_MOUSE_BUTTON_1) + return; + if (state == GLFW_TRUE) + mouseDown = true; + else + mouseDown = false; +} double time_diff(struct timeval x , struct timeval y) { @@ -642,11 +669,11 @@ void cairo_test_fill_rule (VkvgContext cr){ vkvg_rectangle (cr, 12, 12, 232, 70); //vkvg_stroke (cr); // vkvg_new_sub_path (cr); - vkvg_arc (cr, 64, 64, 40, 0, M_PI*2); + vkvg_arc (cr, 64, 64, 40, 0, (float)M_PI*2.f); //vkvg_close_path(cr); vkvg_new_sub_path (cr); - vkvg_arc_negative (cr, 192, 64, 40, 2*M_PI, 0); + vkvg_arc_negative (cr, 192, 64, 40, (float)M_PI*2.f, 0); //vkvg_close_path(cr); //vkvg_rectangle (cr, 30, 30, 20, 200); @@ -678,6 +705,7 @@ void cairo_test_text (VkvgContext cr) { /* draw helping lines */ vkvg_set_source_rgba (cr, 1, 0.2, 0.2, 0.6); vkvg_set_line_width (cr, 6.0); + vkvg_new_path(cr); vkvg_arc (cr, x, y, 10.0, 0, 2*M_PI); vkvg_fill (cr); vkvg_move_to (cr, x,y); @@ -811,13 +839,13 @@ void cairo_print_arc_neg (VkvgContext cr){ float angle2 = 180.0 * (M_PI/180.0); /* in radians */ vkvg_set_source_rgba(cr, 0, 0, 0, 1); - vkvg_set_line_width (cr, 10.0); + vkvg_set_line_width (cr, 5.0); vkvg_arc_negative (cr, xc, yc, radius, angle1, angle2); vkvg_stroke (cr); /* draw helping lines */ vkvg_set_source_rgba (cr, 1, 0.2, 0.2, 0.6); - vkvg_set_line_width (cr, 6.0); + vkvg_set_line_width (cr, 10.0); vkvg_arc (cr, xc, yc, 10.0, 0, 2*M_PI); vkvg_fill (cr); @@ -896,13 +924,16 @@ void cairo_print_arc (VkvgContext cr) { vkvg_stroke (cr); } static float rotation = 0.f; + void cairo_tests () { rotation+=0.01f; vkvg_matrix_t mat; vkvg_matrix_init_translate (&mat, 512,400); vkvg_matrix_rotate(&mat,rotation); - vkvg_matrix_translate(&mat,-512,-400); + vkvg_matrix_scale(&mat,zoom,zoom); + vkvg_matrix_translate(&mat,-512.f + panX,-400.f +panY); + VkvgContext ctx = vkvg_create(surf); vkvg_set_source_rgba(ctx,0.7,0.7,0.7,1); @@ -970,10 +1001,19 @@ void svg_set_color (VkvgContext ctx, uint32_t c, float alpha) { } void test_svg () { + rotation+=0.01f; + + vkvg_matrix_t mat; + vkvg_matrix_init_translate (&mat, 512,400); + vkvg_matrix_rotate(&mat,rotation); + vkvg_matrix_translate(&mat,-512,-400); + VkvgContext ctx = vkvg_create(surf); vkvg_set_source_rgba(ctx,1.0,1.0,1.0,1); vkvg_paint(ctx); + vkvg_set_matrix(ctx,&mat); + NSVGimage* svg; NSVGshape* shape; NSVGpath* path; @@ -1149,11 +1189,11 @@ void simple_rectangle_fill () { void simple_rectangle_stroke () { VkvgContext ctx = vkvg_create(surf); vkvg_clear(ctx); - vkvg_line_to(ctx,100,100); + vkvg_set_line_width(ctx,100.f); + vkvg_arc (ctx, 300, 300, 200, 0, M_PI*2.0); vkvg_set_source_rgba(ctx,0,0,1,1); - vkvg_set_line_width(ctx,50.f); - vkvg_set_line_join(ctx,VKVG_LINE_JOIN_ROUND); - vkvg_rectangle(ctx,100,100,200,200); + vkvg_fill_preserve(ctx); + vkvg_set_source_rgba(ctx,1,0,1,1); vkvg_stroke(ctx); vkvg_destroy(ctx); } @@ -1172,16 +1212,21 @@ int main(int argc, char *argv[]) { //dumpLayerExts(); uint width=1024, height=768; - vk_engine_t* e = vkengine_create (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, VK_PRESENT_MODE_FIFO_KHR, width, height); + vk_engine_t* e = vkengine_create (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, VK_PRESENT_MODE_MAILBOX_KHR, width, height); VkhPresenter r = e->renderer; vkengine_set_key_callback (e, key_callback); + vkengine_set_mouse_but_callback(e, mouse_button_callback); + vkengine_set_cursor_pos_callback(e, mouse_move_callback); + vkengine_set_scroll_callback(e, scroll_callback); - device = vkvg_device_create (vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0); + bool deferredResolve = false; + + device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, VK_SAMPLE_COUNT_4_BIT, deferredResolve); surf = vkvg_surface_create(device, width, height); - //test_svg(); //test_grad_transforms(); //test_colinear(); + //simple_rectangle_stroke(); vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), width, height); @@ -1193,19 +1238,22 @@ int main(int argc, char *argv[]) { gettimeofday(&before , NULL); + //test_svg(); cairo_tests(); //random_rectangles(); //simple_rectangle_stroke(); //test_1(); //vkvg_surface_clear(surf); //simple_paint(); - //simple_rectangle_stroke(); + //simple_rectangle_fill(); //test_img_surface(); //multi_test1(); //test_painting(); //vkvg_surface_clear(surf); //lines_stroke(); + if (deferredResolve) + vkvg_multisample_surface_resolve(surf); if (!vkh_presenter_draw (r)) vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), width, height); diff --git a/tests/vkengine.c b/tests/vkengine.c index d005245..6d0f0ef 100644 --- a/tests/vkengine.c +++ b/tests/vkengine.c @@ -86,7 +86,7 @@ vk_engine_t* vkengine_create (VkPhysicalDeviceType preferedGPU, VkPresentModeKHR uint32_t enabledExtsCount = 0, phyCount = 0; const char ** enabledExts = glfwGetRequiredInstanceExtensions (&enabledExtsCount); - e->app = vkh_app_create("vkvgTest", (int)enabledExtsCount, enabledExts); + e->app = vkh_app_create("vkvgTest", enabledExtsCount, enabledExts); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); @@ -150,23 +150,15 @@ vk_engine_t* vkengine_create (VkPhysicalDeviceType preferedGPU, VkPresentModeKHR } char const * dex [] = {"VK_KHR_swapchain"}; -#if VKVG_USE_VALIDATION - uint32_t dlayCpt = 1; - static char const * dlay [] = {"VK_LAYER_LUNARG_standard_validation"}; -#else - uint32_t dlayCpt = 0; - static char const * dlay [] = {NULL}; -#endif + VkPhysicalDeviceFeatures enabledFeatures = { .fillModeNonSolid = true, - .sampleRateShading = true + //.sampleRateShading = true }; VkDeviceCreateInfo device_info = { .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, .queueCreateInfoCount = qCount, .pQueueCreateInfos = (VkDeviceQueueCreateInfo*)&pQueueInfos, - .enabledLayerCount = dlayCpt, - .ppEnabledLayerNames = dlay, .enabledExtensionCount = 1, .ppEnabledExtensionNames = dex, .pEnabledFeatures = &enabledFeatures @@ -175,6 +167,7 @@ vk_engine_t* vkengine_create (VkPhysicalDeviceType preferedGPU, VkPresentModeKHR VkDevice dev; VK_CHECK_RESULT(vkCreateDevice (pi->phy, &device_info, NULL, &dev)); e->dev = vkh_device_create(pi->phy, dev); + e->dev->instance = vkh_app_get_inst (e->app); e->renderer = vkh_presenter_create (e->dev, (uint32_t) pi->pQueue, surf, width, height, VK_FORMAT_B8G8R8A8_UNORM, presentMode); @@ -194,7 +187,7 @@ void vkengine_destroy (VkEngine e) { vkh_presenter_destroy (e->renderer); vkDestroySurfaceKHR (e->app->inst, surf, NULL); - vkDestroyDevice (e->dev->dev, NULL); + vkh_device_destroy (e->dev); glfwDestroyWindow (e->window); glfwTerminate (); diff --git a/vkh b/vkh index 012ca28..041a39c 160000 --- a/vkh +++ b/vkh @@ -1 +1 @@ -Subproject commit 012ca283a29bca6dd6b828406fe490ff356484f1 +Subproject commit 041a39cf003ece2604c167cb115c3210bde5c9b0 -- 2.47.3