I have a following MTLBuffer created. How can I send INPUTVALUE to the memINPUT buffer? I need to send repeatedly in Objective-C.
// header file
@property id<MTLBuffer> memINPUT;
// main file
int length = 1000;
...
memINPUT = [_device newBufferWithLength:(sizeof(float)*length) options:0];
...
float INPUTVALUE[length];
for (int i=0; i < length; i++) {
INPUTVALUE[i] = (float)i;
}
// How to send to INPUTVALUE to memINPUT?
...
The following is Swift version. I am looking for Objective-c version.
memINPUT.contents().copyMemory(from: INPUTVALUE, byteCount: length * MemoryLayout<Float>.stride);
Delve into the world of graphics and game development. Discuss creating stunning visuals, optimizing game mechanics, and share resources for game developers.
Post
Replies
Boosts
Views
Activity
just using SKView func texture(from node: SKNode, crop: CGRect) -> SKTexture?
crash_info_entry_0 -[MTLTextureDescriptorInternal validateWithDevice:]:1325: failed assertion `Texture Descriptor Validation MTLTextureDescriptor has width (8256) greater than the maximum allowed size of 8192. MTLTextureDescriptor has height (8242) greater than the maximum allowed size of 8192. '
Help!
I've got a scene which renders as I expect:
but in the acceleration structure inspector, the kraken primitive doesn't render:
In the list on the left, the structure is there. As expected, there is just one bounding-box primitive as a lot happens in the intersection function (doing it this way since I've already built my own octree and it takes too long to rebuild BVHs for dynamic geometry)
This is just based on the SimplePathTracer example.
The signatures of the sphereIntersectionFunction and octreeIntersectionFunction aren't that different:
[[intersection(bounding_box, triangle_data, instancing)]]
BoundingBoxIntersection sphereIntersectionFunction(// Ray parameters passed to the ray intersector below
float3 origin [[origin]],
float3 direction [[direction]],
float minDistance [[min_distance]],
float maxDistance [[max_distance]],
// Information about the primitive.
unsigned int primitiveIndex [[primitive_id]],
unsigned int geometryIndex [[geometry_intersection_function_table_offset]],
// Custom resources bound to the intersection function table.
device void *resources [[buffer(0), function_constant(useResourcesBuffer)]]
#if SUPPORTS_METAL_3
,const device Sphere* perPrimitiveData [[primitive_data]]
#endif
,ray_data IntersectionPayload& payload [[payload]])
{
vs.
[[intersection(bounding_box, triangle_data, instancing)]]
BoundingBoxIntersection octreeIntersectionFunction(// Ray parameters passed to the ray intersector below
float3 origin [[origin]],
float3 direction [[direction]],
float minDistance [[min_distance]],
float maxDistance [[max_distance]],
// Information about the primitive.
unsigned int primitiveIndex [[primitive_id]],
unsigned int geometryIndex [[geometry_intersection_function_table_offset]],
// Custom resources bound to the intersection function table.
device void *resources [[buffer(0)]],
const device BlockInfo* perPrimitiveData [[primitive_data]],
ray_data IntersectionPayload& payload [[payload]])
Note: running 15.0 beta 5 (15A5209g) since even the unmodified SimplePathTracer example project will hang the acceleration structure viewer on Xcode 14.
Update:
Replacing the octreeIntersectionFunction's code with just a hard-coded sphere does render. Perhaps the viewer imposes a time (or instruction count) limit on intersection functions so as to not hang the GPU?
I see the documentation says visionOS,
but when I run the code it return nil on nextDrawable()
Error: Failure while executing; /usr/bin/env /usr/local/Homebrew/Library/Homebrew/shims/shared/curl --disable --cookie /dev/null --globoff --show-error --user-agent Homebrew/4.1.3\ \(Macintosh\;\ Intel\ Mac\ OS\ X\ 14.0\)\ curl/8.1.2 --header Accept-Language:\ en --retry 3 --fail --location --silent --head https://mirrors.ustc.edu.cn/homebrew-bottles/bison-3.8.2.ventura.bottle.tar.gz exited with 35.
Hi there,
I can't find a way to share constants, e.g. an int with Swift via a bridging header. I have tried a number of ways. Would love a simple no or an explanation for how to do this, so I can ideally share some constants used by the CPU and GPU.
Thank you!
What is the most efficient way to use a MTLTexture (created procedurally at run-time) as a RealityKit TextureResource? I update the MTLTexture per-frame using regular Metal rendering, so it’s not something I can do offline. Is there a way to wrap it without doing a copy?
A specific example would be great.
Thank you!
I’m working with Metal on iPad Playgrounds and made a simple editor to help craft shaders. Press a button, it tries to make the library, and reports any errors or warnings. The problem is it doesn’t report warnings if the compile was successful.
I’m using the version of makeLibrary with a completion handler which passes in both a MTLLibrary? and Error? because the docs specifically say “Both library and error can be non-nil if the compiler successfully generates a library with warnings.” However I’m not seeing that happen, when there’s only warnings the Error parameter is nil.
Maybe I’m misunderstanding or using something wrong. Is this a bug or how do I get the warnings on a successful compile?
Here’s a demo. It should show 2 warnings but doesn’t because err is nil. Add an extraneous character in source to cause an error and then err is not nil and shows the 2 warnings.
import SwiftUI
let source = """
#include <metal_stdlib>
using namespace metal;
float something() {}
#warning "foo";
"""
struct ContentView: View {
var body: some View {
Button("test") {
guard let device = MTLCreateSystemDefaultDevice() else { return }
device.makeLibrary(source: source, options: nil) { lib, err in
if err == nil {
print("no errors or warnings")
} else if let err = err as? MTLLibraryError {
print("found errors or warnings")
print(err.localizedDescription)
} else {
print("unknown error type")
}
}
}
}
}
Oh, and this is where it says both library and error can be non-nil
https://developer.apple.com/documentation/metal/mtlnewlibrarycompletionhandler
Disclaimer: I am new to all things 3D. There could be a variety of things wrong with what I'm doing that are not unique to RealityKit. Any domain info would be appreciated.
So, I'm following, what I think are, the recommended steps to import a shader-node material from reality composer pro and apply it to another modelEntity.
I do the following:
guard let entity = try? Entity.load(named: "Materials", in: RealityKitContent.realityKitContentBundle) else { return model }
let materialEntity = entity.findEntity(named: "materialModel") as? ModelEntity
guard let materialEntity else { return model }
I then configure a property on it like so:
guard var material = materialEntity.model?.materials[0] as? ShaderGraphMaterial else { return model }
try coreMaterial.setParameter(name: "BaseColor", value: .color(matModel.matCoreUIColor))
I then apply it.
This is what my texture looks like in RealityComposer:
I notice that my rendered object has distortions in the actual RealityView. Note the diagonal lines that appear "Stretched".
What could be doing this? I thought Node Shaders were supposed to be more resilient to distortions like this? I'm not sure if I've got a bug or if I'm using it wrong.
FWIW, this is a shader based on apple's felt material shader. My graph looks like this:
Thanks
Is there an example app?
Am writing a visual music app. It uses a custom SwiftUI menus over a UIKit (UIHostingController) canvas. The metal pipeline is custom.
A fully functional example app would be super helpful. Nothing fancy; an immersive hello triangle would be a great start.
Later, will need to port UITouches to draw and CMMotionManager to track pov within a Cubemap. Meanwhile, baby steps.
Thanks!
Hello,
I’ve started testing the Metal Shader Converter to convert my HLSL shaders to metallib directly, and I was wondering if the option ’-frecord-sources’ was supported in any way?
Usually I’m compiling my shaders as follows (from Metal):
xcrun -sdk macosx metal -c -frecord-sources shaders/shaders.metal -o shaders/shaders.air
xcrun -sdk macosx metallib shaders/shaders.air -o shaders/shaders.metallib
The -frecord-sources allow me to see the source when debugging and profiling a Metal frame.
Now with DXC we have a similar option, I can compile a typical HLSL shader with embedded debug symbols with:
dxc -T vs_6_0 -E VSMain shaders/triangle.hlsl -Fo shaders/triangle.dxil -Zi -O0 -Qembed_debug
The important options here are ’-Zi` and ’-Qembed_debug’, as they make sure debug symbols are embedded in the DXIL.
It seems that right now Metal Shader Converter doesn’t pass through the DXIL debug information, and I was wondering if it was possible. I’ve looked at all the options in the utility and haven’t seen anything that looked like it.
Right now debug symbols in my shaders is a must-have both for profiling and debugging.
For reference an alternative pipeline would be to use spir-v cross instead. For reference here's what a typical pipeline with dxc and spir-v cross look like:
HLSL -> SPIRV -> AIR -> METALLIB
dxc -T ps_6_0 -E PSMain -spirv shaders/triangle.hlsl -Zi -Qembed_debug -O0 -Fo shaders/triangle.frag.spirv
spirv-cross --msl shaders/triangle.frag.spirv --output shaders/triangle.frag.metal
xcrun -sdk macosx metal -c -frecord-sources shaders/triangle.frag.metal -o shaders/triangle.frag.air
xcrun -sdk macosx metallib shaders/triangle.frag.air -o shaders/triangle.frag.metallib
As you can see, it's a lot more steps than metal shader converter, but after all those steps you can get some sort of shader symbols in xcode when debugging a metal frame, which is better than nothing:
Please let me know if I can provide files, projects or anything that can help supporting shader symbols directly with metal shader converter.
Thank you for your time!
I'm trying to make a real-time peer-to-peer multiplayer game with GameKit/Game Center. I'm trying to store a dictionary of player IDs and scores ([String:Int]) to keep track of and share player scores during a game. Essentially, I want to be able to increment the score of a player locally, then send the updated scores dictionary to all the other players.
However, the GKLocalPlayer.local.gamePlayerID seems to be in a completely different format than any other connected GKPlayer, so when I try to access the GKMatch.players with the gamePlayerID, it isn't found (and yes, I'm aware that GKMatch.players doesn't contain the local player).
The GKPlayer has an 18-digit long integer, whereas the GKLocalPlayer has A:_ and then a long hexadecimal number (I think it's 37 digits in decimal).
Can someone explain this difference or point to some resources that explain how I can implement this functionality correctly?
Here's a simplified example of what I'm doing:
var scores: [String:Int] // dictionary of [gamePlayerID:Score]
scores[myMatch.players.first.gamePlayerID] = 3
scores[GKLocalPlayer.local.gamePlayerID] = 5
sendScores(scores) // sends data to all players using myMatch.sendData()
/*
When the receiving players decode and try to access scores[gamePlayerIDOfSendingPlayer],
it isn't found because it's different from that player's gamePlayerID
in the receiving player's GKMatch.players array
*/
Hello,
Yesterday I updated xCode 15.2 Beta to 15.5. Now i tried to run my App but after starting i I recognized that when I open my volumetric window that the USDA scene in my RealityView doesn't file doesn't appear anymore. RealityView will be executed.+
When I use a 3D Model in my volumetric window the USDA appears without any problems.
Here is my code:
//
//
//
// Created by Patrick Schnitzer on 30.07.23.
//
import SwiftUI
import RealityKit
import RealityKitContent
struct MyWindow: View {
var body: some View {
RealityView { content in
async let object = ModelEntity(named: "testScene", in: realityKitContentBundle)
print("I exec")
guard let object1 = try? await cloudyWeather else {return }
object1.generateCollisionShapes(recursive: false)
object1.components.set(InputTargetComponent())
object1.location = .init(0,0.5,0)
object1.scale *= 1
content.add(object1)
}.gesture(dragGesture)
}
var dragGesture: some Gesture {
DragGesture()
.targetedToAnyEntity()
.onChanged { value in
print(value.entity.name)
value.entity.position = value.convert(value.location3D, from: .local, to: value.entity.parent!)
}
}
}
#Preview {
MyWindow()
}
I'm working on an Immersive game that requires Controller input. The Happy Beam sample is supposed to support hand tracking and controller input.
I have tested the controller input with a PS5 Dual Sense controller and all I can do is move around the scene while the game plays. But cannot interact with anything in the scene.
Can anyone confirm this and or suggest how I can use a controller in an immersive space?
I cannot find a single working example.
Hi,
I'm aware that the EnvironmentResource has to be put into a folder ended with ".skybox", because Xcode need to compile the image at build time.
But why? Is it possible to load the EnvironmentResource on demand?
Mac Studio won't show scene in canvas assist
Device : iPhone 13 Pro, iOS 17 Beta 5.
Xcode : Both 14.3.1 and 15 Beta 5
My app is crashing for no reason after a touch gesture on my device, but it's working fine on a simulator.
I have used GameKit but not imported Metal or SpriteKit.
I'm getting these errors.
CleverJacks[791:45451] Metal API Validation Enabled
-[MTLDebugRenderCommandEncoder setRenderPipelineState:]:1615: failed assertion `Set Render Pipeline State Validation
For color attachment 2, the render pipeline's pixelFormat (MTLPixelFormatRGBA16Float) does not match the framebuffer's pixelFormat (MTLPixelFormatR16Float).
the pipelineState's per sample imageBlock usage(14) is greater than the encoder's perSample imageBlock usage(8)
This is an spinoff from forum post xrOS+Metal example code here
Am porting Warren Moore's example here
Have the most of the conversion to Swift complete but am stuck at a couple places
ar_data_providers_create_with_data_providers(...)
cp_time_to_cf_time_interval(...)
Any hints on how to track these down? Thanks!
is any one else having issues with game scene-view .dae and or .scn files
it seems these new beta release is very incompatible with files that work perfect with previous Xcode releases up to Xcode 14 I'm working on upgrading a simple striped down version of my chess game and run in to strange and bogus errors messages and crashes
/Users/helmut/Desktop/schachGame8423/schach2023/scntool:1:1 failed to convert file with failure reason: *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
all tools reality converter exporting the .dae file to other graphic files working fine as in prior Xcode releases but some thing is missing in current beta release of Xcode 15
Reality Composer had some rudimentary animation. I have not been able to find an equivalent in the Pro version. Are there any planned? I'd rather avoid the steep learning curve of the available high end tools for some basic transform animations.