Sfoglia il codice sorgente

Fixing read-write structured buffer creation on DX11

BearishSun 8 anni fa
parent
commit
16c24db708

+ 3 - 1
Source/BansheeD3D11RenderAPI/Include/BsD3D11HardwareBuffer.h

@@ -33,7 +33,9 @@ namespace bs { namespace ct
 			/** Generic buffer that is used for holding parameters used for indirect rendering. */
 			BT_INDIRECTARGUMENT = BT_GROUP_GENERIC | 0x40, 
 			/** Generic buffer that allows the GPU program to use append/consume functionality. */
-			BT_APPENDCONSUME = BT_GROUP_GENERIC | 0x80 
+			BT_APPENDCONSUME = BT_GROUP_GENERIC | 0x80, 
+			/** Generic buffer that contains primitive types. */
+			BT_STANDARD = BT_GROUP_GENERIC | 0x100
 		};
 
 		D3D11HardwareBuffer(BufferType btype, GpuBufferUsage usage, UINT32 elementCount, UINT32 elementSize, 

+ 2 - 0
Source/BansheeD3D11RenderAPI/Source/BsD3D11GpuBuffer.cpp

@@ -39,6 +39,8 @@ namespace bs { namespace ct
 		switch (props.getType())
 		{
 		case GBT_STANDARD:
+			bufferType = D3D11HardwareBuffer::BT_STANDARD;
+			break;
 		case GBT_STRUCTURED:
 			bufferType = D3D11HardwareBuffer::BT_STRUCTURED;
 			break;

+ 19 - 1
Source/BansheeD3D11RenderAPI/Source/BsD3D11HardwareBuffer.cpp

@@ -30,13 +30,28 @@ namespace bs { namespace ct
 		{
 			mDesc.Usage = D3D11_USAGE_STAGING;
 			mDesc.BindFlags = 0;
-			mDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ ;
+			mDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
 		}
 		else if(randomGpuWrite)
 		{
 			mDesc.Usage = D3D11_USAGE_DEFAULT;
 			mDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
 			mDesc.CPUAccessFlags = 0;
+
+			switch (btype)
+			{
+			case BT_STRUCTURED:
+			case BT_APPENDCONSUME:
+				mDesc.StructureByteStride = elementSize;
+				mDesc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
+				break;
+			case BT_RAW:
+				mDesc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
+				break;
+			case BT_INDIRECTARGUMENT:
+				mDesc.MiscFlags = D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS;
+				break;
+			}
 		}
 		else
 		{
@@ -45,6 +60,9 @@ namespace bs { namespace ct
 
 			switch(btype)
 			{
+			case BT_STANDARD:
+				mDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
+				break;
 			case BT_VERTEX:
 				mDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
 				if (streamOut)