Page MenuHome

GPU: Compute Pipeline.
ClosedPublic

Authored by Jeroen Bakker (jbakker) on Apr 7 2021, 3:58 PM.

Details

Summary

With the compute pipeline calculation can be offloaded to the GPU.
This patch only adds the framework for compute. So no changes for users at
this moment.

NOTE: As this is an OpenGL4.3 feature it must always have a fallback.

Use GPU_compute_shader_support to check if compute pipeline can be used.
Check gpu_shader_compute* test cases for usage.

This patch also adds support for shader storage buffer objects and device only
vertex/index buffers.

An alternative that had been discussed was adding this to the GPUBatch, this
was eventually not chosen as it would lead to more code when used as part of a
shading group. The idea is that we add an eDRWCommandType in the near
future.

Diff Detail

Repository
rB Blender
Branch
temp-gpu-compute-shaders
Build Status
Buildable 14274
Build 14274: arc lint + arc unit

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
  • Use GPUBatch to handle compute pipeline.
Jeroen Bakker (jbakker) retitled this revision from [WIP] GPU: Compute Shaders. to GPU: Compute Pipeline..Apr 9 2021, 9:54 AM
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)
source/blender/gpu/GPU_compute.h
28

Use uint here. This is what GL expect.

source/blender/gpu/tests/gpu_shader_test.cc
56

I think you need a barrier here to wait for compute to finish before reading. We already have GPU_memory_barrier for that.

Maybe the sync is implicit due to GPU_texture_read but I don't know how it will work for vulkan. Moreover, it does not hurt since it's just a test.

Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
  • Revert "Use GPUBatch to handle compute pipeline."
  • Use proposed GPU_compute_dispatch
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Apr 9 2021, 11:10 AM
Jeroen Bakker (jbakker) marked an inline comment as done.
  • Added memory barrier.
  • Remove commented out code.
source/blender/gpu/tests/gpu_shader_test.cc
56

Yes I removed the barrier as I couldn't detect any difference. No problem to add it back.

  • Merge branch 'master' into temp-gpu-compute-shaders
  • Fix issue where library glsl isn't included in compute shaders.
  • Merge branch 'master' into temp-gpu-compute-shaders
  • Fix issue where library glsl isn't included for compute shaders.
  • Use storage objects.
  • More research inside test cases.
Jeroen Bakker (jbakker) marked an inline comment as done.Apr 26 2021, 3:18 PM
Jeroen Bakker (jbakker) added inline comments.
source/blender/gpu/intern/gpu_shader.cc
360

add if (lib)

  • Merge branch 'master' into temp-gpu-compute-shaders
  • Test using direct opengl calls.
  • Use IBO buffer as a target for a compute shader.
  • Added device only vertex buffer.
  • Small cleanupSmall cleanups,s,
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Apr 28 2021, 1:15 PM
source/blender/gpu/GPU_shader.h
92–93

I would prefer the vertex and index buffers to be treated as other resources (texture, ubos) in that regard. Meaning you should only expose getting the binding location from the shader and have a dedicated GPU_vertbuf_bind_as_ssbo(GPUVertBuf* verts, int binding) method (similar for ibos too).

  • Merge branch 'master' into temp-gpu-compute-shaders
  • Migrated to GPU_*buf_bind_as_ssbo
  • Add shader interface for shader storage buffers.
  • Remove obsolete attach_buffers.
  • Added support for device only index buffers.
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)May 7 2021, 3:11 PM

Some small cleanups.

  • Use ssbo_binding method.
  • Remove unneeded changes.
  • Rename test case,
source/blender/gpu/tests/gpu_testing.cc
5

Commit this change in master directly.

  • Merge branch 'master' into temp-gpu-compute-shaders
  • Cleanup: codeformat in glsl test cases.
source/blender/gpu/GPU_index_buffer.h
50 ↗(On Diff #36916)

Instead of exposing this, could we only support U32 for device only buffers? This way readback would always produce uint32_t data.

54 ↗(On Diff #36916)

I'm not 100% sold on the device only name. If you can read it back, it is not device only. Maybe GPU_indexbuf_create_empty or GPU_indexbuf_create_noinit and make it return the GPUIndexBuf pointer.

Also from the parameters, I expect this goes below void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len); at L.60.

Maybe another better option is to have it named like this:

GPUIndexBuf *GPU_indexbuf_build_on_device(GPUPrimType, uint prim_len);

With a getter to get the type of indices.
This has the benefits of isolating the selection of GPUIndexBufType inside the GPU module. This way we can easily override the type if we need to.

source/blender/gpu/tests/gpu_shader_test.cc
236

use uint for all bitwise operations. Also the indices are uints too.

the mask index2 & 0xFFFF is redundant.

257

I would wrap this inside a GPU_indexbuf_read which should be similar to GPU_texture_read.
Meaning it would return a buffer (with its ownership) and eventually convert the data if data format mismatches.

259

Copy/Paste failure? Not sure what texture is for here.

288

uint

Jeroen Bakker (jbakker) marked 7 inline comments as done.
  • Updated gpu index buffer interface.
  • Cleanup: use correct codestyle in inline glsl.
  • Cleanup use uint for indexes in ibo tests.
  • Cleanup: remove incorrect comments.
  • Add GPU api to read vertex/index buffers.
source/blender/gpu/GPU_index_buffer.h
50 ↗(On Diff #36916)

I don't have objections to support U32 only. It makes code more clear, but would loose some performance when drawing meshes up to 64k-1 verts.

54 ↗(On Diff #36916)

I would go for build_on_device.

In the current structure of the draw manager we want to allocate it before we initialize it. The compile unit that allocates is different than the module who initializes it (draw_cache_impl_mesh vs draw_cache_extract_mesh). We might want to add an init function later when we want to use it in use it in draw_cache_impl_mesh. Emphasis on "might" as it isn't clear if that will be needed.

source/blender/gpu/tests/gpu_shader_test.cc
40

Remove comments

235

code format

source/blender/gpu/intern/gpu_index_buffer.cc
256 ↗(On Diff #36966)

We should not call indices per primitive, the number of elements should be a parameter. Not all primitives has a constant for this.

  • Size of indexbuffer needs to be given by the caller.
Clément Foucault (fclem) added inline comments.
source/blender/gpu/opengl/gl_index_buffer.cc
72 ↗(On Diff #37016)

maybe unmap after read?

source/blender/gpu/opengl/gl_vertex_buffer.hh
70

Nitpcik: Why not merge with above case?

This revision is now accepted and ready to land.May 26 2021, 3:54 PM
Jeroen Bakker (jbakker) marked an inline comment as done.
  • Merge branch 'master' into temp-gpu-compute-shaders
  • Splitted read and unmap in different calls.
  • Merged similar cases in switch statement.
  • Cleanup: Code formatting.
  • Use const signature for driver owned data.
This revision was automatically updated to reflect the committed changes.