public static UnorderedAccessView CreateBufferUAV(SharpDX.Direct3D11.Device device, Buffer buffer)
        {
            UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription
            {
                Dimension = UnorderedAccessViewDimension.Buffer,
                Buffer = new UnorderedAccessViewDescription.BufferResource { FirstElement = 0 }
            };
            if ((buffer.Description.OptionFlags & ResourceOptionFlags.BufferAllowRawViews) == ResourceOptionFlags.BufferAllowRawViews)
            {
                // A raw buffer requires R32_Typeless
                uavDesc.Format = Format.R32_Typeless;
                uavDesc.Buffer.Flags = UnorderedAccessViewBufferFlags.Raw;
                uavDesc.Buffer.ElementCount = buffer.Description.SizeInBytes / 4;
            }
            else if ((buffer.Description.OptionFlags & ResourceOptionFlags.BufferStructured) == ResourceOptionFlags.BufferStructured)
            {
                uavDesc.Format = Format.Unknown;
                uavDesc.Buffer.ElementCount = buffer.Description.SizeInBytes / buffer.Description.StructureByteStride;
            }
            else
            {
                throw new ArgumentException("Buffer must be raw or structured", "buffer");
            }

            return new UnorderedAccessView(device, buffer, uavDesc);
        }
예제 #2
0
        public DX11MipSliceRenderTarget2D(DX11RenderContext context, DX11Texture2D texture, int mipindex, int w, int h)
        {
            this.context = context;
            this.Resource = texture.Resource;

            RenderTargetViewDescription rtd = new RenderTargetViewDescription()
            {
                Dimension = RenderTargetViewDimension.Texture2D,
                Format = texture.Format,
                MipSlice = mipindex
            };

            UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription()
            {
                Dimension = UnorderedAccessViewDimension.Texture2D,
                Format = texture.Format,
                MipSlice = mipindex,
            };

            ShaderResourceViewDescription srvd = new ShaderResourceViewDescription();
            srvd.Dimension = ShaderResourceViewDimension.Texture2D;
            srvd.MipLevels = 1;
            srvd.MostDetailedMip = mipindex;
            srvd.Format = texture.Format;

            this.SRV = new ShaderResourceView(context.Device, texture.Resource, srvd);
        }
예제 #3
0
        public DX11RawBuffer(Device dev, int size, DX11RawBufferFlags flags= new DX11RawBufferFlags())
        {
            this.Size = size;

            BufferDescription bd = new BufferDescription()
            {
                BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.RawBuffer,
                SizeInBytes = this.Size,
                Usage = ResourceUsage.Default,
            };
            this.Buffer = new Buffer(dev, bd);

            ShaderResourceViewDescription srvd = new ShaderResourceViewDescription()
            {
                Format = SlimDX.DXGI.Format.R32_Typeless,
                Dimension = ShaderResourceViewDimension.ExtendedBuffer,
                Flags = ShaderResourceViewExtendedBufferFlags.RawData,
                ElementCount = size / 4
            };
            this.SRV = new ShaderResourceView(dev, this.Buffer, srvd);

            UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription()
            {
                Format = SlimDX.DXGI.Format.R32_Typeless,
                Dimension = UnorderedAccessViewDimension.Buffer,
                Flags = UnorderedAccessViewBufferFlags.RawData,
                ElementCount = size / 4
            };

            this.UAV = new UnorderedAccessView(dev, this.Buffer, uavd);
        }
예제 #4
0
		/// <summary>
		/// Creates texture
		/// </summary>
		/// <param name="device"></param>
		public VolumeRWTexture ( GraphicsDevice device, int width, int height, int depth, ColorFormat format, bool mips ) : base( device )
		{
			this.Width		=	width;
			this.Height		=	height;
			this.Depth		=	depth;
			this.format		=	format;
			this.mipCount	=	mips ? ShaderResource.CalculateMipLevels(Width,Height,Depth) : 1;

			var texDesc = new Texture3DDescription();
			texDesc.BindFlags		=	BindFlags.ShaderResource | BindFlags.UnorderedAccess;
			texDesc.CpuAccessFlags	=	CpuAccessFlags.None;
			texDesc.Format			=	Converter.Convert( format );
			texDesc.Height			=	Height;
			texDesc.MipLevels		=	mipCount;
			texDesc.OptionFlags		=	ResourceOptionFlags.None;
			texDesc.Usage			=	ResourceUsage.Default;
			texDesc.Width			=	Width;
			texDesc.Depth			=	Depth;

			var uavDesc = new UnorderedAccessViewDescription();
			uavDesc.Format		=	Converter.Convert( format );
			uavDesc.Dimension	=	UnorderedAccessViewDimension.Texture3D;
			uavDesc.Texture3D.FirstWSlice	=	0;
			uavDesc.Texture3D.MipSlice		=	0;
			uavDesc.Texture3D.WSize			=	depth;

			tex3D	=	new D3D.Texture3D( device.Device, texDesc );
			SRV		=	new D3D.ShaderResourceView( device.Device, tex3D );
			uav		=	new UnorderedAccessView( device.Device, tex3D, uavDesc );
		}
예제 #5
0
        public D3D11Buffer(Device device, uint sizeInBytes, BufferUsage usage, uint structureByteStride)
        {
            SizeInBytes = sizeInBytes;
            Usage       = usage;
            SharpDX.Direct3D11.BufferDescription bd = new SharpDX.Direct3D11.BufferDescription(
                (int)sizeInBytes,
                D3D11Formats.VdToD3D11BindFlags(usage),
                ResourceUsage.Default);
            if ((usage & BufferUsage.StructuredBufferReadOnly) == BufferUsage.StructuredBufferReadOnly ||
                (usage & BufferUsage.StructuredBufferReadWrite) == BufferUsage.StructuredBufferReadWrite)
            {
                bd.OptionFlags         = ResourceOptionFlags.BufferStructured;
                bd.StructureByteStride = (int)structureByteStride;
            }
            if ((usage & BufferUsage.IndirectBuffer) == BufferUsage.IndirectBuffer)
            {
                bd.OptionFlags = ResourceOptionFlags.DrawIndirectArguments;
            }

            if ((usage & BufferUsage.Dynamic) == BufferUsage.Dynamic)
            {
                bd.Usage          = ResourceUsage.Dynamic;
                bd.CpuAccessFlags = CpuAccessFlags.Write;
            }
            else if ((usage & BufferUsage.Staging) == BufferUsage.Staging)
            {
                bd.Usage          = ResourceUsage.Staging;
                bd.CpuAccessFlags = CpuAccessFlags.Read | CpuAccessFlags.Write;
            }

            _buffer = new SharpDX.Direct3D11.Buffer(device, bd);

            if ((usage & BufferUsage.StructuredBufferReadWrite) == BufferUsage.StructuredBufferReadWrite ||
                (usage & BufferUsage.StructuredBufferReadOnly) == BufferUsage.StructuredBufferReadOnly)
            {
                ShaderResourceViewDescription srvDesc = new ShaderResourceViewDescription
                {
                    Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.ExtendedBuffer
                };
                srvDesc.BufferEx.ElementCount = (int)(SizeInBytes / structureByteStride);
                ShaderResourceView            = new ShaderResourceView(device, _buffer, srvDesc);
            }

            if ((usage & BufferUsage.StructuredBufferReadWrite) == BufferUsage.StructuredBufferReadWrite)
            {
                UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription
                {
                    Dimension = UnorderedAccessViewDimension.Buffer
                };

                uavDesc.Buffer.ElementCount = (int)(SizeInBytes / structureByteStride);
                uavDesc.Format = SharpDX.DXGI.Format.Unknown;

                UnorderedAccessView = new UnorderedAccessView(device, _buffer, uavDesc);
            }
        }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="desc"></param>
        public void Initialize(BufferDesc desc)
        {
            var device = GraphicsCore.D3D11Device;

            stride_ = desc.stride;

            BindFlags flags = BindFlags.ShaderResource;

            if (desc.bindUAV)
            {
                flags |= BindFlags.UnorderedAccess;
            }

            BufferDescription bufDesc = new BufferDescription {
                SizeInBytes         = desc.size,
                StructureByteStride = desc.stride,
                BindFlags           = flags,
                OptionFlags         = ResourceOptionFlags.StructuredBuffer,
                Usage          = ResourceUsage.Default,
                CpuAccessFlags = CpuAccessFlags.None,
            };

            // 初期化データ
            if (desc.initData != null)
            {
                DataStream stream = new DataStream(desc.initData, true, false);
                buffer_ = new D3D11Buffer(device, stream, bufDesc);
                stream.Close();
            }
            else
            {
                buffer_ = new D3D11Buffer(device, bufDesc);
            }

            // SRV
            ShaderResourceViewDescription srvViewDesc = new ShaderResourceViewDescription {
                Format       = Format.Unknown,
                Dimension    = ShaderResourceViewDimension.Buffer,
                ElementWidth = desc.size / desc.stride,
            };

            shaderResourceView_ = new ShaderResourceView(device, buffer_, srvViewDesc);

            if (desc.bindUAV)
            {
                UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription {
                    Dimension    = UnorderedAccessViewDimension.Buffer,
                    ElementCount = desc.size / desc.stride,
                    Flags        = UnorderedAccessViewBufferFlags.None,
                    Format       = Format.Unknown,
                };
                unorderedAccessView_ = new UnorderedAccessView(device, buffer_, uavDesc);
            }
        }
