Page MenuHome

DrawManager: Use Compute Shader to Update Hair.
ClosedPublic

Authored by Jeroen Bakker (jbakker) on Apr 23 2021, 2:12 PM.

Details

Summary

This patch will use compute shaders to create the VBO for hair.
The previous implementation uses transform feedback.

Timings before: between 0.000069s and 0.000362s.
Timings after: between 0.000032s and 0.000092s.

Speedup isn't noticeable by end-users. The patch is used to test
the new compute shader pipeline and integrate it with the draw
manager. Allowing EEVEE, Workbench and other draw engines to
use compute shaders with the introduction of DRW_shgroup_call_compute
and DRW_shgroup_vertex_buffer.

Future improvements are possible by generating the index buffer
of hair directly on the GPU.

NOTE: that compute shaders aren't supported by Apple and still use the transform feedback workaround.

Diff Detail

Repository
rB Blender
Branch
temp-gpu-compute-shader-hair
Build Status
Buildable 14500
Build 14500: arc lint + arc unit

Event Timeline

Jeroen Bakker (jbakker) requested review of this revision.Apr 23 2021, 2:12 PM
Jeroen Bakker (jbakker) created this revision.
  • Merge branch 'temp-gpu-compute-shader-hair' of git.blender.org:blender into temp-gpu-compute-shader-hair
  • Added memory barrier.

Retry with correct base.

Reupload as arcanist did select too many commits.

Jeroen Bakker (jbakker) retitled this revision from DrawManager: Use Compute Shader to Update Hair. to [WIP] DrawManager: Use Compute Shader to Update Hair..Apr 23 2021, 3:53 PM
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Apr 23 2021, 4:05 PM
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Apr 28 2021, 2:35 PM
  • Merge branch 'temp-gpu-compute-shaders' into temp-gpu-compute-shader-hair
  • Merge branch 'temp-gpu-compute-shaders' into temp-gpu-compute-shader-hair
  • Use GPU calls for hair.
  • Merge branch 'temp-gpu-compute-shaders' into temp-gpu-compute-shader-hair
  • Use attach vertex buffer.
  • Remove unused code.
Jeroen Bakker (jbakker) retitled this revision from [WIP] DrawManager: Use Compute Shader to Update Hair. to DrawManager: Use Compute Shader to Update Hair..Apr 28 2021, 2:46 PM
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Apr 28 2021, 2:49 PM
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Apr 28 2021, 3:36 PM
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Apr 28 2021, 3:49 PM

Reusing the uniform storage in DRWShadingGroup when not an uniform. Similar to Transform feedback

I don't see it as a weak point. The uniforms inside DRWShadingGroup are actually resources (which should be renamed one day). Binding a SSBO enters this category.

increase the number of hairs (655 and it fails. Related to 65536?

This might be linked to one of the limit of the implementation. See https://www.reddit.com/r/opengl/comments/6thlhy/how_big_can_a_single_compute_shader_work_group_get/ .
Check:

GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS
GL_MAX_COMPUTE_WORK_GROUP_COUNT
GL_MAX_COMPUTE_WORK_GROUP_SIZE

I don't know if these have a minimum size guaranteed by the standard. So you might want to make this exposed from the GPU module.

source/blender/draw/intern/DRW_render.h
583

Do not expose location. Expose name.

source/blender/draw/intern/draw_manager.h
301–302

I would still call it DRW_UNIFORM_VERTEX_BUFFER to make it clear it is a value of this enum.

Also you could eventually bind these to other shader stages if that's needed in the future. So I would remove the for compute shaders part.

If you want to make it extra clear, you could name it DRW_UNIFORM_VERTEX_BUFFER_AS_STORAGE.

While the normal storage buffer would be DRW_UNIFORM_STORAGE.

All things considered, the UNIFORM should be renamed to RESOURCE, but that's for a later cleanup.

source/blender/draw/intern/draw_manager_data.c
454

Get location from name here.

source/blender/draw/intern/shaders/common_hair_refine_vert.glsl
4

I would advise against this for new code. This is something that creates hard to read code with #ifdefs everywhere and it's hard to see what resources are needed.

I would prefer to see the refine functions go into a shared lib.glsl file and have a dedicated _comp.glsl file.

Jeroen Bakker (jbakker) marked 4 inline comments as done.
  • Merge branch 'temp-gpu-compute-shaders' into temp-gpu-compute-shader-hair
  • Draw: Bind vertex buffers on name.
  • Separate vertex and compute shaders.
  • Rename to DRW_UNIFORM_VERTEX_BUFFER_AS_STORAGE
  • Batch hair when using compute shaders.

Updating using parent patch as base.

Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)May 7 2021, 4:23 PM

Can this same compute pipe be used for GPU armature skinning down the line?

Not related to this patch but I think we should enforce the vertex format is at least using 32bit floats/ints as expected by the buffer backed storage (I think). Better enforce this in the GPU module directly.

source/blender/draw/intern/shaders/common_hair_refine_comp.glsl
8

Use writeonly qualifier.

10

Not sure where this capitalization came from. :) Also unless blender became a spatial 4D app, the positions are only 3D ;). From the vertex format, I think it is posTime and would prefer to reuse it to keep consistency.

In new code I tend to prefix all the outputs with out_* so shader stage outputs are easily identifiable .

Alternatively you can name the instance of the buffer out_vertbuf like so.

layout(std430, binding = 0) buffer hairPointOutputBuffer
{
  vec4 posTime[];
} out_vertbuf;
  • Addressed comments from code review. shader interface.
Jeroen Bakker (jbakker) marked 2 inline comments as done.
  • Reverted unneeded changes in vertex shader.
  • Use max work group count from GPU module.
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)May 26 2021, 4:15 PM
This revision is now accepted and ready to land.May 26 2021, 4:17 PM
  • Merge branch 'temp-gpu-compute-shaders' into temp-gpu-compute-shader-hair
  • Merge branch 'master' into temp-gpu-compute-shader-hair
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)May 28 2021, 8:26 AM