From 7525b54ff12f9bf47aab2c5b6a79e338b2a13d7a Mon Sep 17 00:00:00 2001 From: Hirek193 Date: Wed, 6 May 2026 20:41:01 +0200 Subject: [PATCH] Enable GLM_FORCE_DEFAULT_ALIGNED_GENTYPES --- betterRenderer/CMakeLists.txt | 19 ++++++++++++------- gl/ubo.h | 21 +++++++++++++++------ rendering/opengl33renderer.cpp | 2 +- scene/scenenode.h | 4 ++-- stdafx.h | 7 +++++++ 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/betterRenderer/CMakeLists.txt b/betterRenderer/CMakeLists.txt index 1d60abd2..803ab1cd 100644 --- a/betterRenderer/CMakeLists.txt +++ b/betterRenderer/CMakeLists.txt @@ -67,7 +67,11 @@ target_include_directories(${LIBMANUL_NAME} PRIVATE target_compile_definitions(${LIBMANUL_NAME} PRIVATE GLM_ENABLE_EXPERIMENTAL - GLM_FORCE_SWIZZLE) + GLM_FORCE_SWIZZLE + GLM_FORCE_CTOR_INIT + GLM_FORCE_INLINE + GLM_FORCE_DEFAULT_ALIGNED_GENTYPES + GLM_FORCE_INTRINSICS) target_compile_definitions(${LIBMANUL_NAME} PRIVATE _USE_MATH_DEFINES) @@ -99,12 +103,13 @@ else () target_compile_definitions(${LIBMANUL_NAME} PUBLIC "LIBMANUL_WITH_VULKAN=0") endif () -## For double-precision vector goodness -#if (WIN32) -# target_compile_options(${LIBMANUL_NAME} PRIVATE "/arch:AVX2") -#elseif (UNIX) -# target_compile_options(${LIBMANUL_NAME} PRIVATE "-mavx2") -#endif () +if(ENABLE_AVX2) + if (WIN32) + target_compile_options(${LIBMANUL_NAME} PRIVATE "/arch:AVX2") + elseif (UNIX) + target_compile_options(${LIBMANUL_NAME} PRIVATE "-mavx2") + endif () +endif() target_sources(${LIBMANUL_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/eu07_source/register.cpp") set_target_properties(nvrhi yaml-cpp fmt EnTT glfw yaml-cpp-parse yaml-cpp-read yaml-cpp-sandbox PROPERTIES FOLDER "libraries") diff --git a/gl/ubo.h b/gl/ubo.h index 8bac33b7..9932bfbe 100644 --- a/gl/ubo.h +++ b/gl/ubo.h @@ -3,9 +3,18 @@ #include "object.h" #include "bindable.h" #include "buffer.h" +#include #define UBS_PAD(x) uint8_t PAD[x] +// 12-byte vec3 for structs that must match an exact binary layout (UBOs, vertex data). +// Stays packed regardless of GLM_FORCE_DEFAULT_ALIGNED_GENTYPES. +// Guard prevents redefinition when stdafx.h also defines it. +#ifndef PACKED_VEC3_DEFINED +#define PACKED_VEC3_DEFINED +using packed_vec3 = glm::vec<3, float, glm::packed_highp>; +#endif + namespace gl { class ubo : public buffer @@ -43,7 +52,7 @@ namespace gl glm::mat4 projection; glm::mat4 inv_view; glm::mat4 lightview[MAX_CASCADES]; - glm::vec3 cascade_end; + packed_vec3 cascade_end; float time; glm::vec4 rain_params; glm::vec4 wiper_pos; @@ -88,13 +97,13 @@ namespace gl HEADLIGHTS }; - glm::vec3 pos; + packed_vec3 pos; type_e type; - glm::vec3 dir; + packed_vec3 dir; float in_cutoff; - glm::vec3 color; + packed_vec3 color; float out_cutoff; float linear; @@ -113,10 +122,10 @@ namespace gl struct light_ubs { - glm::vec3 ambient; + packed_vec3 ambient; UBS_PAD(4); - glm::vec3 fog_color; + packed_vec3 fog_color; uint32_t lights_count; light_element_ubs lights[MAX_LIGHTS]; diff --git a/rendering/opengl33renderer.cpp b/rendering/opengl33renderer.cpp index 43fef6b4..708d0878 100644 --- a/rendering/opengl33renderer.cpp +++ b/rendering/opengl33renderer.cpp @@ -3101,7 +3101,7 @@ bool opengl33_renderer::Render_cab(TDynamicObject const *Dynamic, float const Li auto const luminance { Global.fLuminance * ( Dynamic->fShade > 0.0f ? Dynamic->fShade : 1.0f ) }; if( Lightlevel > 0.f ) { // crude way to light the cabin, until we have something more complete in place - light_ubs.ambient += ( Dynamic->InteriorLight * Lightlevel ) * std::clamp( 1.25f - (float)luminance, 0.f, 1.f ); + light_ubs.ambient += packed_vec3( ( Dynamic->InteriorLight * Lightlevel ) * std::clamp( 1.25f - (float)luminance, 0.f, 1.f ) ); light_ubo->update( light_ubs ); } diff --git a/scene/scenenode.h b/scene/scenenode.h index eac74651..10be9c1b 100644 --- a/scene/scenenode.h +++ b/scene/scenenode.h @@ -48,7 +48,7 @@ operator!=( lighting_data const &Left, lighting_data const &Right ) { namespace scene { struct bounding_area { - glm::highp_dvec3 center; // mid point of the rectangle + glm::dvec3 center; // mid point of the rectangle float radius { -1.0f }; // radius of the bounding sphere bounding_area() = default; @@ -94,7 +94,7 @@ public: material_handle material { null_handle }; lighting_data lighting; // geometry data - glm::highp_dvec3 origin; // world position of the relative coordinate system origin + glm::dvec3 origin; // world position of the relative coordinate system origin gfx::geometry_handle geometry { 0, 0 }; // relative origin-centered chunk of geometry held by gfx renderer std::vector vertices; // world space source data of the geometry gfx::userdata_array userdata; diff --git a/stdafx.h b/stdafx.h index 73340a69..fec02883 100644 --- a/stdafx.h +++ b/stdafx.h @@ -94,6 +94,7 @@ #define GLM_ENABLE_EXPERIMENTAL #define GLM_FORCE_CTOR_INIT #define GLM_FORCE_INLINE +#define GLM_FORCE_DEFAULT_ALIGNED_GENTYPES #define GLM_FORCE_INTRINSICS #include #include @@ -107,6 +108,12 @@ #include #include +#ifndef PACKED_VEC3_DEFINED +#define PACKED_VEC3_DEFINED +// 12-byte vec3 that stays packed regardless of GLM_FORCE_DEFAULT_ALIGNED_GENTYPES. +// Use in structs that must match an exact binary layout (UBOs, vertex data, serialized formats). +using packed_vec3 = glm::vec<3, float, glm::packed_highp>; +#endif #include "rendering/openglmatrixstack.h"