예제 #7
0
        public HardwareOutputBuffer([NotNull] AccelerationDevice provider, [NotNull] Type itemType, int itemCount) : base(provider, Marshal.SizeOf(itemType) * itemCount)
        {
            if (itemType == null)
            {
                throw new ArgumentNullException(nameof(itemType));
            }

            if (!itemType.IsValueType)
            {
                throw new ArgumentException("Can't use a reference type as buffer structure.", nameof(itemType));
            }

            var nStructure = Marshal.SizeOf(itemType);
            var nBytes     = nStructure * itemCount;

            if (Context.IsDebugModeEnabled)
            {
                Context.DiagnosticsWriter.WriteDebug("Allocating {0:###,###,###,###,###,##0} bytes of UAV memory with a structure stride of {1:###,###,###,###,###,##0} bytes",
                                                     nBytes, nStructure);
            }

            var bufferDescription = new BufferDescription
            {
                BindFlags           = BindFlags.ShaderResource | BindFlags.UnorderedAccess,
                CpuAccessFlags      = CpuAccessFlags.None,
                OptionFlags         = ResourceOptionFlags.StructuredBuffer,
                SizeInBytes         = nBytes,
                StructureByteStride = nStructure,
                Usage = ResourceUsage.Default
            };

            var swapDescription = new BufferDescription
            {
                BindFlags           = BindFlags.None,
                CpuAccessFlags      = CpuAccessFlags.Read | CpuAccessFlags.Write,
                OptionFlags         = ResourceOptionFlags.StructuredBuffer,
                SizeInBytes         = bufferDescription.SizeInBytes,
                StructureByteStride = bufferDescription.StructureByteStride,
                Usage = ResourceUsage.Staging
            };

            var viewDescription = new UnorderedAccessViewDescription
            {
                ElementCount = itemCount,
                Format       = SlimDX.DXGI.Format.Unknown,
                Dimension    = UnorderedAccessViewDimension.Buffer,
                Flags        = UnorderedAccessViewBufferFlags.None
            };

            mSwapBuffer          = new Buffer(Device, swapDescription);
            mHardwareBuffer      = new Buffer(Device, bufferDescription);
            mResourceView        = new ShaderResourceView(Device, mHardwareBuffer);
            mUnorderedAccessView = new UnorderedAccessView(Device, mHardwareBuffer, viewDescription);
        }
예제 #8
0
            public void OnDeviceInit()
            {
                UnorderedAccessViewDescription desc = new UnorderedAccessViewDescription();

                desc.Format    = m_format;
                desc.Dimension = UnorderedAccessViewDimension.Texture2DArray;
                desc.Texture2DArray.ArraySize       = 1;
                desc.Texture2DArray.FirstArraySlice = m_slice;
                desc.Texture2DArray.MipSlice        = m_mipmap;
                m_uav = new UnorderedAccessView(MyRender11.Device, m_owner.Resource, desc);
            }
예제 #9
0
        private UnorderedAccessViewDescription CreateUAVDescription(int mipSlice)
        {
            UnorderedAccessViewDescription desc = new UnorderedAccessViewDescription();

            desc.Format    = SharpDX.DXGI.Format.R8G8B8A8_UNorm;
            desc.Dimension = UnorderedAccessViewDimension.Texture2DArray;
            desc.Texture2DArray.ArraySize       = numOfSlices;
            desc.Texture2DArray.FirstArraySlice = 0;
            desc.Texture2DArray.MipSlice        = mipSlice;
            return(desc);
        }
예제 #10
0
        private void MipGenerationSimple2LevelsOn2DTexture()
        {
            //Given
            Material computeShader = LoadComputeShader(device);

            Texture2DDescription emptyTextureDesc = CreateTextureDescription();

            SharpDX.Direct3D11.Texture2D emptyTexture = new SharpDX.Direct3D11.Texture2D(device, emptyTextureDesc);

            ShaderResourceViewDescription srvDesc = CreateSRVDescription();
            ShaderResourceView            srv     = new ShaderResourceView(device, emptyTexture, srvDesc);

            UnorderedAccessViewDescription uavDesc = CreateUAVDescription(0);
            UnorderedAccessView            uavMip0 = new UnorderedAccessView(device, emptyTexture, uavDesc);

            uavDesc = CreateUAVDescription(1);
            UnorderedAccessView uavMip1 = new UnorderedAccessView(device, emptyTexture, uavDesc);

            uavDesc = CreateUAVDescription(2);
            UnorderedAccessView uavMip2 = new UnorderedAccessView(device, emptyTexture, uavDesc);

            BufferDescription bufferDesc = CreateLocalBufferDesc();

            SharpDX.Direct3D11.Buffer localbuffer = new SharpDX.Direct3D11.Buffer(device, bufferDesc);

            int mipSize  = 0;
            int subIndex = emptyTexture.CalculateSubResourceIndex(1, 0, out mipSize);

            //When
            computeShader.SetParameterResource("gOutput", uavMip0);
            computeShader.SetParameterValue("fillColour", new Vector4(0.1f, 0.2f, 0.3f, 1.0f));

            computeShader.Apply();

            //IS THIS ACTUALLY DOING ANYTHING AT ALL? Do we need to set up more of the pipeline before this will actually work??
            device.Dispatch(1, 32, 1);

            device.Copy(emptyTexture, 1, localbuffer, 0);

            DataStream data = new DataStream(8 * 32 * 32, true, true);

            ((DeviceContext)device).MapSubresource(localbuffer, MapMode.Read, MapFlags.None, out data);


            Half4 quickTest;

            for (int i = 0; i < 32 * 32; i++)
            {
                quickTest = data.ReadHalf4();
            }

            ((DeviceContext)device).UnmapSubresource(localbuffer, 0);
        }
예제 #11
0
        public DX11RawBuffer(Device dev, int size, DX11RawBufferFlags flags = new DX11RawBufferFlags())
        {
            this.Size = size;

            BufferDescription bd = new BufferDescription()
            {
                BindFlags      = BindFlags.ShaderResource | BindFlags.UnorderedAccess,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags    = ResourceOptionFlags.RawBuffer,
                SizeInBytes    = this.Size,
                Usage          = ResourceUsage.Default,
            };

            if (flags.AllowIndexBuffer)
            {
                bd.BindFlags |= BindFlags.IndexBuffer;
            }

            if (flags.AllowVertexBuffer)
            {
                bd.BindFlags |= BindFlags.VertexBuffer;
            }

            if (flags.AllowArgumentBuffer)
            {
                bd.OptionFlags |= ResourceOptionFlags.DrawIndirect;
            }


            this.Buffer = new Buffer(dev, bd);

            ShaderResourceViewDescription srvd = new ShaderResourceViewDescription()
            {
                Format       = SlimDX.DXGI.Format.R32_Typeless,
                Dimension    = ShaderResourceViewDimension.ExtendedBuffer,
                Flags        = ShaderResourceViewExtendedBufferFlags.RawData,
                ElementCount = size / 4
            };

            this.SRV = new ShaderResourceView(dev, this.Buffer, srvd);

            UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription()
            {
                Format       = SlimDX.DXGI.Format.R32_Typeless,
                Dimension    = UnorderedAccessViewDimension.Buffer,
                Flags        = UnorderedAccessViewBufferFlags.RawData,
                ElementCount = size / 4
            };

            this.UAV = new UnorderedAccessView(dev, this.Buffer, uavd);
        }
예제 #12
0
        private (CpuDescriptorHandle, GpuDescriptorHandle) CreateUnorderedAccessView()
        {
            (CpuDescriptorHandle cpuHandle, GpuDescriptorHandle gpuHandle) = GraphicsDevice.ShaderResourceViewAllocator.Allocate();

            UnorderedAccessViewDescription description = new UnorderedAccessViewDescription
            {
                ViewDimension = UnorderedAccessViewDimension.Buffer,
                Buffer        = { NumElements = Size, StructureByteStride = ElementSizeInBytes }
            };

            GraphicsDevice.NativeDevice.CreateUnorderedAccessView(NativeResource, null, description, cpuHandle);

            return(cpuHandle, gpuHandle);
        }
예제 #13
0
        /// <summary>
        /// Initializes the views.
        /// </summary>
        private void InitializeViews()
        {
            var bindFlags = nativeDescription.BindFlags;

            var srvFormat = ViewFormat;
            var uavFormat = ViewFormat;

            if (((ViewFlags & BufferFlags.RawBuffer) != 0))
            {
                srvFormat = PixelFormat.R32_Typeless;
                uavFormat = PixelFormat.R32_Typeless;
            }

            if ((bindFlags & BindFlags.ShaderResource) != 0)
            {
                this.NativeShaderResourceView = GetShaderResourceView(srvFormat);
            }

            if ((bindFlags & BindFlags.UnorderedAccess) != 0)
            {
                var description = new UnorderedAccessViewDescription()
                {
                    Format    = (SharpDX.DXGI.Format)uavFormat,
                    Dimension = UnorderedAccessViewDimension.Buffer,
                    Buffer    =
                    {
                        ElementCount = this.ElementCount,
                        FirstElement =                                   0,
                        Flags        = UnorderedAccessViewBufferFlags.None,
                    },
                };

                if (((ViewFlags & BufferFlags.RawBuffer) == BufferFlags.RawBuffer))
                {
                    description.Buffer.Flags |= UnorderedAccessViewBufferFlags.Raw;
                }

                if (((ViewFlags & BufferFlags.StructuredAppendBuffer) == BufferFlags.StructuredAppendBuffer))
                {
                    description.Buffer.Flags |= UnorderedAccessViewBufferFlags.Append;
                }

                if (((ViewFlags & BufferFlags.StructuredCounterBuffer) == BufferFlags.StructuredCounterBuffer))
                {
                    description.Buffer.Flags |= UnorderedAccessViewBufferFlags.Counter;
                }

                this.NativeUnorderedAccessView = new UnorderedAccessView(this.GraphicsDevice.NativeDevice, NativeBuffer, description);
            }
        }
