Skip to content

Commit b9896a4

Browse files
committed
Fix for Windows CI. No longer uses GPU physics.
1 parent 5db9ccc commit b9896a4

4 files changed

Lines changed: 23 additions & 181 deletions

File tree

attachments/advanced_gltf/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,24 @@ set(DEBUG_RENDERER_IN_DEBUG_AND_RELEASE ON CACHE BOOL "" FORCE)
8585
set(ENABLE_OBJECT_STREAM ON CACHE BOOL "" FORCE)
8686
set(FLOATING_POINT_EXCEPTIONS_ENABLED ON CACHE BOOL "" FORCE)
8787
set(INTERPROCEDURAL_OPTIMIZATION ON CACHE BOOL "" FORCE)
88-
set(WARNINGS_AS_ERRORS OFF CACHE BOOL "" FORCE)
88+
set(ENABLE_ALL_WARNINGS OFF CACHE BOOL "" FORCE)
8989
if(MSVC)
9090
set(USE_STATIC_MSVC_RUNTIME_LIBRARY OFF CACHE BOOL "" FORCE)
9191
endif()
9292
FetchContent_MakeAvailable(JoltPhysics)
9393

94+
# ---------------------------------------------------------------------------
95+
# JoltPhysics MSVC Fix
96+
# Suppress C4865: "underlying type of enum will change when /Zc:enumTypes is specified"
97+
# This warning is triggered in Windows SDK headers when Jolt is built with /Wall.
98+
# We also disable /WX (Warnings as Errors) for Jolt via ENABLE_ALL_WARNINGS=OFF above.
99+
# ---------------------------------------------------------------------------
100+
if(MSVC)
101+
if(TARGET Jolt)
102+
target_compile_options(Jolt PRIVATE /wd4865)
103+
endif()
104+
endif()
105+
94106
# ---------------------------------------------------------------------------
95107
# Advanced glTF shader compilation.
96108
# Uses SLANGC_EXECUTABLE set by simple_engine's find_program() call above.

attachments/advanced_gltf/physics_system.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,4 @@ void PhysicsSystem::RegisterStreamingCollider(Entity* entity,
504504

505505
void PhysicsSystem::CleanupMarkedBodies() {
506506
// Handled via DestroyRigidBody
507-
}
508-
509-
void PhysicsSystem::UpdateGPUPhysicsData(std::chrono::milliseconds deltaTime) const {}
510-
void PhysicsSystem::ReadbackGPUPhysicsData() const {}
511-
void PhysicsSystem::SimulatePhysicsOnGPU(std::chrono::milliseconds deltaTime) const {}
512-
void PhysicsSystem::CleanupVulkanResources() {}
513-
514-
void PhysicsSystem::CreateMappedBuffer(vk::DeviceSize size, vk::BufferUsageFlags usage, vk::raii::Buffer& buffer, vk::raii::DeviceMemory& memory, const std::string& errorPrefix) {}
507+
}

attachments/advanced_gltf/physics_system.h

Lines changed: 6 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -152,53 +152,6 @@ class RigidBody {
152152
[[nodiscard]] virtual bool IsKinematic() const = 0;
153153
};
154154

155-
/**
156-
* @brief Structure for GPU physics data.
157-
*/
158-
struct GPUPhysicsData {
159-
glm::vec4 position; // xyz = position, w = inverse mass
160-
glm::vec4 rotation; // quaternion
161-
glm::vec4 linearVelocity; // xyz = velocity, w = restitution
162-
glm::vec4 angularVelocity; // xyz = angular velocity, w = friction
163-
glm::vec4 force; // xyz = force, w = is kinematic (0 or 1)
164-
glm::vec4 torque; // xyz = torque, w = use gravity (0 or 1)
165-
glm::vec4 colliderData; // type-specific data (e.g., radius for spheres)
166-
glm::vec4 colliderData2; // additional collider data (e.g., box half extents)
167-
};
168-
169-
/**
170-
* @brief Structure for GPU collision data.
171-
*/
172-
struct GPUCollisionData {
173-
uint32_t bodyA;
174-
uint32_t bodyB;
175-
glm::vec4 contactNormal; // xyz = normal, w = penetration depth
176-
glm::vec4 contactPoint; // xyz = contact point, w = unused
177-
};
178-
179-
/**
180-
* @brief Structure for physics simulation parameters.
181-
*/
182-
struct PhysicsParams {
183-
float deltaTime; // Time step - 4 bytes
184-
uint32_t numBodies; // Number of rigid bodies - 4 bytes
185-
uint32_t maxCollisions; // Maximum number of collisions - 4 bytes
186-
float padding; // Explicit padding to align gravity to 16-byte boundary - 4 bytes
187-
glm::vec4 gravity; // Gravity vector (xyz) + padding (w) - 16 bytes
188-
// Total: 32 bytes (aligned to 16-byte boundaries for std140 layout)
189-
};
190-
191-
/**
192-
* @brief Structure to store collision prediction data for a ray-based collision system.
193-
*/
194-
struct CollisionPrediction {
195-
float collisionTime = -1.0f; // Time within deltaTime when the collision occurs (-1 = no collision)
196-
glm::vec3 collisionPoint; // World position where collision occurs
197-
glm::vec3 collisionNormal; // Surface normal at collision point
198-
glm::vec3 newVelocity; // Predicted velocity after bounce
199-
Entity* hitEntity = nullptr; // Entity that was hit
200-
bool isValid = false; // Whether this prediction is valid
201-
};
202155

