User avatar
jsantos
Site Admin
Posts: 2905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Problems with buffers

01 Apr 2020, 19:30

is batch.vertexOffset the offset in bytes or the offset in strides of that batches layout?
It is the offset in bytes to the last vertex buffer set using MapVertices.
 
sunnlok
Topic Author
Posts: 30
Joined: 04 Jul 2017, 17:45

Re: Problems with buffers

01 Apr 2020, 19:43

Ok, that is good to know.
I still have a hard time solving my problems on an architectural level.
The sample creates one big buffere it writes into and then maps the vertices via offsets.

My problem now is that i somehow need to translate the order of the map/unmap/draw calls into individual buffers.
Cryengine already pools all underlying buffers so when i ask it to allocate me a buffer it returns a handle that will then later be used as an offset in IASetVertexBuffers to the global buffer it updates, which in turn means i cant use the the vtx offset to a subregion for that. I can only use it as an offset in the later DrawIndexed call.

So now i am stuck with tyring to find the right spot to create and set a new buffer.
Are there multiple map calls before a draw? Or can i just use a fresh buffer on each map call?

If its just one map/umap pair before a bunch of drawcalls i can create a transient buffer on each map call and delete it on the next, create a new one and so on.
 
User avatar
jsantos
Site Admin
Posts: 2905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Problems with buffers

01 Apr 2020, 20:00

Are there multiple map calls before a draw? Or can i just use a fresh buffer on each map call?
You will get one map call and then a lot of draw calls. That's the optimal scenario, but you can also get several Map + N Draws cycles in the same frame. The geometry you receive in the Map call should be streamed to the GPU. I don't know if there is the concept of streaming in CryEngine.
 
sunnlok
Topic Author
Posts: 30
Joined: 04 Jul 2017, 17:45

Re: Problems with buffers

01 Apr 2020, 20:12

The buffers are streamed, but the way its handled obviously has some of its own optimizations which makes it not behave exactly like raw dx11.
I am gonna try creating new "buffers" each map call, which is pasically just a view into a region that gets streamed into the gpu and does what the manual offset counting in the sample does.

But I think i found the cause of the problem. Draw indexed takes an offset index for the vertex base offset which gets added to the indices on the gpu. A batch only provides the raw byte count which then becomes tricky to turn back into indices if vertices with different layouts are written to the stream.

I "solved" it for now by changing the cryengine renderer to accept a byte offset when setting a vertex stream. This makes it platform dependant though since the implementation might vary for vulkan/dx12/dx11/ps4 so the ability to get the vertex offset as a simple index also would be incredibly awesome!
 
User avatar
jsantos
Site Admin
Posts: 2905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Problems with buffers

03 Apr 2020, 12:37

This makes it platform dependant though since the implementation might vary for vulkan/dx12/dx11/ps4 so the ability to get the vertex offset as a simple index also would be incredibly awesome!
That's not possible because in a single Map there are multiple vertex formats with different strides. The only way to offset the content is using bytes. There should be a better way in CryEngine, for example, how would you go about creating dynamic particles? That's a similar scenario to this one.
 
sunnlok
Topic Author
Posts: 30
Joined: 04 Jul 2017, 17:45

Re: Problems with buffers

03 Apr 2020, 14:08

I sadly see no other way from what i have done right now. The "buffers" that are used by the engine already are an offset view into the memory pool that gets streamed to the gpu.
So particles for example simple get different buffer handles for different layouts. Sadly i cant do that here because the map call obviously only maps one continues opaque memory blob.
For now this works though and i might even get crytek to merge that extension. Depending on weather it has sideffects or not :D
I still have other issues to fix though!
 
User avatar
jsantos
Site Admin
Posts: 2905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Problems with buffers

04 Apr 2020, 14:28

Great! Please keep us posted.

Who is online

Users browsing this forum: No registered users and 0 guests