예제 #14
0
        public D3D11TextureView(D3D11GraphicsDevice gd, ref TextureViewDescription description)
            : base(ref description)
        {
            Device       device = gd.Device;
            D3D11Texture d3dTex = Util.AssertSubtype <Texture, D3D11Texture>(description.Target);
            ShaderResourceViewDescription srvDesc = D3D11Util.GetSrvDesc(
                d3dTex,
                description.BaseMipLevel,
                description.MipLevels,
                description.BaseArrayLayer,
                description.ArrayLayers,
                Format);

            ShaderResourceView = new ShaderResourceView(device, d3dTex.DeviceTexture, srvDesc);

            if ((d3dTex.Usage & TextureUsage.Storage) == TextureUsage.Storage)
            {
                UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription();
                uavDesc.Format = D3D11Formats.GetViewFormat(d3dTex.DxgiFormat);

                if ((d3dTex.Usage & TextureUsage.Cubemap) == TextureUsage.Cubemap)
                {
                    throw new NotSupportedException();
                }
                else if (d3dTex.Depth == 1)
                {
                    if (d3dTex.ArrayLayers == 1)
                    {
                        uavDesc.Dimension          = UnorderedAccessViewDimension.Texture2D;
                        uavDesc.Texture2D.MipSlice = (int)description.BaseMipLevel;
                    }
                    else
                    {
                        uavDesc.Dimension = UnorderedAccessViewDimension.Texture2DArray;
                        uavDesc.Texture2DArray.MipSlice        = (int)description.BaseMipLevel;
                        uavDesc.Texture2DArray.FirstArraySlice = (int)description.BaseArrayLayer;
                        uavDesc.Texture2DArray.ArraySize       = (int)description.ArrayLayers;
                    }
                }
                else
                {
                    uavDesc.Dimension             = UnorderedAccessViewDimension.Texture3D;
                    uavDesc.Texture3D.MipSlice    = (int)description.BaseMipLevel;
                    uavDesc.Texture3D.FirstWSlice = (int)description.BaseArrayLayer;
                    uavDesc.Texture3D.WSize       = (int)description.ArrayLayers;
                }

                UnorderedAccessView = new UnorderedAccessView(device, d3dTex.DeviceTexture, uavDesc);
            }
        }
예제 #15
0
        public static UnorderedAccessView CreateUnorderedAccessView(Device device, Resource resource, Format format, UnorderedAccessViewDimension viewDimension, int firstElement, int numElements, UnorderedAccessViewBufferFlags flags, int mipSlice)
        {
            UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription();

            uavd.Format    = format;
            uavd.Dimension = viewDimension;

            switch (viewDimension)
            {
            case UnorderedAccessViewDimension.Texture1D:
                uavd.Texture1D.MipSlice = mipSlice;
                break;

            case UnorderedAccessViewDimension.Texture1DArray:
                uavd.Texture1DArray.MipSlice        = mipSlice;
                uavd.Texture1DArray.ArraySize       = numElements;
                uavd.Texture1DArray.FirstArraySlice = firstElement;
                break;

            case UnorderedAccessViewDimension.Texture2D:
                uavd.Texture2D.MipSlice = mipSlice;
                break;

            case UnorderedAccessViewDimension.Texture2DArray:
                uavd.Texture2DArray.MipSlice        = mipSlice;
                uavd.Texture2DArray.ArraySize       = numElements;
                uavd.Texture2DArray.FirstArraySlice = firstElement;
                break;

            case UnorderedAccessViewDimension.Texture3D:
                uavd.Texture3D.MipSlice    = mipSlice;
                uavd.Texture3D.WSize       = numElements;
                uavd.Texture3D.FirstWSlice = firstElement;
                break;

            case UnorderedAccessViewDimension.Buffer:
                uavd.Buffer.ElementCount = numElements;
                uavd.Buffer.FirstElement = firstElement;
                uavd.Buffer.Flags        = flags;
                break;

            case UnorderedAccessViewDimension.Unknown:
            default:
                return(null);
            }
            var uav = new UnorderedAccessView(device, resource, uavd);

            return(uav);
        }
예제 #16
0
        internal MyUavView(MyBindableResource from, Format fmt)
        {
            m_owner = from;

            var desc = new UnorderedAccessViewDescription
            {
                Format    = fmt,
                Dimension = UnorderedAccessViewDimension.Texture2D,
                Texture2D = new UnorderedAccessViewDescription.Texture2DResource {
                    MipSlice = 0
                }
            };

            m_uav = new UnorderedAccessView(MyRender11.Device, m_owner.m_resource, desc);
        }
예제 #17
0
        // Static functions
        static public GPUBufferObject CreateBuffer(Device device, int size, int elementSizeInBytes, DataStream stream = null, bool append = false, bool allowStaging = false)
        {
            GPUBufferObject newBuffer = new GPUBufferObject();

            // Variables
            newBuffer.m_Size = size;

            BindFlags bindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess;

            BufferDescription description = new BufferDescription(size * elementSizeInBytes, ResourceUsage.Default, bindFlags, CpuAccessFlags.None, ResourceOptionFlags.StructuredBuffer, elementSizeInBytes);

            newBuffer.m_BufferObject = stream != null ? new Buffer(device, stream, description) : new Buffer(device, description);

            ShaderResourceViewDescription srvViewDesc = new ShaderResourceViewDescription
            {
                FirstElement = 0,
                ElementCount = size,
                Format       = Format.Unknown,
                Dimension    = ShaderResourceViewDimension.ExtendedBuffer,
                Flags        = 0,
            };

            newBuffer.m_ShaderResourceView = new ShaderResourceView(device, newBuffer.m_BufferObject, srvViewDesc);


            UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription
            {
                ArraySize    = 0,
                Dimension    = UnorderedAccessViewDimension.Buffer,
                ElementCount = size,
                Flags        = append ? UnorderedAccessViewBufferFlags.AllowAppend : UnorderedAccessViewBufferFlags.None,
                Format       = Format.Unknown,
                MipSlice     = 0
            };

            newBuffer.m_UnorderedAccessView = new UnorderedAccessView(device, newBuffer.m_BufferObject, uavDesc);

            if (allowStaging)
            {
                description = new BufferDescription(size * elementSizeInBytes, ResourceUsage.Staging, BindFlags.None, CpuAccessFlags.Read, ResourceOptionFlags.StructuredBuffer, elementSizeInBytes);
                newBuffer.m_StagingBufferObject = new Buffer(device, description);

                description = new BufferDescription(16, ResourceUsage.Staging, BindFlags.None, CpuAccessFlags.Read, ResourceOptionFlags.None, 4);
                newBuffer.m_StagingCountBufferObject = new Buffer(device, description);
            }

            return(newBuffer);
        }
예제 #18
0
        public DX11RWTextureArray2D(DX11RenderContext context, Texture2D resource) : base(context, resource)
        {
            var uavd = new UnorderedAccessViewDescription()
            {
                ArraySize       = this.desc.ArraySize,
                FirstArraySlice = 0,
                Dimension       = UnorderedAccessViewDimension.Texture2DArray,
                Format          = this.desc.Format,
                DepthSliceCount = 1,
                FirstDepthSlice = 0,
                ElementCount    = desc.ArraySize,
                FirstElement    = 0
            };

            UAV = new UnorderedAccessView(context.Device, resource, uavd);
        }
예제 #19
0
            public void OnDeviceInit()
            {
                UnorderedAccessViewDescription desc = new UnorderedAccessViewDescription
                {
                    Format         = m_format,
                    Dimension      = UnorderedAccessViewDimension.Texture2DArray,
                    Texture2DArray =
                    {
                        ArraySize       =       1,
                        FirstArraySlice = m_slice,
                        MipSlice        = m_mipmap
                    }
                };

                m_uav = new UnorderedAccessView(MyRender11.Device, m_owner.Resource, desc);
            }
예제 #20
0
        // Creates a view of a buffer so that the shader can read and write to it
        private UnorderedAccessView CreateUnorderedAccessView(Buffer buffer, int elements)
        {
            var description = new UnorderedAccessViewDescription()
            {
                Buffer = new UnorderedAccessViewDescription.BufferResource()
                {
                    FirstElement = 0,
                    Flags        = UnorderedAccessViewBufferFlags.None,
                    ElementCount = elements
                },
                Format    = SharpDX.DXGI.Format.Unknown,
                Dimension = UnorderedAccessViewDimension.Buffer
            };

            return(new UnorderedAccessView(this.Device, buffer, description));
        }
예제 #21
0
        // Static functions
        static public GPUBufferObject CreateBuffer(Device device, int size, int elementSizeInBytes, DataStream stream = null, bool append = false, bool allowStaging = false)
        {
            GPUBufferObject newBuffer = new GPUBufferObject();

            // Variables
            newBuffer.m_Size = size;

            BindFlags bindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess;

            BufferDescription description = new BufferDescription(size * elementSizeInBytes, ResourceUsage.Default, bindFlags, CpuAccessFlags.None, ResourceOptionFlags.StructuredBuffer, elementSizeInBytes);

            newBuffer.m_BufferObject = stream != null ? new Buffer(device, stream, description) : new Buffer(device, description);

            ShaderResourceViewDescription srvViewDesc = new ShaderResourceViewDescription
            {
                FirstElement = 0,
                ElementCount = size,
                Format = Format.Unknown,
                Dimension = ShaderResourceViewDimension.ExtendedBuffer,
                Flags = 0,
            };

            newBuffer.m_ShaderResourceView = new ShaderResourceView(device, newBuffer.m_BufferObject, srvViewDesc);


            UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription
            {
                ArraySize = 0,
                Dimension = UnorderedAccessViewDimension.Buffer,
                ElementCount = size,
                Flags = append ? UnorderedAccessViewBufferFlags.AllowAppend : UnorderedAccessViewBufferFlags.None,
                Format = Format.Unknown,
                MipSlice = 0
            };
            newBuffer.m_UnorderedAccessView = new UnorderedAccessView(device, newBuffer.m_BufferObject, uavDesc);

            if (allowStaging)
            {
                description = new BufferDescription(size * elementSizeInBytes, ResourceUsage.Staging, BindFlags.None, CpuAccessFlags.Read, ResourceOptionFlags.StructuredBuffer, elementSizeInBytes);
                newBuffer.m_StagingBufferObject = new Buffer(device, description);

                description = new BufferDescription(16, ResourceUsage.Staging, BindFlags.None, CpuAccessFlags.Read, ResourceOptionFlags.None, 4);
                newBuffer.m_StagingCountBufferObject = new Buffer(device, description);
            }

            return newBuffer;
        }
