ECToo / slimdx

Automatically exported from code.google.com/p/slimdx
MIT License
0 stars 0 forks source link

MapSubresource for Buffer no longer supports defining the length (Sep 2011) #843

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have a buffer of structures (RenderTileDetailed), written by the CPU and used 
by the shader. The buffer is often bigger than what is needed currently, and so 
I'd like to transfer only the required amount of data to the GPU. This no 
longer seems to be possible with Sep 2011. Is that a bug or am I doing 
something wrong?

So I have:

m_tileBuffer = new SlimDX.Direct3D11.Buffer(m_device, new BufferDescription()
{
    BindFlags = BindFlags.ShaderResource,
    CpuAccessFlags = CpuAccessFlags.Write,
    OptionFlags = ResourceOptionFlags.StructuredBuffer,
    SizeInBytes = tileBufferWidth * tileBufferHeight * Marshal.SizeOf(typeof(RenderTileDetailed)),
    StructureByteStride = Marshal.SizeOf(typeof(RenderTileDetailed)),
    Usage = ResourceUsage.Dynamic,
});

And I update the buffer every frame, mapping only the required amount of bytes:

var box = m_device.ImmediateContext.MapSubresource(m_tileBuffer, 0, columns * 
rows * elemSize, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None);
var stream = box.Data;

unsafe
{
    fixed (RenderTileDetailed* p = mapData.Grid)
    {
        stream.WriteRange((IntPtr)p, arrLen * elemSize);
    }
}

m_device.ImmediateContext.UnmapSubresource(m_tileBuffer, 0);

This worked fine on March 2011 SlimDX.

Original issue reported on code.google.com by to...@iki.fi on 26 Oct 2011 at 6:35

GoogleCodeExporter commented 9 years ago
I dont think this is a problem with SlimDX, since the underlying D3D 
MapSubresource() call does not allow you to specify a size(or box) when 
mapping. 

You should probably just remove the size arg from the call.

Original comment by dbl...@fastmail.fm on 15 Nov 2011 at 12:51

GoogleCodeExporter commented 9 years ago
Perhaps you could also add your own range checks if you wish(or an extension 
method).

Original comment by dbl...@fastmail.fm on 15 Nov 2011 at 12:52

GoogleCodeExporter commented 9 years ago
Yes, the native call always mapped the entire range of the resource. The length 
argument didn't affect what got mapped, only how big the DataStream thought the 
memory was. Since this was confusing and did not match native behavior, we 
changed it to figure out how big the size should be on its own.

Original comment by Mike.Popoloski on 15 Nov 2011 at 4:52