Update libktx to 4.4.0

- Use UASTC textures instead of ASTC, transcode to ASTC or BC7 at load time
- Add cmake helpers to generate assets, optimize controller models
- Textures are resized to 512x512 and compressed in UASTC
- Always use libktx
This commit is contained in:
Guillaume Meunier
2025-10-23 21:39:12 +02:00
parent 8854b1b548
commit be6028982e
52 changed files with 668 additions and 627 deletions
+11 -2
View File
@@ -181,9 +181,13 @@ jobs:
vulkan-use-cache: true
- name: Install dependencies
run: >
run: |
sudo apt-get update && sudo apt-get install libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev libxcb-glx0-dev gettext libfontconfig-dev libboost-all-dev librsvg2-bin libssl-dev sway grim mesa-vulkan-drivers wayland-protocols fonts-noto-cjk fonts-roboto
wget https://github.com/KhronosGroup/KTX-Software/releases/download/v4.4.0/KTX-Software-4.4.0-Linux-x86_64.deb
sudo dpkg --install KTX-Software-4.4.0-Linux-x86_64.deb
npm install --global @gltf-transform/cli
- name: install server dependencies
run: >
sudo apt-get update && sudo apt-get install libavahi-glib-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libnotify-dev librsvg2-dev libarchive-dev
@@ -341,6 +345,7 @@ jobs:
sudo apt-get update && sudo apt-get install glslang-tools librsvg2-bin gettext
wget https://github.com/KhronosGroup/KTX-Software/releases/download/v4.3.2/KTX-Software-4.3.2-Linux-x86_64.deb
sudo dpkg --install KTX-Software-4.3.2-Linux-x86_64.deb
npm install --global @gltf-transform/cli
- name: Check for Secret availability
id: secret-check
@@ -470,7 +475,11 @@ jobs:
- name: Install dependencies
run: |
apt update
apt install --yes libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin dpkg-dev pkg-config debhelper-compat build-essential lintian cmake libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git wget libssl-dev qcoro-qt6-dev librsvg2-dev libarchive-dev
apt install --yes libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin dpkg-dev pkg-config debhelper-compat build-essential lintian cmake libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git wget libssl-dev qcoro-qt6-dev librsvg2-dev libarchive-dev npm
wget https://github.com/KhronosGroup/KTX-Software/releases/download/v4.3.2/KTX-Software-4.3.2-Linux-x86_64.deb
sudo dpkg --install KTX-Software-4.3.2-Linux-x86_64.deb
npm install --global @gltf-transform/cli
- uses: actions/checkout@v4
with:
+9 -1
View File
@@ -23,7 +23,7 @@ option(WIVRN_USE_SYSTEM_FREETYPE "Use system FreeType" ON)
option(WIVRN_USE_SYSTEM_BOOST "Use system Boost headers" ON)
option(WIVRN_USE_SYSTEM_OPENXR "Use system OpenXR headers" ON)
option(WIVRN_USE_SYSTEMD "Use libsystemd" ON)
option(WIVRN_USE_LIBKTX "Use libktx" ${ANDROID})
option(WIVRN_COMPRESS_GLB "Compress textures in GLB files with gltf-transform" ON)
option(WIVRN_USE_ANDROID_VALIDATION_LAYER "Download the android version of the Vulkan validation layer" OFF)
option(WIVRN_BUILD_CLIENT "Build WiVRn client" OFF)
option(WIVRN_BUILD_SERVER "Build WiVRn server" ON)
@@ -174,6 +174,14 @@ if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_DASHBOARD)
find_package(Gettext REQUIRED)
endif()
if (WIVRN_BUILD_CLIENT)
find_program(TOKTX toktx REQUIRED)
if (WIVRN_COMPRESS_GLB)
find_program(GLTF_TRANSFORM gltf-transform REQUIRED)
endif()
endif()
if (WIVRN_BUILD_CLIENT AND NOT ANDROID)
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET libavcodec libavutil libswscale libavfilter)
find_package(Fontconfig REQUIRED)

Before

Width:  |  Height:  |  Size: 1023 KiB

After

Width:  |  Height:  |  Size: 1023 KiB

Before

Width:  |  Height:  |  Size: 930 B

After

Width:  |  Height:  |  Size: 930 B