예제 #22
0
        internal override UnorderedAccessView GetUnorderedAccessView(int arrayOrDepthSlice, int mipIndex)
        {
            if ((this.Description.BindFlags & BindFlags.UnorderedAccess) == 0)
            {
                return(null);
            }

            int arrayCount = 1;

            // Use Full although we are binding to a single array/mimap slice, just to get the correct index
            var uavIndex = GetViewIndex(ViewType.Full, arrayOrDepthSlice, mipIndex);

            lock (this.unorderedAccessViews)
            {
                var uav = this.unorderedAccessViews[uavIndex];

                // Creates the unordered access view
                if (uav == null)
                {
                    var uavDescription = new UnorderedAccessViewDescription()
                    {
                        Format    = this.Description.Format,
                        Dimension = this.Description.ArraySize > 1 ? UnorderedAccessViewDimension.Texture2DArray : UnorderedAccessViewDimension.Texture2D
                    };

                    if (this.Description.ArraySize > 1)
                    {
                        uavDescription.Texture2DArray.ArraySize       = arrayCount;
                        uavDescription.Texture2DArray.FirstArraySlice = arrayOrDepthSlice;
                        uavDescription.Texture2DArray.MipSlice        = mipIndex;
                    }
                    else
                    {
                        uavDescription.Texture2D.MipSlice = mipIndex;
                    }

                    uav = new UnorderedAccessView(GraphicsDevice, Resource, uavDescription)
                    {
                        Tag = this
                    };
                    this.unorderedAccessViews[uavIndex] = ToDispose(uav);
                }

                return(uav);
            }
        }
        public DxMipSliceRenderTarget(DxDevice device, IDxTexture3D texture, int mipindex, int w, int h, int d)
        {
            this.device = device;

            RenderTargetViewDescription rtd = new RenderTargetViewDescription()
            {
                Dimension = RenderTargetViewDimension.Texture3D,
                Format = texture.Format,
                Texture3D = new RenderTargetViewDescription.Texture3DResource()
                {
                    MipSlice = mipindex
                }
            };

            ShaderResourceViewDescription srvd = new ShaderResourceViewDescription()
            {
                Dimension = ShaderResourceViewDimension.Texture3D,
                Format = texture.Format,
                Texture3D = new ShaderResourceViewDescription.Texture3DResource()
                {
                    MipLevels = 1,
                    MostDetailedMip = mipindex
                }
            };

            UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription()
            {
                Dimension = UnorderedAccessViewDimension.Texture3D,
                Format = texture.Format,
                Texture3D = new UnorderedAccessViewDescription.Texture3DResource()
                {
                    FirstWSlice = 0,
                    MipSlice = mipindex,
                    WSize = d
                }
            };

            this.RenderView = new RenderTargetView(device.Device, texture.Texture, rtd);
            this.ShaderView = new ShaderResourceView(device.Device, texture.Texture, srvd);
            this.UnorderedView = new UnorderedAccessView(device.Device, texture.Texture, uavd);

            this.Width = w;
            this.Height = h;
            this.Depth = d;
        }
예제 #24
0
        public ShaderResourceView GenerateIrradianceCubemapFromTextureCube(TextureCube originalCube)
        {
            Texture2DDescription emptyTextureDesc = CreateTextureDescription();
            Texture2D            emptyTexture     = new Texture2D(device, emptyTextureDesc);

            UnorderedAccessViewDescription uavDesc = CreateUAVDescription(0);
            UnorderedAccessView            view    = new UnorderedAccessView(device, emptyTexture, uavDesc);

            computeShader.SetParameterResource("gSource", originalCube.ShaderView);
            computeShader.SetParameterResource("gOutput", view);
            computeShader.Apply();

            int groups = textureSize / 64;

            device.Dispatch(groups, textureSize, numOfSlices);

            return(null);
        }
예제 #25
0
        public DX11IndexBuffer(DX11RenderContext context, int elementcount, bool uav = false, bool streamout = false)
        {
            this.context      = context;
            this.IndicesCount = elementcount;
            format            = SlimDX.DXGI.Format.R32_UInt;


            BufferDescription bd = new BufferDescription()
            {
                BindFlags      = BindFlags.IndexBuffer,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags    = ResourceOptionFlags.None,
                SizeInBytes    = elementcount * sizeof(int),
                Usage          = ResourceUsage.Default,
            };

            if (streamout)
            {
                bd.BindFlags |= BindFlags.StreamOutput;
            }

            if (uav && context.IsFeatureLevel11)
            {
                bd.BindFlags   |= BindFlags.UnorderedAccess;
                bd.BindFlags   |= BindFlags.ShaderResource;
                bd.OptionFlags |= ResourceOptionFlags.RawBuffer;
            }

            this.Buffer = new SlimDX.Direct3D11.Buffer(context.Device, bd);

            if (uav)
            {
                UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription()
                {
                    Format       = SlimDX.DXGI.Format.R32_Typeless,
                    Dimension    = UnorderedAccessViewDimension.Buffer,
                    Flags        = UnorderedAccessViewBufferFlags.RawData,
                    ElementCount = elementcount
                };

                this.uav = new UnorderedAccessView(context.Device, this.Buffer, uavd);
                this.CreateSRV();
            }
        }
예제 #26
0
        protected DX11RawBuffer(DxDevice device, BufferDescription desc, IntPtr ptr, bool createUAV)
        {
            this.device = device;
            this.Size   = desc.SizeInBytes;

            this.Buffer      = new SharpDX.Direct3D11.Buffer(device.Device, ptr, desc);
            this.Description = this.Buffer.Description;

            if (desc.BindFlags.HasFlag(BindFlags.ShaderResource))
            {
                ShaderResourceViewDescription srvd = new ShaderResourceViewDescription()
                {
                    Format    = SharpDX.DXGI.Format.R32_Typeless,
                    Dimension = ShaderResourceViewDimension.ExtendedBuffer,

                    BufferEx = new ShaderResourceViewDescription.ExtendedBufferResource()
                    {
                        ElementCount = desc.SizeInBytes / 4,
                        FirstElement = 0,
                        Flags        = ShaderResourceViewExtendedBufferFlags.Raw
                    }
                };

                this.ShaderView = new ShaderResourceView(device.Device, this.Buffer, srvd);
            }

            if (createUAV)
            {
                UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription()
                {
                    Format    = SharpDX.DXGI.Format.R32_Typeless,
                    Dimension = UnorderedAccessViewDimension.Buffer,
                    Buffer    = new UnorderedAccessViewDescription.BufferResource()
                    {
                        ElementCount = this.Size / 4,
                        FirstElement = 0,
                        Flags        = UnorderedAccessViewBufferFlags.Raw
                    }
                };

                this.UnorderedView = new UnorderedAccessView(device.Device, this.Buffer, uavd);
            }
        }
예제 #27
0
        private void CreateShaderResources()
        {
            HeapProperties heapProperties = new HeapProperties(HeapType.Default, CpuPageProperty.Unknown, MemoryPool.Unknown, 0, 0);

            // Create the output resource. The dimensions and format should match the swap-chain
            ResourceDescription resDesc = new ResourceDescription();

            resDesc.Alignment               = 0;
            resDesc.DepthOrArraySize        = 1;
            resDesc.Dimension               = ResourceDimension.Texture2D;
            resDesc.Flags                   = ResourceFlags.AllowUnorderedAccess;
            resDesc.Format                  = Format.R8G8B8A8_UNorm;
            resDesc.Width                   = Window.Width;
            resDesc.Height                  = Window.Height;
            resDesc.Layout                  = TextureLayout.Unknown;
            resDesc.MipLevels               = 1;
            resDesc.SampleDescription       = new SampleDescription();
            resDesc.SampleDescription.Count = 1;

            outputResource = device.CreateCommittedResource(heapProperties, HeapFlags.None, resDesc, ResourceStates.CopySource, null);

            // Create an SRV/UAV descriptor heap. Need 2 entries - 1 SRV for the scene and 1 UAV for the output
            srvUavHeap = CreateDescriptorHeap(device, 2, DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView, true);

            // Create the UAV. Based on the root signature we created it should be the first entry
            UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription();

            uavDesc.ViewDimension = UnorderedAccessViewDimension.Texture2D;
            device.CreateUnorderedAccessView(outputResource, null, uavDesc, srvUavHeap.GetCPUDescriptorHandleForHeapStart());

            // Create the TLAS SRV right after the UAV. Note that we are using a different SRV desc here
            ShaderResourceViewDescription srvDesc = new ShaderResourceViewDescription();

            srvDesc.ViewDimension                            = ShaderResourceViewDimension.RaytracingAccelerationStructure;
            srvDesc.Shader4ComponentMapping                  = 5768; // D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING
            srvDesc.RaytracingAccelerationStructure          = new RaytracingAccelerationStructureShaderResourceView();
            srvDesc.RaytracingAccelerationStructure.Location = topLevelAS.GPUVirtualAddress;

            CpuDescriptorHandle srvHandle = srvUavHeap.GetCPUDescriptorHandleForHeapStart();

            srvHandle.Ptr += device.GetDescriptorHandleIncrementSize(DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView);
            device.CreateShaderResourceView(null, srvDesc, srvHandle);
        }
