From 9c7388ff1572dfac7cf067c1b406102e2d45e694 Mon Sep 17 00:00:00 2001 From: Matteo De Carlo Date: Fri, 23 Feb 2024 21:48:32 +0100 Subject: [PATCH] blender exporter improvements --- BlenderExporter/python_bindings.cpp | 6 ++- BlenderExporter/test.py | 8 +++ .../wicked_blender_exporter/__init__.py | 2 +- CMakeLists.txt | 36 +++++++++++-- WickedEngine/BULLET/CMakeLists.txt | 2 +- WickedEngine/CMakeLists.txt | 27 +++++----- WickedEngine/LUA/CMakeLists.txt | 2 +- WickedEngine/Utility/CMakeLists.txt | 4 +- WickedEngine/Utility/FAudio/CMakeLists.txt | 4 +- WickedEngine/Utility/robin_hood.h | 6 ++- WickedEngine/wiECS.h | 3 +- WickedEngine/wiFont.h | 4 +- WickedEngine/wiGraphicsDevice.h | 14 ++--- WickedEngine/wiGraphicsDevice_DX12.cpp | 15 +++--- WickedEngine/wiGraphicsDevice_Vulkan.cpp | 36 +++++++------ WickedEngine/wiRenderer.h | 24 ++++----- WickedEngine/wiScene.cpp | 53 ++++++++++--------- WickedEngine/wiScene.h | 10 ++-- WickedEngine/wiTerrain.cpp | 5 +- 19 files changed, 158 insertions(+), 103 deletions(-) diff --git a/BlenderExporter/python_bindings.cpp b/BlenderExporter/python_bindings.cpp index 5831277266..f5ed8fbc8d 100644 --- a/BlenderExporter/python_bindings.cpp +++ b/BlenderExporter/python_bindings.cpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace py = pybind11; @@ -36,6 +37,7 @@ void init_wicked(py::module_& mod) mod.def("init", []() { + return; if (INIT_DONE) return; INIT_DONE = true; @@ -56,8 +58,8 @@ void init_wicked(py::module_& mod) } app.SetWindow(sdl_window.get()); - wi::renderer::SetShaderSourcePath(WICKED_ROOT_DIR"/WickedEngine/shaders/"); - wi::renderer::SetShaderPath(WICKED_ROOT_DIR"/build/BlenderExporter/shaders/"); + wi::renderer::SetShaderSourcePath(std::string{WICKED_ROOT_DIR"/WickedEngine/shaders/"}); + wi::renderer::SetShaderPath(std::string{WICKED_ROOT_DIR"/build/BlenderExporter/shaders/"}); //wi::initializer::InitializeComponentsImmediate(); app.Initialize(); diff --git a/BlenderExporter/test.py b/BlenderExporter/test.py index 1e9ebf2068..864923dea1 100755 --- a/BlenderExporter/test.py +++ b/BlenderExporter/test.py @@ -1,10 +1,16 @@ #!/usr/bin/env python3 +import os +import sys +importpath=os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(importpath, "wicked_blender_exporter")) import pywickedengine dump_to_header = False def main(): + pywickedengine.init() + filename = "/tmp/test.wiscene" ar = pywickedengine.Archive() if dump_to_header else pywickedengine.Archive(filename, False) if not ar.IsOpen(): @@ -19,5 +25,7 @@ def main(): ar.Close() + pywickedengine.deinit() + if __name__ == "__main__": main() diff --git a/BlenderExporter/wicked_blender_exporter/__init__.py b/BlenderExporter/wicked_blender_exporter/__init__.py index 9b9e705c50..06055db691 100644 --- a/BlenderExporter/wicked_blender_exporter/__init__.py +++ b/BlenderExporter/wicked_blender_exporter/__init__.py @@ -22,7 +22,7 @@ 'description': 'Addon to add wiscene export to file functionality.', 'tracker_url': "https://github.com/turanszkij/WickedEngine/issues/", 'isDraft': True, - 'developer': "Matteo De Carlo", # Replace this + 'developer': "Matteo De Carlo", 'url': 'https://github.com/turanszkij/WickedEngine/', } diff --git a/CMakeLists.txt b/CMakeLists.txt index 46682e002f..c3bed4a1e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,20 +2,22 @@ cmake_minimum_required(VERSION 3.8) set(WICKED_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -option(WICKED_DYNAMIC_LIBRARY "Build WickedEngine as a dynamic library" OFF) +include(CMakeDependentOption) +option(WICKED_PIC_CODE "Build WickedEngine as portable code, to include in a dynamic library" OFF) +cmake_dependent_option(WICKED_DYNAMIC_LIBRARY "Build WickedEngine as a dynamic library" OFF "WICKED_PIC_CODE" OFF) option(USE_LIBCXX "Link WickedEngine to llvm libc++ library - only available with the Clang compiler" OFF) option(WICKED_EDITOR "Build WickedEngine editor" ON) option(WICKED_TESTS "Build WickedEngine tests" ON) option(WICKED_IMGUI_EXAMPLE "Build WickedEngine imgui example" ON) option(WICKED_LINUX_TEMPLATE "Build WickedEngine Linux template" ON) -option(BLENDER_EXPORTER "Build blender wiscene exporter plugin" OFF) - +cmake_dependent_option(BLENDER_EXPORTER "Build blender wiscene exporter plugin" OFF "WICKED_PIC_CODE" OFF) # Configure CMake global variables set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +set(THREADS_PREFER_PTHREAD_FLAG ON) # Use solution folders to organize projects set_property(GLOBAL PROPERTY USE_FOLDERS ON) @@ -31,6 +33,25 @@ elseif(UNIX) set(PLATFORM "SDL2") add_compile_definitions(SDL2=1) set(DXC_TARGET "dxc") + + + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdeclspec -fms-extensions -fmodules -fbuiltin-module-map") + #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdeclspec -fms-extensions -stdlib=libc++ -fmodules -fbuiltin-module-map") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi") + if (CMAKE_CXX_COMPILER_VERSION LESS 16 ) + message(FATAL_ERROR "Clang supported only from version 16") + elseif (CMAKE_CXX_COMPILER_VERSION EQUAL 16) + # Default to C++ extensions being off. Clang16's modules support have trouble + # with extensions right now and it is not required for any other compiler + set(CMAKE_CXX_EXTENSIONS OFF) + endif() + #if (CMAKE_CXX_COMPILER_VERSION LESS 18 ) + # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wread-modules-implicitly") + #endif() + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + endif() endif() @@ -49,25 +70,30 @@ endif() add_subdirectory(WickedEngine) if (WICKED_EDITOR) + message("Building Wicked Editor") add_subdirectory(Editor) endif() if (WICKED_TESTS) + message("Building Wicked Tests") add_subdirectory(Tests) endif() if (WICKED_IMGUI_EXAMPLE) + message("Building IMGUI Examples") add_subdirectory(Example_ImGui) add_subdirectory(Example_ImGui_Docking) endif() if (WICKED_LINUX_TEMPLATE) + message("Building Linux Template") add_subdirectory(Template_Linux) endif() if (BLENDER_EXPORTER) - if (NOT ${WICKED_DYNAMIC_LIBRARY}) - message(FATAL_ERROR "WICKED_DYNAMIC_LIBRARY required to build blender exporter") + if (NOT ${WICKED_PIC_CODE}) + message(FATAL_ERROR "WICKED_PIC_CODE required to build blender exporter") endif() + message("Building Blender Exporter") add_subdirectory(BlenderExporter) endif() diff --git a/WickedEngine/BULLET/CMakeLists.txt b/WickedEngine/BULLET/CMakeLists.txt index 341f1f3dca..82ca867a7f 100644 --- a/WickedEngine/BULLET/CMakeLists.txt +++ b/WickedEngine/BULLET/CMakeLists.txt @@ -459,5 +459,5 @@ target_include_directories(Bullet SYSTEM PUBLIC set_target_properties(Bullet PROPERTIES FOLDER "ThirdParty" - POSITION_INDEPENDENT_CODE ${WICKED_DYNAMIC_LIBRARY} + POSITION_INDEPENDENT_CODE ${WICKED_PIC_CODE} ) diff --git a/WickedEngine/CMakeLists.txt b/WickedEngine/CMakeLists.txt index 2970fd5808..fd68eb758d 100644 --- a/WickedEngine/CMakeLists.txt +++ b/WickedEngine/CMakeLists.txt @@ -235,7 +235,10 @@ add_library(${TARGET_NAME} ${WICKED_LIBRARY_TYPE} ${HEADER_FILES} ) add_library(WickedEngine ALIAS ${TARGET_NAME}) -set_target_properties(${TARGET_NAME} PROPERTIES PUBLIC_HEADER "${HEADER_FILES}") +set_target_properties(${TARGET_NAME} PROPERTIES + PUBLIC_HEADER "${HEADER_FILES}" + POSITION_INDEPENDENT_CODE ${WICKED_PIC_CODE} +) target_include_directories(${TARGET_NAME} SYSTEM PUBLIC $ @@ -269,17 +272,17 @@ else () set(WICKEDENGINE_STATIC_LIBRARIES ${WICKEDENGINE_STATIC_LIBRARIES} FAudio) if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_compile_options(${TARGET_NAME} PRIVATE - -Wuninitialized - #-Wwrite-strings - #-Winit-self - #-Wreturn-type - #-Wreorder - #-Werror=delete-non-virtual-dtor - #-Werror - #uncomment this to stop the compilation at the first error - # -Wfatal-errors - ) + target_compile_options(${TARGET_NAME} PRIVATE + -Wuninitialized + -Wwrite-strings + -Winit-self + -Wreturn-type + -Wreorder + -Werror=delete-non-virtual-dtor + #-Werror + #uncomment this to stop the compilation at the first error + # -Wfatal-errors + ) elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # add some warnings and set them as errors # read more details here: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html diff --git a/WickedEngine/LUA/CMakeLists.txt b/WickedEngine/LUA/CMakeLists.txt index b0eb071d7a..e583248d7e 100644 --- a/WickedEngine/LUA/CMakeLists.txt +++ b/WickedEngine/LUA/CMakeLists.txt @@ -71,7 +71,7 @@ endif() set_target_properties(LUA PROPERTIES FOLDER "ThirdParty" - POSITION_INDEPENDENT_CODE ${WICKED_DYNAMIC_LIBRARY} + POSITION_INDEPENDENT_CODE ${WICKED_PIC_CODE} ) install(FILES ${LUA_HEADERS} diff --git a/WickedEngine/Utility/CMakeLists.txt b/WickedEngine/Utility/CMakeLists.txt index 6ad733f8a7..958088bbd1 100644 --- a/WickedEngine/Utility/CMakeLists.txt +++ b/WickedEngine/Utility/CMakeLists.txt @@ -96,7 +96,7 @@ set(HEADER_FILES_vulkan install(FILES ${HEADER_FILES_vulkan} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/WickedEngine/Utility/vulkan/") - + set(HEADER_FILES_vk_video ${CMAKE_CURRENT_SOURCE_DIR}/vulkan/vk_video/vulkan_video_codec_h264std.h ${CMAKE_CURRENT_SOURCE_DIR}/vulkan/vk_video/vulkan_video_codec_h264std_decode.h @@ -139,5 +139,5 @@ add_library(Utility STATIC set_target_properties("Utility" PROPERTIES FOLDER "ThirdParty" - POSITION_INDEPENDENT_CODE ${WICKED_DYNAMIC_LIBRARY} + POSITION_INDEPENDENT_CODE ${WICKED_PIC_CODE} ) diff --git a/WickedEngine/Utility/FAudio/CMakeLists.txt b/WickedEngine/Utility/FAudio/CMakeLists.txt index 09b4cae2cf..45969bcbfb 100644 --- a/WickedEngine/Utility/FAudio/CMakeLists.txt +++ b/WickedEngine/Utility/FAudio/CMakeLists.txt @@ -1,6 +1,6 @@ # CMake Project for FAudio # Written by @NeroBurner -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.5) project(FAudio C) # Options @@ -94,7 +94,7 @@ set_target_properties(FAudio PROPERTIES OUTPUT_NAME "FAudio" VERSION ${LIB_VERSION} SOVERSION ${LIB_MAJOR_VERSION} - POSITION_INDEPENDENT_CODE ${WICKED_DYNAMIC_LIBRARY} + POSITION_INDEPENDENT_CODE ${WICKED_PIC_CODE} ) # SDL2 Dependency diff --git a/WickedEngine/Utility/robin_hood.h b/WickedEngine/Utility/robin_hood.h index 111d5f68c9..b316347e1a 100644 --- a/WickedEngine/Utility/robin_hood.h +++ b/WickedEngine/Utility/robin_hood.h @@ -207,7 +207,11 @@ static Counts& counts() { // workaround missing "is_trivially_copyable" in g++ < 5.0 // See https://stackoverflow.com/a/31798726/48181 #if defined(__GNUC__) && __GNUC__ < 5 -# define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) __has_trivial_copy(__VA_ARGS__) + #if defined(__is_trivially_copyable) + # define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) __is_trivially_copyable(__VA_ARGS__) + #else + # define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) __has_trivial_copy(__VA_ARGS__) + #endif #else # define ROBIN_HOOD_IS_TRIVIALLY_COPYABLE(...) std::is_trivially_copyable<__VA_ARGS__>::value #endif diff --git a/WickedEngine/wiECS.h b/WickedEngine/wiECS.h index d9f20d67d8..b9550d9033 100644 --- a/WickedEngine/wiECS.h +++ b/WickedEngine/wiECS.h @@ -23,9 +23,10 @@ namespace wi::ecs using Entity = uint32_t; inline constexpr Entity INVALID_ENTITY = 0; // Runtime can create a new entity with this + + extern std::atomic next;//{ INVALID_ENTITY + 1 }; inline Entity CreateEntity() { - static std::atomic next{ INVALID_ENTITY + 1 }; return next.fetch_add(1); } diff --git a/WickedEngine/wiFont.h b/WickedEngine/wiFont.h index 7b552136e9..8d247850d7 100644 --- a/WickedEngine/wiFont.h +++ b/WickedEngine/wiFont.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "CommonInclude.h" #include "wiGraphicsDevice.h" #include "wiColor.h" @@ -19,7 +19,7 @@ namespace wi::font WIFALIGN_BOTTOM // bottom alignment (vertical) }; - static constexpr int WIFONTSIZE_DEFAULT = 16; + inline constexpr int WIFONTSIZE_DEFAULT = 16; struct Cursor { diff --git a/WickedEngine/wiGraphicsDevice.h b/WickedEngine/wiGraphicsDevice.h index 6510b3eae8..191034ff01 100644 --- a/WickedEngine/wiGraphicsDevice.h +++ b/WickedEngine/wiGraphicsDevice.h @@ -23,10 +23,10 @@ namespace wi::graphics // Descriptor binding counts: // It's OK increase these limits if not enough // But it's better to refactor shaders to use bindless descriptors if they require more resources - static constexpr uint32_t DESCRIPTORBINDER_CBV_COUNT = 14; - static constexpr uint32_t DESCRIPTORBINDER_SRV_COUNT = 16; - static constexpr uint32_t DESCRIPTORBINDER_UAV_COUNT = 16; - static constexpr uint32_t DESCRIPTORBINDER_SAMPLER_COUNT = 8; + inline static constexpr uint32_t DESCRIPTORBINDER_CBV_COUNT = 14; + inline static constexpr uint32_t DESCRIPTORBINDER_SRV_COUNT = 16; + inline static constexpr uint32_t DESCRIPTORBINDER_UAV_COUNT = 16; + inline static constexpr uint32_t DESCRIPTORBINDER_SAMPLER_COUNT = 8; struct DescriptorBindingTable { GPUBuffer CBV[DESCRIPTORBINDER_CBV_COUNT]; @@ -270,7 +270,7 @@ namespace wi::graphics inline bool IsValid() const { return data != nullptr && buffer.IsValid(); } }; - // Allocates temporary memory that the CPU can write and GPU can read. + // Allocates temporary memory that the CPU can write and GPU can read. // It is only alive for one frame and automatically invalidated after that. GPUAllocation AllocateGPU(uint64_t dataSize, CommandList cmd) { @@ -355,13 +355,13 @@ namespace wi::graphics }; + extern GraphicsDevice* static_device; // This is a helper to get access to a global device instance // - The engine uses this, but it is not necessary to use a single global device object // - This is not a lifetime managing object, just a way to globally expose a reference to an object by pointer inline GraphicsDevice*& GetDevice() { - static GraphicsDevice* device = nullptr; - return device; + return static_device; } } diff --git a/WickedEngine/wiGraphicsDevice_DX12.cpp b/WickedEngine/wiGraphicsDevice_DX12.cpp index 3313d57a38..a8e96ee855 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.cpp +++ b/WickedEngine/wiGraphicsDevice_DX12.cpp @@ -34,6 +34,9 @@ using namespace Microsoft::WRL; namespace wi::graphics { + + GraphicsDevice* static_device = nullptr; + namespace dx12_internal { // Bindless allocation limits: @@ -1003,7 +1006,7 @@ namespace dx12_internal constexpr TextureDesc _ConvertTextureDesc_Inv(const D3D12_RESOURCE_DESC& desc) { TextureDesc retVal; - + switch (desc.Dimension) { case D3D12_RESOURCE_DIMENSION_TEXTURE1D: @@ -1610,7 +1613,7 @@ namespace dx12_internal } using namespace dx12_internal; - + void GraphicsDevice_DX12::CopyAllocator::init(GraphicsDevice_DX12* device) { @@ -4315,7 +4318,7 @@ using namespace dx12_internal; { internal_state->desc.Flags |= D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_MINIMIZE_MEMORY; } - + switch (desc->type) { @@ -4349,7 +4352,7 @@ using namespace dx12_internal; } else if (x.type == RaytracingAccelerationStructureDesc::BottomLevel::Geometry::Type::PROCEDURAL_AABBS) { - geometry.Type = D3D12_RAYTRACING_GEOMETRY_TYPE_PROCEDURAL_PRIMITIVE_AABBS; + geometry.Type = D3D12_RAYTRACING_GEOMETRY_TYPE_PROCEDURAL_PRIMITIVE_AABBS; geometry.AABBs.AABBs.StartAddress = to_internal(&x.aabbs.aabb_buffer)->gpu_address + (D3D12_GPU_VIRTUAL_ADDRESS)x.aabbs.offset; geometry.AABBs.AABBs.StrideInBytes = (UINT64)x.aabbs.stride; @@ -5210,7 +5213,7 @@ using namespace dx12_internal; const void* identifier = internal_state->stateObjectProperties->GetShaderIdentifier(internal_state->group_strings[group_index].c_str()); std::memcpy(dest, identifier, D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES); } - + void GraphicsDevice_DX12::SetName(GPUResource* pResource, const char* name) const { wchar_t text[256]; @@ -7212,7 +7215,7 @@ using namespace dx12_internal; if (x.type == RaytracingAccelerationStructureDesc::BottomLevel::Geometry::Type::TRIANGLES) { - geometry.Triangles.VertexBuffer.StartAddress = to_internal(&x.triangles.vertex_buffer)->gpu_address + + geometry.Triangles.VertexBuffer.StartAddress = to_internal(&x.triangles.vertex_buffer)->gpu_address + (D3D12_GPU_VIRTUAL_ADDRESS)x.triangles.vertex_byte_offset; geometry.Triangles.IndexBuffer = to_internal(&x.triangles.index_buffer)->gpu_address + (D3D12_GPU_VIRTUAL_ADDRESS)x.triangles.index_offset * (x.triangles.index_format == IndexBufferFormat::UINT16 ? sizeof(uint16_t) : sizeof(uint32_t)); diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.cpp b/WickedEngine/wiGraphicsDevice_Vulkan.cpp index daa2ed40ea..f98986ece0 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.cpp +++ b/WickedEngine/wiGraphicsDevice_Vulkan.cpp @@ -33,6 +33,8 @@ namespace wi::graphics { + GraphicsDevice* static_device = nullptr; + namespace vulkan_internal { // These shifts are made so that Vulkan resource bindings slots don't interfere with each other across shader stages: @@ -600,7 +602,7 @@ namespace vulkan_internal } VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessengerCallback( - VkDebugUtilsMessageSeverityFlagBitsEXT message_severity, + VkDebugUtilsMessageSeverityFlagBitsEXT message_severity, VkDebugUtilsMessageTypeFlagsEXT message_type, const VkDebugUtilsMessengerCallbackDataEXT* callback_data, void* user_data) @@ -2411,7 +2413,7 @@ using namespace vulkan_internal; } } #endif // _WIN32 - + if (validationMode != ValidationMode::Disabled) { // Determine the optimal validation layers to enable that are necessary for useful debugging @@ -2902,7 +2904,7 @@ using namespace vulkan_internal; queueFamiliesVideo[i].sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_VIDEO_PROPERTIES_KHR; } vkGetPhysicalDeviceQueueFamilyProperties2(physicalDevice, &queueFamilyCount, queueFamilies.data()); - + // Query base queue families: for (uint32_t i = 0; i < queueFamilyCount; ++i) { @@ -3147,7 +3149,7 @@ using namespace vulkan_internal; res = vmaCreateBuffer(allocationhandler->allocator, &bufferInfo, &allocInfo, &nullBuffer, &nullBufferAllocation, nullptr); assert(res == VK_SUCCESS); - + VkBufferViewCreateInfo viewInfo = {}; viewInfo.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; viewInfo.format = VK_FORMAT_R32G32B32A32_SFLOAT; @@ -3350,7 +3352,7 @@ using namespace vulkan_internal; // Try to read pipeline cache file if exists. wi::vector pipelineData; - std::string cachePath = GetCachePath(); + std::string cachePath = GetCachePath(); if (!wi::helper::FileRead(cachePath, pipelineData)) { pipelineData.clear(); @@ -3614,7 +3616,7 @@ using namespace vulkan_internal; res = vkGetPipelineCacheData(device, pipelineCache, &size, nullptr); assert(res == VK_SUCCESS); - // Get data of pipeline cache + // Get data of pipeline cache wi::vector data(size); res = vkGetPipelineCacheData(device, pipelineCache, &size, data.data()); assert(res == VK_SUCCESS); @@ -3623,7 +3625,7 @@ using namespace vulkan_internal; std::string cachePath = GetCachePath(); wi::helper::FileWrite(cachePath, data.data(), size); - // Destroy Vulkan pipeline cache + // Destroy Vulkan pipeline cache vkDestroyPipelineCache(device, pipelineCache, nullptr); pipelineCache = VK_NULL_HANDLE; } @@ -4006,7 +4008,7 @@ using namespace vulkan_internal; dependencyInfo.pBufferMemoryBarriers = &barrier; vkCmdPipelineBarrier2(cmd.transitionCommandBuffer, &dependencyInfo); - + copyAllocator.submit(cmd); } } @@ -5380,7 +5382,7 @@ using namespace vulkan_internal; default: break; } - + } VkPipelineLayoutCreateInfo pipelineLayoutInfo = {}; @@ -6359,7 +6361,7 @@ using namespace vulkan_internal; info.referencePictureFormat = info.pictureFormat; info.pVideoProfile = &video_capability_h264.profile; info.pStdHeaderVersion = &video_capability_h264.video_capabilities.stdHeaderVersion; - + res = vkCreateVideoSessionKHR(device, &info, nullptr, &internal_state->video_session); assert(res == VK_SUCCESS); @@ -6940,7 +6942,7 @@ using namespace vulkan_internal; VkResult res = vkGetRayTracingShaderGroupHandlesKHR(device, to_internal(rtpso)->pipeline, group_index, 1, SHADER_IDENTIFIER_SIZE, dest); assert(res == VK_SUCCESS); } - + void GraphicsDevice_Vulkan::SetName(GPUResource* pResource, const char* name) const { if (!debugUtils || pResource == nullptr || !pResource->IsValid()) @@ -7246,7 +7248,7 @@ using namespace vulkan_internal; } allocationhandler->destroylocker.unlock(); - // Destroy Vulkan pipeline cache + // Destroy Vulkan pipeline cache vkDestroyPipelineCache(device, pipelineCache, nullptr); pipelineCache = VK_NULL_HANDLE; @@ -7562,7 +7564,7 @@ using namespace vulkan_internal; assert(0); } commandlist.prev_swapchains.push_back(*swapchain); - + VkRenderingInfo info = {}; info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO; info.renderArea.offset.x = 0; @@ -7801,7 +7803,7 @@ using namespace vulkan_internal; barrier.newLayout = _ConvertImageLayout(image.layout); assert(barrier.newLayout != VK_IMAGE_LAYOUT_UNDEFINED); - + barrier.srcStageMask = _ConvertPipelineStage(image.layout_before); barrier.dstStageMask = _ConvertPipelineStage(image.layout); barrier.srcAccessMask = _ParseResourceState(image.layout_before); @@ -8955,7 +8957,7 @@ using namespace vulkan_internal; raygen.deviceAddress += desc->ray_generation.offset; raygen.size = desc->ray_generation.size; raygen.stride = raygen.size; // raygen specifically must be size == stride - + VkStridedDeviceAddressRegionKHR miss = {}; miss.deviceAddress = desc->miss.buffer ? to_internal(desc->miss.buffer)->address : 0; miss.deviceAddress += desc->miss.offset; @@ -8980,8 +8982,8 @@ using namespace vulkan_internal; &miss, &hitgroup, &callable, - desc->width, - desc->height, + desc->width, + desc->height, desc->depth ); } diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 6e58f18b11..ec841bc81c 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -24,16 +24,16 @@ namespace wi namespace wi::renderer { - constexpr wi::graphics::Format format_depthbuffer_main = wi::graphics::Format::D32_FLOAT_S8X24_UINT; - constexpr wi::graphics::Format format_rendertarget_main = wi::graphics::Format::R11G11B10_FLOAT; - constexpr wi::graphics::Format format_idbuffer = wi::graphics::Format::R32_UINT; - constexpr wi::graphics::Format format_rendertarget_shadowmap = wi::graphics::Format::R16G16B16A16_FLOAT; - constexpr wi::graphics::Format format_depthbuffer_shadowmap = wi::graphics::Format::D16_UNORM; - constexpr wi::graphics::Format format_rendertarget_envprobe = wi::graphics::Format::R11G11B10_FLOAT; - constexpr wi::graphics::Format format_depthbuffer_envprobe = wi::graphics::Format::D16_UNORM; + inline constexpr wi::graphics::Format format_depthbuffer_main = wi::graphics::Format::D32_FLOAT_S8X24_UINT; + inline constexpr wi::graphics::Format format_rendertarget_main = wi::graphics::Format::R11G11B10_FLOAT; + inline constexpr wi::graphics::Format format_idbuffer = wi::graphics::Format::R32_UINT; + inline constexpr wi::graphics::Format format_rendertarget_shadowmap = wi::graphics::Format::R16G16B16A16_FLOAT; + inline constexpr wi::graphics::Format format_depthbuffer_shadowmap = wi::graphics::Format::D16_UNORM; + inline constexpr wi::graphics::Format format_rendertarget_envprobe = wi::graphics::Format::R11G11B10_FLOAT; + inline constexpr wi::graphics::Format format_depthbuffer_envprobe = wi::graphics::Format::D16_UNORM; - constexpr uint8_t raytracing_inclusion_mask_shadow = 1 << 0; - constexpr uint8_t raytracing_inclusion_mask_reflection = 1 << 1; + inline constexpr uint8_t raytracing_inclusion_mask_shadow = 1 << 0; + inline constexpr uint8_t raytracing_inclusion_mask_reflection = 1 << 1; constexpr uint32_t CombineStencilrefs(wi::enums::STENCILREF engineStencilRef, uint8_t userStencilRef) { @@ -267,7 +267,7 @@ namespace wi::renderer // Draw Soft offscreen particles. void DrawSoftParticles( const Visibility& vis, - bool distortion, + bool distortion, wi::graphics::CommandList cmd ); // Draw the sprites and fonts from the scene @@ -799,7 +799,7 @@ namespace wi::renderer const wi::graphics::GPUBuffer* buffer_luminance = nullptr, const wi::graphics::Texture* texture_bloom = nullptr, wi::graphics::ColorSpace display_colorspace = wi::graphics::ColorSpace::SRGB, - Tonemap tonemap = Tonemap::Reinhard + Tonemap tonemap = Tonemap::Reinhard ); void Postprocess_FSR( const wi::graphics::Texture& input, @@ -1192,7 +1192,7 @@ namespace wi::renderer uint32_t filterMask = wi::enums::FILTER_OPAQUE; wi::graphics::PipelineState pso[wi::enums::RENDERPASS_COUNT] = {}; }; - // Registers a custom shader that can be set to materials. + // Registers a custom shader that can be set to materials. // Returns the ID of the custom shader that can be used with MaterialComponent::SetCustomShaderID() int RegisterCustomShader(const CustomShader& customShader); const wi::vector& GetCustomShaders(); diff --git a/WickedEngine/wiScene.cpp b/WickedEngine/wiScene.cpp index 0b4959ad21..087f9827ac 100644 --- a/WickedEngine/wiScene.cpp +++ b/WickedEngine/wiScene.cpp @@ -22,6 +22,11 @@ using namespace wi::enums; using namespace wi::graphics; using namespace wi::primitive; +namespace wi::ecs { + //TODO this is not the right place + std::atomic next { INVALID_ENTITY + 1 }; +} + namespace wi::scene { const uint32_t small_subtask_groupsize = 64u; @@ -3529,7 +3534,7 @@ namespace wi::scene return; const TransformComponent& transform = *transforms.GetComponent(entity); - // The transform world matrices are in world space, but skinning needs them in armature-local space, + // The transform world matrices are in world space, but skinning needs them in armature-local space, // so that the skin is reusable for instanced meshes. // We remove the armature's world matrix from the bone world matrix to obtain the bone local transform // These local bone matrices will only be used for skinning, the actual transform components for the bones @@ -3537,7 +3542,7 @@ namespace wi::scene // // This is useful for an other thing too: // If a whole transform tree is transformed by some parent (even gltf import does that to convert from RH to LH space) - // then the inverseBindMatrices are not reflected in that because they are not contained in the hierarchy system. + // then the inverseBindMatrices are not reflected in that because they are not contained in the hierarchy system. // But this will correct them too. XMMATRIX R = XMMatrixInverse(nullptr, XMLoadFloat4x4(&transform.world)); @@ -3977,7 +3982,7 @@ namespace wi::scene parallel_bounds.clear(); parallel_bounds.resize((size_t)wi::jobsystem::DispatchGroupCount((uint32_t)objects.GetCount(), small_subtask_groupsize)); - + wi::jobsystem::Dispatch(ctx, (uint32_t)objects.GetCount(), small_subtask_groupsize, [&](wi::jobsystem::JobArgs args) { Entity entity = objects.GetEntity(args.jobIndex); @@ -4251,7 +4256,7 @@ namespace wi::scene desc.width = object.lightmapWidth; desc.height = object.lightmapHeight; desc.bind_flags = BindFlag::RENDER_TARGET | BindFlag::SHADER_RESOURCE; - // Note: we need the full precision format to achieve correct accumulative blending! + // Note: we need the full precision format to achieve correct accumulative blending! // But the final lightmap will be compressed into an optimal format when the rendering is finished desc.format = Format::R32G32B32A32_FLOAT; @@ -5535,11 +5540,11 @@ namespace wi::scene // Project the center of the sphere onto the plane of the triangle. XMVECTOR Point0 = XMVectorNegativeMultiplySubtract(N, Dist, Center); - // Is it inside all the edges? If so we intersect because the distance + // Is it inside all the edges? If so we intersect because the distance // to the plane is less than the radius. //XMVECTOR Intersection = DirectX::Internal::PointOnPlaneInsideTriangle(Point0, p0, p1, p2); - // Compute the cross products of the vector from the base of each edge to + // Compute the cross products of the vector from the base of each edge to // the point with each edge vector. XMVECTOR C0 = XMVector3Cross(XMVectorSubtract(Point0, p0), XMVectorSubtract(p1, p0)); XMVECTOR C1 = XMVector3Cross(XMVectorSubtract(Point0, p1), XMVectorSubtract(p2, p1)); @@ -5562,21 +5567,21 @@ namespace wi::scene // Edge 0,1 XMVECTOR Point1 = DirectX::Internal::PointOnLineSegmentNearestPoint(p0, p1, Center); - // If the distance to the center of the sphere to the point is less than + // If the distance to the center of the sphere to the point is less than // the radius of the sphere then it must intersect. Intersection = XMVectorOrInt(Intersection, XMVectorLessOrEqual(XMVector3LengthSq(XMVectorSubtract(Center, Point1)), RadiusSq)); // Edge 1,2 XMVECTOR Point2 = DirectX::Internal::PointOnLineSegmentNearestPoint(p1, p2, Center); - // If the distance to the center of the sphere to the point is less than + // If the distance to the center of the sphere to the point is less than // the radius of the sphere then it must intersect. Intersection = XMVectorOrInt(Intersection, XMVectorLessOrEqual(XMVector3LengthSq(XMVectorSubtract(Center, Point2)), RadiusSq)); // Edge 2,0 XMVECTOR Point3 = DirectX::Internal::PointOnLineSegmentNearestPoint(p2, p0, Center); - // If the distance to the center of the sphere to the point is less than + // If the distance to the center of the sphere to the point is less than // the radius of the sphere then it must intersect. Intersection = XMVectorOrInt(Intersection, XMVectorLessOrEqual(XMVector3LengthSq(XMVectorSubtract(Center, Point3)), RadiusSq)); @@ -5752,7 +5757,7 @@ namespace wi::scene const XMMATRIX objectMatPrev = XMLoadFloat4x4(&matrix_objects_prev[objectIndex]); const ArmatureComponent* armature = mesh->IsSkinned() ? armatures.GetComponent(mesh->armatureID) : nullptr; const XMMATRIX objectMat_Inverse = XMMatrixInverse(nullptr, objectMat); - + auto intersect_triangle = [&](uint32_t subsetIndex, uint32_t indexOffset, uint32_t triangleIndex) { const uint32_t i0 = mesh->indices[indexOffset + triangleIndex * 3 + 0]; @@ -5814,7 +5819,7 @@ namespace wi::scene XMVECTOR t = XMVector3Dot(N, (Base - p0) / XMVectorAbs(XMVector3Dot(N, d))); XMVECTOR LinePlaneIntersection = Base + d * t; - // Compute the cross products of the vector from the base of each edge to + // Compute the cross products of the vector from the base of each edge to // the point with each edge vector. XMVECTOR C0 = XMVector3Cross(XMVectorSubtract(LinePlaneIntersection, p0), XMVectorSubtract(p1, p0)); XMVECTOR C1 = XMVector3Cross(XMVectorSubtract(LinePlaneIntersection, p1), XMVectorSubtract(p2, p1)); @@ -5889,11 +5894,11 @@ namespace wi::scene // Project the center of the sphere onto the plane of the triangle. XMVECTOR Point0 = XMVectorNegativeMultiplySubtract(N, Dist, Center); - // Is it inside all the edges? If so we intersect because the distance + // Is it inside all the edges? If so we intersect because the distance // to the plane is less than the radius. //XMVECTOR Intersection = DirectX::Internal::PointOnPlaneInsideTriangle(Point0, p0, p1, p2); - // Compute the cross products of the vector from the base of each edge to + // Compute the cross products of the vector from the base of each edge to // the point with each edge vector. XMVECTOR C0 = XMVector3Cross(XMVectorSubtract(Point0, p0), XMVectorSubtract(p1, p0)); XMVECTOR C1 = XMVector3Cross(XMVectorSubtract(Point0, p1), XMVectorSubtract(p2, p1)); @@ -5916,21 +5921,21 @@ namespace wi::scene // Edge 0,1 XMVECTOR Point1 = wi::math::ClosestPointOnLineSegment(p0, p1, Center); - // If the distance to the center of the sphere to the point is less than + // If the distance to the center of the sphere to the point is less than // the radius of the sphere then it must intersect. Intersection = XMVectorOrInt(Intersection, XMVectorLessOrEqual(XMVector3LengthSq(XMVectorSubtract(Center, Point1)), RadiusSq)); // Edge 1,2 XMVECTOR Point2 = wi::math::ClosestPointOnLineSegment(p1, p2, Center); - // If the distance to the center of the sphere to the point is less than + // If the distance to the center of the sphere to the point is less than // the radius of the sphere then it must intersect. Intersection = XMVectorOrInt(Intersection, XMVectorLessOrEqual(XMVector3LengthSq(XMVectorSubtract(Center, Point2)), RadiusSq)); // Edge 2,0 XMVECTOR Point3 = wi::math::ClosestPointOnLineSegment(p2, p0, Center); - // If the distance to the center of the sphere to the point is less than + // If the distance to the center of the sphere to the point is less than // the radius of the sphere then it must intersect. Intersection = XMVectorOrInt(Intersection, XMVectorLessOrEqual(XMVector3LengthSq(XMVectorSubtract(Center, Point3)), RadiusSq)); @@ -5972,17 +5977,17 @@ namespace wi::scene { result.depth = depth; XMStoreFloat3(&result.normal, intersectionVec / intersectionVecLen); - } - else + } + else { - // The line segment that makes the spine of the capsule has - // intersected the triangle plane, so interSectionVec ~= Zero, + // The line segment that makes the spine of the capsule has + // intersected the triangle plane, so interSectionVec ~= Zero, // and depth ~= capsule.radius. Use the triangle normal. - XMVECTOR CandNorm; + XMVECTOR CandNorm; if (onBackside) { CandNorm = N; - } else + } else { CandNorm = XMVectorNegate(N); } @@ -5998,11 +6003,11 @@ namespace wi::scene XMVECTOR A_C = XMVector3LengthSq(Center - A); XMVECTOR B_C = XMVector3LengthSq(Center - B); XMVECTOR CDiff; - if (XMVector3Less(A_C, B_C)) + if (XMVector3Less(A_C, B_C)) { CDiff = XMVectorSubtract(A, Center); } - else + else { CDiff = XMVectorSubtract(B, Center); } diff --git a/WickedEngine/wiScene.h b/WickedEngine/wiScene.h index d8d8f689d3..dd7ab6ade5 100644 --- a/WickedEngine/wiScene.h +++ b/WickedEngine/wiScene.h @@ -318,7 +318,7 @@ namespace wi::scene // seri : serializer state for entity component system // entity : if archive is in write mode, this is the entity to serialize. If archive is in read mode, it should be INVALID_ENTITY // flags : specify options as EntitySerializeFlags bits to control internal behaviour - // + // // Returns either the new entity that was read, or the original entity that was written wi::ecs::Entity Entity_Serialize( wi::Archive& archive, @@ -340,10 +340,10 @@ namespace wi::scene const std::string& name ); wi::ecs::Entity Entity_CreateLight( - const std::string& name, - const XMFLOAT3& position = XMFLOAT3(0, 0, 0), - const XMFLOAT3& color = XMFLOAT3(1, 1, 1), - float intensity = 1, + const std::string& name, + const XMFLOAT3& position = XMFLOAT3(0, 0, 0), + const XMFLOAT3& color = XMFLOAT3(1, 1, 1), + float intensity = 1, float range = 10, LightComponent::LightType type = LightComponent::POINT, float outerConeAngle = XM_PIDIV4, diff --git a/WickedEngine/wiTerrain.cpp b/WickedEngine/wiTerrain.cpp index fa1d4a52e6..d2fbfbefb2 100644 --- a/WickedEngine/wiTerrain.cpp +++ b/WickedEngine/wiTerrain.cpp @@ -1360,8 +1360,9 @@ namespace wi::terrain coordinate.y = 0; commands[0].coordinates = &coordinate; SparseRegionSize region; - region.width = atlas.maps[map_type].texture.desc.width / atlas.maps[map_type].texture.sparse_properties->tile_width; - region.height = atlas.maps[map_type].texture.desc.height / atlas.maps[map_type].texture.sparse_properties->tile_height; + const SparseTextureProperties* sparse_properties = atlas.maps[map_type].texture.sparse_properties; + region.width = atlas.maps[map_type].texture.desc.width / sparse_properties->tile_width; + region.height = atlas.maps[map_type].texture.desc.height / sparse_properties->tile_height; commands[0].sizes = ®ion; TileRangeFlags flags = {}; commands[0].range_flags = &flags;