Binary file not shown.
@@ -70,9 +70,6 @@
"generator": "Aspose.3D 24.1.0",
"version": "2.0"
},
"extensionsUsed": [
"KHR_texture_basisu"
],
"buffers": [
{
"uri": "data:application/octet-stream;base64,AAABAAIAAwAEAAUAAAAAAAAAIMEAAAAAAAAgwQAAAAAAAIA/AAAAACUAgD8AAAAAAAAgwQAAAAAAACBBAACgQAAAgD8AAAAAJQCAPwAAAAAAACBBAAAAAAAAIMEAAAAAAACAwAAAAAAlAIA/AAAAAAAAIEEAAAAAAAAgQQAAoEAAAIDAAAAAACUAgD8AAAAAAAAgQQAAAAAAACDBAAAAAAAAgMAAAAAAJQCAPwAAAAAAACDBAAAAAAAAIEEAAKBAAACAPwAAAAAlAIA/AAAAAAAAAAA=",
@@ -82,9 +79,6 @@
"images": [
{
"uri": "WoodFloor051_1K-JPG_Color.jpg"
},
{
"uri": "WoodFloor051_1K-JPG_Color.ktx2"
}
],
"bufferViews": [
@@ -129,12 +123,7 @@
"textures": [
{
"sampler": 0,
"source": 0,
"extensions": {
"KHR_texture_basisu": {
"source": 1
}
}
"source": 0
}
],
"materials": [
Binary file not shown.
-148
View File
@@ -1,148 +0,0 @@
{
"asset":{
"generator":"Khronos glTF Blender I/O v4.2.70",
"version":"2.0"
},
"scene":0,
"scenes":[
{
"name":"Scene",
"nodes":[
0
]
}
],
"nodes":[
{
"mesh":0,
"name":"Cylinder",
"rotation":[
0.7071068286895752,
0,
0,
0.7071068286895752
],
"translation":[
0,
0,
-0.5
],
"scale":[0.7,1,0.7]
}
],
"materials":[
{
"name":"Material.001",
"pbrMetallicRoughness":{
"baseColorFactor":[0,0,0,0.5]
},
"emissiveTexture":{
"index":0
},
"emissiveFactor": [ 2.0, 2.0, 2.0 ]
}
],
"meshes":[
{
"name":"Cylinder.001",
"primitives":[
{
"attributes":{
"POSITION":0,
"NORMAL":1,
"TEXCOORD_0":2
},
"indices":3,
"material":0
}
]
}
],
"textures":[
{
"sampler":0,
"source":0
}
],
"images":[
{
"mimeType":"image/png",
"name":"Untitled",
"uri":"ray.png"
}
],
"accessors":[
{
"bufferView":0,
"componentType":5126,
"count":18,
"max":[
0.004000000189989805,
0.5,
0.004000000189989805
],
"min":[
-0.004000000189989805,
-0.5,
-0.004000000189989805
],
"type":"VEC3"
},
{
"bufferView":1,
"componentType":5126,
"count":18,
"type":"VEC3"
},
{
"bufferView":2,
"componentType":5126,
"count":18,
"type":"VEC2"
},
{
"bufferView":3,
"componentType":5123,
"count":48,
"type":"SCALAR"
}
],
"bufferViews":[
{
"buffer":0,
"byteLength":216,
"byteOffset":0,
"target":34962
},
{
"buffer":0,
"byteLength":216,
"byteOffset":216,
"target":34962
},
{
"buffer":0,
"byteLength":144,
"byteOffset":432,
"target":34962
},
{
"buffer":0,
"byteLength":96,
"byteOffset":576,
"target":34963
}
],
"samplers":[
{
"magFilter":9729,
"minFilter":9987
}
],
"buffers":[
{
"byteLength":672,
"uri":"ray.bin"
}
]
}
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
-148
View File
@@ -1,148 +0,0 @@
{
"asset":{
"generator":"Khronos glTF Blender I/O v4.2.70",
"version":"2.0"
},
"scene":0,
"scenes":[
{
"name":"Scene",
"nodes":[
0
]
}
],
"nodes":[
{
"mesh":0,
"name":"Cylinder",
"rotation":[
0.7071068286895752,
0,
0,
0.7071068286895752
],
"translation":[
0,
0,
-0.5
],
"scale":[0.7,1,0.7]
}
],
"materials":[
{
"name":"Material.001",
"pbrMetallicRoughness":{
"baseColorFactor":[0,0,0,0]
},
"emissiveTexture":{
"index":0
},
"emissiveFactor": [ 1.0, 1.0, 1.0 ]
}
],
"meshes":[
{
"name":"Cylinder.001",
"primitives":[
{
"attributes":{
"POSITION":0,
"NORMAL":1,
"TEXCOORD_0":2
},
"indices":3,
"material":0
}
]
}
],
"textures":[
{
"sampler":0,
"source":0
}
],
"images":[
{
"mimeType":"image/png",
"name":"Untitled",
"uri":"ray.png"
}
],
"accessors":[
{
"bufferView":0,
"componentType":5126,
"count":18,
"max":[
0.004000000189989805,
0.5,
0.004000000189989805
],
"min":[
-0.004000000189989805,
-0.5,
-0.004000000189989805
],
"type":"VEC3"
},
{
"bufferView":1,
"componentType":5126,
"count":18,
"type":"VEC3"
},
{
"bufferView":2,
"componentType":5126,
"count":18,
"type":"VEC2"
},
{
"bufferView":3,
"componentType":5123,
"count":48,
"type":"SCALAR"
}
],
"bufferViews":[
{
"buffer":0,
"byteLength":216,
"byteOffset":0,
"target":34962
},
{
"buffer":0,
"byteLength":216,
"byteOffset":216,
"target":34962
},
{
"buffer":0,
"byteLength":144,
"byteOffset":432,
"target":34962
},
{
"buffer":0,
"byteLength":96,
"byteOffset":576,
"target":34963
}
],
"samplers":[
{
"magFilter":9729,
"minFilter":9987
}
],
"buffers":[
{
"byteLength":672,
"uri":"ray.bin"
}
]
}
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 581 B

+22 -55
View File
@@ -7,11 +7,7 @@ set(KTX_FEATURE_LOADTEST_APPS OFF)
set(FASTGLTF_COMPILE_AS_CPP20 ON)
FetchContent_MakeAvailable(simdjson spdlog glm fastgltf imgui stb implot uni-algo entt)
if (WIVRN_USE_LIBKTX)
FetchContent_MakeAvailable(libktx)
endif()
FetchContent_MakeAvailable(simdjson spdlog glm fastgltf imgui stb implot uni-algo entt libktx)
if (NOT WIVRN_USE_SYSTEM_BOOST)
FetchContent_MakeAvailable(boost)
@@ -19,6 +15,7 @@ endif()
include(FreetypeHarfbuzz)
include(CompileGLSL)
include(GenerateAssets)
include(I18n)
add_library(stb INTERFACE)
@@ -99,6 +96,7 @@ target_link_libraries(wivrn
FreetypeHarfbuzz
glm::glm
imspinner
ktx_read
simdjson
spdlog::spdlog
stb
@@ -108,10 +106,6 @@ target_link_libraries(wivrn
wivrn-external
)
if (WIVRN_USE_LIBKTX)
target_link_libraries(wivrn ktx_read)
endif()
target_compile_definitions(wivrn PRIVATE -DXR_USE_GRAPHICS_API_VULKAN)
target_compile_definitions(wivrn PRIVATE -DVMA_STATS_STRING_ENABLED=0)
target_compile_definitions(wivrn PRIVATE -DGLM_ENABLE_EXPERIMENTAL)
@@ -224,62 +218,35 @@ endif()
##############################################################################
# Generate assets from SVGs
# Generate assets
#
file(REAL_PATH ${WIVRN_CSS} WIVRN_CSS_ABS BASE_DIRECTORY "${CMAKE_SOURCE_DIR}")
set(RSVG_OPTS "--stylesheet=${WIVRN_CSS_ABS}")
set(IMG_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../images)
set(AST_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../assets)
set(IMAGES_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../images)
set(ASSETS_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../assets-source)
add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn.png
COMMAND ${RSVG_CONVERT} ${IMG_SRC_DIR}/wivrn.svg -w 540 -h 540 -o ${ASSETS_DIR}/wivrn.png ${RSVG_OPTS}
DEPENDS ${IMG_SRC_DIR}/wivrn.svg ${WIVRN_CSS_ABS})
wivrn_rasterize_svg(SOURCE ${IMAGES_SRC_DIR}/wivrn.svg DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/wivrn.png WIDTH 540 HEIGHT 540 CSS ${WIVRN_CSS_ABS})
wivrn_rasterize_svg(SOURCE ${IMAGES_SRC_DIR}/wivrn-pride.svg DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/wivrn-pride.png WIDTH 540 HEIGHT 540 CSS ${WIVRN_CSS_ABS})
add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn-pride.png
COMMAND ${RSVG_CONVERT} ${IMG_SRC_DIR}/wivrn-pride.svg -w 540 -h 540 -o ${ASSETS_DIR}/wivrn-pride.png ${RSVG_OPTS}
DEPENDS ${IMG_SRC_DIR}/wivrn-pride.svg ${WIVRN_CSS_ABS})
wivrn_generate_ktx( SOURCE ${CMAKE_CURRENT_BINARY_DIR}/wivrn.png DESTINATION ${ASSETS_DIR}/wivrn.ktx2 TARGET wivrn)
wivrn_generate_ktx( SOURCE ${CMAKE_CURRENT_BINARY_DIR}/wivrn-pride.png DESTINATION ${ASSETS_DIR}/wivrn-pride.ktx2 TARGET wivrn)
wivrn_generate_ktx( SOURCE ${ASSETS_SRC_DIR}/default_icon.png DESTINATION ${ASSETS_DIR}/default_icon.ktx2 TARGET wivrn)
wivrn_gltf_transform_uastc(SOURCE ${ASSETS_SRC_DIR}/ground.glb DESTINATION ${ASSETS_DIR}/ground.glb TARGET wivrn ZSTD 20)
wivrn_webxr_controller( SOURCE ${ASSETS_SRC_DIR}/controllers/generic-trigger-squeeze DESTINATION ${ASSETS_DIR}/controllers/generic-trigger-squeeze TARGET wivrn)
wivrn_webxr_controller( SOURCE ${ASSETS_SRC_DIR}/controllers/htc-vive-focus-3 DESTINATION ${ASSETS_DIR}/controllers/htc-vive-focus-3 TARGET wivrn)
wivrn_webxr_controller( SOURCE ${ASSETS_SRC_DIR}/controllers/meta-quest-touch-plus DESTINATION ${ASSETS_DIR}/controllers/meta-quest-touch-plus TARGET wivrn)
wivrn_webxr_controller( SOURCE ${ASSETS_SRC_DIR}/controllers/meta-quest-touch-pro DESTINATION ${ASSETS_DIR}/controllers/meta-quest-touch-pro TARGET wivrn)
wivrn_webxr_controller( SOURCE ${ASSETS_SRC_DIR}/controllers/oculus-touch-v2 DESTINATION ${ASSETS_DIR}/controllers/oculus-touch-v2 TARGET wivrn)
wivrn_webxr_controller( SOURCE ${ASSETS_SRC_DIR}/controllers/oculus-touch-v3 DESTINATION ${ASSETS_DIR}/controllers/oculus-touch-v3 TARGET wivrn)
wivrn_webxr_controller( SOURCE ${ASSETS_SRC_DIR}/controllers/pico-4 DESTINATION ${ASSETS_DIR}/controllers/pico-4 TARGET wivrn)
wivrn_webxr_controller( SOURCE ${ASSETS_SRC_DIR}/controllers/pico-neo3 DESTINATION ${ASSETS_DIR}/controllers/pico-neo3 TARGET wivrn)
add_custom_target(assets ALL DEPENDS
${ASSETS_DIR}/wivrn.png
${ASSETS_DIR}/wivrn-pride.png
)
add_dependencies(wivrn assets)
# Add the VR splash screen (only used on Quest)
if(ANDROID)
find_program(TOKTX toktx REQUIRED)
add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn.ktx2
COMMAND ${TOKTX} --encode astc --astc_blk_d 4x4 --astc_quality 100 --genmipmap ${ASSETS_DIR}/wivrn.ktx2 ${ASSETS_DIR}/wivrn.png
DEPENDS ${ASSETS_DIR}/wivrn.png)
add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn-pride.ktx2
COMMAND ${TOKTX} --encode astc --astc_blk_d 4x4 --astc_quality 100 --genmipmap ${ASSETS_DIR}/wivrn-pride.ktx2 ${ASSETS_DIR}/wivrn-pride.png
DEPENDS ${ASSETS_DIR}/wivrn-pride.png)
add_custom_command(OUTPUT ${ASSETS_DIR}/default_icon.ktx2
COMMAND ${TOKTX} --encode astc --astc_blk_d 4x4 --astc_quality 100 --genmipmap ${ASSETS_DIR}/default_icon.ktx2 ${AST_SRC_DIR}/default_icon.png
DEPENDS ${AST_SRC_DIR}/default_icon.png)
add_custom_command(OUTPUT ${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2
COMMAND ${TOKTX} --encode astc --astc_blk_d 12x12 --astc_quality 100 --genmipmap ${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2 ${AST_SRC_DIR}/WoodFloor051_1K-JPG_Color.jpg
DEPENDS ${AST_SRC_DIR}/WoodFloor051_1K-JPG_Color.jpg)
add_custom_command(OUTPUT ${ASSETS_DIR}/vr_splash.png
COMMAND ${CMAKE_COMMAND} -E copy ${ASSETS_DIR}/wivrn.png ${ASSETS_DIR}/vr_splash.png
DEPENDS ${ASSETS_DIR}/wivrn.png)
add_custom_target(assets-android ALL DEPENDS
${ASSETS_DIR}/wivrn.ktx2
${ASSETS_DIR}/wivrn-pride.ktx2
${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2
${ASSETS_DIR}/vr_splash.png
)
add_dependencies(assets-android assets)
add_dependencies(wivrn assets-android)
wivrn_copy_file(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/wivrn.png DESTINATION ${ASSETS_DIR}/vr_splash.png TARGET wivrn)
endif()
##############################################################################
# Copy the assets to be able to find them when started from the build
# directory
+5
View File
@@ -357,6 +357,11 @@ public:
return instance().vk_instance;
}
static vk::raii::PhysicalDevice & get_physical_device()
{
return instance().vk_physical_device;
}
static xr::system & get_system()
{
return instance().xr_system_id;
+2 -2
View File
@@ -403,9 +403,9 @@ std::string controller_ray_model_name()
case model::htc_vive_xr_elite:
// XR Elite's runtime always assume alpha is unpremultiplied in the composition layers
// Assume it's the same for all HTC headsets
return "ray-htc.gltf";
return "ray-htc.glb";
default:
return "ray.gltf";
return "ray.glb";
}
}
+289 -151
View File
@@ -18,18 +18,21 @@
*/
#include "image_loader.h"
#include "wivrn_config.h"
#if WIVRN_USE_LIBKTX
#include <ktxvulkan.h>
#endif
#include "application.h"
#include "utils/thread_safe.h"
#include "vk/allocation.h"
#include "vk/vk_allocator.h"
#include <chrono>
#include <cstdint>
#include <ktx.h>
#include <ktxvulkan.h>
#include <memory>
#include <span>
#include <spdlog/fmt/chrono.h>
#include <spdlog/spdlog.h>
#include <stdexcept>
#include <tuple>
#include <vulkan/vulkan_raii.hpp>
#define STB_IMAGE_IMPLEMENTATION
@@ -48,28 +51,146 @@ namespace
{
struct image_resources
{
image_allocation allocation;
vk::Image image;
image_allocation image;
vk::raii::ImageView image_view = nullptr;
};
#if WIVRN_USE_LIBKTX
struct ktx_image_resources
class KTXTexture2
{
ktxVulkanTexture ktx_texture;
VkDevice device;
vk::Image image;
vk::raii::ImageView image_view = nullptr;
private:
ktxTexture2 * handle_ = nullptr;
ktx_image_resources() = default;
ktx_image_resources(const ktx_image_resources &) = delete;
ktx_image_resources & operator=(const ktx_image_resources &) = delete;
~ktx_image_resources()
public:
KTXTexture2() = default;
explicit KTXTexture2(ktxTexture2 * handle) :
handle_{handle} {}
KTXTexture2(const KTXTexture2 &) = delete;
KTXTexture2 & operator=(const KTXTexture2 &) = delete;
KTXTexture2(KTXTexture2 && other) noexcept :
handle_{other.handle_}
{
ktxVulkanTexture_Destruct(&ktx_texture, device, nullptr);
other.handle_ = nullptr;
}
KTXTexture2 & operator=(KTXTexture2 && other) &
{
std::swap(handle_, other.handle_);
return *this;
}
~KTXTexture2()
{
if (handle_)
{
ktxTexture_Destroy(ktxTexture(handle_));
handle_ = nullptr;
}
}
ktxTexture2 ** operator&()
{
return &handle_;
}
operator ktxTexture2 *()
{
return handle_;
}
ktxTexture2 * operator->() const
{
return handle_;
}
};
#endif
namespace libktx_vma_glue
{
thread_safe<std::map<uint64_t, VmaAllocation>> allocations;
uint64_t add(VmaAllocation allocation)
{
auto allocs = allocations.lock();
uint64_t allocation_id = allocs->empty() ? 1 : (allocs->rbegin()->first + 1);
allocs->emplace(allocation_id, allocation);
return allocation_id;
}
VmaAllocation find(uint64_t allocation_id)
{
auto allocs = allocations.lock();
auto iter = allocs->find(allocation_id);
assert(iter != allocs->end());
return iter->second;
}
VmaAllocation release(uint64_t allocation_id)
{
auto allocs = allocations.lock();
auto iter = allocs->find(allocation_id);
assert(iter != allocs->end());
VmaAllocation allocation = iter->second;
allocs->erase(iter);
return allocation;
}
VmaAllocation remove(uint64_t allocation_id)
{
auto allocs = allocations.lock();
auto iter = allocs->find(allocation_id);
assert(iter != allocs->end());
auto allocation = iter->second;
allocs->erase(iter);
return allocation;
}
ktxVulkanTexture_subAllocatorCallbacks suballocator_callbacks{
// Adapted from https://github.com/KhronosGroup/KTX-Software/blob/main/tests/loadtests/vkloadtests/VulkanLoadTestSample.cpp
.allocMemFuncPtr = [](VkMemoryAllocateInfo * allocation_info, VkMemoryRequirements * memory_requirements, uint64_t * number_of_pages) -> uint64_t {
VmaAllocationCreateInfo info{};
static const vk::PhysicalDeviceMemoryProperties memory_properties = application::instance().get_physical_device().getMemoryProperties();
if ((memory_properties.memoryTypes[allocation_info->memoryTypeIndex].propertyFlags & vk::MemoryPropertyFlagBits::eHostVisible) ||
(memory_properties.memoryTypes[allocation_info->memoryTypeIndex].propertyFlags & vk::MemoryPropertyFlagBits::eHostCoherent))
{
info.usage = VMA_MEMORY_USAGE_CPU_TO_GPU;
info.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT;
}
else
{
info.usage = VMA_MEMORY_USAGE_GPU_ONLY;
}
VmaAllocation allocation;
VkResult result = vmaAllocateMemory(vk_allocator::instance(), memory_requirements, &info, &allocation, nullptr);
if (result != VK_SUCCESS)
return 0;
return add(allocation);
},
.bindBufferFuncPtr = [](VkBuffer buffer, uint64_t allocation_id) -> VkResult { return vmaBindBufferMemory(vk_allocator::instance(), find(allocation_id), buffer); },
.bindImageFuncPtr = [](VkImage image, uint64_t allocation_id) -> VkResult { return vmaBindImageMemory(vk_allocator::instance(), find(allocation_id), image); },
.memoryMapFuncPtr = [](uint64_t allocation_id, uint64_t, VkDeviceSize * map_length, void ** data) -> VkResult {
auto allocation = find(allocation_id);
VmaAllocationInfo info{};
vmaGetAllocationInfo(vk_allocator::instance(), allocation, &info);
*map_length = info.size;
return vmaMapMemory(vk_allocator::instance(), allocation, data);
},
.memoryUnmapFuncPtr = [](uint64_t allocation_id, uint64_t) { vmaUnmapMemory(vk_allocator::instance(), find(allocation_id)); },
.freeMemFuncPtr = [](uint64_t allocation_id) { vmaFreeMemory(vk_allocator::instance(), remove(allocation_id)); },
};
} // namespace libktx_vma_glue
template <typename T>
constexpr vk::Format formats[4] = {vk::Format::eUndefined, vk::Format::eUndefined, vk::Format::eUndefined, vk::Format::eUndefined};
@@ -167,19 +288,37 @@ image_loader::image_loader(vk::raii::PhysicalDevice physical_device, vk::raii::D
queue(queue),
cb_pool(cb_pool)
{
#if WIVRN_USE_LIBKTX
ktxVulkanDeviceInfo_Construct(&vdi, *physical_device, *device, *queue.get_unsafe(), *cb_pool, nullptr);
#endif
std::array<std::tuple<vk::Format, ktx_transcode_fmt_e, bool>, 6> formats{{
{vk::Format::eAstc4x4SrgbBlock, KTX_TTF_ASTC_4x4_RGBA, true},
{vk::Format::eAstc4x4UnormBlock, KTX_TTF_ASTC_4x4_RGBA, false},
{vk::Format::eBc7SrgbBlock, KTX_TTF_BC7_RGBA, true},
{vk::Format::eBc7UnormBlock, KTX_TTF_BC7_RGBA, false},
{vk::Format::eR8G8B8A8Srgb, KTX_TTF_RGBA32, true},
{vk::Format::eR8G8B8Unorm, KTX_TTF_RGBA32, false},
}};
for (auto [vk_format, ktx_format, srgb]: formats)
{
auto prop = physical_device.getFormatProperties(vk_format);
if (prop.optimalTilingFeatures & vk::FormatFeatureFlagBits::eSampledImage)
{
if (srgb)
supported_srgb_formats.emplace_back(vk_format, ktx_format);
else
supported_linear_formats.emplace_back(vk_format, ktx_format);
}
}
}
image_loader::~image_loader()
{
#if WIVRN_USE_LIBKTX
ktxVulkanDeviceInfo_Destruct(&vdi);
#endif
}
void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::Format format)
loaded_image image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::Format format, const std::string & name)
{
auto cb = std::move(device.allocateCommandBuffers({
.commandPool = *cb_pool,
@@ -191,14 +330,7 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
assert(format != vk::Format::eUndefined);
this->format = format;
this->extent = extent;
if (extent.depth > 1)
image_view_type = vk::ImageViewType::e3D;
else
image_view_type = vk::ImageViewType::e2D;
num_mipmaps = std::floor(std::log2(std::max(extent.width, extent.height))) + 1;
uint32_t num_mipmaps = std::floor(std::log2(std::max(extent.width, extent.height))) + 1;
size_t byte_size = extent.width * extent.height * extent.depth * bytes_per_pixel(format);
@@ -212,14 +344,13 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
},
"image_loader::do_load (staging)"};
name + " (staging)"};
memcpy(staging_buffer.map(), pixels, byte_size);
staging_buffer.unmap();
// Allocate image
auto r = std::make_shared<image_resources>();
r->allocation = image_allocation{
image_allocation image{
device,
vk::ImageCreateInfo{
.imageType = vk::ImageType::e2D,
@@ -235,9 +366,7 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
.flags = 0,
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
},
"image_loader::do_load"};
r->image = (vk::Image)r->allocation;
name};
// Transition all mipmap levels layout to eTransferDstOptimal
cb.pipelineBarrier(
@@ -251,7 +380,7 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
.dstAccessMask = vk::AccessFlagBits::eTransferWrite,
.oldLayout = vk::ImageLayout::eUndefined,
.newLayout = vk::ImageLayout::eTransferDstOptimal,
.image = r->image,
.image = image,
.subresourceRange = {
.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = 0,
@@ -264,7 +393,7 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
// Copy image data
cb.copyBufferToImage(
staging_buffer,
r->image,
image,
vk::ImageLayout::eTransferDstOptimal,
vk::BufferImageCopy{
.bufferOffset = 0,
@@ -300,7 +429,7 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
.dstAccessMask = vk::AccessFlagBits::eShaderRead,
.oldLayout = vk::ImageLayout::eTransferDstOptimal,
.newLayout = vk::ImageLayout::eTransferSrcOptimal,
.image = r->image,
.image = image,
.subresourceRange = {
.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = level - 1,
@@ -312,9 +441,9 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
// Blit level n-1 to level n
cb.blitImage(
r->image,
image,
vk::ImageLayout::eTransferSrcOptimal,
r->image,
image,
vk::ImageLayout::eTransferDstOptimal,
vk::ImageBlit{
.srcSubresource = {.aspectMask = vk::ImageAspectFlagBits::eColor, .mipLevel = level - 1, .baseArrayLayer = 0, .layerCount = 1},
@@ -342,7 +471,7 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
.dstAccessMask = vk::AccessFlagBits::eShaderRead,
.oldLayout = vk::ImageLayout::eTransferSrcOptimal,
.newLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
.image = r->image,
.image = image,
.subresourceRange = {
.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = level - 1,
@@ -368,7 +497,7 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
.dstAccessMask = vk::AccessFlagBits::eShaderRead,
.oldLayout = vk::ImageLayout::eTransferDstOptimal,
.newLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
.image = r->image,
.image = image,
.subresourceRange = {
.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = num_mipmaps - 1,
@@ -386,10 +515,16 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
if (auto result = device.waitForFences(*fence, true, 1'000'000'000); result != vk::Result::eSuccess)
throw std::runtime_error("vkWaitForfences: " + vk::to_string(result));
r->image_view = vk::raii::ImageView{
vk::ImageViewType image_view_type;
if (extent.depth > 1)
image_view_type = vk::ImageViewType::e3D;
else
image_view_type = vk::ImageViewType::e2D;
vk::raii::ImageView image_view{
device,
vk::ImageViewCreateInfo{
.image = r->image,
.image = image,
.viewType = image_view_type,
.format = format,
.subresourceRange = {
@@ -402,76 +537,79 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
},
};
image_view = std::shared_ptr<vk::raii::ImageView>(r, &r->image_view);
return loaded_image{
.image = std::move(image),
.image_view = std::move(image_view),
.format = format,
.extent = extent,
.num_mipmaps = num_mipmaps,
.image_view_type = image_view_type,
};
}
void image_loader::do_load_ktx(std::span<const std::byte> bytes)
loaded_image image_loader::do_load_ktx(std::span<const std::byte> bytes, bool srgb, const std::string & name)
{
#if WIVRN_USE_LIBKTX
ktxTexture * texture;
KTXTexture2 texture{};
// KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT checks that the file is compatible with the KHR_texture_basisu glTF extension
// ktxResult err = ktxTexture2_CreateFromMemory(reinterpret_cast<const uint8_t *>(bytes.data()), bytes.size(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &texture);
ktxResult err = ktxTexture2_CreateFromMemory(reinterpret_cast<const uint8_t *>(bytes.data()), bytes.size(), 0, &texture);
// ktxResult err = ktxTexture2_CreateFromMemory(reinterpret_cast<const uint8_t *>(bytes.data()), bytes.size(), KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT | KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &texture);
if (err != KTX_SUCCESS)
{
spdlog::warn("ktxTexture2_CreateFromMemory: error {}", ktxErrorString(err));
throw std::runtime_error("ktxTexture2_CreateFromMemory");
}
if (ktxTexture2_NeedsTranscoding(texture))
{
auto format = srgb ? supported_srgb_formats.front() : supported_linear_formats.front();
auto t0 = std::chrono::steady_clock::now();
if (ktxTexture2_TranscodeBasis(texture, format.second, 0) != KTX_SUCCESS)
{
spdlog::warn("ktxTexture2_TranscodeBasis: error {}", ktxErrorString(err));
throw std::runtime_error("ktxTexture2_TranscodeBasis");
}
auto dt = std::chrono::steady_clock::now() - t0;
spdlog::debug("{}: transcoded to {} in {}", name, vk::to_string(format.first), std::chrono::duration_cast<std::chrono::microseconds>(dt));
}
ktxVulkanTexture vk_texture;
ktxResult err = ktxTexture_CreateFromMemory(reinterpret_cast<const uint8_t *>(bytes.data()), bytes.size(), /*KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT*/ 0, &texture);
if (err != KTX_SUCCESS)
{
spdlog::warn("ktxTexture_CreateFromMemory: error {}", (int)err);
throw std::runtime_error("ktxTexture_CreateFromMemory");
}
auto _ = queue.lock(); // ktxTexture2_VkUploadEx uses the queue internally (in ktxTexture_VkUploadEx_WithSuballocator)
if (ktxTexture_NeedsTranscoding(texture))
{
// TODO
spdlog::warn("ktxTexture_NeedsTranscoding");
throw std::runtime_error("ktxTexture_NeedsTranscoding");
}
{
auto _ = queue.lock(); // ktxTexture_VkUploadEx uses the queue internally (in ktxTexture_VkUploadEx_WithSuballocator)
// TODO: patch vkloader.c to accept a mutex
err = ktxTexture_VkUploadEx(texture, &vdi, &vk_texture, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
err = ktxTexture2_VkUploadEx_WithSuballocator(texture, &vdi, &vk_texture, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, &libktx_vma_glue::suballocator_callbacks);
}
if (err != KTX_SUCCESS)
{
// TODO try uncompressing the texture
ktxTexture_Destroy(texture);
spdlog::warn("ktxTexture_CreateFromMemory: error {}", (int)err);
throw std::runtime_error("ktxTexture_VkUploadEx");
spdlog::warn("ktxTexture2_VkUploadEx: {}", ktxErrorString(err));
throw std::runtime_error("ktxTexture2_VkUploadEx");
}
format = vk::Format(vk_texture.imageFormat);
extent = vk::Extent3D(texture->baseWidth, texture->baseHeight, texture->baseDepth);
image_view_type = vk::ImageViewType(vk_texture.viewType);
num_mipmaps = texture->numLevels;
ktxTexture_Destroy(texture);
auto r = std::make_shared<ktx_image_resources>();
r->ktx_texture = vk_texture;
r->device = *device;
r->image = vk::Image(vk_texture.image);
r->image_view = vk::raii::ImageView{
device,
vk::ImageViewCreateInfo{
.image = r->image,
.viewType = image_view_type,
.format = format,
.subresourceRange = {
.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = 0,
.levelCount = num_mipmaps,
.baseArrayLayer = 0,
.layerCount = 1,
},
},
return loaded_image{
.image{libktx_vma_glue::release(vk_texture.allocationId), device, vk_texture.image, name}, // Take over ownership of vk_texture, do not call ktxTexture2_destruct
.image_view{
device,
vk::ImageViewCreateInfo{
.image = vk_texture.image,
.viewType = vk::ImageViewType(vk_texture.viewType),
.format = vk::Format(vk_texture.imageFormat),
.subresourceRange = {
.aspectMask = vk::ImageAspectFlagBits::eColor,
.baseMipLevel = 0,
.levelCount = texture->numLevels,
.baseArrayLayer = 0,
.layerCount = 1,
},
}},
.format = vk::Format(vk_texture.imageFormat),
.extent{vk::Extent3D(texture->baseWidth, texture->baseHeight, texture->baseDepth)},
.num_mipmaps = texture->numLevels,
.image_view_type = vk::ImageViewType(vk_texture.viewType),
};
image_view = std::shared_ptr<vk::raii::ImageView>(r, &r->image_view);
#else
throw std::runtime_error("Compiled without KTX support");
#endif
}
static constexpr bool starts_with(std::span<const std::byte> data, std::span<const uint8_t> prefix)
@@ -514,67 +652,67 @@ static void premultiply_alpha(void * pixels, vk::Extent3D extent, vk::Format for
}
}
loaded_image image_loader::do_load_image(std::span<const std::byte> bytes, bool srgb, const std::string & name)
{
const stbi_uc * image_data = (const stbi_uc *)bytes.data();
size_t image_size = bytes.size();
int w, h, num_channels, channels_in_file;
stbi_ptr pixels;
if (!stbi_info_from_memory(image_data, image_size, &w, &h, &num_channels))
throw std::runtime_error("Unsupported image format");
assert(num_channels >= 1 && num_channels <= 4);
if (num_channels == 3)
num_channels = 4;
vk::Format format;
if (stbi_is_hdr_from_memory(image_data, image_size))
{
pixels = stbi_ptr(stbi_loadf_from_memory(image_data, image_size, &w, &h, &channels_in_file, num_channels));
format = get_format<float>(num_channels);
}
else if (stbi_is_16_bit_from_memory(image_data, image_size))
{
pixels = stbi_ptr(stbi_load_16_from_memory(image_data, image_size, &w, &h, &channels_in_file, num_channels));
format = get_format<uint16_t>(num_channels);
}
else
{
pixels = stbi_ptr(stbi_load_from_memory(image_data, image_size, &w, &h, &channels_in_file, num_channels));
format = srgb ? get_format_srgb(num_channels) : get_format<uint8_t>(num_channels);
}
vk::Extent3D extent{
.width = uint32_t(w),
.height = uint32_t(h),
.depth = 1,
};
premultiply_alpha(pixels.get(), extent, format);
return do_load_raw(pixels.get(), extent, format, name);
}
// Load a PNG/JPEG/KTX2 file
void image_loader::load(std::span<const std::byte> bytes, bool srgb)
loaded_image image_loader::load(std::span<const std::byte> bytes, bool srgb, const std::string & name)
{
const uint8_t ktx1_magic[] = {0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A};
const uint8_t ktx2_magic[] = {0xAB, 0x4B, 0x54, 0x58, 0x20, 0x32, 0x30, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A};
if (starts_with(bytes, ktx1_magic) || starts_with(bytes, ktx2_magic))
{
do_load_ktx(bytes);
}
return do_load_ktx(bytes, srgb, name);
else
{
const stbi_uc * image_data = (const stbi_uc *)bytes.data();
size_t image_size = bytes.size();
int w, h, num_channels, channels_in_file;
stbi_ptr pixels;
if (!stbi_info_from_memory(image_data, image_size, &w, &h, &num_channels))
throw std::runtime_error("Unsupported image format");
assert(num_channels >= 1 && num_channels <= 4);
if (num_channels == 3)
num_channels = 4;
if (stbi_is_hdr_from_memory(image_data, image_size))
{
pixels = stbi_ptr(stbi_loadf_from_memory(image_data, image_size, &w, &h, &channels_in_file, num_channels));
format = get_format<float>(num_channels);
}
else if (stbi_is_16_bit_from_memory(image_data, image_size))
{
pixels = stbi_ptr(stbi_load_16_from_memory(image_data, image_size, &w, &h, &channels_in_file, num_channels));
format = get_format<uint16_t>(num_channels);
}
else
{
pixels = stbi_ptr(stbi_load_from_memory(image_data, image_size, &w, &h, &channels_in_file, num_channels));
format = srgb ? get_format_srgb(num_channels) : get_format<uint8_t>(num_channels);
}
extent.width = w;
extent.height = h;
extent.depth = 1;
premultiply_alpha(pixels.get(), extent, format);
do_load_raw(pixels.get(), extent, format);
}
return do_load_image(bytes, srgb, name);
}
// Load raw pixel data
void image_loader::load(const void * pixels, size_t size, vk::Extent3D extent_, vk::Format format_)
loaded_image image_loader::load(const void * pixels, size_t size, vk::Extent3D extent, vk::Format format, const std::string & name)
{
extent = extent_;
format = format_;
image_view_type = vk::ImageViewType::e2D;
if (size < extent.width * extent.height * extent.depth * bytes_per_pixel(format))
throw std::invalid_argument("size");
do_load_raw(pixels, extent_, format_);
return do_load_raw(pixels, extent, format, name);
}
+26 -29
View File
@@ -22,73 +22,70 @@
#include "utils/thread_safe.h"
#include "vk/allocation.h"
#include "vk/fwd.h"
#include "wivrn_config.h"
#include <cstddef>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <memory>
#include <ktxvulkan.h>
#include <span>
#include <vector>
#include <vulkan/vulkan.hpp>
#if WIVRN_USE_LIBKTX
#include <ktxvulkan.h>
#endif
struct loaded_image
{
image_allocation image;
vk::raii::ImageView image_view;
vk::Format format;
vk::Extent3D extent;
uint32_t num_mipmaps;
vk::ImageViewType image_view_type;
};
struct image_loader
{
vk::Image image;
vk::Format format;
vk::Extent3D extent;
vk::ImageViewType image_view_type;
std::shared_ptr<vk::raii::ImageView> image_view;
uint32_t num_mipmaps;
image_loader(vk::raii::PhysicalDevice physical_device, vk::raii::Device & device, thread_safe<vk::raii::Queue> & queue, vk::raii::CommandPool & cb_pool);
image_loader(const image_loader &) = delete;
image_loader & operator=(const image_loader &) = delete;
~image_loader();
// Load a PNG/JPEG/KTX2 file
void load(std::span<const std::byte> bytes, bool srgb);
loaded_image load(std::span<const std::byte> bytes, bool srgb, const std::string & name = "");
// Load raw pixel data
void load(const void * pixels, size_t size, vk::Extent3D extent, vk::Format format);
loaded_image load(const void * pixels, size_t size, vk::Extent3D extent, vk::Format format, const std::string & name = "");
template <typename T>
void load(std::span<T> pixels, vk::Extent3D extent, vk::Format format)
loaded_image load(std::span<T> pixels, vk::Extent3D extent, vk::Format format, const std::string & name = "")
{
load(pixels.data(), pixels.size() * sizeof(T), extent, format);
return load(pixels.data(), pixels.size() * sizeof(T), extent, format, name);
}
template <typename T, size_t N>
void load(const std::array<T, N> & pixels, vk::Extent3D extent, vk::Format format)
loaded_image load(const std::array<T, N> & pixels, vk::Extent3D extent, vk::Format format, const std::string & name = "")
{
load(pixels.data(), pixels.size() * sizeof(T), extent, format);
return load(pixels.data(), pixels.size() * sizeof(T), extent, format, name);
}
template <typename T>
void load(const std::vector<T> & pixels, vk::Extent3D extent, vk::Format format)
loaded_image load(const std::vector<T> & pixels, vk::Extent3D extent, vk::Format format, const std::string & name = "")
{
load(pixels.data(), pixels.size() * sizeof(T), extent, format);
return load(pixels.data(), pixels.size() * sizeof(T), extent, format, name);
}
private:
#if WIVRN_USE_LIBKTX
ktxVulkanDeviceInfo vdi;
#endif
vk::raii::Device & device;
thread_safe<vk::raii::Queue> & queue;
vk::raii::CommandPool & cb_pool;
std::vector<std::pair<vk::Format, ktx_transcode_fmt_e>> supported_srgb_formats;
std::vector<std::pair<vk::Format, ktx_transcode_fmt_e>> supported_linear_formats;
buffer_allocation staging_buffer;
void do_load_raw(const void * pixels, vk::Extent3D extent, vk::Format format);
loaded_image do_load_raw(const void * pixels, vk::Extent3D extent, vk::Format format, const std::string & name);
void do_load_ktx(std::span<const std::byte> bytes);
void create_image_view();
loaded_image do_load_image(std::span<const std::byte> bytes, bool srgb, const std::string & name);
loaded_image do_load_ktx(std::span<const std::byte> bytes, bool srgb, const std::string & name);
};
+9 -8
View File
@@ -1034,20 +1034,21 @@ imgui_context::~imgui_context()
ImTextureID imgui_textures::load_texture(const std::string & filename, vk::raii::Sampler && sampler)
{
return load_texture(std::span<const std::byte>{asset{filename}}, std::move(sampler));
return load_texture(std::span<const std::byte>{asset{filename}}, std::move(sampler), filename);
}
ImTextureID imgui_textures::load_texture(const std::span<const std::byte> & bytes, vk::raii::Sampler && sampler)
ImTextureID imgui_textures::load_texture(const std::span<const std::byte> & bytes, vk::raii::Sampler && sampler, const std::string & name)
{
bool srgb = true;
// TODO: reuse the image loader
image_loader loader(physical_device, device, queue, command_pool);
loader.load(bytes, srgb);
auto image = loader.load(bytes, srgb, name);
std::shared_ptr<vk::raii::DescriptorSet> ds = descriptor_pool.allocate();
vk::DescriptorImageInfo image_info{
.sampler = *sampler,
.imageView = **loader.image_view,
.imageView = *image.image_view,
.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
};
@@ -1065,15 +1066,14 @@ ImTextureID imgui_textures::load_texture(const std::span<const std::byte> & byte
id,
texture_data{
.sampler = std::move(sampler),
// .image = std::move(loader.image),
.image_view = std::move(loader.image_view),
.image = std::move(image),
.descriptor_set = std::move(ds),
});
return id;
}
ImTextureID imgui_textures::load_texture(const std::span<const std::byte> & bytes)
ImTextureID imgui_textures::load_texture(const std::span<const std::byte> & bytes, const std::string & name)
{
return load_texture(
bytes,
@@ -1088,7 +1088,8 @@ ImTextureID imgui_textures::load_texture(const std::span<const std::byte> & byte
.addressModeW = vk::SamplerAddressMode::eClampToEdge,
.borderColor = vk::BorderColor::eFloatTransparentBlack,
},
});
},
name);
}
ImTextureID imgui_textures::load_texture(const std::string & filename)
+4 -3
View File
@@ -18,6 +18,7 @@
#pragma once
#include "image_loader.h"
#include "render/growable_descriptor_pool.h"
#include "utils/thread_safe.h"
#include "wivrn_config.h"
@@ -41,7 +42,7 @@ class imgui_textures
struct texture_data
{
vk::raii::Sampler sampler;
std::shared_ptr<vk::raii::ImageView> image_view;
loaded_image image;
std::shared_ptr<vk::raii::DescriptorSet> descriptor_set;
};
@@ -64,8 +65,8 @@ public:
thread_safe<vk::raii::Queue> & queue);
ImTextureID load_texture(const std::string & filename, vk::raii::Sampler && sampler);
ImTextureID load_texture(const std::string & filename);
ImTextureID load_texture(const std::span<const std::byte> & bytes, vk::raii::Sampler && sampler);
ImTextureID load_texture(const std::span<const std::byte> & bytes);
ImTextureID load_texture(const std::span<const std::byte> & bytes, vk::raii::Sampler && sampler, const std::string & name = "");
ImTextureID load_texture(const std::span<const std::byte> & bytes, const std::string & name = "");
void free_texture(ImTextureID);
};
+61 -40
View File
@@ -257,37 +257,30 @@ fastgltf::MimeType guess_mime_type(std::span<const std::byte> image_data)
return fastgltf::MimeType::None;
}
std::shared_ptr<vk::raii::ImageView> do_load_image(
loaded_image do_load_image(
vk::raii::PhysicalDevice & physical_device,
vk::raii::Device & device,
thread_safe<vk::raii::Queue> & queue,
vk::raii::CommandPool & cb_pool,
std::span<const std::byte> image_data,
bool srgb)
bool srgb,
const std::pmr::string & name)
{
switch (guess_mime_type(image_data))
{
case fastgltf::MimeType::JPEG:
case fastgltf::MimeType::PNG:
case fastgltf::MimeType::KTX2: {
try
{
image_loader loader(physical_device, device, queue, cb_pool);
loader.load(image_data, srgb);
// TODO reuse image loader
image_loader loader(physical_device, device, queue, cb_pool);
auto image = loader.load(image_data, srgb, name.c_str());
spdlog::debug("Loaded image {}x{}, format {}, {} mipmaps", loader.extent.width, loader.extent.height, vk::to_string(loader.format), loader.num_mipmaps);
return loader.image_view;
}
catch (std::exception & e)
{
spdlog::info("Cannot load image: {}", e.what());
return {};
}
spdlog::debug("{}: {}x{}, format {}, {} mipmaps, {} bytes", name, image.extent.width, image.extent.height, vk::to_string(image.format), image.num_mipmaps, image.image.size());
return image;
}
default:
spdlog::error("Unsupported image MIME type");
return {};
throw std::runtime_error{"Unsupported image MIME type"};
}
}
// END
@@ -313,6 +306,7 @@ fastgltf::Asset load_gltf_asset(fastgltf::GltfDataBuffer & buffer, const std::fi
class loader_context
{
std::filesystem::path base_directory;
std::string name;
fastgltf::Asset & gltf;
vk::raii::PhysicalDevice physical_device;
vk::raii::Device & device;
@@ -322,17 +316,27 @@ class loader_context
std::vector<asset> loaded_assets;
asset & load_from_asset(const std::filesystem::path & path)
{
return loaded_assets.emplace_back(path);
try
{
return loaded_assets.emplace_back(path);
}
catch (std::exception & e)
{
spdlog::error("{}: error loading {}: {}", name, path.native(), e.what());
throw;
}
}
public:
loader_context(std::filesystem::path base_directory,
std::string name,
fastgltf::Asset & gltf,
vk::raii::PhysicalDevice physical_device,
vk::raii::Device & device,
thread_safe<vk::raii::Queue> & queue,
vk::raii::CommandPool & cb_pool) :
base_directory(base_directory),
base_directory(std::move(base_directory)),
name(std::move(name)),
gltf(gltf),
physical_device(physical_device),
device(device),
@@ -422,18 +426,20 @@ public:
if (it != images.end())
return it->second;
try
{
auto [image_data, mime_type] = visit_source(gltf.images[index].data);
auto image = do_load_image(physical_device, device, queue, cb_pool, image_data, srgb);
if (index > gltf.images.size())
throw std::runtime_error(std::format("Image index {} out of range", index));
images.emplace(index, image);
return image;
}
catch (...)
{
return nullptr;
}
auto [image_data, mime_type] = visit_source(gltf.images[index].data);
std::pmr::string image_name;
if (gltf.images[index].name == "")
image_name = std::format("{}(image {})", name, index);
else
image_name = std::format("{}({})", name, gltf.images[index].name);
auto image_ptr = std::make_shared<loaded_image>(do_load_image(physical_device, device, queue, cb_pool, image_data, srgb, image_name));
return std::shared_ptr<vk::raii::ImageView>(image_ptr, &image_ptr->image_view);
}
std::vector<std::shared_ptr<renderer::texture>> load_all_textures()
@@ -457,16 +463,21 @@ public:
auto & texture_ref = *textures.emplace_back(std::make_shared<renderer::texture>());
if (gltf_texture.samplerIndex)
{
fastgltf::Sampler & sampler = gltf.samplers.at(*gltf_texture.samplerIndex);
texture_ref.sampler = convert(sampler);
}
texture_ref.sampler = convert(gltf.samplers.at(*gltf_texture.samplerIndex));
std::vector<std::string> errors;
if (gltf_texture.basisuImageIndex)
{
texture_ref.image_view = load_image(*gltf_texture.basisuImageIndex, srgb);
if (texture_ref.image_view)
try
{
texture_ref.image_view = load_image(*gltf_texture.basisuImageIndex, srgb);
continue;
}
catch (std::exception & e)
{
errors.push_back(std::format("Cannot load image {}: {}", *gltf_texture.basisuImageIndex, e.what()));
}
}
// if (gltf_texture.ddsImageIndex)
@@ -481,11 +492,21 @@ public:
if (gltf_texture.imageIndex)
{
texture_ref.image_view = load_image(*gltf_texture.imageIndex, srgb);
if (texture_ref.image_view)
try
{
texture_ref.image_view = load_image(*gltf_texture.imageIndex, srgb);
continue;
}
catch (std::exception & e)
{
errors.push_back(std::format("Cannot load image {}: {}", *gltf_texture.imageIndex, e.what()));
}
}
spdlog::error("{}: cannot load texture {}:", name, name);
for (auto & error: errors)
spdlog::error(" {}", error);
throw std::runtime_error("Unsupported image type");
}
@@ -515,7 +536,6 @@ public:
// Copy the default material, without references to its buffer or descriptor set
auto & material_ref = *materials.emplace_back(std::make_shared<renderer::material>(default_material));
material_ref.name = gltf_material.name;
spdlog::info("Loading material \"{}\"", material_ref.name);
material_ref.buffer.reset();
material_ref.ds.reset();
@@ -699,7 +719,8 @@ public:
} // namespace
renderer::vertex::description renderer::vertex::describe()
renderer::vertex::description
renderer::vertex::describe()
{
renderer::vertex::description desc;
@@ -759,7 +780,7 @@ entt::registry scene_loader::operator()(const std::filesystem::path & gltf_path)
data_buffer.copyBytes(reinterpret_cast<const uint8_t *>(asset_file.data()), asset_file.size());
fastgltf::Asset asset = load_gltf_asset(data_buffer, gltf_path.parent_path());
loader_context ctx(gltf_path.parent_path(), asset, physical_device, device, queue, cb_pool);
loader_context ctx(gltf_path.parent_path(), gltf_path, asset, physical_device, device, queue, cb_pool);
#ifndef NDEBUG
if (auto error = fastgltf::validate(asset); error != fastgltf::Error::None)
+9 -8
View File
@@ -76,7 +76,7 @@ vk::Format scene_renderer::find_usable_image_format(
return vk::Format::eUndefined;
}
std::shared_ptr<renderer::texture> scene_renderer::create_default_texture(vk::raii::CommandPool & cb_pool, std::vector<uint8_t> pixel)
std::shared_ptr<renderer::texture> scene_renderer::create_default_texture(vk::raii::CommandPool & cb_pool, std::vector<uint8_t> pixel, const std::string & name)
{
vk::Format format;
@@ -96,10 +96,11 @@ std::shared_ptr<renderer::texture> scene_renderer::create_default_texture(vk::ra
__builtin_unreachable();
}
// TODO reuse image loader
image_loader loader(physical_device, device, queue, cb_pool);
loader.load(pixel, vk::Extent3D{1, 1, 1}, format);
auto image = std::make_shared<loaded_image>(loader.load(pixel, vk::Extent3D{1, 1, 1}, format, name));
std::shared_ptr<vk::raii::ImageView> image_view = loader.image_view;
std::shared_ptr<vk::raii::ImageView> image_view{image, &image->image_view};
return std::make_shared<renderer::texture>(image_view, renderer::sampler_info{});
}
@@ -109,11 +110,11 @@ std::shared_ptr<renderer::material> scene_renderer::create_default_material(vk::
auto default_material = std::make_shared<renderer::material>();
default_material->name = "default";
default_material->base_color_texture = create_default_texture(cb_pool, {255, 255, 255, 255});
default_material->metallic_roughness_texture = create_default_texture(cb_pool, {255, 255});
default_material->occlusion_texture = create_default_texture(cb_pool, {255});
default_material->emissive_texture = create_default_texture(cb_pool, {0, 0, 0, 0});
default_material->normal_texture = create_default_texture(cb_pool, {128, 128, 255, 255});
default_material->base_color_texture = create_default_texture(cb_pool, {255, 255, 255, 255}, "Default base color");
default_material->metallic_roughness_texture = create_default_texture(cb_pool, {255, 255}, "Default metallic roughness map");
default_material->occlusion_texture = create_default_texture(cb_pool, {255}, "Default occlusion map");
default_material->emissive_texture = create_default_texture(cb_pool, {0, 0, 0, 0}, "Default emissive color");
default_material->normal_texture = create_default_texture(cb_pool, {128, 128, 255, 255}, "Default normal map");
default_material->buffer = std::make_shared<buffer_allocation>(
device,
+1 -1
View File
@@ -125,7 +125,7 @@ class scene_renderer
vk::raii::PipelineLayout create_pipeline_layout(std::span<vk::DescriptorSetLayout> layouts);
vk::raii::Pipeline create_pipeline(const pipeline_info & info);
std::shared_ptr<renderer::texture> create_default_texture(vk::raii::CommandPool & cb_pool, std::vector<uint8_t> pixel);
std::shared_ptr<renderer::texture> create_default_texture(vk::raii::CommandPool & cb_pool, std::vector<uint8_t> pixel, const std::string & name);
std::shared_ptr<renderer::material> create_default_material(vk::raii::CommandPool & cb_pool);
vk::raii::DescriptorSetLayout create_descriptor_set_layout(std::span<vk::DescriptorSetLayoutBinding> bindings, vk::DescriptorSetLayoutCreateFlags flags = {});
+1 -8
View File
@@ -100,14 +100,7 @@ app_launcher::app_launcher(
stream.queue_family_index,
stream.queue)
{
try
{
default_icon = textures.load_texture("default_icon.ktx2");
}
catch (...)
{
default_icon = textures.load_texture("default_icon.png");
}
default_icon = textures.load_texture("default_icon.ktx2");
}
app_launcher::~app_launcher()
+3 -9
View File
@@ -799,7 +799,7 @@ void scenes::lobby::on_focused()
renderer.emplace(device, physical_device, queue, commandpool);
loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material());
lobby_entity = load_gltf("ground.gltf", layer_lobby).first;
lobby_entity = load_gltf("ground.glb", layer_lobby).first;
std::string profile = controller_name();
input.emplace(
@@ -913,14 +913,8 @@ void scenes::lobby::on_focused()
auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
auto tm = std::localtime(&t);
std::string image = tm->tm_mon == 5 ? "wivrn-pride" : "wivrn";
try
{
about_picture = imgui_ctx->load_texture(image + ".ktx2");
}
catch (...)
{
about_picture = imgui_ctx->load_texture(image + ".png");
}
about_picture = imgui_ctx->load_texture(image + ".ktx2");
setup_passthrough();
session.set_refresh_rate(application::get_config().preferred_refresh_rate.value_or(0));
+159
View File
@@ -0,0 +1,159 @@
function(add_file_to_target TARGET OUTPUT_FILE)
string(REPLACE "/" "_" TARGET_SUFFIX ${OUTPUT_FILE})
add_custom_target(${TARGET}-${TARGET_SUFFIX} ALL DEPENDS ${OUTPUT_FILE})
add_dependencies(${TARGET} ${TARGET}-${TARGET_SUFFIX})
endfunction()
function(wivrn_generate_ktx)
set(options)
set(oneValueArgs SOURCE DESTINATION TARGET)
set(multiValueArgs)
cmake_parse_arguments(PARSE_ARGV 0 arg "${options}" "${oneValueArgs}" "${multiValueArgs}")
cmake_path(GET arg_DESTINATION PARENT_PATH DEST_DIR)
file(MAKE_DIRECTORY ${DEST_DIR})
add_custom_command(OUTPUT ${arg_DESTINATION}
COMMAND ${TOKTX} --encode uastc --uastc_quality 4 --genmipmap --zcmp 20 ${arg_DESTINATION} ${arg_SOURCE}
DEPENDS ${arg_SOURCE})
if (DEFINED arg_TARGET)
add_file_to_target(${arg_TARGET} ${arg_DESTINATION})
endif()
endfunction()
function(wivrn_rasterize_svg)
set(options)
set(oneValueArgs SOURCE DESTINATION TARGET CSS WIDTH HEIGHT)
set(multiValueArgs)
cmake_parse_arguments(PARSE_ARGV 0 arg "${options}" "${oneValueArgs}" "${multiValueArgs}")
set(RSVG_OPTS)
if(arg_WIDTH)
set(RSVG_OPTS ${RSVG_OPTS} --width ${arg_WIDTH})
endif()
if(arg_HEIGHT)
set(RSVG_OPTS ${RSVG_OPTS} --height ${arg_HEIGHT})
endif()
if(arg_CSS)
set(RSVG_OPTS ${RSVG_OPTS} --stylesheet ${arg_CSS})
endif()
cmake_path(GET arg_DESTINATION PARENT_PATH DEST_DIR)
file(MAKE_DIRECTORY ${DEST_DIR})
add_custom_command(OUTPUT ${arg_DESTINATION}
COMMAND ${RSVG_CONVERT} ${arg_SOURCE} ${RSVG_OPTS} -o ${arg_DESTINATION}
DEPENDS ${arg_SOURCE} ${arg_CSS})
if (DEFINED arg_TARGET)
add_file_to_target(${arg_TARGET} ${arg_DESTINATION})
endif()
endfunction()
function(wivrn_gltf_transform_uastc)
set(options)
set(oneValueArgs SOURCE DESTINATION TARGET ZSTD)
set(multiValueArgs)
cmake_parse_arguments(PARSE_ARGV 0 arg "${options}" "${oneValueArgs}" "${multiValueArgs}")
set(ARGS)
if (DEFINED arg_ZSTD)
set(ARGS ${ARGS} --zstd ${arg_ZSTD})
endif()
cmake_path(GET arg_DESTINATION PARENT_PATH DEST_DIR)
file(MAKE_DIRECTORY ${DEST_DIR})
add_custom_command(OUTPUT ${arg_DESTINATION}
COMMAND ${GLTF_TRANSFORM} uastc ${ARGS} ${arg_SOURCE} ${arg_DESTINATION}
DEPENDS ${arg_SOURCE})
if (DEFINED arg_TARGET)
add_file_to_target(${arg_TARGET} ${arg_DESTINATION})
endif()
endfunction()
function(wivrn_gltf_transform_resize)
set(options)
set(oneValueArgs SOURCE DESTINATION TARGET WIDTH HEIGHT)
set(multiValueArgs)
cmake_parse_arguments(PARSE_ARGV 0 arg "${options}" "${oneValueArgs}" "${multiValueArgs}")
set(ARGS)
if (DEFINED arg_WIDTH)
set(ARGS ${ARGS} --width ${arg_WIDTH})
endif()
if (DEFINED arg_HEIGHT)
set(ARGS ${ARGS} --height ${arg_HEIGHT})
endif()
cmake_path(GET arg_DESTINATION PARENT_PATH DEST_DIR)
file(MAKE_DIRECTORY ${DEST_DIR})
add_custom_command(OUTPUT ${arg_DESTINATION}
COMMAND ${GLTF_TRANSFORM} resize ${ARGS} ${arg_SOURCE} ${arg_DESTINATION}
DEPENDS ${arg_SOURCE})
if (DEFINED arg_TARGET)
add_file_to_target(${arg_TARGET} ${arg_DESTINATION})
endif()
endfunction()
function(wivrn_copy_file)
set(options)
set(oneValueArgs SOURCE DESTINATION TARGET)
set(multiValueArgs)
cmake_parse_arguments(PARSE_ARGV 0 arg "${options}" "${oneValueArgs}" "${multiValueArgs}")
cmake_path(GET arg_DESTINATION PARENT_PATH DEST_DIR)
file(MAKE_DIRECTORY ${DEST_DIR})
add_custom_command(OUTPUT ${arg_DESTINATION}
COMMAND ${CMAKE_COMMAND} -E copy ${arg_SOURCE} ${arg_DESTINATION}
DEPENDS ${arg_SOURCE})
if (DEFINED arg_TARGET)
add_file_to_target(${arg_TARGET} ${arg_DESTINATION})
endif()
endfunction()
function(wivrn_webxr_controller)
set(options)
set(oneValueArgs SOURCE DESTINATION TARGET)
set(multiValueArgs)
cmake_parse_arguments(PARSE_ARGV 0 arg "${options}" "${oneValueArgs}" "${multiValueArgs}")
file(READ ${arg_SOURCE}/profile.json PROFILE_JSON)
string(JSON NB_LAYOUTS LENGTH "${PROFILE_JSON}" layouts)
math(EXPR NB_LAYOUTS "${NB_LAYOUTS} - 1")
string(JSON PROFILE_ID GET "${PROFILE_JSON}" profileId)
foreach(I RANGE ${NB_LAYOUTS})
string(JSON LAYOUT_NAME MEMBER "${PROFILE_JSON}" layouts ${I})
string(JSON ASSET_PATH GET "${PROFILE_JSON}" layouts ${LAYOUT_NAME} assetPath)
if(WIVRN_COMPRESS_GLB)
set(TEMPFILE ${PROFILE_ID}-${LAYOUT_NAME}.glb)
wivrn_gltf_transform_resize(SOURCE ${arg_SOURCE}/${ASSET_PATH} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${TEMPFILE} WIDTH 512 HEIGHT 512)
wivrn_gltf_transform_uastc(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${TEMPFILE} DESTINATION ${arg_DESTINATION}/${ASSET_PATH} ZSTD 20 TARGET ${arg_TARGET})
else()
wivrn_copy_file(SOURCE ${arg_SOURCE}/${ASSET_PATH} DESTINATION ${arg_DESTINATION}/${ASSET_PATH} TARGET ${arg_TARGET})
endif()
endforeach()
wivrn_copy_file(SOURCE ${arg_SOURCE}/profile.json DESTINATION ${arg_DESTINATION}/profile.json TARGET ${arg_TARGET})
endfunction()
+56 -1
View File
@@ -125,7 +125,7 @@ public:
std::tie(resource, allocation) = traits::create(device, create_info, alloc_info);
}
basic_allocation(vk::raii::Device & device, const CreateInfo & create_info, VmaAllocationCreateInfo alloc_info, const std::string & name) :
basic_allocation(vk::raii::Device & device, const CreateInfo & create_info, const VmaAllocationCreateInfo & alloc_info, const std::string & name) :
create_info(create_info)
{
std::tie(resource, allocation) = traits::create(device, create_info, alloc_info);
@@ -139,6 +139,54 @@ public:
});
}
basic_allocation(VmaAllocation allocation, RaiiType && resource) :
allocation(allocation), resource(std::move(resource))
{}
basic_allocation(VmaAllocation allocation, vk::raii::Device & device, RaiiType::CppType resource) :
allocation(allocation), resource(RaiiType{device, resource})
{}
basic_allocation(VmaAllocation allocation, vk::raii::Device & device, RaiiType::CType resource) :
allocation(allocation), resource(RaiiType{device, resource})
{}
basic_allocation(VmaAllocation allocation, vk::raii::Device & device, RaiiType && resource, const std::string & name) :
allocation(allocation), resource(std::move(resource))
{
vmaSetAllocationName(vk_allocator::instance(), allocation, name.c_str());
if (vk_allocator::instance().has_debug_utils)
device.setDebugUtilsObjectNameEXT(vk::DebugUtilsObjectNameInfoEXT{
.objectType = T::objectType,
.objectHandle = uint64_t(CType(*resource)),
.pObjectName = name.c_str(),
});
}
basic_allocation(VmaAllocation allocation, vk::raii::Device & device, RaiiType::CppType resource, const std::string & name) :
allocation(allocation), resource(RaiiType{device, resource})
{
vmaSetAllocationName(vk_allocator::instance(), allocation, name.c_str());
if (vk_allocator::instance().has_debug_utils)
device.setDebugUtilsObjectNameEXT(vk::DebugUtilsObjectNameInfoEXT{
.objectType = T::objectType,
.objectHandle = uint64_t(CType(*resource)),
.pObjectName = name.c_str(),
});
}
basic_allocation(VmaAllocation allocation, vk::raii::Device & device, RaiiType::CType resource, const std::string & name) :
allocation(allocation), resource(RaiiType{device, resource})
{
vmaSetAllocationName(vk_allocator::instance(), allocation, name.c_str());
if (vk_allocator::instance().has_debug_utils)
device.setDebugUtilsObjectNameEXT(vk::DebugUtilsObjectNameInfoEXT{
.objectType = T::objectType,
.objectHandle = uint64_t(resource),
.pObjectName = name.c_str(),
});
}
basic_allocation(const basic_allocation &) = delete;
basic_allocation(basic_allocation && other) :
allocation(other.allocation),
@@ -184,6 +232,13 @@ public:
mapped = nullptr;
}
vk::DeviceSize size() const
{
VmaAllocationInfo info{};
vmaGetAllocationInfo(vk_allocator::instance(), allocation, &info);
return info.size;
}
template <typename U = uint8_t>
U * data()
{
-1
View File
@@ -42,7 +42,6 @@ static const int default_port = 9757;
#cmakedefine01 WIVRN_SHOW_IMGUI_DEMO_WINDOW
#cmakedefine01 WIVRN_CLIENT_DEBUG_MENU
#cmakedefine01 WIVRN_USE_LIBKTX
#define WIVRN_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@"
#define OVR_COMPAT_SEARCH_PATH "@OVR_COMPAT_SEARCH_PATH@"