diff --git a/filament/backend/include/backend/DriverEnums.h b/filament/backend/include/backend/DriverEnums.h index be9133f4cf..79cf448f65 100644 --- a/filament/backend/include/backend/DriverEnums.h +++ b/filament/backend/include/backend/DriverEnums.h @@ -46,6 +46,9 @@ static constexpr size_t MAX_ATTRIBUTE_BUFFER_COUNT = 8; // FIXME: what should th static constexpr size_t MAX_VERTEX_ATTRIBUTE_COUNT = 7; // FIXME: what should this be? static constexpr size_t MAX_SAMPLER_COUNT = 16; // Matches the Adreno Vulkan driver. +static constexpr size_t CONFIG_UNIFORM_BINDING_COUNT = 6; +static constexpr size_t CONFIG_SAMPLER_BINDING_COUNT = 6; + /** * Selects which driver a particular Engine should use. */ diff --git a/filament/backend/include/private/backend/Program.h b/filament/backend/include/private/backend/Program.h index 48228b1bf3..09871f09c9 100644 --- a/filament/backend/include/private/backend/Program.h +++ b/filament/backend/include/private/backend/Program.h @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include @@ -33,8 +33,8 @@ class Program { public: static constexpr size_t SHADER_TYPE_COUNT = 2; - static constexpr size_t UNIFORM_BINDING_COUNT = filament::CONFIG_UNIFORM_BINDING_COUNT; - static constexpr size_t SAMPLER_BINDING_COUNT = filament::CONFIG_SAMPLER_BINDING_COUNT; + static constexpr size_t UNIFORM_BINDING_COUNT = CONFIG_UNIFORM_BINDING_COUNT; + static constexpr size_t SAMPLER_BINDING_COUNT = CONFIG_SAMPLER_BINDING_COUNT; enum class Shader : uint8_t { VERTEX = 0, diff --git a/filament/backend/src/vulkan/VulkanBinder.h b/filament/backend/src/vulkan/VulkanBinder.h index fa571aa181..739bf3793b 100644 --- a/filament/backend/src/vulkan/VulkanBinder.h +++ b/filament/backend/src/vulkan/VulkanBinder.h @@ -22,6 +22,8 @@ #include #include + +#include #include #include @@ -166,8 +168,7 @@ private: // The pipeline key is a POD that represents all currently bound states that form the immutable // VkPipeline object. We apply a hash function to its contents only if has been mutated since // the previous call to getOrCreatePipeline. - #pragma pack(push, 1) - struct PipelineKey { + struct UTILS_PACKED PipelineKey { VkShaderModule shaders[SHADER_MODULE_COUNT]; // 8*2 bytes RasterState rasterState; // 248 bytes VkRenderPass renderPass; // 8 bytes @@ -175,7 +176,6 @@ private: VkVertexInputAttributeDescription vertexAttributes[VERTEX_ATTRIBUTE_COUNT]; // 16*5 bytes VkVertexInputBindingDescription vertexBuffers[VERTEX_ATTRIBUTE_COUNT]; // 12*5 bytes }; - #pragma pack(pop) static_assert(std::is_pod::value, "PipelineKey must be a POD for fast hashing."); @@ -199,14 +199,12 @@ private: // The descriptor key is a POD that represents all currently bound states that go into the // descriptor set. We apply a hash function to its contents only if has been mutated since // the previous call to getOrCreateDescriptor. - #pragma pack(push, 1) - struct DescriptorKey { + struct UTILS_PACKED DescriptorKey { VkBuffer uniformBuffers[UBUFFER_BINDING_COUNT]; VkDescriptorImageInfo samplers[SAMPLER_BINDING_COUNT]; VkDeviceSize uniformBufferOffsets[UBUFFER_BINDING_COUNT]; VkDeviceSize uniformBufferSizes[UBUFFER_BINDING_COUNT]; }; - #pragma pack(pop) static_assert(std::is_pod::value, "DescriptorKey must be a POD."); diff --git a/libs/filabridge/include/private/filament/EngineEnums.h b/libs/filabridge/include/private/filament/EngineEnums.h index e516975835..b6db447fe1 100644 --- a/libs/filabridge/include/private/filament/EngineEnums.h +++ b/libs/filabridge/include/private/filament/EngineEnums.h @@ -59,9 +59,6 @@ constexpr size_t CONFIG_MAX_BONE_COUNT = 256; static constexpr bool CONFIG_IBL_RGBM = true; static constexpr size_t CONFIG_IBL_SIZE = 256; -static constexpr size_t CONFIG_UNIFORM_BINDING_COUNT = 6; -static constexpr size_t CONFIG_SAMPLER_BINDING_COUNT = 6; - } // namespace filament #endif // TNT_FILAMENT_driver/EngineEnums.h diff --git a/libs/filabridge/include/private/filament/SibGenerator.h b/libs/filabridge/include/private/filament/SibGenerator.h index f11bb7e1e1..ec9b6b3274 100644 --- a/libs/filabridge/include/private/filament/SibGenerator.h +++ b/libs/filabridge/include/private/filament/SibGenerator.h @@ -59,7 +59,7 @@ inline constexpr uint8_t getSamplerBindingsStart(backend::Backend api) noexcept case backend::Backend::VULKAN: // The Vulkan backend has single namespace for uniforms and samplers. // To avoid collision, the sampler bindings start after the last UBO binding. - return CONFIG_UNIFORM_BINDING_COUNT; + return backend::CONFIG_UNIFORM_BINDING_COUNT; case backend::Backend::OPENGL: case backend::Backend::METAL: diff --git a/libs/utils/include/utils/compiler.h b/libs/utils/include/utils/compiler.h index ee6ec8df7b..07a7e90e34 100644 --- a/libs/utils/include/utils/compiler.h +++ b/libs/utils/include/utils/compiler.h @@ -36,6 +36,14 @@ # define UTILS_PUBLIC #endif +#if __has_attribute(packed) +# define UTILS_PACKED __attribute__((packed)) +#else +// If this happens, we may need to use "#pragma pack(push, 1)" instead. +# error Compiler does not support the packed attribute. +# define UTILS_PACKED +#endif + #if __has_attribute(visibility) # ifndef TNT_DEV # define UTILS_PRIVATE __attribute__((visibility("hidden")))