203156
/**
204157
* @brief Class for managing physics simulation.
@@ -212,12 +165,12 @@ class PhysicsSystem {
212165
/**
213166
* @brief Default constructor.
214167
*/
215-
PhysicsSystem() = default;
216-
217-
// Constructor-based initialization replacing separate Initialize/Set* calls
218-
explicit PhysicsSystem(Renderer* _renderer, bool enableGPU = true) {
219-
SetRenderer(_renderer);
220-
SetGPUAccelerationEnabled(enableGPU);
168+
/**
169+
* @brief Constructor.
170+
* @param _renderer Optional renderer (unused in Jolt implementation).
171+
* @param _enableGPU Optional GPU flag (unused in Jolt implementation).
172+
*/
173+
explicit PhysicsSystem(Renderer* _renderer = nullptr, bool _enableGPU = true) {
221174
if (!Initialize()) {
222175
throw std::runtime_error("PhysicsSystem: initialization failed");
223176
}
@@ -279,39 +232,6 @@ class PhysicsSystem {
279232
glm::vec3* hitNormal,
280233
Entity** hitEntity) const;
281234

282-
/**
283-
* @brief Enable or disable GPU acceleration.
284-
* @param enabled Whether GPU acceleration is enabled.
285-
*/
286-
void SetGPUAccelerationEnabled(bool enabled) {
287-
// Enforce GPU-only policy: disabling GPU acceleration is not allowed in this project.
288-
// Ignore attempts to disable and keep GPU acceleration enabled.
289-
gpuAccelerationEnabled = true;
290-
}
291-
292-
/**
293-
* @brief Check if GPU acceleration is enabled.
294-
* @return True, if GPU acceleration is enabled, false otherwise.
295-
*/
296-
[[nodiscard]] bool IsGPUAccelerationEnabled() const {
297-
return gpuAccelerationEnabled;
298-
}
299-
300-
/**
301-
* @brief Set the maximum number of objects that can be simulated on the GPU.
302-
* @param maxObjects The maximum number of objects.
303-
*/
304-
void SetMaxGPUObjects(uint32_t maxObjects) {
305-
maxGPUObjects = maxObjects;
306-
}
307-
308-
/**
309-
* @brief Set the renderer to use during GPU acceleration.
310-
* @param _renderer The renderer.
311-
*/
312-
void SetRenderer(Renderer* _renderer) {
313-
renderer = _renderer;
314-
}
315235

316236
/**
317237
* @brief Set the current camera position for geometry-relative ball checking.
@@ -342,20 +262,6 @@ class PhysicsSystem {
342262
*/
343263
void CleanupMarkedBodies();
344264

345-
/**
346-
* @brief Helper function to create a mapped buffer with memory allocation.
347-
* @param size The size of the buffer in bytes.
348-
* @param usage The buffer usage flags.
349-
* @param buffer Reference to the buffer RAII object.
350-
* @param memory Reference to the memory RAII object.
351-
* @param errorPrefix Prefix for error messages.
352-
*/
353-
void CreateMappedBuffer(vk::DeviceSize size,
354-
vk::BufferUsageFlags usage,
355-
vk::raii::Buffer& buffer,
356-
vk::raii::DeviceMemory& memory,
357-
const std::string& errorPrefix);
358-
359265
// Pending rigid body creations queued from background threads
360266
struct PendingCreation {
361267
Entity* entity;
@@ -419,73 +325,7 @@ class PhysicsSystem {
419325
// Whether the physics system is initialized
420326
bool initialized = false;
421327

422-
// GPU acceleration
423-
bool gpuAccelerationEnabled = false;
424-
uint32_t maxGPUObjects = 1024;
425-
uint32_t maxGPUCollisions = 4096;
426-
Renderer* renderer = nullptr;
427-
428328
// Camera position for geometry-relative ball checking
429329
mutable std::mutex cameraPositionMutex;
430330
glm::vec3 cameraPosition = glm::vec3(0.0f, 0.0f, 0.0f);
431-
432-
// Vulkan resources for physics simulation
433-
struct VulkanResources {
434-
// Shader modules
435-
vk::raii::ShaderModule integrateShaderModule = nullptr;
436-
vk::raii::ShaderModule broadPhaseShaderModule = nullptr;
437-
vk::raii::ShaderModule narrowPhaseShaderModule = nullptr;
438-
vk::raii::ShaderModule resolveShaderModule = nullptr;
439-
440-
// Pipeline layouts and compute pipelines
441-
vk::raii::DescriptorSetLayout descriptorSetLayout = nullptr;
442-
vk::raii::PipelineLayout pipelineLayout = nullptr;
443-
vk::raii::Pipeline integratePipeline = nullptr;
444-
vk::raii::Pipeline broadPhasePipeline = nullptr;
445-
vk::raii::Pipeline narrowPhasePipeline = nullptr;
446-
vk::raii::Pipeline resolvePipeline = nullptr;
447-
448-
// Descriptor pool and sets
449-
vk::raii::DescriptorPool descriptorPool = nullptr;
450-
std::vector<vk::raii::DescriptorSet> descriptorSets;
451-
452-
// Buffers for physics data
453-
vk::raii::Buffer physicsBuffer = nullptr;
454-
vk::raii::DeviceMemory physicsBufferMemory = nullptr;
455-
vk::raii::Buffer collisionBuffer = nullptr;
456-
vk::raii::DeviceMemory collisionBufferMemory = nullptr;
457-
vk::raii::Buffer pairBuffer = nullptr;
458-
vk::raii::DeviceMemory pairBufferMemory = nullptr;
459-
vk::raii::Buffer counterBuffer = nullptr;
460-
vk::raii::DeviceMemory counterBufferMemory = nullptr;
461-
vk::raii::Buffer paramsBuffer = nullptr;
462-
vk::raii::DeviceMemory paramsBufferMemory = nullptr;
463-
464-
// Persistent mapped memory pointers for improved performance
465-
void* persistentPhysicsMemory = nullptr;
466-
void* persistentCounterMemory = nullptr;
467-
void* persistentParamsMemory = nullptr;
468-
469-
// Command buffer for compute operations
470-
vk::raii::CommandPool commandPool = nullptr;
471-
vk::raii::CommandBuffer commandBuffer = nullptr;
472-
473-
// Dedicated fence for compute synchronization
474-
vk::raii::Fence computeFence = nullptr;
475-
};
476-
477-
VulkanResources vulkanResources;
478-
479-
// Initialize Vulkan resources for physics simulation
480-
bool InitializeVulkanResources();
481-
void CleanupVulkanResources();
482-
483-
// Update physics data on the GPU
484-
void UpdateGPUPhysicsData(std::chrono::milliseconds deltaTime) const;
485-
486-
// Read back physics data from the GPU
487-
void ReadbackGPUPhysicsData() const;
488-
489-
// Perform GPU-accelerated physics simulation
490-
void SimulatePhysicsOnGPU(std::chrono::milliseconds deltaTime) const;
491331
};

attachments/advanced_gltf/tutorial_demo.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,9 @@ void TutorialDemoComponent::DrawPhysicsPanel()
266266
}
267267

268268
ImGui::Spacing();
269-
ImGui::TextWrapped("PhysicsSystem drives a GPU compute pipeline: broadphase, narrowphase, "
270-
"and constraint resolution all run as Vulkan compute dispatches. "
271-
"ColliderDef and ConstraintDef in node.h describe the per-node physics "
272-
"metadata that add_physics_extras.py injects into a glTF file.");
269+
ImGui::TextWrapped("PhysicsSystem drives Jolt Physics for collision and rigid body simulation. "
270+
"Static environment meshes are streamed in and out based on camera distance "
271+
"to maintain high performance in large scenes.");
273272
}
274273

275274
// ---------------------------------------------------------------------------
@@ -443,8 +442,6 @@ void TutorialDemoComponent::DrawDebugPanel()
443442
{
444443
glm::vec3 g = physics->GetGravity();
445444
ImGui::BulletText("Gravity : (%.2f, %.2f, %.2f)", g.x, g.y, g.z);
446-
ImGui::BulletText("GPU physics : %s",
447-
physics->IsGPUAccelerationEnabled() ? "enabled" : "disabled");
448445
}
449446
}
450447

0 commit comments

Comments
 (0)