15 #ifndef BT_SOFT_BODY_SOLVER_BUFFER_DX11_H
16 #define BT_SOFT_BODY_SOLVER_BUFFER_DX11_H
23 #include <d3dcompiler.h>
26 #define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
39 ID3D11ShaderResourceView*
m_SRV;
40 ID3D11UnorderedAccessView*
m_UAV;
57 if( preexistingBuffer )
61 D3D11_BUFFER_DESC buffer_desc;
62 ZeroMemory(&buffer_desc,
sizeof(buffer_desc));
63 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
65 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
67 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
68 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
72 if( buffer_desc.ByteWidth == 0 )
73 buffer_desc.ByteWidth =
sizeof(ElementType);
74 buffer_desc.StructureByteStride =
sizeof(ElementType);
82 D3D11_SHADER_RESOURCE_VIEW_DESC srvbuffer_desc;
83 ZeroMemory(&srvbuffer_desc,
sizeof(srvbuffer_desc));
84 srvbuffer_desc.Format = DXGI_FORMAT_UNKNOWN;
85 srvbuffer_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
88 if( srvbuffer_desc.Buffer.ElementWidth == 0 )
89 srvbuffer_desc.Buffer.ElementWidth = 1;
95 D3D11_SHADER_RESOURCE_VIEW_DESC srvbuffer_desc;
96 ZeroMemory(&srvbuffer_desc,
sizeof(srvbuffer_desc));
97 srvbuffer_desc.Format = DXGI_FORMAT_UNKNOWN;
98 srvbuffer_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
101 if( srvbuffer_desc.Buffer.ElementWidth == 0 )
102 srvbuffer_desc.Buffer.ElementWidth = 1;
108 D3D11_UNORDERED_ACCESS_VIEW_DESC uavbuffer_desc;
109 ZeroMemory(&uavbuffer_desc,
sizeof(uavbuffer_desc));
110 uavbuffer_desc.Format = DXGI_FORMAT_UNKNOWN;
111 uavbuffer_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
114 if( uavbuffer_desc.Buffer.NumElements == 0 )
115 uavbuffer_desc.Buffer.NumElements = 1;
121 D3D11_BUFFER_DESC readback_buffer_desc;
122 ZeroMemory(&readback_buffer_desc,
sizeof(readback_buffer_desc));
124 readback_buffer_desc.ByteWidth =
m_CPUBuffer->
size() *
sizeof(ElementType);
125 readback_buffer_desc.Usage = D3D11_USAGE_STAGING;
126 readback_buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
127 readback_buffer_desc.StructureByteStride =
sizeof(ElementType);
200 btAssert(
"Buffer creation failed.");
207 D3D11_BOX destRegion;
209 destRegion.front = 0;
211 destRegion.bottom = 1;
234 D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
237 D3D11_BOX destRegion;
239 destRegion.front = 0;
241 destRegion.bottom = 1;
280 D3D11_MAPPED_SUBRESOURCE MappedResource = {0};
282 D3D11_BOX destRegion;
284 destRegion.front = 0;
286 destRegion.bottom = 1;
323 #endif // #ifndef BT_SOFT_BODY_SOLVER_BUFFER_DX11_H
ID3D11Buffer *& getBuffer()
bool moveToGPU()
Move the data to the GPU if it is not there already.
ID3D11Device * m_d3dDevice
bool createBuffer(ID3D11Buffer *preexistingBuffer=0)
ID3D11UnorderedAccessView * m_UAV
ID3D11Buffer * m_readBackBuffer
ID3D11ShaderResourceView * m_SRV
bool copyFromGPU()
Copy the data back from the GPU without changing its state to be CPU-side.
int size() const
return the number of elements in the array
virtual void changedOnCPU()
Call if data has changed on the CPU.
btDX11Buffer(ID3D11Device *d3dDevice, ID3D11DeviceContext *d3dDeviceContext, btAlignedObjectArray< ElementType > *CPUBuffer, bool readOnly)
ID3D11ShaderResourceView *& getSRV()
ID3D11UnorderedAccessView *& getUAV()
ID3D11DeviceContext * m_d3dDeviceContext
btAlignedObjectArray< ElementType > * m_CPUBuffer
DX11 Buffer that tracks a host buffer on use to ensure size-correctness.
bool moveFromGPU()
Move the data back from the GPU if it is on there and isn't read only.