예제 #28
0
        // Static functions
        static public GPUBufferObject CreateBuffer(Device device, int size)
        {
            GPUBufferObject newBuffer = new GPUBufferObject();

            // Variables
            newBuffer.m_Size = size;

            BindFlags bindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess;

            BufferDescription description = new BufferDescription(size * 4, ResourceUsage.Default, bindFlags, CpuAccessFlags.None, ResourceOptionFlags.StructuredBuffer, 4);

            newBuffer.m_BufferObject = new Buffer(device, description);

            ShaderResourceViewDescription srvViewDesc = new ShaderResourceViewDescription
            {
                ArraySize       = 0,
                ElementCount    = size,
                ElementWidth    = size,
                Format          = Format.Unknown,
                Dimension       = ShaderResourceViewDimension.Buffer,
                Flags           = 0,
                FirstArraySlice = 0,
                MostDetailedMip = 0,
                MipLevels       = 0
            };

            newBuffer.m_ShaderResourceView = new ShaderResourceView(device, newBuffer.m_BufferObject, srvViewDesc);


            UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription
            {
                ArraySize    = 0,
                Dimension    = UnorderedAccessViewDimension.Buffer,
                ElementCount = size,
                Flags        = UnorderedAccessViewBufferFlags.None,
                Format       = Format.Unknown,
                MipSlice     = 0
            };

            newBuffer.m_UnorderedAccessView = new UnorderedAccessView(device, newBuffer.m_BufferObject, uavDesc);

            return(newBuffer);
        }
예제 #29
0
        protected override void AfterBufferInit()
        {
            var description = new UnorderedAccessViewDescription()
            {
                Buffer = new UnorderedAccessViewDescription.BufferResource()
                {
                    ElementCount = ElementCount,
                    FirstElement = 0,
                    Flags        = 0
                },
                Format    = Format,
                Dimension = UnorderedAccessViewDimension.Buffer
            };

            m_uav = new UnorderedAccessView(MyRender11.Device, Resource, description)
            {
                DebugName = Name + "_Uav"
            };
        }
예제 #30
0
        public override void CreateDerivedViews()
        {
            var srvDesc = new ShaderResourceViewDescription
            {
                Dimension = ShaderResourceViewDimension.Buffer,
                Format    = SharpDX.DXGI.Format.Unknown,
                Buffer    = new ShaderResourceViewDescription.BufferResource
                {
                    FirstElement        = 0,
                    ElementCount        = _ElementCount,
                    StructureByteStride = _ElementSize,
                    Flags = BufferShaderResourceViewFlags.None
                }
            };

            if (_SRV.Ptr == Constants.GPU_VIRTUAL_ADDRESS_UNKNOWN)
            {
                _SRV = Globals.AllocateDescriptor(DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView);
            }
            Globals.Device.CreateShaderResourceView(_Resource, srvDesc, _SRV);

            var uavDesc = new UnorderedAccessViewDescription
            {
                Dimension = UnorderedAccessViewDimension.Buffer,
                Format    = SharpDX.DXGI.Format.Unknown,
                Buffer    = new UnorderedAccessViewDescription.BufferResource
                {
                    CounterOffsetInBytes = 0,
                    ElementCount         = _ElementCount,
                    StructureByteStride  = _ElementSize,
                    Flags = BufferUnorderedAccessViewFlags.None
                }
            };

            _CounterBuffer.Create("StructuredBuffer.Counter", 1, 4);

            if (_UAV.Ptr == Constants.GPU_VIRTUAL_ADDRESS_UNKNOWN)
            {
                _UAV = Globals.AllocateDescriptor(DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView);
            }
            Globals.Device.CreateUnorderedAccessView(_Resource, _CounterBuffer.Resource, uavDesc, _UAV);
        }
예제 #31
0
        public Buffer CreateBufferRW(int elements, int elementSize, int slot)
        {
            Buffer buf = new Buffer(device, new BufferDescription
            {
                BindFlags           = BindFlags.UnorderedAccess | BindFlags.ShaderResource,
                OptionFlags         = ResourceOptionFlags.BufferStructured,
                SizeInBytes         = elements * elementSize,
                StructureByteStride = elementSize
            });
            var uavDesc = new UnorderedAccessViewDescription();

            uavDesc.Dimension           = UnorderedAccessViewDimension.Buffer;
            uavDesc.Format              = SharpDX.DXGI.Format.Unknown;
            uavDesc.Buffer.ElementCount = elements;

            using (var uav = new UnorderedAccessView(device, buf, uavDesc)) {
                ctx.ComputeShader.SetUnorderedAccessView(slot, uav);
            }
            return(buf);
        }
예제 #32
0
        public DX11MipSliceRenderTarget3D(DX11RenderContext context, DX11Texture3D texture, int mipindex, int w, int h, int d) : base(context)
        {
            this.Resource = texture.Resource;

            RenderTargetViewDescription rtd = new RenderTargetViewDescription()
            {
                Dimension       = RenderTargetViewDimension.Texture3D,
                Format          = texture.Format,
                MipSlice        = mipindex,
                DepthSliceCount = d
            };


            UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription()
            {
                Dimension       = UnorderedAccessViewDimension.Texture3D,
                Format          = texture.Format,
                MipSlice        = mipindex,
                FirstDepthSlice = 0,
                DepthSliceCount = d
            };

            ShaderResourceViewDescription srvd = new ShaderResourceViewDescription();

            srvd.Dimension       = ShaderResourceViewDimension.Texture3D;
            srvd.MipLevels       = 1;
            srvd.MostDetailedMip = mipindex;
            srvd.Format          = texture.Format;
            srvd.ArraySize       = d;
            srvd.FirstArraySlice = 0;



            this.RTV = new RenderTargetView(context.Device, texture.Resource, rtd);
            this.SRV = new ShaderResourceView(context.Device, texture.Resource, srvd);
            this.UAV = new UnorderedAccessView(context.Device, texture.Resource, uavd);

            this.Width  = w;
            this.Height = h;
            this.Depth  = d;
        }
예제 #33
0
        internal override UnorderedAccessView GetUnorderedAccessView(int zSlice, int mipIndex)
        {
            if ((this.Description.BindFlags & BindFlags.UnorderedAccess) == 0)
            {
                return(null);
            }

            int sliceCount = 1;

            // Use Full although we are binding to a single array/mimap slice, just to get the correct index
            var uavIndex = GetViewIndex(ViewType.Full, zSlice, mipIndex);

            lock (this.unorderedAccessViews)
            {
                var uav = this.unorderedAccessViews[uavIndex];

                // Creates the unordered access view
                if (uav == null)
                {
                    var uavDescription = new UnorderedAccessViewDescription()
                    {
                        Format    = this.Description.Format,
                        Dimension = UnorderedAccessViewDimension.Texture3D,
                        Texture3D =
                        {
                            FirstWSlice = zSlice,
                            MipSlice    = mipIndex,
                            WSize       = sliceCount
                        }
                    };

                    uav = new UnorderedAccessView(GraphicsDevice, Resource, uavDescription)
                    {
                        Tag = this
                    };
                    this.unorderedAccessViews[uavIndex] = ToDispose(uav);
                }

                return(uav);
            }
        }
예제 #34
0
        public void BuildDescriptors(CpuDescriptorHandle cpuDescriptor, GpuDescriptorHandle gpuDescriptor, int descriptorSize)
        {
            var srvDesc = new ShaderResourceViewDescription
            {
                Shader4ComponentMapping = D3DUtil.DefaultShader4ComponentMapping,
                Format    = Format.R32_Float,
                Dimension = ShaderResourceViewDimension.Texture2D,
                Texture2D = new ShaderResourceViewDescription.Texture2DResource
                {
                    MostDetailedMip = 0,
                    MipLevels       = 1
                }
            };

            var uavDesc = new UnorderedAccessViewDescription
            {
                Format    = Format.R32_Float,
                Dimension = UnorderedAccessViewDimension.Texture2D,
                Texture2D = new UnorderedAccessViewDescription.Texture2DResource
                {
                    MipSlice = 0
                }
            };

            _device.CreateShaderResourceView(_prevSol, srvDesc, cpuDescriptor);
            _device.CreateShaderResourceView(_currSol, srvDesc, cpuDescriptor + descriptorSize);
            _device.CreateShaderResourceView(_nextSol, srvDesc, cpuDescriptor + descriptorSize * 2);

            _device.CreateUnorderedAccessView(_prevSol, null, uavDesc, cpuDescriptor + descriptorSize * 3);
            _device.CreateUnorderedAccessView(_currSol, null, uavDesc, cpuDescriptor + descriptorSize * 4);
            _device.CreateUnorderedAccessView(_nextSol, null, uavDesc, cpuDescriptor + descriptorSize * 5);

            // Save references to the GPU descriptors.
            _prevSolSrv = gpuDescriptor;
            _currSolSrv = gpuDescriptor + descriptorSize;
            _nextSolSrv = gpuDescriptor + descriptorSize * 2;
            _prevSolUav = gpuDescriptor + descriptorSize * 3;
            _currSolUav = gpuDescriptor + descriptorSize * 4;
            _nextSolUav = gpuDescriptor + descriptorSize * 5;
        }
예제 #35
0
        protected DX11StructuredBuffer(DxDevice device, int elementcount, int stride, BufferDescription desc, eDxBufferMode buffermode = eDxBufferMode.Default)
        {
            this.device       = device;
            this.ElementCount = elementcount;
            this.Stride       = stride;
            this.Buffer       = new SharpDX.Direct3D11.Buffer(device.Device, desc);
            this.ShaderView   = new ShaderResourceView(device.Device, this.Buffer);
            this.BufferMode   = buffermode;

            UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription()
            {
                Format    = SharpDX.DXGI.Format.Unknown,
                Dimension = UnorderedAccessViewDimension.Buffer,
                Buffer    = new UnorderedAccessViewDescription.BufferResource()
                {
                    ElementCount = this.ElementCount,
                    Flags        = (UnorderedAccessViewBufferFlags)buffermode
                }
            };

            this.UnorderedView = new UnorderedAccessView(device.Device, this.Buffer, uavd);
        }
