metal

UIImage created from MTKView results in color/opacity differences

两盒软妹~` 提交于 2019-12-09 06:47:41
问题 When I capture the contents of an MTKView into a UIImage, the resulting image looks qualitatively different, as shown below: The code I use to generate the UIImage is as follows: let kciOptions = [kCIContextWorkingColorSpace: CGColorSpace(name: CGColorSpace.sRGB)!, kCIContextOutputPremultiplied: true, kCIContextUseSoftwareRenderer: false] as [String : Any] let lastDrawableDisplayed = self.currentDrawable! // needed to hold the last drawable presented to screen drawingUIView.image = UIImage

iOS: drawbacks of disabling Metal API Validation in order to fix pipeline failed assertion?

对着背影说爱祢 提交于 2019-12-08 21:05:30
Adding a SKEmitterNode to a SceneKit Scene via a SpriteKit overlay generates the following exception: -[MTLDebugRenderCommandEncoder validateFramebufferWithRenderPipelineState:]:1196: failed assertion `For color attachment 0, the render pipeline's pixelFormat (MTLPixelFormatRGBA8Unorm_sRGB) does not match the framebuffer's pixelFormat (MTLPixelFormatBGR10_XR).' This exception occurs on an iPhone 7 device, but does not appear in the simulator. Searching online yielded one valid workaround: disabling Metal API Validation (in Edit Scheme > Options). What are the drawbacks or gotchas with this

overlapping Metal Point primitives and blending

血红的双手。 提交于 2019-12-08 20:53:33
I am rendering Points primitives that overlap partially. The fragment shader shades parts of each Point primitive square transparent (solid center circle). A point primitive that does not overlap any other point primitive, shades as expected (the transparent areas of the square show the background). When such a point primitive overlaps another point primitive, the behavior is a unexpected. specifically: the transparent area does not show the opaque color of the unlerlying points primitive, but instead clears it and shows the background color. In other words, point primitives with a higher

how to use an array of textures in metal

非 Y 不嫁゛ 提交于 2019-12-08 12:05:12
问题 I want to use array of textures in metal shader, but it crash when running my app(iPhone6, A8), here is the error log: Failed to created pipeline state, error Error Domain=AGXMetalA8 Code=3 "Could not resolve texture/sampler references" UserInfo={NSLocalizedDescription=Could not resolve texture/sampler references} I have try to google but did not find useful information, can anyone give me some suggestions, Thanks. Here is my code: fragment float4 fragment_texture (ShaderInput vert [[stage_in

64-bit RGBA UIImage? CGBitmapInfo for 64-bit

不想你离开。 提交于 2019-12-08 12:04:27
问题 I'm trying to save a 16-bit depth PNG image with P3 color space from a Metal texture on iOS. The texture has pixelformat = .rgba16Unorm, and I extract the data with this code func dataProviderRef() -> CGDataProvider? { let pixelCount = width * height var imageBytes = [UInt8](repeating: 0, count: pixelCount * bytesPerPixel) let region = MTLRegionMake2D(0, 0, width, height) getBytes(&imageBytes, bytesPerRow: bytesPerRow, from: region, mipmapLevel: 0) return CGDataProvider(data: NSData(bytes:

iOS: drawbacks of disabling Metal API Validation in order to fix pipeline failed assertion?

隐身守侯 提交于 2019-12-08 07:20:46
问题 Adding a SKEmitterNode to a SceneKit Scene via a SpriteKit overlay generates the following exception: -[MTLDebugRenderCommandEncoder validateFramebufferWithRenderPipelineState:]:1196: failed assertion `For color attachment 0, the render pipeline's pixelFormat (MTLPixelFormatRGBA8Unorm_sRGB) does not match the framebuffer's pixelFormat (MTLPixelFormatBGR10_XR).' This exception occurs on an iPhone 7 device, but does not appear in the simulator. Searching online yielded one valid workaround:

overlapping Metal Point primitives and blending

断了今生、忘了曾经 提交于 2019-12-08 07:17:21
问题 I am rendering Points primitives that overlap partially. The fragment shader shades parts of each Point primitive square transparent (solid center circle). A point primitive that does not overlap any other point primitive, shades as expected (the transparent areas of the square show the background). When such a point primitive overlaps another point primitive, the behavior is a unexpected. specifically: the transparent area does not show the opaque color of the unlerlying points primitive,

Wider and smoother lines in Metal shader

放肆的年华 提交于 2019-12-08 05:08:08
问题 I’m converting some glsl / opengl code to Metal for a SceneKit app so it can be rendered by Metal. I have a SCNNode (solidNode) created with primitive type SCNGeometryPrimitiveTypePolygon, and a childNode (wireframeNode) created with primitive type SCNGeometryPrimitiveTypeLine. The child node has the same vertices, ie. is the same model, and is placed slightly closer to the camera/eye position to prevent z-fighting. In OpenGL I simply used glLineWidth to draw lines more than 1px wide but it

Metal rendering really slow - how to speed it up

限于喜欢 提交于 2019-12-08 02:03:57
问题 I have a working metal application that is extremely slow, and needs to run faster. I believe the problem is I am creating too many MTLCommandBuffer objects. The reason I am creating so many MTLCommandBuffer objects is I need to send different uniform values to the pixel shader. I've pasted a snippit of code to illustrate the problem below. for (int obj_i = 0 ; obj_i < n ; ++obj_i) { // I create one render command buffer per object I draw so I can use different uniforms id <MTLCommandBuffer>

Confusion About CIContext, OpenGL and Metal (SWIFT). Does CIContext use CPU or GPU by default?

眉间皱痕 提交于 2019-12-08 00:10:50
问题 So I'm making an app where some of the main features revolve around applying CIFilters to images. let context = CIContext() let context = CIContext(eaglContext: EAGLContext(api: .openGLES3)!) let context = CIContext(mtlDevice: MTLCreateSystemDefaultDevice()!) All of these give me about the same CPU usage (70%) on my CameraViewController where I apply filters to frames and update the imageview. All of these seem to work the exact same way which makes me think I am missing some vital piece of