Skip to content

Commit

Permalink
blender exporter improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
portaloffreedom committed Apr 16, 2024
1 parent a5b4bc6 commit 9c7388f
Show file tree
Hide file tree
Showing 19 changed files with 158 additions and 103 deletions.
6 changes: 4 additions & 2 deletions BlenderExporter/python_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
#include <wiScene_Components.h>
#include <string>

namespace py = pybind11;

Expand All @@ -36,6 +37,7 @@ void init_wicked(py::module_& mod)

mod.def("init", []()
{
return;
if (INIT_DONE) return;
INIT_DONE = true;

Expand All @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions BlenderExporter/test.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -19,5 +25,7 @@ def main():

ar.Close()

pywickedengine.deinit()

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion BlenderExporter/wicked_blender_exporter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
}

Expand Down
36 changes: 31 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()


Expand All @@ -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()
2 changes: 1 addition & 1 deletion WickedEngine/BULLET/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
27 changes: 15 additions & 12 deletions WickedEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/LUA/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions WickedEngine/Utility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
)
4 changes: 2 additions & 2 deletions WickedEngine/Utility/FAudio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion WickedEngine/Utility/robin_hood.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion WickedEngine/wiECS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity> next;//{ INVALID_ENTITY + 1 };
inline Entity CreateEntity()
{
static std::atomic<Entity> next{ INVALID_ENTITY + 1 };
return next.fetch_add(1);
}

Expand Down
4 changes: 2 additions & 2 deletions WickedEngine/wiFont.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include "CommonInclude.h"
#include "wiGraphicsDevice.h"
#include "wiColor.h"
Expand All @@ -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
{
Expand Down
14 changes: 7 additions & 7 deletions WickedEngine/wiGraphicsDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

}
15 changes: 9 additions & 6 deletions WickedEngine/wiGraphicsDevice_DX12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ using namespace Microsoft::WRL;

namespace wi::graphics
{

GraphicsDevice* static_device = nullptr;

namespace dx12_internal
{
// Bindless allocation limits:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1610,7 +1613,7 @@ namespace dx12_internal
}
using namespace dx12_internal;



void GraphicsDevice_DX12::CopyAllocator::init(GraphicsDevice_DX12* device)
{
Expand Down Expand Up @@ -4315,7 +4318,7 @@ using namespace dx12_internal;
{
internal_state->desc.Flags |= D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_MINIMIZE_MEMORY;
}


switch (desc->type)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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));
Expand Down
Loading

0 comments on commit 9c7388f

Please sign in to comment.