예제 #36
0
        public DX11MipSliceRenderTarget3D(DX11RenderContext context, DX11Texture3D texture, int mipindex, int w, int h, int d)
            : base(context)
        {
            this.Resource = texture.Resource;

            RenderTargetViewDescription rtd = new RenderTargetViewDescription()
            {
                Dimension = RenderTargetViewDimension.Texture3D,
                Format = texture.Format,
                MipSlice = mipindex,
                DepthSliceCount = d
            };

            UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription()
            {
                Dimension = UnorderedAccessViewDimension.Texture3D,
                Format = texture.Format,
                MipSlice = mipindex,
                FirstDepthSlice = 0,
                DepthSliceCount = d
            };

            ShaderResourceViewDescription srvd = new ShaderResourceViewDescription();
            srvd.Dimension = ShaderResourceViewDimension.Texture3D;
            srvd.MipLevels = 1;
            srvd.MostDetailedMip = mipindex;
            srvd.Format = texture.Format;
            srvd.ArraySize = d;
            srvd.FirstArraySlice = 0;

            this.RTV = new RenderTargetView(context.Device, texture.Resource, rtd);
            this.SRV = new ShaderResourceView(context.Device, texture.Resource, srvd);
            this.UAV = new UnorderedAccessView(context.Device, texture.Resource, uavd);

            this.Width = w;
            this.Height = h;
            this.Depth = d;
        }
예제 #37
0
 public void OnDeviceInit()
 {
     UnorderedAccessViewDescription desc = new UnorderedAccessViewDescription();
     desc.Format = m_format;
     desc.Dimension = UnorderedAccessViewDimension.Texture2DArray;
     desc.Texture2DArray.ArraySize = 1;
     desc.Texture2DArray.FirstArraySlice = m_slice;
     desc.Texture2DArray.MipSlice = m_mipmap;
     m_uav = new UnorderedAccessView(MyRender11.Device, m_owner.Resource, desc);
 }
예제 #38
0
 protected override void AfterBufferInit()
 {
     if (UavType == MyUavType.Default)
         m_uav = new UnorderedAccessView(MyRender11.Device, Resource);
     else
     {
         var description = new UnorderedAccessViewDescription()
         {
             Buffer = new UnorderedAccessViewDescription.BufferResource()
             {
                 ElementCount = ElementCount,
                 FirstElement = 0,
                 Flags =
                     UavType == MyUavType.Append
                         ? UnorderedAccessViewBufferFlags.Append
                         : UnorderedAccessViewBufferFlags.Counter
             },
             Format = SharpDX.DXGI.Format.Unknown,
             Dimension = UnorderedAccessViewDimension.Buffer
         };
         m_uav = new UnorderedAccessView(MyRender11.Device, Resource, description);
     }
     m_uav.DebugName = Name + "_Uav";
 }
예제 #39
0
        public DX11RWStructuredBuffer(Device dev, int elementcount,int stride, eDX11BufferMode mode)
        {
            this.Stride = stride;
            this.Size = elementcount * stride;
            this.ElementCount = elementcount;
            this.BufferType = mode;

            BufferDescription bd = new BufferDescription()
            {
                BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.StructuredBuffer,
                SizeInBytes = this.Size,
                StructureByteStride = this.Stride,
                Usage = ResourceUsage.Default,
            };
            this.Buffer = new Buffer(dev, bd);
            this.SRV = new ShaderResourceView(dev, this.Buffer);

            UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription()
            {
                ElementCount = this.ElementCount,
                Format = SlimDX.DXGI.Format.Unknown,
                Dimension = UnorderedAccessViewDimension.Buffer,
                Flags = (UnorderedAccessViewBufferFlags)mode
            };

            this.UAV = new UnorderedAccessView(dev, this.Buffer, uavd);
        }
예제 #40
0
 protected override void AfterBufferInit()
 {
     var description = new UnorderedAccessViewDescription()
     {
         Buffer = new UnorderedAccessViewDescription.BufferResource()
         {
             ElementCount = ElementCount,
             FirstElement = 0,
             Flags = 0
         },
         Format = Format,
         Dimension = UnorderedAccessViewDimension.Buffer
     };
     m_uav = new UnorderedAccessView(MyRender11.Device, Resource, description)
     {
         DebugName = Name + "_Uav"
     };
 }
예제 #41
0
        // has 6 rtv subresources and mipLevels * 6 srv/uav subresources
        internal static RwTexId CreateCubemap(int resolution, Format resourceFormat, string debugName = null)
        {
            int mipLevels = 1;
            while ((resolution >> mipLevels) > 0)
            {
                ++mipLevels;
            }

            var desc = new Texture2DDescription
            {
                ArraySize = 6,
                BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget | BindFlags.UnorderedAccess,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = resourceFormat,
                MipLevels = mipLevels,
                Usage = ResourceUsage.Default,
                Width = resolution,
                Height = resolution,
                OptionFlags = ResourceOptionFlags.TextureCube,
                SampleDescription = new SampleDescription(1, 0)
            };

            var handle = new RwTexId { Index = Textures.Allocate() };
            Textures.Data[handle.Index] = new MyRwTextureInfo { Description2D = desc };
            Textures.Data[handle.Index].Resource = new Texture2D(MyRender11.Device, desc);

            var res = Textures.Data[handle.Index].Resource;
            Srvs[handle] = new MySrvInfo { Description = null, View = new ShaderResourceView(MyRender11.Device, Textures.Data[handle.Index].Resource) };
            Index.Add(handle);

            var srvDesc = new ShaderResourceViewDescription();
            srvDesc.Dimension = ShaderResourceViewDimension.Texture2DArray;
            srvDesc.Format = resourceFormat;
            srvDesc.Texture2DArray.MipLevels = 1;
            srvDesc.Texture2DArray.ArraySize = 1;

            var uavDesc = new UnorderedAccessViewDescription();
            uavDesc.Dimension = UnorderedAccessViewDimension.Texture2DArray;
            uavDesc.Format = resourceFormat;
            uavDesc.Texture2DArray.ArraySize = 1;

            for (int m = 0; m < mipLevels; ++m)
            {
                for (int i = 0; i < 6; i++)
                {
                    var subresource = i * mipLevels + m;

                    srvDesc.Texture2DArray.FirstArraySlice = i;
                    srvDesc.Texture2DArray.MostDetailedMip = m;

                    SubresourceSrvs[new MySubresourceId { Id = handle, Subresource = subresource }] = new MySrvInfo
                    {
                        Description = srvDesc,
                        View = new ShaderResourceView(MyRender11.Device, res, srvDesc)
                    };

                    uavDesc.Texture2DArray.FirstArraySlice = i;
                    uavDesc.Texture2DArray.MipSlice = m;

                    SubresourceUavs[new MySubresourceId { Id = handle, Subresource = subresource }] = new MyUavInfo
                    {
                        Description = uavDesc,
                        View = new UnorderedAccessView(MyRender11.Device, res, uavDesc)
                    };
                }
            }

            var rtvDesc = new RenderTargetViewDescription();
            rtvDesc.Dimension = RenderTargetViewDimension.Texture2DArray;
            rtvDesc.Format = resourceFormat;
            for (int i = 0; i < 6; i++)
            {
                rtvDesc.Texture2DArray.MipSlice = 0;

                rtvDesc.Texture2DArray.FirstArraySlice = i;
                rtvDesc.Texture2DArray.ArraySize = 1;

                SubresourceRtvs[new MySubresourceId { Id = handle, Subresource = i }] = new MyRtvInfo
                {
                    Description = rtvDesc,
                    View = new RenderTargetView(MyRender11.Device, res, rtvDesc)
                };
            }
                

            return handle;
        }
예제 #42
0
        internal override UnorderedAccessView GetUnorderedAccessView(int arrayOrDepthSlice, int mipIndex)
        {
            if ((this.Description.BindFlags & BindFlags.UnorderedAccess) == 0)
                return null;

            int arrayCount = 1;
            // Use Full although we are binding to a single array/mimap slice, just to get the correct index
            var uavIndex = GetViewIndex(ViewType.Full, arrayOrDepthSlice, mipIndex);

            lock (this.unorderedAccessViews)
            {
                var uav = this.unorderedAccessViews[uavIndex];

                // Creates the unordered access view
                if (uav == null)
                {
                    var uavDescription = new UnorderedAccessViewDescription() {
                        Format = this.Description.Format,
                        Dimension = this.Description.ArraySize > 1 ? UnorderedAccessViewDimension.Texture1DArray : UnorderedAccessViewDimension.Texture1D
                    };

                    if (this.Description.ArraySize > 1)
                    {
                        uavDescription.Texture1DArray.ArraySize = arrayCount;
                        uavDescription.Texture1DArray.FirstArraySlice = arrayOrDepthSlice;
                        uavDescription.Texture1DArray.MipSlice = mipIndex;
                    }
                    else
                    {
                        uavDescription.Texture1D.MipSlice = mipIndex;
                    }

                    uav = new UnorderedAccessView(GraphicsDevice, Resource, uavDescription);
                    this.unorderedAccessViews[uavIndex] = ToDispose(uav);
                }

                // Associate this instance
                uav.Tag = this;

                return uav;
            }
        }
