[2.1+] Dynamic buffer with compute shaders

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
al2950
OGRE Expert User
OGRE Expert User
Posts: 1196
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 76

[2.1+] Dynamic buffer with compute shaders

Post by al2950 » Sat Apr 13, 2019 2:13 pm

Hi

As the title suggests... how with Ogre! I know you cant create a UAV which which is a dynamic buffer, but as far as I understand I should be able to create a ''TexBuffer'' which is dynamic and use it as a read only buffer in the compute shader,map it each frame and copy data to it from the CPU, however when I try this Ogre throws the following exception in DescriptorSetTexture2::checkValidity

Code: Select all

"Dynamic buffers cannot be baked into a static DescriptorSet"
I dont really understand this ... You definitely can normally bind a dynamic GPU read only buffer to a compute shader in Dx11, so why does Ogre not allow it?

Thanks in advance :)
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4036
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 214
Contact:

Re: [2.1+] Dynamic buffer with compute shaders

Post by dark_sylinc » Sat Apr 13, 2019 3:17 pm

I made a joke about this.

Bottom line: Yes, I am an idiot.

In the medium term I figured out a solution: We need "discardable/temporary" Descriptor sets, which is how it is addressed in modern APIs (D3D12/Vulkan).

In the short term: Workaround this bug by either using copyTo() to copy to a non-dynamic buffer, or use a non-dynamic buffer and upload the data via BufferPacked::upload from a C pointer (that's what the voxelizer does), or write to a StagingBuffer and then use unmap()'s arguments to copy to the non-dynamic buffer.

I apologize for this inconvenience.
0 x

al2950
OGRE Expert User
OGRE Expert User
Posts: 1196
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 76

Re: [2.1+] Dynamic buffer with compute shaders

Post by al2950 » Sat Apr 13, 2019 11:57 pm

dark_sylinc wrote:
Sat Apr 13, 2019 3:17 pm
I apologize for this inconvenience.
Ha.. I am just relieved I have not misunderstood something!

Thanks for the tips on how to work around. I might wait until you merge your VCT changes, as its has some useful bits in it.

One other question on a similar tack, as I have been playing with compute shaders quite a bit now, is there a way to bind buffers that persist over multiple dispatch calls. I have not done any tests, but I am assuming binding a particular buffer multiple times for different compute jobs will have some unnecessary overheads? Looking at the code, UAVs get cleared after every dispatch, but I am not sure about const or tex buffers.......?? .FYI I am using compute jobs directly and not the compositor.
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4036
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 214
Contact:

Re: [2.1+] Dynamic buffer with compute shaders

Post by dark_sylinc » Sun Apr 14, 2019 8:47 pm

Not really.

Ogre uses descriptors to be more efficient at (re-)binding state; but it is still obviously wasteful if you don't need to do it.
Hopefully the amount of work your Compute Shader runs is probably way bigger than this overhead (otherwise you could run the algorithm in the CPU?).

But yeah, we don't provide a way to make multiple dispatch without affecting any current binding.

Note though: Unless your compute code has a feedback loop (re-running the same code over the same memory region produces different output, e.g. an iterative algorithm), then without changing the bindings two consecutive dispatches would produce the same output.
0 x

al2950
OGRE Expert User
OGRE Expert User
Posts: 1196
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 76

Re: [2.1+] Dynamic buffer with compute shaders

Post by al2950 » Sun Apr 14, 2019 10:00 pm

ok thanks for the reply.

FYI its for this particle work, and there is an equivalent of a pass buffer, which is the same for multiple emitters... But I have not yet decided on a final design, I have gone through multiple iterations in my head, but I quite like the idea of using vector fields to control particles. So its something I would imagine I would process and upload vector fields to a global buffer, where multiple particle systems would access it... so would only really want to bind it once per frame.
0 x

Post Reply