• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

D3DX11 Buffer ByteWidth

Status
Not open for further replies.
Level 10
Joined
Sep 14, 2007
Messages
227
Hey I got one question, about c++ Directx 3d 11 buffers. Is it possible to change created buffer ByteWidth value? I only found a way how to change pSysMem (as I understand its a info that buffer holding) with memcpy, but its no use without changing ByteWidth.

Code:
        D3D11_BUFFER_DESC m_vertexBufferDesc;
        ID3D11Buffer *m_vertexBuffer;
        D3D11_SUBRESOURCE_DATA vertexData;


//Create vertex buffer
	m_vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
	m_vertexBufferDesc.[COLOR="Red"]ByteWidth[/COLOR] = sizeof(VertexType) * m_vertexCount;
	m_vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	m_vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	m_vertexBufferDesc.MiscFlags = 0;
	m_vertexBufferDesc.StructureByteStride = 0;

	//Creates a pointer to vertex array
	vertexData.pSysMem = m_vertices;
	vertexData.SysMemPitch = 0;
	vertexData.SysMemSlicePitch = 0;

	device->CreateBuffer(&m_vertexBufferDesc, &vertexData, &m_vertexBuffer);
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
Is it possible to change created buffer ByteWidth value?
From the API there should be no problem changing ByteWidth at any time you wish. After all the structure seems to be nothing more than describe the buffers to create and so has no linking with the buffers it was used to create.

Any positive value should be fine as long as it is less than buffer max size and follows the below restriction.
If the bind flag is D3D11_BIND_CONSTANT_BUFFER, you must set the ByteWidth value in multiples of 16, and less than or equal to D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT.

If you want to resize a buffer you already created I have a feeling that may not be possible. Resizing of dynamic memory is notoriously slow as it often results in full memory copies and peak memory usage of (old memory size + new memory size + 2 dynamic memory overhead size). I think you can only resize buffers by unload the data from the existing buffer (or discarding it if the CPU already has the data), and then allocating a new buffer that is larger.
 
Status
Not open for further replies.
Top