예제 #43
0
        /// <summary>
        /// Gets a specific <see cref="UnorderedAccessView" /> from this texture.
        /// </summary>
        /// <param name="viewType">The desired view type on the unordered resource</param>
        /// <param name="arrayOrDepthSlice">The texture array slice index.</param>
        /// <param name="mipIndex">Index of the mip.</param>
        /// <returns>An <see cref="UnorderedAccessView" /></returns>
        private UnorderedAccessView GetUnorderedAccessView(ViewType viewType, int arrayOrDepthSlice, int mipIndex)
        {
            if (!IsUnorderedAccess)
                return null;

            if (IsMultiSample)
                throw new NotSupportedException("Multisampling is not supported for unordered access views");

            int arrayCount;
            int mipCount;
            GetViewSliceBounds(viewType, ref arrayOrDepthSlice, ref mipIndex, out arrayCount, out mipCount);

            var uavDescription = new UnorderedAccessViewDescription
            {
                Format = (SharpDX.DXGI.Format)ViewFormat
            };

            if (ArraySize > 1)
            {
                switch (Dimension)
                {
                    case TextureDimension.Texture1D:
                        uavDescription.Dimension = UnorderedAccessViewDimension.Texture1DArray;
                        break;
                    case TextureDimension.TextureCube:
                    case TextureDimension.Texture2D:
                        uavDescription.Dimension = UnorderedAccessViewDimension.Texture2DArray;
                        break;
                    case TextureDimension.Texture3D:
                        throw new NotSupportedException("Texture 3D is not supported for Texture Arrays");
                }

                uavDescription.Texture1DArray.ArraySize = arrayCount;
                uavDescription.Texture1DArray.FirstArraySlice = arrayOrDepthSlice;
                uavDescription.Texture1DArray.MipSlice = mipIndex;
            }
            else
            {
                switch (Dimension)
                {
                    case TextureDimension.Texture1D:
                        uavDescription.Dimension = UnorderedAccessViewDimension.Texture1D;
                        uavDescription.Texture1D.MipSlice = mipIndex;
                        break;
                    case TextureDimension.Texture2D:
                        uavDescription.Dimension = UnorderedAccessViewDimension.Texture2D;
                        uavDescription.Texture2D.MipSlice = mipIndex;
                        break;
                    case TextureDimension.Texture3D:
                        uavDescription.Dimension = UnorderedAccessViewDimension.Texture3D;
                        uavDescription.Texture3D.FirstWSlice = arrayOrDepthSlice;
                        uavDescription.Texture3D.MipSlice = mipIndex;
                        uavDescription.Texture3D.WSize = arrayCount;
                        break;
                    case TextureDimension.TextureCube:
                        throw new NotSupportedException("TextureCube dimension is expecting an array size > 1");
                }
            }

            return new UnorderedAccessView(GraphicsDevice.NativeDevice, NativeResource, uavDescription);
        }
예제 #44
0
        internal MyUavView(MyBindableResource from, Format fmt)
        {
            m_owner = from;

            var desc = new UnorderedAccessViewDescription
            {
                Format = fmt,
                Dimension = UnorderedAccessViewDimension.Texture2D,
                Texture2D = new UnorderedAccessViewDescription.Texture2DResource { MipSlice = 0 }
            };

            m_uav = new UnorderedAccessView(MyRender11.Device, m_owner.m_resource, desc);
        }
        internal static UnorderedAccessView CreateUnorderedAccessView(Device device, SharpDX.Direct3D11.Buffer buffer)
        {
            UnorderedAccessViewDescription desc = new UnorderedAccessViewDescription
            {
                Dimension = UnorderedAccessViewDimension.Buffer,
                Format = SharpDX.DXGI.Format.Unknown,
                Buffer = { FirstElement = 0, ElementCount = buffer.Description.SizeInBytes / buffer.Description.StructureByteStride }
            };

            return new UnorderedAccessView(device, buffer, desc);
        }
예제 #46
0
        /// <summary>
        /// Initializes the views.
        /// </summary>
        private void InitializeViews()
        {
            var bindFlags = nativeDescription.BindFlags;

            var srvFormat = ViewFormat;
            var uavFormat = ViewFormat;

            if (((ViewFlags & BufferFlags.RawBuffer) != 0))
            {
                srvFormat = PixelFormat.R32_Typeless;
                uavFormat = PixelFormat.R32_Typeless;
            }

            if ((bindFlags & BindFlags.ShaderResource) != 0)
            {
                this.NativeShaderResourceView = GetShaderResourceView(srvFormat);
            }

            if ((bindFlags & BindFlags.UnorderedAccess) != 0)
            {
                var description = new UnorderedAccessViewDescription()
                {
                    Format = (SharpDX.DXGI.Format)uavFormat,
                    Dimension = UnorderedAccessViewDimension.Buffer,
                    Buffer =
                    {
                        ElementCount = this.ElementCount,
                        FirstElement = 0,
                        Flags = UnorderedAccessViewBufferFlags.None
                    },
                };

                if (((ViewFlags & BufferFlags.RawBuffer) == BufferFlags.RawBuffer))
                    description.Buffer.Flags |= UnorderedAccessViewBufferFlags.Raw;

                if (((ViewFlags & BufferFlags.StructuredAppendBuffer) == BufferFlags.StructuredAppendBuffer))
                    description.Buffer.Flags |= UnorderedAccessViewBufferFlags.Append;

                if (((ViewFlags & BufferFlags.StructuredCounterBuffer) == BufferFlags.StructuredCounterBuffer))
                    description.Buffer.Flags |= UnorderedAccessViewBufferFlags.Counter;

                this.NativeUnorderedAccessView = new UnorderedAccessView(this.GraphicsDevice.NativeDevice, NativeBuffer, description);
            }
        }
예제 #47
0
        // Static functions
        static public TextureObject CreateCubeTexture(Device device, int width, int height, int mips, Format format, bool isDepthStencil, bool needsGpuWrite)
        {
            if (isDepthStencil && format != Format.R32_Typeless && format != Format.R24G8_Typeless)
            {
                throw new Exception("Unsupported depth format");
            }

            TextureObject newTexture = new TextureObject();

            // Variables
            newTexture.m_Width = width;
            newTexture.m_Height = height;
            newTexture.m_TexFormat = format;
            newTexture.m_Mips = mips;
            newTexture.m_IsCube = true;
            newTexture.m_ArraySize = 6;

            BindFlags bindFlags = BindFlags.ShaderResource;
            if (isDepthStencil) bindFlags |= BindFlags.DepthStencil;
            if (needsGpuWrite && !isDepthStencil) bindFlags |= BindFlags.RenderTarget;
            if (needsGpuWrite && !isDepthStencil) bindFlags |= BindFlags.UnorderedAccess;

            Texture2DDescription textureDescription = new Texture2DDescription
            {
                ArraySize = 6,
                BindFlags = bindFlags,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = format,
                Height = height,
                Width = width,
                MipLevels = mips,
                OptionFlags = ResourceOptionFlags.TextureCube | ((mips > 1 && needsGpuWrite) ? ResourceOptionFlags.GenerateMipMaps : ResourceOptionFlags.None),
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default
            };

            newTexture.m_TextureObject2D = new Texture2D(device, textureDescription);

            Format srvFormat = format;

            // Special case for depth
            if (isDepthStencil)
            {
                srvFormat = (format == Format.R32_Typeless) ? Format.R32_Float : Format.R24_UNorm_X8_Typeless;
            }

            ShaderResourceViewDescription srvViewDesc = new ShaderResourceViewDescription
            {
                ArraySize = 6,
                Format = srvFormat,
                Dimension = ShaderResourceViewDimension.Texture2DArray,
                Flags = 0,
                FirstArraySlice = 0,
                MostDetailedMip = 0,
                MipLevels = mips
            };

            newTexture.m_ShaderResourceView = new ShaderResourceView(device, newTexture.m_TextureObject2D, srvViewDesc);

            newTexture.m_ArrayShaderResourceViews = new ShaderResourceView[6]; 
            for (int i = 0; i < 6; ++ i )
            {
                srvViewDesc.ArraySize = 1;
                srvViewDesc.FirstArraySlice = i;
                newTexture.m_ArrayShaderResourceViews[i] = new ShaderResourceView(device, newTexture.m_TextureObject2D, srvViewDesc);
            }

            if (isDepthStencil)
            {
                DepthStencilViewDescription dsViewDesc = new DepthStencilViewDescription
                {
                    ArraySize = 6,
                    Format = (format == Format.R32_Typeless) ? Format.D32_Float : Format.D24_UNorm_S8_UInt,
                    Dimension = DepthStencilViewDimension.Texture2DArray,
                    MipSlice = 0,
                    Flags = 0,
                    FirstArraySlice = 0
                };

                newTexture.m_DepthStencilView = new DepthStencilView(device, newTexture.m_TextureObject2D, dsViewDesc);

                newTexture.m_ArrayDepthStencilViews = new DepthStencilView[6];
                for (int i = 0; i < 6; ++i)
                {
                    dsViewDesc.ArraySize = 1;
                    dsViewDesc.FirstArraySlice = i;
                    newTexture.m_ArrayDepthStencilViews[i] = new DepthStencilView(device, newTexture.m_TextureObject2D, dsViewDesc);
                }
            }

            // No RTV for depth stencil, sorry
            if (needsGpuWrite && !isDepthStencil)
            {
                newTexture.m_RenderTargetView = new RenderTargetView(device, newTexture.m_TextureObject2D);

                RenderTargetViewDescription rtvDesc = new RenderTargetViewDescription
                {
                    ArraySize = 6,
                    Dimension = RenderTargetViewDimension.Texture2DArray,
                    FirstArraySlice = 0,
                    Format = format,
                };

                newTexture.m_ArrayRenderTargetViews = new RenderTargetView[6];
                for (int i = 0; i < 6; ++i)
                {
                    rtvDesc.ArraySize = 1;
                    rtvDesc.FirstArraySlice = i;
                    newTexture.m_ArrayRenderTargetViews[i] = new RenderTargetView(device, newTexture.m_TextureObject2D, rtvDesc);
                }

                UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription
                {
                    ArraySize = 6,
                    Dimension = UnorderedAccessViewDimension.Texture2DArray,
                    FirstArraySlice = 0,
                    Format = format,
                };
                newTexture.m_UnorderedAccessView = new UnorderedAccessView(device, newTexture.m_TextureObject2D, uavDesc);

                newTexture.m_ArrayUnorderedAccessViews = new UnorderedAccessView[6];
                for (int i = 0; i < 6; ++i)
                {
                    uavDesc.ArraySize = 1;
                    uavDesc.FirstArraySlice = i;
                    newTexture.m_ArrayUnorderedAccessViews[i] = new UnorderedAccessView(device, newTexture.m_TextureObject2D, uavDesc);
                }
            }

            return newTexture;
        }
