Post

Replies

Boosts

Views

Activity

Hashable, Equatable and Measurement
So Swift documentation states that when a == b, then a.hashValue == b.hashValue (but the opposite is not necessarily true). However, is there ever a case where the first statement isn't true? To voice the argument, I have been considering Foundation.Measurement. It is clear that: import Foundation let a = Measurement(value: 1.0, unit: UnitLength.meters) let b = Measurement(value: 100.0, unit: UnitLength.centimeters) a==b // true because obviously 100 cm is equal to 1 meter. However, it is less clear to me that a.hashValue == b.hashValue // true. This is TRUE a.value // 1.0 b.value // 100.0 So this seems like a case where a and b should be equal but have different hash values because they have different units. I am running into this because I am finding Measurement completely useless in SwiftUI when equality holds and two different (but equal) values have different units. Wanting to know people's thoughts. I am considering posting something in the Swift recommendations for changes but I don't know enough about this to be sure that this isn't an already discussed problem. -Matt
1
0
544
Jan ’23
Metal Ray Tracing, RealityKit, SwiftUI Problems
First of all, I apologize for such a general question, but my code is far too long to post. However, I have narrowed down my problems and am seeking advice for any solutions/workarounds that may help me. I recently updated my physics simulation code from using Metal Performance Shaders for ray tracing to using the (fairly) new Metal ray tracing routines directly. A few notes on my program: I perform the ray tracing entirely in a separate thread using Compute Kernels -- there is no rendering based on the ray tracing results. The compute kernels are called repeatedly and each ends with a waitUntilCompleted() command. The main thread is running a SwiftUI interface with some renderings that use RealityKit to display the scene (i.e., the vertices), and the rays that traverse the scene using Metal Ray Tracing. This is purely a Mac program and has no IOS support. So, the problem is that there seems to be some conflict between RealityKit rendering and the ray-tracing compute kernels where I will get a "GPU Soft Fault" when I run the "intersect" command in Metal. After this soft-fault error, my Ray Tracing results are completely bogus. I have figured out a solution to this which is to refit my acceleration structures semi-regularly. However, this solution is inelegant and probably not sustainable. This problem gets worse the more I render in my RealityKit display UI (rendered as a SwiftUI view) so I am now confident that the problem is some "collision" between the GPU resources needed by my program and RealityKit. I have not been able to find any information on what a "GPU Soft Fault" actually is although I suspect it is a memory violation. I suspect that I need to use fences to cordon off my ray tracing compute kernel from other things that use Metal (i.e., RealityKit), however I am just not sure if this is the case or how to accomplish this. Again, I apologize for the vague question, but I am really stuck. I have confirmed that every Metal buffer I pass to my compute kernel is correct. I did this confirmation by making my object a simple cube and having only one instance of this cube. Something happens to either corrupt the acceleration structure data or to make it inaccessible during certain times when RealityKit needs to use the GPU. Any advice would be appreciated. I have not submitted a bug report since I am still not sure if this is just my lack of advanced knowledge of multiple actors requiring GPU use or if there is something more serious here. Thanks in advance, -Matt
2
0
1.3k
Feb ’22
Scene with over 12,000 duplicate entities
I am creating a RealityKit scene that will contain over 12,000 duplicate cubes arranged in a circle (see image below). This is for some high-energy physical simulations I am doing. I accomplish this scene by creating a single cube and cloning it a bunch of times. So, I there is a single MeshResource and Material even though there are a lot of entities. I have confirmed this by checking with Swift's === operator. Even with this, the program is unworkably slow. Any suggestions or tricks that could help with this type of scene? Using a single geometry was the trick to getting SceneKit to work fast with geometries like this. I've been updating my software to RealityKit because I far prefer the structure of RealityKit over SceneKit.
5
0
1.2k
Nov ’21
PhysicallyBasedMaterial being converted to SimpleMaterial
I am creating a ModelEntity with a programatic mesh. var mat = PhysicallyBasedMaterial() mat.baseColor = .init(tint: .lightGray) mat.roughness = 0.0 mat.metallic = 1.0 let newEnt = ModelEntity(mesh: try! .generate(from: [hex.generateMeshDescriptor()]), materials: [mat])     stages.worldStage.addChild(newEnt) where hex.generateMeshDescriptor() generates the custom mesh. On the screen, everything looks great. The material looks exactly like I expect it to. However, a simple, print shows that my ModelEntity has a single material in its list and its a SimpleMaterial, not a PhysicallyBasedMaterial. This causes my program to crash as I am using PhysicallyBasedMaterial's emissiveColor and emissiveIntensity later on to highlight the objects. print(newEnt.components[ModelComponent.self]!.materials) shows [RealityKit.SimpleMaterial(__resource: RealityKit.__MaterialResource, ... ...] I even try to force the material to be PhysicallyBasedMaterial and it doesn't stick. It's always somehow converted to a SimpleMaterial. I figured I would ask on the forums before I submit a bug report in case there is something basic that I am not understanding. Mac OS Monterey Beta 8. iMac Pro. Xcode 13 Beta 5. Thanks in advance. -Matt
1
0
639
Oct ’21