Quantcast
Channel: Questions in topic: "compute shader"
Viewing all 287 articles
Browse latest View live

I can't get AsyncGPUReadback.RequestIntoNativeArray to work. Error in Job with owner being Invalidated.

$
0
0
Hey guys, I'd love to get AsyncGPUReadback.RequestIntoNativeArray working, as streaming the data from my compute shader directly into a native array would just be beautiful. Note that the compute shader really doesn't generate any important data. I want to get this concept working in the test environment so that I can build jobs into a bigger project I have going with dynamic mesh generation. However, I'm getting the following error and can't figure out why! > InvalidOperationException: The> Unity.Collections.NativeArray`1[DataTest+test_struct]> SimpleJob.my_test_data can no longer> be accessed, since its owner has been> invalidated. You can simply Dispose()> the container and create a new one.> Unity.Jobs.LowLevel.Unsafe.JobsUtility.Schedule> (Unity.Jobs.LowLevel.Unsafe.JobsUtility+JobScheduleParameters&> parameters) (at> :0)> Unity.Jobs.IJobExtensions.Schedule[T]> (T jobData, Unity.Jobs.JobHandle> dependsOn) (at> :0)> DataTest+d__3.MoveNext> () (at Assets/DataTest/DataTest.cs:54) Here's my struct on the processor: public struct test_struct { public int val; } Here's the Coroutine that runs my **compute shader** and my **job** IEnumerator computeShaderThenJob() { ComputeBuffer test_buffer = new ComputeBuffer(10, sizeof(byte) * 4, ComputeBufferType.Raw); int kernalHandle = compute_test.FindKernel("CSMain"); compute_test.SetBuffer(kernalHandle, "TestBuffer", test_buffer); compute_test.Dispatch(kernalHandle, 10, 1, 1); NativeArray test_data = new NativeArray(10, Allocator.Persistent); AsyncGPUReadbackRequest test_data_request = AsyncGPUReadback.RequestIntoNativeArray(ref test_data, test_buffer); while (!test_data_request.done) { yield return null; } test_buffer.Dispose(); MeshFilter meshFilter = GetComponent(); Mesh mesh = meshFilter.mesh; Mesh.MeshDataArray mesh_data = Mesh.AllocateWritableMeshData(1); SimpleJob myJob = new SimpleJob(); myJob.my_test_data = test_data; myJob.outputMesh = mesh_data[0]; JobHandle handle = myJob.Schedule(); while (!handle.IsCompleted) { yield return null; } handle.Complete(); mesh.name = "tetrahedron"; Mesh.ApplyAndDisposeWritableMeshData(mesh_data, mesh); mesh.RecalculateTangents(); mesh.RecalculateBounds(); test_data.Dispose(); } My Compute Shader: // Each #kernel tells which function to compile; you can have many kernels #pragma kernel CSMain // Create a RenderTexture with enableRandomWrite flag and set it // with cs.SetTexture struct test_struct { int value; }; RWStructuredBuffer TestBuffer; [numthreads(1,1,1)] void CSMain (uint3 id : SV_DispatchThreadID) { TestBuffer[0].value = 5; } My Job: private struct SimpleJob : Unity.Jobs.IJob { [ReadOnly] public NativeArray my_test_data; public Mesh.MeshData outputMesh; public void Execute() { int num_vertices = 12; int num_triangle_indices = 12; outputMesh.SetVertexBufferParams(num_vertices, new VertexAttributeDescriptor(VertexAttribute.Position), new VertexAttributeDescriptor(VertexAttribute.Normal, stream: 1)); NativeArray vertex_data = outputMesh.GetVertexData(); NativeArray normals_data = outputMesh.GetVertexData(stream: 1); // Four tetrahedron vertex positions: var sqrt075 = Mathf.Sqrt(0.75f); var p0 = new Vector3(0, 0, 0); var p1 = new Vector3(1, 0, 0); var p2 = new Vector3(0.5f, 0, sqrt075); var p3 = new Vector3(0.5f, sqrt075, sqrt075 / 3); vertex_data[0] = p0; vertex_data[1] = p1; vertex_data[2] = p2; vertex_data[3] = p0; vertex_data[4] = p2; vertex_data[5] = p3; vertex_data[6] = p2; vertex_data[7] = p1; vertex_data[8] = p3; vertex_data[9] = p0; vertex_data[10] = p3; vertex_data[11] = p1; outputMesh.SetIndexBufferParams(num_triangle_indices, IndexFormat.UInt16); NativeArray triangle_data = outputMesh.GetIndexData(); for (ushort i = 0; i < triangle_data.Length; ++i) triangle_data[i] = i; for (ushort i = 0; i < triangle_data.Length; ++i) normals_data[i] = new Vector3(1, 1, 1); outputMesh.subMeshCount = 1; outputMesh.SetSubMesh(0, new SubMeshDescriptor(0, num_triangle_indices)); } } This has got me well and truly stumped. Any pointers in the right direction would be greatly appreciated. Thanks!

ComputeBuffer-Can multiple Indices of compute shader modify the same index???

$
0
0
Hello my friends! I'm having a problem with using too much memory in my dynamic mesh creation >_< Part of my algorithm computes lots and lots and lots of Booleans. > ___________________________ As far as I can tell though, the smallest blittable data type I can send back and forth between the processor and gpu is 4 bytes. (int, for example). > ___________________________ So I'm thinking...well, if I could find a way in my compute shader to modify the first index of my ComputeBuffer on multiple SV_DispatchThreadIDs, I could store 32 of my booleans in a single int with a few bit shifts and Bitwise Operations!> ___________________________ Is such a thing possible???> ___________________________ If not, does anyone have any tricks for getting the most out of those 4 byte chunks?> ___________________________ (I also had the thought of packing the data the way I described after reading the memory back from the ComputeBuffer. But, I would still be temporarily using some big chunks of memory). > ___________________________ For anyone curious there is a different trick I've found. I can set up a struct on the cpu as bytes public struct test_struct { public byte value1; public byte value2; public byte value3; public byte value4; } Then in the compute shader as an integer struct test_struct { int value; }; And by bit shifting by 8 spaces I can assign 4 different values into a single integer.

Create Mesh from Triangle Data Created on ComputeShader

$
0
0
Hi!

I have recently finished working on a terrain generation system that utilizes the GPU to generate the noise for the terrain and calculate the vertices and triangles of each terrain chunk.

After I got it fully working, I have been trying to optimize it as best as I can, and I noticed that calling `ComputeBuffer.GetData()` on a buffer with a large amount of data stored in it can be very costly.
One such buffer is the buffer that stores the triangulation data of the mesh of a terrain chunk, which is later used to create the actual mesh for the terrain chunk `GameObject` in the scene.

So my question is this: is there a way to skip getting the data from the GPU back to the CPU to generate the mesh? i.e is there a way to generate the mesh for a `GameObject` in the scene straight from the `ComputeShader` I use to generate the triangles in the first place?

Thank you!

Compute shader works in editor, but not found when built and running in browser

$
0
0
Running my project in the browser after building gives the error "Kernel CSMain not found." Since I have only one kernel, I tried setting the kernel handle to 0. This also works in the editor but gives the error "IndexOutOfRangeException: Invalid kernelIndex (0) passed, must be non-negative less than 0."

The platform for this project is WebGL 2.0. My compute shader is very simple, it takes a randomized vector and outputs a texture with a single color based on the vector.

Why would it work in editor but not in browser? It should be using the same WebGL 2.0 api and the same drivers right? My guess was that the compute shader failed to compile, but aren't shaders precompiled on build? On build I got no errors. And yet the shader is missing somehow. Is there a way to view shader compiler errors when in browser?

I also got an error in browser "RenderTexture.Create failed" because it doesn't support the format RGBA8 UNorm. This is strange to me, because the texture I am using is RGBA32, which it says is supported. There doesn't seem to be a problem with the texture either if I don't try to access the kernel.

Kernel threads are of dimension (8, 8, 1). My output texture is of type RWTexture2D.

- Unity build 2020.1.9f1 (I have tried other builds with no success)
- Browser: Firefox 81.02 (I have tried other browsers with no success)

How to share constant variables between Compute Shaders?

$
0
0
So, I have two compute shaders A and B. Right now, before every dispatch, I send my mouse coordinates to both of them every update. So, from my understanding, you can actually determine which register the mouse coordinates go to like so: float2 mxy :register(c1); // at the top of the shader And by declaring this in both shaders, you can actually avoid sending the mouse coordinates twice. The problem is, that this does not work! I've tried making cbuffers as well, but to no avail. (I don't actually know how to work with cbuffers on the CPU side that said) **TLDR:** why can't I share variables between two compute shaders using float2 mxy :register(c1); ?

Replacing a geometry shader with a compute shader. How do I output an arbitrary number of triangles?

$
0
0
Hi everyone. I have been trying to recreate a geometry shader in a compute shader, and I am having trouble outputting an arbitrary number of triangles. ---------- Basically, I want to take in mesh, and for each triangle on that mesh, create a variable amount of triangles extruded above it. I have a buffer filled with vertex data and another with the triangle indices taken from the mesh. Then, I dispatch a compute shader to run once per triangle. Once that's done, I call DrawProceduralIndirect. ---------- To create triangles, I was I was using an append buffer and appending a triplet of vertices. Like this: ---------- #pragma kernel Main ... StructuredBuffer _SourceVertices; StructuredBuffer _SourceTriangles; AppendStructuredBuffer _DrawVertices; ... [numthreads(128,1,1)] void Main(uint3 id : SV_DispatchThreadID) { int triStart = id.x * 3; SourceVertex a = _SourceVertices[_SourceTriangles[triStart]]; SourceVertex b = _SourceVertices[_SourceTriangles[triStart + 1]]; SourceVertex c = _SourceVertices[_SourceTriangles[triStart + 2]]; ... for(int i = 0; i < NumExtrusions; i++) { _DrawVertices.Append(MakeDrawVertex(a), i); _DrawVertices.Append(MakeDrawVertex(b), i); _DrawVertices.Append(MakeDrawVertex(c), i); } } ---------- The problem is that the order of an append buffer is not guaranteed to be the order of insertion (because of multithreading). So, when I get to the graphics shader, the triangles are all out of order. I feel like I'm missing something simple. Is the "correct" way to do this to output a triangle structure and then dispatch another compute shader which decomposes those into vertices? ---------- Thanks so much for your help.

Why is my compute shader returning values I explicitly avoided?

$
0
0
CONTEXT: I've been working with the Marching Cubes algorithm to do some terrain generation stuff. The end goal is pretty much a clone of Worms 3D, but right now the first thing I need is some terrain to work with. I'm fairly new to unity, but not a scrub. I've been hacking apart [Sebastian Lague's][1] Marching Cubes coding adventure to make it fit my needs ([github][2]). The main things I wanted to salvage from his code was his use of compute shaders to generate some nice noise (perlin I think?) and to perform the marching cube algorithm. Right now, I'm stuck on the first part. I'm trying to get the points and the noise back from my compute shader. However, points I have EXPLICTLY SAID TO NOT RETURN are being returned somehow, and I'm having a *bad time.* Here's the code for the compute shader as it stands right now. There's no noise code here in my noise shader because I have been debugging this for HOURS. I've got a ComputeBuffer to store points and their noise values as Vector4's/float4's. "points" is defined inside Density.compute, and it works in SL's code, so idk what's up. #pragma kernel Density #include "/Includes/Density.compute" #include "/Includes/Noise.compute" [numthreads(4, 4, 4)] void Density (int3 id : SV_DispatchThreadID) { if (id.x >= 6|| id.y >= 6|| id.z >= 6) { return; } int index = indexFromCoord(id.x,id.y,id.z); points[index] = float4(id, 0.5); } Yet through extensive use of Debug.Log(), I'm finding I'm getting really weird points in the mix, like (0.0, 7.0, 23.0, -6.9). I'm getting the points out of the compute buffer by the following code: Vector4[] noiseVectors = new Vector4[pointsBuffer.count]; pointsBuffer.GetData(noiseVectors); and then looping through the array to put it all in a dictionary for future modification. That's how I'm ultimately getting it back and getting it out of Debug.Log(). The last places I can think of problems arising are: - Are my buffers being populated by random stuff from like data already in memory? - Am I not being careful enough when pulling the data out of the ComputeBuffer? - - If so, why does it work for some points and not others? - Is my ComputeBuffer not being properly defined (code not shown, but it's near verbatim from SL's github) I dunno folks. Any chance y'all could help me out? also my first time posting a question. any feedback? [1]: https://www.youtube.com/c/SebastianLague/ [2]: https://github.com/SebLague/Marching-Cubes

how do i make functions in compute shaders .

$
0
0
i have written this simple piece of code but it does not work. with some testing i have isolated the problem to it not being run , with occupied(float3(1,1,1)); i want to run this from the GPU ,what did i do wrong bool occupied(float2 idf) { if (Result[idf.xy].w >0 ) { return true; } else{ return false;} }

Copying references via Compute Buffers to shaders

$
0
0
I have an array of struct's like so: ` struct Node { Node a, b, ... ... } Node[] nodes = ... ` When I send this via a buffer to a shader, `buffer.SetData(nodes);`, can I get the child nodes `node.a`, `node.b` etc. In the compute shader? How do the pointers convert? If not, what options do I have to fix this?,

AsyncGPUReadback.GetData with computeBufferType.Append

$
0
0
Hello here :) I'm working on a procedural terrain generator base on the transvoxel algorithm. For generating chunks on my terrain, I implemented a compute shader which computes triangles of the chunk mesh with the marching cube algorithm. I want to use AsyncGPUReadback to get data from the GPU back to the CPU for rendering. Without the async method I use the ComputeBuffer.CopyCount method to get the number of triangles in my buffer and then get the data with triangleBuffer.GetData : // Create my triangle buffer ComputeBuffer triangleBuffer = new ComputeBuffer(maxTriangleCount, sizeof (float) * 3 * 3, ComputeBufferType.Append); // Send data to the compute shader // Get triangle count ComputeBuffer triCountBuffer = new ComputeBuffer (1, sizeof (int), ComputeBufferType.Raw); ComputeBuffer.CopyCount(triangleBuffer, triCountBuffer, 0); int[] triCountArray = { 0 }; triCountBuffer.GetData(triCountArray); int numTris = triCountArray[0]; // Get triangle data from shader Triangle[] tris = new Triangle[numTris]; triangleBuffer.GetData(tris, 0, 0, numTris); This allow me to only get the data I want from the GPU since it's impossible for me to know how many triangles the algorithm will create. With AsyncGPUReadback I don't know how to do this since the only method that I see to get the data is if (request.hasError) { return; } if (request.done) { // Get triangle data from shader NativeArray triangles = request.GetData(); // Generate the mesh } Someone know how to manage this ? Nathan

SampleteLevel don't work on ps4

$
0
0
I use SampleLevel to sample texture, it's work on pc, but don't work on ps4. Here is the Script and ComputeShader: using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using UnityEngine; public class CommandBufferTest : MonoBehaviour { private static int _Map = Shader.PropertyToID("_Map"); private static int _TestDataBuffer = Shader.PropertyToID("_TestDataBuffer"); public ComputeShader m_shader; public RenderTexture m_rt; private ComputeBuffer m_testDataBuffer; private TestData[] testDatas = null; private int k_id; void Start() { k_id = m_shader.FindKernel("CSMain"); m_shader.SetTexture(k_id, _Map, m_rt); testDatas = new TestData[1]; testDatas[0].x = 1; int inputSize = Marshal.SizeOf(typeof(TestData)); m_testDataBuffer = new ComputeBuffer(1, inputSize, ComputeBufferType.Default); m_shader.SetBuffer(k_id, _TestDataBuffer, m_testDataBuffer); m_testDataBuffer.GetData(testDatas); Debug.Log(testDatas[0].x); } // Update is called once per frame void Update() { m_shader.Dispatch(k_id, 8, 1, 1); m_testDataBuffer.GetData(testDatas); Debug.Log(testDatas[0].x); } private void OnGUI() { GUILayout.Label("buffer_X:" + testDatas[0].x + "|buffer_Y:" + testDatas[0].y + "|buffer_Z" + testDatas[0].z); } } =============================================== #pragma kernel CSMain cbuffer CB { Texture2D _Map; SamplerState sampler_Map; } struct TestData//for test { float x; float y; float z; }; RWStructuredBuffer _TestDataBuffer; [numthreads(8,1,1)] void CSMain (uint3 id : SV_DispatchThreadID) { TestData a; float3 _Color = _Map.SampleLevel(sampler_Map, float2(-0.1,-0.1),0); a.x = _Color.r; a.y = _Color.g; a.z = _Color.b; _TestDataBuffer[id.x] = a; } I want to know why it don't work on ps4.

Compute shader not working, should be changing mesh vertices positions

$
0
0
So, currently I am trying to change vertex positions in a mesh using a Compute Shader and Compute Buffer. As you can see in my compute shader, I'm just trying to make the vertices move around on the y axis. My goal for this is just to learn how it is done, however regardless of what I do nothing seems to work. I feel like there is a very obvious flaw that I am not seeing. When I run the code, absolutely nothing happens. My main C# Script below using System.Collections; using System.Collections.Generic; using UnityEngine; public class MeshDeformScript : MonoBehaviour { public struct MyTestVertexData { public uint id; public Vector4 pos; public Vector3 nor; public Vector4 tan; public Vector4 uv; } public GameObject go; public ComputeShader shader; //Compute private int _kernel; private int dispatchCount = 0; private ComputeBuffer vertexBuffer; private MyTestVertexData[] meshVertData; private Mesh mesh; // Start is called before the first frame update void Start() { //The Mesh mesh = go.GetComponent().mesh; mesh.name = "My Mesh"; //MeshVertexData array meshVertData = new MyTestVertexData[mesh.vertexCount]; for (int j=0; j< mesh.vertexCount; j++) { meshVertData[j].id = (uint)j; meshVertData[j].pos = mesh.vertices[j]; meshVertData[j].nor = mesh.normals[j]; meshVertData[j].uv = mesh.uv[j]; meshVertData[j].tan = mesh.tangents[j]; } //Compute Buffer vertexBuffer = new ComputeBuffer(mesh.vertexCount, 16*4); vertexBuffer.SetData(meshVertData); //Compute Shader kernel _kernel = shader.FindKernel ("CSMain"); uint threadX = 0; uint threadY = 0; uint threadZ = 0; shader.GetKernelThreadGroupSizes(_kernel, out threadX, out threadY, out threadZ); dispatchCount = Mathf.CeilToInt(meshVertData.Length / threadX)+1; shader.SetBuffer(_kernel, "vertexBuffer", vertexBuffer); // read & write shader.SetInt("_VertexCount",meshVertData.Length); } // Update is called once per frame void Update() { shader.SetFloat("_Time",Time.time); shader.Dispatch (_kernel, dispatchCount , 1, 1); } void OnDestroy() { vertexBuffer.Release(); } } ___________________________________________________________________________________ My Compute Shader #pragma kernel CSMain struct MyTestVertexData { uint id; float4 pos; float3 nor; float4 tan; float4 uv; }; //This is only for vertex kernel RWStructuredBuffer vertexBuffer; float _Time; uint _VertexCount; //----------------------VERTEX----------------------------- [numthreads(1,1,1)] void CSMain (uint3 id : SV_DispatchThreadID) { //Real id uint rid = vertexBuffer[id.x].id; vertexBuffer[rid].pos.y = sin(_Time); }

Why is this compute-shader being slowed by a 1MB buffer?

$
0
0
Hi all. I had a compute shader that was working just fine, untill I quadrupled the size of one of the compute buffers from 65,536 bytes to 262,144 bytes. After that increase, the performance profiler tells me that this shader takes about 70ms to complete, when previously the time was insignificant. This buffer is only set once, at launch, and is never read back into the main C# script, so I don't think it can be anything to do with data transfer. I can only assume that I've crossed some sort of subtle but important memory threshhold: some register is overflowing or something. Shader memory management is a pretty arcane topic, so I don't know where to start. Can anyone give me a clue? Any help is appreciated. --and here's the shader. The buffer in question is "imageLibrary:" RWStructuredBuffer bugger; RWStructuredBuffer imageLibrary; RWStructuredBuffer world; RWStructuredBuffer cameraDimensions; RWStructuredBuffer hereNow; RWStructuredBuffer scale; RWStructuredBuffer output; #pragma kernel action [numthreads(1,1,1)] void action (uint3 group : SV_GroupID, uint3 thread : SV_GroupThreadID) { uint members, stride; imageLibrary.GetDimensions(members, stride); for (int i = 0; i < members; ++i) { bugger[i] = world [i]; } uint totalWidth = cameraDimensions[0].x; float halfWidth = totalWidth / 2; uint totalHeight = cameraDimensions[0].y; float halfHeight = totalHeight / 2; uint offset, nevermind; world.GetDimensions(offset, nevermind); offset = sqrt(offset * 4) / 2; uint sectorLength = totalWidth / 8; //THE DIVISOR CHANGES IF THE THREAD-GROUP COUNT IS CHANGED uint sectorHeight = totalHeight / 8; //THE DIVISOR CHANGES IF THE THREAD-GROUP COUNT IS CHANGED uint xStart = group.x * sectorLength; uint yStart = group.y * sectorHeight; int k = 0; for (uint i = 0; i < sectorHeight; ++i) { for (uint j = 0; j < sectorLength; ++j) { float worldX = hereNow[0].x + ((float)(xStart - halfWidth) + (float) j) * scale[0].x / halfWidth; float worldY = hereNow[0].y + ((float)(yStart - halfHeight) + (float) i) * scale[0].y / halfHeight; int xInSquare = floor(worldX); int yInSquare = floor(worldY); int index = ((xInSquare + offset) * offset * 2 + (yInSquare + offset)); int byteInFloat = index % 4; index = index / 4; int tileType = world[index]; tileType = tileType >> (byteInFloat * 8); tileType = tileType & 0x000000ff; int2 fromPixel = int2((float)(worldX - xInSquare) * 128, (float)(worldY - yInSquare) * 128); int2 toPixel = int2 (j + xStart, i + yStart); output[cameraDimensions[0].x * toPixel.y + toPixel.x] = imageLibrary.Load(16384 * tileType + 128 * fromPixel.y + fromPixel.x); } } }

Render texture copy to splat map problem

$
0
0
Hi, i'm modifying renderTextures in a compute shader thrue this simplified code: Compute shader RWTexture2D splat0; // splat map RWTexture2D splat1; [numthreads(8, 8, 1)] void UpdateAll(uint2 id : SV_DispatchThreadID) { splat0[coord] = color0; splat1[coord] = color1; } Then i copy the render textures directly into my terrain splatmaps like this: C# Graphics.CopyTexture(_splat0Temp, splatMap0); Graphics.CopyTexture(_splat1Temp, splatMap1); But something is going wrong (I can't show you here how cause when i try to upload an image or a gif i get this error "Error parsing the uploaded file." so i will try to explain it...) When i zoom in the modifications shows up but if i zoom out modifications fade out, maybe this is something due to mip maps but i don't know how to resolve it. If someone is having a clue of what's going on, i would be very happy to know. Thanks

[iOS] App freezes when executing pose detection (PoseNet + Barracuda)

$
0
0
Hello. In our project we implemented pose detection function which is implemented using PoseNet + Barracuda. It works well on Android devices, but on iOS, when first starting pose detection, app freezes about 5~10 seconds, then it starts work. During freezing, The following error occurred in XCode output: Metal: Compute shader (Conv.Conv2DKernelKxK_T16x16_R4x4_NHWC) has 256 threads in a threadgroup which is more than the supported max of 224 in this device 2021-01-26 14:13:40.428697+0900 bodygramdev[2764:1014125] Compiler failed with XPC_ERROR_CONNECTION_INTERRUPTED 2021-01-26 14:13:40.513960+0900 bodygramdev[2764:1014125] Compiler failed with XPC_ERROR_CONNECTION_INTERRUPTED 2021-01-26 14:13:40.544636+0900 bodygramdev[2764:1014125] Compiler failed with XPC_ERROR_CONNECTION_INTERRUPTED 2021-01-26 14:13:40.544773+0900 bodygramdev[2764:1014125] MTLCompiler: Compilation failed with XPC_ERROR_CONNECTION_INTERRUPTED on 3 try Metal: Error creating compute pipeline state: Compiler encountered an internal error (null) What I have tried: - upgrade/downgrade Barracuda version from 0.7.1 preview ~1.2.1 preview - change training models - try to modify pose detection code, but does not work The relevant code is as follows: IEnumerator PoseUpdateNoTex(NativeArray buffer, int width, int height, float secondsToWait) { Model _model; if (Application.platform == RuntimePlatform.Android) { byte[] modelBytes = BetterStreamingAssets.ReadAllBytes(modelName + ".bytes"); _model = ModelLoader.Load(modelBytes); } else { _model = ModelLoader.LoadFromStreamingAssets(modelName + ".bytes"); } var _worker = WorkerFactory.CreateWorker(WorkerFactory.Type.CSharpBurst, _model); #if UNITY_EDITOR var frame = new Texture2D(width, height, TextureFormat.RGB24, false); frame.SetPixels32(buffer.ToArray()); frame.Apply(); #else var bLot = false; if (webcamTexture.videoRotationAngle == 90) { bLot = true; } var _colors = GetRotatedColors(buffer.ToArray(), width, height, bLot); var frame = new Texture2D(height, width, TextureFormat.RGB24, false); frame.SetPixels32(_colors); frame.Apply(); var t = height; height = width; width = t; #endif yield return new WaitForEndOfFrame(); int _Width, _Height; if (width > height) { _Width = 257; _Height = Mathf.CeilToInt(257f * ((float)height / (float)width)); } else { _Width = Mathf.CeilToInt(257f * ((float)width / (float)height)); _Height = 257; } frame.ResizePro(_Width, _Height); var inputs = new Dictionary(); var tensor = new Tensor(frame, 3); inputs.Add("image", tensor); _worker.ExecuteAndWaitForCompletion(inputs); yield return new WaitForEndOfFrame(); var Heatmap = _worker.CopyOutput("heatmap"); yield return new WaitForEndOfFrame(); var Offset = _worker.CopyOutput("offset_2"); yield return new WaitForEndOfFrame(); var Dis_fwd = _worker.CopyOutput("displacement_fwd_2"); yield return new WaitForEndOfFrame(); var Dis_bwd = _worker.CopyOutput("displacement_bwd_2"); yield return new WaitForEndOfFrame(); poses = posenet.DecodeMultiplePosesOG(Heatmap, Offset, Dis_fwd, Dis_bwd, outputStride: 16, maxPoseDetections: 1, scoreThreshold: 0.5f, nmsRadius: 20); Offset.Dispose(); Dis_fwd.Dispose(); Dis_bwd.Dispose(); Heatmap.Dispose(); _worker.Dispose(); tensor.Dispose(); poseUpdated = true; isPosing = false; frame = null; inputs = null; yield return null; } I tried our app on several iOS devices, the errors are identical. I've been struggling this error for several days but found no clues. I'd appreciate it if anyone can help me. Thanks in advance. My develop environment: - Unity 2019.4.16f1 - XCode 12.3 - iPhone 7: iOS 14.0.1 - iPhone 12: iOS 14.3 - iPhone 8: iOS 13.7 - Barracuda: 1.0.2 (current)

Graphics.CopyTexture copies wrong mip on Windows 10 build

$
0
0
Hey folks, so I have this super simple example code that runs fine on the **editor** but behaves weird on a **build**: // _tex is a 2D Texture with mipmap displayed on left quad leftQuad.material.mainTexture = _tex; // Create a texture without a mipmap var tex = new Texture2D(_tex.width, _tex.height, _tex.graphicsFormat, 0, TextureCreationFlags.None); // copy full resolution texture (mip 0) and show it on right quad Graphics.CopyTexture(_tex, 0, 0, tex, 0, 0); rightQuad.material.mainTexture = tex; ---------- Te result looks like this: ![alt text][1] ---------- In other words: whenever I try to access `_tex.mip[0]` it behaves as if it was `_tex.mip[1]` meaning the mip with only half the width/height. I have tried this in a **compute shader**, using `GetPixels` and using `Graphics.CopyTexture`as above. Always the same result! ---------- I have tested all this using: - Unity 2020.2.3f1 - Unity 2020.2.2f1 Any idea? Help would be highly appreciated. [1]: /storage/temp/175439-copytexture-result.png

_Time variable in compute shaders

$
0
0
Is the _Time variable not available to compute shaders? I'm seeing `undeclared identifier '_Time' at kernel CSMain`. Do I need to send the time variable manually?

ComputeBuffer stays empty after executing a Compute Shader

$
0
0
I was trying to implement Clustered Forward Rendering in custom srp and build the clusters in compute shader.In C# script, I have followed the general way:declare the compute shader and compute buffer, find the kernel, set the compute buffer and dispatch the compute shader, but finally I just got empty compute buffer. Here is my C# code: public static ComputeBuffer clusters; ComputeShader computeClusters; CommandBuffer buffer = new CommandBuffer{name = bufferName}; public void Setup(ScriptableRenderContext context, ...) { ... ComputeCluster(); context.ExecuteCommandBuffer(buffer); buffer.Clear(); } void ComputeCluster() { clusters = new ComputeBuffer(16 * 9 * 24, 2 * 16 * 16); int kernel = computeClusters.FindKernel("ComputeCluster"); buffer.SetComputeBufferParam(computeClusters, kernel, clusterId, clusters); buffer.DispatchCompute(computeClusters, kernel, 16, 9, 24); } And here is my compute shader: #pragma kernel ComputeCluster #include "../ShaderLibrary/Common.hlsl" struct VolumeTileAABB { float4 minPoint; float4 maxPoint; }; RWStructuredBuffer _Cluster; float4 TransformScreenToView(float4 positionSS) { float2 uv = positionSS.xy / _ScreenParams.xy; float4 positionCS = float4(float2(uv.x, uv.y) * 2.0 - 1.0, positionSS.z, positionSS.w); float4 positionVS = mul(unity_CameraInvProjection, positionCS); positionVS = positionVS / positionVS.w; return positionVS; } float3 lineIntersectionToZPlane(float3 A, float3 B, float zDistance) { float3 normal = float3(0.0, 0.0, 1.0); float3 ab = B - A; float t = (zDistance - dot(normal, A)) / dot(normal, ab); float3 result = A + t * ab; return result; } [numthreads(1,1,1)] void ComputeCluster(uint3 id : SV_DispatchThreadID) { const float3 eyePos = float3(0.0, 0.0, 0.0); uint tileSizePx = _ScreenParams.x / 16; uint tileIndex = id.x + id.y * 16 + id.z * 16 * 9; float4 maxPointSS = float4(float2(id.x + 1, id.y + 1) * tileSizePx, -1.0, 1.0); float4 minPointSS = float4(id.xy * tileSizePx, -1.0, 1.0); float3 maxPointVS = TransformScreenToView(maxPointSS).xyz; float3 minPointVS = TransformScreenToView(minPointSS).xyz; float tileNear = -_ProjectionParams.y * pow(_ProjectionParams.z / _ProjectionParams.y, id.z / 24.0); float tileFar = -_ProjectionParams.y * pow(_ProjectionParams.z / _ProjectionParams.y, (id.z + 1) / 24.0); float3 minPointNear = lineIntersectionToZPlane(eyePos, minPointVS, tileNear); float3 minPointFar = lineIntersectionToZPlane(eyePos, minPointVS, tileFar); float3 maxPointNear = lineIntersectionToZPlane(eyePos, maxPointVS, tileNear); float3 maxPointFar = lineIntersectionToZPlane(eyePos, maxPointVS, tileFar); float3 minPointAABB = min(min(minPointNear, minPointFar), min(maxPointNear, maxPointFar)); float3 maxPointAABB = max(max(minPointNear, minPointFar), max(maxPointNear, maxPointFar)); _Cluster[tileIndex].minPoint = float4(minPointAABB, 0.0); _Cluster[tileIndex].maxPoint = float4(maxPointAABB, 0.0); } I tried to use GetData to log the array and all the outputs are 0. I also tried to debug in RenderDoc and got the result "No Resource" ![alt text][1] [1]: /storage/temp/177173-qq截图20210308152614.png

Sending struct containing array to compute shader

$
0
0
So I have been making an octree to accelerate a ray tracing compute shader, but I have hit a major block on the last hurdle to testing it, actually sending it to the compute shader. What I am trying to do is send a List(with OctreeData being a struct with 2 arrays in it among other things) to a compute shader via a structured buffer, but turns out this is not blittable(so cant be sent). Is there any way for me to be able to send this at all, or do I have to unroll the arrays into individual elements(and then unroll 512 loops worth of code in the shader)? alternatively, can I send an array within a list easily to a compute shader? Thank you for any help, as this is driving me nuts, as ive come so close to testing it Incase it matters, extra information: I do know the size of the arrays in the struct, I just dont know how to tell it that and make it blittable, and one array is for storing children nodes(will have 8 integers always in it), and the other one is to index which triangles in a mesh a leaf node(final nodes) contains(will have 16 integers always in it)

remove empty values from computebuffer in computeshaders

$
0
0
i have a 3d computeshader that transfers a large float3 computebuffer with locations to the cpu to make draw calls and a float4 one with the colors , but this also ends up creating uneccesery draw calls for posisitons with an apha of zero .Also i have to solve this in Hlsl as it would be too slow on the cpu
Viewing all 287 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>