예제 #48
0
        public DX11IndexBuffer(DX11RenderContext context, int elementcount, bool uav = false)
        {
            this.context = context;
            this.IndicesCount = elementcount;
            format =SlimDX.DXGI.Format.R32_UInt;

            BufferDescription bd = new BufferDescription()
            {
                BindFlags = BindFlags.IndexBuffer | BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags =ResourceOptionFlags.None,
                SizeInBytes = elementcount * sizeof(int),
                Usage = ResourceUsage.Default,
            };

            if (uav && context.IsFeatureLevel11)
            {
                bd.BindFlags |= BindFlags.UnorderedAccess;
                bd.OptionFlags |= ResourceOptionFlags.RawBuffer;
            }

            this.Buffer = new SlimDX.Direct3D11.Buffer(context.Device, bd);

            if (uav)
            {
                UnorderedAccessViewDescription uavd = new UnorderedAccessViewDescription()
                {
                    Format = SlimDX.DXGI.Format.R32_Typeless,
                    Dimension = UnorderedAccessViewDimension.Buffer,
                    Flags = UnorderedAccessViewBufferFlags.RawData,
                    ElementCount = elementcount
                };

                this.uav = new UnorderedAccessView(context.Device, this.Buffer, uavd);
            }

            this.CreateSRV();
        }
예제 #49
0
        internal MyIndirectArgsBuffer(int elements, int stride, string debugName)
        {
            m_resolution = new Vector2I(elements, 1);

            var bufferDesc = new BufferDescription(elements * stride, ResourceUsage.Default, BindFlags.UnorderedAccess,
                CpuAccessFlags.None, ResourceOptionFlags.DrawIndirectArguments, stride);

            m_resource = new SharpDX.Direct3D11.Buffer(MyRender11.Device, bufferDesc);
            m_resource.DebugName = debugName;

            var description = new UnorderedAccessViewDescription()
            {
                Buffer = new UnorderedAccessViewDescription.BufferResource()
                {
                    ElementCount = elements,
                    FirstElement = 0,
                    Flags = 0
                },
                Format = Format.R32_UInt,
                Dimension = UnorderedAccessViewDimension.Buffer
            };
            m_uav = new UnorderedAccessView(MyRender11.Device, m_resource, description);
            m_uav.DebugName = debugName + "Uav";
        }
예제 #50
0
        internal MyRWStructuredBuffer(int elements, int stride, UavType uav, bool srv, string debugName)
        {
            m_resolution = new Vector2I(elements, 1);

            var bufferDesc = new BufferDescription(elements * stride, ResourceUsage.Default, BindFlags.ShaderResource | BindFlags.UnorderedAccess, 
                CpuAccessFlags.None, ResourceOptionFlags.BufferStructured, stride);

            m_resource = new SharpDX.Direct3D11.Buffer(MyRender11.Device, bufferDesc);
            m_resource.DebugName = debugName;
            if (uav != UavType.None)
            {
                if (uav == UavType.Default)
                    m_uav = new UnorderedAccessView(MyRender11.Device, m_resource);
                else
                {
                    var description = new UnorderedAccessViewDescription()
                    {
                        Buffer = new UnorderedAccessViewDescription.BufferResource()
                        {
                            ElementCount = elements,
                            FirstElement = 0,
                            Flags = uav == UavType.Append ? UnorderedAccessViewBufferFlags.Append : UnorderedAccessViewBufferFlags.Counter
                        },
                        Format = Format.Unknown,
                        Dimension = UnorderedAccessViewDimension.Buffer
                    };
                    m_uav = new UnorderedAccessView(MyRender11.Device, m_resource, description);
                }
                m_uav.DebugName = debugName + "Uav";
            }
            if (srv)
            {
                m_srv = new ShaderResourceView(MyRender11.Device, m_resource);
                m_srv.DebugName = debugName + "Srv";
            }
        }
예제 #51
0
        // Static functions
        static public TextureObject CreateTexture(Device device, int width, int height, int mips, Format format, bool isDepthStencil, bool needsGpuWrite)
        {
            if (isDepthStencil && format != Format.R32_Typeless && format != Format.R24G8_Typeless)
            {
                throw new Exception("Unsupported depth format");
            }

            TextureObject newTexture = new TextureObject();

            // Variables
            newTexture.m_Width = width;
            newTexture.m_Height = height;
            newTexture.m_TexFormat = format;
            newTexture.m_Mips = mips;

            BindFlags bindFlags = BindFlags.ShaderResource;
            if (isDepthStencil) bindFlags |= BindFlags.DepthStencil;
            if (needsGpuWrite && !isDepthStencil) bindFlags |= BindFlags.RenderTarget;
            if (needsGpuWrite && !isDepthStencil) bindFlags |= BindFlags.UnorderedAccess;

            Texture2DDescription textureDescription = new Texture2DDescription
            {
                ArraySize = 1,
                BindFlags = bindFlags,
                CpuAccessFlags = CpuAccessFlags.None,
                Format = format,
                Height = height,
                Width = width,
                MipLevels = mips,
                OptionFlags = (mips > 1 && needsGpuWrite) ? ResourceOptionFlags.GenerateMipMaps : ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default
            };

            newTexture.m_TextureObject2D = new Texture2D(device, textureDescription);

            Format srvFormat = format;

            // Special case for depth
            if (isDepthStencil)
            {
                srvFormat = (format == Format.R32_Typeless) ? Format.R32_Float : Format.R24_UNorm_X8_Typeless;
            }

            ShaderResourceViewDescription srvViewDesc = new ShaderResourceViewDescription
            {
                ArraySize = 0,
                Format = srvFormat,
                Dimension = ShaderResourceViewDimension.Texture2D,
                Flags = 0,
                FirstArraySlice = 0,
                MostDetailedMip = 0,
                MipLevels = mips
            };

            newTexture.m_ShaderResourceView = new ShaderResourceView(device, newTexture.m_TextureObject2D, srvViewDesc);

            if (isDepthStencil)
            {
                DepthStencilViewDescription dsViewDesc = new DepthStencilViewDescription
                {
                    ArraySize = 0,
                    Format = (format == Format.R32_Typeless) ? Format.D32_Float : Format.D24_UNorm_S8_UInt,
                    Dimension = DepthStencilViewDimension.Texture2D,
                    MipSlice = 0,
                    Flags = 0,
                    FirstArraySlice = 0
                };

                newTexture.m_DepthStencilView = new DepthStencilView(device, newTexture.m_TextureObject2D, dsViewDesc);
            }

            // No RTV for depth stencil, sorry
            if (needsGpuWrite && !isDepthStencil)
            {
                newTexture.m_RenderTargetView = new RenderTargetView(device, newTexture.m_TextureObject2D);

                UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription
                {
                    ArraySize = 0,
                    DepthSliceCount = 1,
                    Dimension = UnorderedAccessViewDimension.Texture2D,
                    ElementCount = 1,
                    FirstArraySlice = 0,
                    FirstDepthSlice = 0,
                    FirstElement = 0,
                    Flags = UnorderedAccessViewBufferFlags.None,
                    Format = format,
                    MipSlice = 0
                };
                newTexture.m_UnorderedAccessView = new UnorderedAccessView(device, newTexture.m_TextureObject2D, uavDesc);
            }

            return newTexture;
        }
예제 #52
0
        internal override UnorderedAccessView GetUnorderedAccessView(int zSlice, int mipIndex)
        {
            if ((this.Description.BindFlags & BindFlags.UnorderedAccess) == 0)
                return null;

            int sliceCount = 1;

            // Use Full although we are binding to a single array/mimap slice, just to get the correct index
            var uavIndex = GetViewIndex(ViewType.Full, zSlice, mipIndex);

            lock (this.unorderedAccessViews)
            {
                var uav = this.unorderedAccessViews[uavIndex];

                // Creates the unordered access view
                if (uav == null)
                {
                    var uavDescription = new UnorderedAccessViewDescription() {
                        Format = this.Description.Format,
                        Dimension = UnorderedAccessViewDimension.Texture3D,
                        Texture3D = {
                            FirstWSlice = zSlice,
                            MipSlice = mipIndex,
                            WSize = sliceCount
                        }
                    };

                    uav = new UnorderedAccessView(GraphicsDevice, Resource, uavDescription) { Tag = this };
                    this.unorderedAccessViews[uavIndex] = ToDispose(uav);
                }

                return uav;
            }
        }
예제 #53
0
 /// <summary>
 ///   Creates a <see cref = "T:SharpDX.Direct3D11.UnorderedAccessView" /> for accessing resource data.
 /// </summary>
 /// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D11.UnorderedAccessView" />.</param>
 /// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D11.BindFlags">UnorderedAccess</see> flag.</param>
 /// <param name = "description">A structure describing the <see cref = "T:SharpDX.Direct3D11.UnorderedAccessView" /> to be created.</param>
 /// <unmanaged>ID3D11Device::CreateUnorderedAccessView</unmanaged>
 public UnorderedAccessView(Device device, Resource resource, UnorderedAccessViewDescription description)
     : base(IntPtr.Zero)
 {
     device.CreateUnorderedAccessView(resource, description, this);
 }
예제 #54
0
 public void OnDeviceInit()
 {
     UnorderedAccessViewDescription desc = new UnorderedAccessViewDescription
     {
         Format = m_format,
         Dimension = UnorderedAccessViewDimension.Texture2DArray,
         Texture2DArray =
         {
             ArraySize = 1,
             FirstArraySlice = m_slice,
             MipSlice = m_mipmap
         }
     };
     m_uav = new UnorderedAccessView(MyRender11.Device, m_owner.Resource, desc);
 }