Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Dragon_Baby · Mar 08, 2021 at 07:30 AM · compute shader

ComputeBuffer stays empty after executing a Compute Shader

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<VolumeTileAABB> _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

qq截图20210308152614.png (74.4 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dragon_Baby · Mar 08, 2021 at 08:09 AM

I have tried to use compute shader directly instead of using command buffer, and the problem solved.But I want to use command buffer to control the execution of compute shader. So Is there any way to fix the problem with command buffer?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

113 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Lerp() and compute shader 0 Answers

How (Or Why) to use Consume Buffers safely on arbitrary data lengths 0 Answers

Callback when (compute) shader is reloaded 0 Answers

Two dimensional array in compute shader 1 Answer

How do you use Mathf.PerlinNoise in a compute shader? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges