/// <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 );
		}
Example #2
0
        /// <summary>
        /// Gets an array of views for an unordered resource.
        /// </summary>
        /// <remarks>
        /// Any returned interfaces will have their reference count incremented by one. Applications should call IUnknown::Release on the returned interfaces when they are no longer needed to avoid memory leaks.
        /// </remarks>
        /// <param name="startSlot">Index of the first element in the zero-based array to return (ranges from 0 to D3D11_PS_CS_UAV_REGISTER_COUNT - 1). </param>
        /// <param name="count">Number of views to get (ranges from 0 to D3D11_PS_CS_UAV_REGISTER_COUNT - StartSlot). </param>
        /// <unmanaged>void CSGetUnorderedAccessViews([In] int StartSlot,[In] int NumUAVs,[Out, Buffer] ID3D11UnorderedAccessView** ppUnorderedAccessViews)</unmanaged>
        public UnorderedAccessView[] GetUnorderedAccessViews(int startSlot, int count)
        {
            var temp = new UnorderedAccessView[count];

            GetUnorderedAccessViews(startSlot, count, temp);
            return(temp);
        }
 /// <summary>
 /// Bind all the sub resources to view
 /// </summary>
 /// <param name="view"></param>
 public void SetViewsToResources(UnorderedAccessView view)
 {
     // bind all the sub-resources with the same view
     foreach (var resource in ListWithResourceVariables)
     {
         resource.resource.SetResource(view);
     }
 }
Example #4
0
        /// <summary>
        /// Creates a ConvolutionEngine instance.
        /// </summary>
        /// <param name="device">The graphics device to use.</param>
        /// <param name="context">The graphics context to use.</param>
        /// <param name="resolution">The convolution resolution.</param>
        public ConvolutionEngine(Device device, DeviceContext context, Size resolution)
        {
            fft = FastFourierTransform.Create2DComplex(context, resolution.Width, resolution.Height);
            fft.InverseScale = 1.0f / (float)(resolution.Width * resolution.Height);
            this.resolution = resolution;

            FastFourierTransformBufferRequirements bufferReqs = fft.BufferRequirements;
            precomputed = new FFTBuffer[bufferReqs.PrecomputeBufferCount];
            temporaries = new FFTBuffer[bufferReqs.TemporaryBufferCount];

            for (int t = 0; t < precomputed.Length; ++t)
                precomputed[t] = FFTUtils.AllocateBuffer(device, bufferReqs.PrecomputeBufferSizes[t]);

            for (int t = 0; t < temporaries.Length; ++t)
                temporaries[t] = FFTUtils.AllocateBuffer(device, bufferReqs.TemporaryBufferSizes[t]);

            UnorderedAccessView[] precomputedUAV = new UnorderedAccessView[bufferReqs.PrecomputeBufferCount];
            for (int t = 0; t < precomputed.Length; ++t) precomputedUAV[t] = precomputed[t].view;

            UnorderedAccessView[] temporariesUAV = new UnorderedAccessView[bufferReqs.TemporaryBufferCount];
            for (int t = 0; t < temporaries.Length; ++t) temporariesUAV[t] = temporaries[t].view;

            fft.AttachBuffersAndPrecompute(temporariesUAV, precomputedUAV);

            lBuf = FFTUtils.AllocateBuffer(device, 2 * resolution.Width * resolution.Height);
            rBuf = FFTUtils.AllocateBuffer(device, 2 * resolution.Width * resolution.Height);
            tBuf = FFTUtils.AllocateBuffer(device, 2 * resolution.Width * resolution.Height);

            rConvolved = new GraphicsResource(device, resolution, Format.R32_Float, true, true);
            gConvolved = new GraphicsResource(device, resolution, Format.R32_Float, true, true);
            bConvolved = new GraphicsResource(device, resolution, Format.R32_Float, true, true);
            staging    = new GraphicsResource(device, new Size(resolution.Width / 2, resolution.Height / 2), Format.R32G32B32A32_Float, true, true);

            BlendStateDescription description = new BlendStateDescription()
            {
                AlphaToCoverageEnable = false,
                IndependentBlendEnable = false,
            };

            description.RenderTarget[0] = new RenderTargetBlendDescription()
            {
                IsBlendEnabled = true,

                SourceBlend = BlendOption.One,
                DestinationBlend = BlendOption.One,
                BlendOperation = BlendOperation.Add,

                SourceAlphaBlend = BlendOption.Zero,
                DestinationAlphaBlend = BlendOption.Zero,
                AlphaBlendOperation = BlendOperation.Add,

                RenderTargetWriteMask = ColorWriteMaskFlags.Red
                                      | ColorWriteMaskFlags.Green
                                      | ColorWriteMaskFlags.Blue,
            };

            blendState = new BlendState(device, description);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonReadWriteViewBindings"/> class.
        /// </summary>
        public GorgonReadWriteViewBindings()
            : base(MaximumReadWriteViewCount)
        {
            Native = new D3D11.UnorderedAccessView[MaximumReadWriteViewCount];
            Counts = new int[MaximumReadWriteViewCount];

            // Force us to clear to the empty views instead of the default for the type.
            Clear();
        }
 public WaveSolutionSwapChain(D3D11.ShaderResourceView currentSolutionSRV, D3D11.UnorderedAccessView currentSolutionUAV, D3D11.Buffer currentBuffer, D3D11.ShaderResourceView pastSolutionSRV, D3D11.UnorderedAccessView pastSolutionUAV, D3D11.Buffer pastBuffer)
 {
     this.currentSolutionSRV = currentSolutionSRV;
     this.pastSolutionSRV    = pastSolutionSRV;
     this.currentSolutionUAV = currentSolutionUAV;
     this.pastSolutionUAV    = pastSolutionUAV;
     this.currentBuffer      = currentBuffer;
     this.pastBuffer         = pastBuffer;
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="device">Direct3D11 Device</param>
        public AppendPointCloudBuffer(Device device)
        {
            if (device == null)
                throw new ArgumentNullException("device");

            this.buffer = new SharpDX.Direct3D11.Buffer(device, PointCloudDescriptors.PositionBuffer);
            this.shaderView = new ShaderResourceView(device, this.buffer);
            this.unorderedView = new UnorderedAccessView(device, this.buffer, PointCloudDescriptors.AppendView);
        }
Example #8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="rtv"></param>
 internal RenderTargetSurface( RenderTargetView rtv, UnorderedAccessView uav, Resource resource, int subresource, ColorFormat format, int width, int height, int sampleCount )
 {
     Width			=	width;
     Height			=	height;
     Format			=	format;
     SampleCount		=	sampleCount;
     RTV				=	rtv;
     UAV				=	uav;
     Resource		=	resource;
     Subresource		=	subresource;
 }
            /// <summary>
            /// Function to reset the state of the unordered access views.
            /// </summary>
            internal void Reset()
            {
                var views = new D3D.UnorderedAccessView[_unorderedViews.Length];

                for (int i = 0; i < _unorderedViews.Length; i++)
                {
                    views[i]           = null;
                    _unorderedViews[i] = null;
                }

                _shader.Graphics.Context.ComputeShader.SetUnorderedAccessViews(0, views);
            }
Example #10
0
 /// <summary>
 ///     スキニングを実行する。
 /// </summary>
 /// <param name="d3ddc">
 ///     実行対象のDeviceContext。
 /// </param>
 /// <param name="入力頂点数">
 ///     モデルの全頂点数。
 /// </param>
 /// <param name="ボーンのモデルポーズ行列定数バッファ">
 ///     ボーンのモデルポーズ行列の配列を格納された定数バッファ。
 ///     構造については <see cref="PMXモデル.D3DBoneTrans"/> 参照。
 /// </param>
 /// <param name="ボーンのローカル位置定数バッファ">
 ///     ボーンのローカル位置の配列が格納された定数バッファ。
 ///     構造については <see cref="PMXモデル.D3DBoneLocalPosition"/> 参照。
 /// </param>
 /// <param name="ボーンの回転行列定数バッファ">
 ///     ボーンの回転行列の配列が格納された定数バッファ。
 ///     構造については <see cref="PMXモデル.D3DBoneLocalPosition"/> 参照。
 /// </param>
 /// <param name="変形前頂点データSRV">
 ///     スキニングの入力となる頂点データリソースのSRV。
 ///     構造については <see cref="CS_INPUT"/> 参照。
 /// </param>
 /// <param name="変形後頂点データUAV">
 ///     スキニングの出力を書き込む頂点データリソースのUAV。
 ///     構造については <see cref="VS_INPUT"/> 参照。
 /// </param>
 /// <remarks>
 ///     このメソッドの呼び出し時には、<paramref name="d3ddc"/> には事前に以下のように設定される。
 ///     ComputeShader
 ///         - slot( b1 ) …… <paramref name="ボーンのモデルポーズ行列定数バッファ"/>
 ///         - slot( b2 ) …… <paramref name="ボーンのローカル位置定数バッファ"/>
 ///         - slot( b3 ) …… <paramref name="ボーンの回転行列定数バッファ"/>
 ///         - slot( t0 ) …… <paramref name="変形前頂点データSRV"/>
 ///         - slot( u0 ) …… <paramref name="変形後頂点データUAV"/>
 /// </remarks>
 public void Run(
     SharpDX.Direct3D11.DeviceContext d3ddc,
     int 入力頂点数,
     SharpDX.Direct3D11.Buffer ボーンのモデルポーズ行列定数バッファ,
     SharpDX.Direct3D11.Buffer ボーンのローカル位置定数バッファ,
     SharpDX.Direct3D11.Buffer ボーンの回転行列定数バッファ,
     SharpDX.Direct3D11.ShaderResourceView 形前頂点データSRV,
     SharpDX.Direct3D11.UnorderedAccessView 形後頂点データUAV)
 {
     d3ddc.ComputeShader.Set(this.ComputeShader);
     d3ddc.Dispatch((入力頂点数 / 64) + 1, 1, 1);     // 既定のシェーダー(DefaultSkinningComputeShader.hlsl)に合わせてある
 }
Example #11
0
        internal override void Release()
        {
            if (m_srv != null)
            {
                m_srv.Dispose();
                m_srv = null;
            }
            if (m_uav != null)
            {
                m_uav.Dispose();
                m_uav = null;
            }

            base.Release();
        }
Example #12
0
        /// <summary>
        /// Function to clean up the resources used by the view.
        /// </summary>
        protected override void OnCleanUp()
        {
            if (D3DView == null)
            {
                return;
            }

            Resource.Graphics.Shaders.Unbind(this);     // Unbind this from the compute shaders.
            Resource.Graphics.Output.Unbind(this);      // Unbind pixel shaders/render targets.

            Gorgon.Log.Print("Destroying unordered access resource view for {0}.",
                             LoggingLevel.Verbose,
                             Resource.Name);
            D3DView.Dispose();
            D3DView = null;
        }
            /// <summary>
            /// Function to set a range of unordered access views all at once.
            /// </summary>
            /// <param name="slot">Starting slot for the buffer.</param>
            /// <param name="views">Buffers to set.</param>
            /// <remarks>This will bind unordered access views at the same time.  An unordered access view or its resource must not already be bound to the shader at another index, or an exception will be thrown.
            /// <para>Passing NULL (Nothing in VB.Net) to the <paramref name="views"/> parameter will set the bindings to empty (starting at <paramref name="slot"/>).</para>
            /// </remarks>
            /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="slot"/> is less than 0, or greater than the available number of resource view slots.</exception>
            /// <exception cref="GorgonLibrary.GorgonException">Thrown when one of the views in the <paramref name="views"/> parameter is already bound to another slot or has a resource bound to another slot.</exception>
            public void SetRange(int slot, GorgonUnorderedAccessView[] views)
            {
                int count = _unorderedViews.Length - slot;

                GorgonDebug.AssertParamRange(slot, 0, _unorderedViews.Length, "slot");

                if (views != null)
                {
                    count = views.Length.Min(_unorderedViews.Length);
                }

                var D3DViews      = new D3D.UnorderedAccessView[count];
                var initialCounts = new int[count];

                for (int i = 0; i < count; i++)
                {
                    GorgonUnorderedAccessView buffer = null;
                    var bufferIndex = i + slot;

                    if (views != null)
                    {
                        buffer = views[i];
                    }

#if DEBUG
                    ValidateBinding(buffer);
#endif

                    _unorderedViews[bufferIndex] = buffer;
                    D3DViews[i]      = buffer != null ? buffer.D3DView : null;
                    initialCounts[i] = -1;

                    if (buffer == null)
                    {
                        continue;
                    }

                    var structView = buffer as GorgonStructuredBufferUnorderedAccessView;

                    if (structView != null)
                    {
                        initialCounts[i] = structView.InitialCount;
                    }
                }

                _shader.Graphics.Context.ComputeShader.SetUnorderedAccessViews(slot, D3DViews, initialCounts);
            }
        }                                                                   //used to manipulate and introduce disturbances to water by code
        public void Swap()
        {
            var tempSRV = currentSolutionSRV;

            currentSolutionSRV = pastSolutionSRV;
            pastSolutionSRV    = tempSRV;

            var tempUAV = currentSolutionUAV;

            currentSolutionUAV = pastSolutionUAV;
            pastSolutionUAV    = tempUAV;

            var tempBuffer = currentBuffer;

            currentBuffer = pastBuffer;
            pastBuffer    = tempBuffer;
        }
        /// <summary>
        /// Function to perform initialization of the shader view resource.
        /// </summary>
        protected override void OnInitialize()
        {
            Gorgon.Log.Print("Creating buffer unordered access view for {0}.", LoggingLevel.Verbose, Resource.Name);
            var desc = new D3D.UnorderedAccessViewDescription
            {
                Dimension = D3D.UnorderedAccessViewDimension.Buffer,
                Buffer    =
                {
                    FirstElement = ElementStart,
                    ElementCount = ElementCount,
                    Flags        = IsRaw ? D3D.UnorderedAccessViewBufferFlags.Raw : D3D.UnorderedAccessViewBufferFlags.None
                },
                Format = (Format)Format
            };

            D3DView = new D3D.UnorderedAccessView(Resource.Graphics.D3DDevice, Resource.D3DResource, desc)
            {
                DebugName = "Gorgon Unordered Access View for " + Resource.Name
            };
        }
Example #16
0
        private void BuildBuffers()
        {
            D3D11.BufferDescription buf_desc = new D3D11.BufferDescription();
            buf_desc.BindFlags           = D3D11.BindFlags.ShaderResource | D3D11.BindFlags.UnorderedAccess;
            buf_desc.Usage               = D3D11.ResourceUsage.Default;
            buf_desc.StructureByteStride = WaveSolution.Stride;
            buf_desc.SizeInBytes         = WaveSolution.Stride * VertexCount;
            buf_desc.OptionFlags         = D3D11.ResourceOptionFlags.BufferStructured;
            buf_desc.CpuAccessFlags      = D3D11.CpuAccessFlags.Write | D3D11.CpuAccessFlags.Read;

            _inputBuf1 = new D3D11.Buffer(Device, buf_desc);
            _inputBuf2 = new D3D11.Buffer(Device, buf_desc);

            D3D11.ShaderResourceViewDescription vdesc = new D3D11.ShaderResourceViewDescription();
            vdesc.Dimension           = D3D.ShaderResourceViewDimension.Buffer;
            vdesc.Format              = DXGI.Format.Unknown;
            vdesc.Buffer.FirstElement = 0;
            vdesc.Buffer.ElementCount = VertexCount;


            _inputBuf1View = new D3D11.ShaderResourceView(Device, _inputBuf1, vdesc);
            _inputBuf2View = new D3D11.ShaderResourceView(Device, _inputBuf2, vdesc);



            D3D11.UnorderedAccessViewDescription uavdesc = new D3D11.UnorderedAccessViewDescription();
            uavdesc.Format              = DXGI.Format.Unknown;
            uavdesc.Dimension           = D3D11.UnorderedAccessViewDimension.Buffer;
            uavdesc.Buffer.FirstElement = 0;
            uavdesc.Buffer.ElementCount = VertexCount;

            _inputBuf1UAV = new D3D11.UnorderedAccessView(Device, _inputBuf1, uavdesc);
            _inputBuf2UAV = new D3D11.UnorderedAccessView(Device, _inputBuf2, uavdesc);


            return;
        }
 /// <summary>	
 /// Gets an array of views for an unordered resource.	
 /// </summary>	
 /// <remarks>	
 /// Any returned interfaces will have their reference count incremented by one. Applications should call IUnknown::Release on the returned interfaces when they are no longer needed to avoid memory leaks. 	
 /// </remarks>	
 /// <param name="startSlot">Index of the first element in the zero-based array to return (ranges from 0 to D3D11_PS_CS_UAV_REGISTER_COUNT - 1). </param>
 /// <param name="count">Number of views to get (ranges from 0 to D3D11_PS_CS_UAV_REGISTER_COUNT - StartSlot). </param>
 /// <unmanaged>void OMGetRenderTargetsAndUnorderedAccessViews([In] int NumRTVs,[Out, Buffer, Optional] ID3D11RenderTargetView** ppRenderTargetViews,[Out, Optional] ID3D11DepthStencilView** ppDepthStencilView,[In] int UAVStartSlot,[In] int NumUAVs,[Out, Buffer, Optional] ID3D11UnorderedAccessView** ppUnorderedAccessViews)</unmanaged>
 public UnorderedAccessView[] GetUnorderedAccessViews(int startSlot, int count)
 {
     var temp = new UnorderedAccessView[count];
     DepthStencilView depthStencilView;
     GetRenderTargetsAndUnorderedAccessViews(0, new RenderTargetView[0], out depthStencilView, startSlot, count, temp);
     depthStencilView.Dispose();
     return temp;
 }
Example #18
0
 internal void SetRawUav(int slot, UnorderedAccessView uav, int uavInitialCount)
 {
     if (uav == m_uavs[slot] && uavInitialCount == m_uavsInitialCount[slot])
         return;
     m_uavs[slot] = uav;
     m_uavsInitialCount[slot] = uavInitialCount; 
     m_deviceContext.ComputeShader.SetUnorderedAccessView(slot, uav, uavInitialCount);
     m_statistics.SetUavs++;
 }
Example #19
0
 internal void SetRawUav(int slot, UnorderedAccessView uav)
 {
     if (uav == m_uavs[slot])
         return;
     m_uavs[slot] = uav; 
     m_deviceContext.ComputeShader.SetUnorderedAccessView(slot, uav);
     m_statistics.SetUavs++;
 }
 /// <summary>	
 /// Attaches buffers to an FFT context and performs any required precomputations.	
 /// </summary>	
 /// <remarks>	
 /// The buffers must be no smaller than the corresponding buffer sizes returned by D3DX11CreateFFT*(). Temporary buffers can be shared between multiple contexts, though care should be taken not  to concurrently execute multiple FFTs which share temp buffers. 	
 /// </remarks>	
 /// <param name="temporaryBuffers">Temporary buffers to attach. </param>
 /// <param name="precomputeBuffers">Buffers to hold precomputed data. </param>
 /// <returns>Returns one of the return codes described in the topic {{Direct3D 11 Return Codes}}. </returns>
 /// <unmanaged>HRESULT ID3DX11FFT::AttachBuffersAndPrecompute([In] int NumTempBuffers,[In, Buffer] const ID3D11UnorderedAccessView** ppTempBuffers,[In] int NumPrecomputeBuffers,[In, Buffer] const ID3D11UnorderedAccessView** ppPrecomputeBufferSizes)</unmanaged>
 public void AttachBuffersAndPrecompute(UnorderedAccessView[] temporaryBuffers, UnorderedAccessView[] precomputeBuffers)
 {
     AttachBuffersAndPrecompute(temporaryBuffers.Length, temporaryBuffers, precomputeBuffers.Length, precomputeBuffers);
 }
Example #21
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";
            }
        }
 /// <summary>
 /// Копирует данные из неуправляемого ресурса ( Используемого в Компюте шейдере) в управляемый ресурс обычного шейдера.
 /// </summary>
 /// <param name="device">Устройстов используемое для отрисовки 3д</param>
 /// <param name="srv">ShaderResourceView с данными тестуры в который будем копировать данные UnorderedAccessView.</param>
 /// <param name="uav">UnorderedAccessView из которого будем брать данные</param>
 public static void CopyUAVToSRV(SharpDX.Direct3D11.Device device, ref SharpDX.Direct3D11.ShaderResourceView srv, SharpDX.Direct3D11.UnorderedAccessView uav)
 {
     using (var t = srv.ResourceAs <Texture2D>())
     {
         using (var t2 = uav.ResourceAs <SharpDX.Direct3D11.Texture2D>())
         {
             // Copy the texture for the resource to the typeless texture
             device.ImmediateContext.CopyResource(t2, t);
         }
     }
 }
Example #23
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;
            }
        }
        internal override void Release()
        {
            if (m_SRV != null)
            {
                m_SRV.Dispose();
                m_SRV = null;
            }
            if (m_UAV != null)
            {
                m_UAV.Dispose();
                m_UAV = null;
            }

            base.Release();
        }
        internal MyUnorderedAccessTexture(int width, int height, Format format)
        {
            m_resolution = new Vector2I(width, height);

            Texture2DDescription desc = new Texture2DDescription();
            desc.Width = width;
            desc.Height = height;
            desc.Format = format;
            desc.ArraySize = 1;
            desc.MipLevels = 1;
            desc.BindFlags = BindFlags.UnorderedAccess | BindFlags.ShaderResource | BindFlags.RenderTarget;
            desc.Usage = ResourceUsage.Default;
            desc.CpuAccessFlags = 0;
            desc.SampleDescription.Count = 1;
            desc.SampleDescription.Quality = 0;
            desc.OptionFlags = 0;

            m_resource = new Texture2D(MyRender11.Device, desc);
            m_UAV = new UnorderedAccessView(MyRender11.Device, m_resource);
            m_SRV = new ShaderResourceView(MyRender11.Device, m_resource);
            m_RTV = new RenderTargetView(MyRender11.Device, m_resource);
        }
 /// <summary>
 ///   Binds a depth-stencil buffer, a set of unordered access views, and a single render target to the output-merger stage.
 /// </summary>
 /// <param name = "depthStencilView">A view of the depth-stencil buffer to bind.</param>
 /// <param name = "startSlot">Index into a zero-based array to begin setting unordered access views.</param>
 /// <param name = "unorderedAccessViews">A set of unordered access views to bind.</param>
 /// <param name = "renderTargetView">A view of the render target to bind.</param>
 /// <param name = "initialLengths">An array of Append/Consume buffer offsets. A value of -1 indicates the current offset should be kept. Any other values set the hidden counter for that Appendable/Consumable UAV.</param>
 /// <msdn-id>ff476465</msdn-id>	
 /// <unmanaged>void ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews([In] unsigned int NumRTVs,[In, Buffer, Optional] const ID3D11RenderTargetView** ppRenderTargetViews,[In, Optional] ID3D11DepthStencilView* pDepthStencilView,[In] unsigned int UAVStartSlot,[In] unsigned int NumUAVs,[In, Buffer, Optional] const ID3D11UnorderedAccessView** ppUnorderedAccessViews,[In, Buffer, Optional] const unsigned int* pUAVInitialCounts)</unmanaged>	
 /// <unmanaged-short>ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews</unmanaged-short>	
 public void SetTargets(
     DepthStencilView depthStencilView,
     RenderTargetView renderTargetView,
     int startSlot,
     UnorderedAccessView[] unorderedAccessViews,
     int[] initialLengths)
 {
     SetTargets(depthStencilView, startSlot, unorderedAccessViews, initialLengths, renderTargetView);
 }
        internal void BindUAV(int slot, params MyBindableResource[] UAVs)
        {
            var buffer = new UnorderedAccessView[UAVs.Length];
            for (int i = 0; i < UAVs.Length; i++)
            {
                if (UAVs[i] != null)
                {
                    var ua = UAVs[i] as IUnorderedAccessBindable;
                    Debug.Assert(ua != null);

                    UnbindSRVRead(UAVs[i].GetID());
                    //UnbindDSVReadOnly(UAVs[i].ResId); necessary?

                    int? currentlyBound = null;
                    foreach (var kv in State.m_bindings)
                    {
                        if (kv.Value.UavSlot == slot + i)
                        {
                            currentlyBound = kv.Key;
                            break;
                        }
                    }
                    if (currentlyBound.HasValue)
                    {
                        State.m_bindings.Remove(currentlyBound.Value);
                    }

                    State.m_bindings[UAVs[i].GetID()] = new MyBinding(MyWriteBindingEnum.UAV, slot + i);
                    buffer[i] = ua.UAV;
                }
            }

            Context.ComputeShader.SetUnorderedAccessViews(slot, buffer);
        }
Example #28
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;
            }
        }
 public void SetUAVs(UnorderedAccessView first, UnorderedAccessView second)
 {
     UAVs[0] = first;
     UAVs[1] = second;
 }
 /// <summary>
 ///   Binds a set of unordered access views and a single render target to the output-merger stage.
 /// </summary>
 /// <param name = "startSlot">Index into a zero-based array to begin setting unordered access views.</param>
 /// <param name = "unorderedAccessViews">A set of unordered access views to bind.</param>
 /// <param name = "renderTargetView">A view of the render target to bind.</param>
 /// <param name = "initialLengths">An array of Append/Consume buffer offsets. A value of -1 indicates the current offset should be kept. Any other values set the hidden counter for that Appendable/Consumable UAV.</param>
 /// <msdn-id>ff476465</msdn-id>	
 /// <unmanaged>void ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews([In] unsigned int NumRTVs,[In, Buffer, Optional] const ID3D11RenderTargetView** ppRenderTargetViews,[In, Optional] ID3D11DepthStencilView* pDepthStencilView,[In] unsigned int UAVStartSlot,[In] unsigned int NumUAVs,[In, Buffer, Optional] const ID3D11UnorderedAccessView** ppUnorderedAccessViews,[In, Buffer, Optional] const unsigned int* pUAVInitialCounts)</unmanaged>	
 /// <unmanaged-short>ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews</unmanaged-short>	
 public void SetTargets(
     RenderTargetView renderTargetView,
     int startSlot,
     UnorderedAccessView[] unorderedAccessViews,
     int[] initialLengths)
 {
     SetTargets(startSlot, unorderedAccessViews, initialLengths, renderTargetView);
 }
        /// <summary>
        ///   Binds a depth-stencil buffer, a set of unordered access views, and a set of render targets to the output-merger stage.
        /// </summary>
        /// <param name = "depthStencilView">A view of the depth-stencil buffer to bind.</param>
        /// <param name = "startSlot">Index into a zero-based array to begin setting unordered access views.</param>
        /// <param name = "unorderedAccessViews">A set of unordered access views to bind.</param>
        /// <param name = "renderTargetViews">A set of render target views to bind.</param>
        /// <msdn-id>ff476465</msdn-id>	
        /// <unmanaged>void ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews([In] unsigned int NumRTVs,[In, Buffer, Optional] const ID3D11RenderTargetView** ppRenderTargetViews,[In, Optional] ID3D11DepthStencilView* pDepthStencilView,[In] unsigned int UAVStartSlot,[In] unsigned int NumUAVs,[In, Buffer, Optional] const ID3D11UnorderedAccessView** ppUnorderedAccessViews,[In, Buffer, Optional] const unsigned int* pUAVInitialCounts)</unmanaged>	
        /// <unmanaged-short>ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews</unmanaged-short>	
        public void SetTargets(
            DepthStencilView depthStencilView,
            int startSlot,
            UnorderedAccessView[] unorderedAccessViews,
            params RenderTargetView[] renderTargetViews)
        {
            int[] lengths = new int[unorderedAccessViews.Length];
            for (int i = 0; i < unorderedAccessViews.Length; i++)
                lengths[i] = -1;

            SetTargets(depthStencilView, startSlot, unorderedAccessViews, lengths, renderTargetViews);
        }
 public void SetUIntUAVs(UnorderedAccessView first, UnorderedAccessView second)
 {
     UAVs[2] = first;
     UAVs[3] = second;
 }
 /// <summary>
 ///   Binds a set of unordered access views and a set of render targets to the output-merger stage.
 /// </summary>
 /// <param name = "startSlot">Index into a zero-based array to begin setting unordered access views.</param>
 /// <param name = "unorderedAccessViews">A set of unordered access views to bind.</param>
 /// <param name = "renderTargetViews">A set of render target views to bind.</param>
 /// <param name = "initialLengths">An array of Append/Consume buffer offsets. A value of -1 indicates the current offset should be kept. Any other values set the hidden counter for that Appendable/Consumable UAV.</param>
 /// <msdn-id>ff476465</msdn-id>	
 /// <unmanaged>void ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews([In] unsigned int NumRTVs,[In, Buffer, Optional] const ID3D11RenderTargetView** ppRenderTargetViews,[In, Optional] ID3D11DepthStencilView* pDepthStencilView,[In] unsigned int UAVStartSlot,[In] unsigned int NumUAVs,[In, Buffer, Optional] const ID3D11UnorderedAccessView** ppUnorderedAccessViews,[In, Buffer, Optional] const unsigned int* pUAVInitialCounts)</unmanaged>	
 /// <unmanaged-short>ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews</unmanaged-short>	
 public void SetTargets(
     int startSlot,
     UnorderedAccessView[] unorderedAccessViews,
     int[] initialLengths,
     params RenderTargetView[] renderTargetViews)
 {
     SetTargets(null, startSlot, unorderedAccessViews, initialLengths, renderTargetViews);
 }
Example #34
0
 public ViewBuffer(SharpDX.Direct3D11.Buffer buffer, SharpDX.Direct3D11.UnorderedAccessView view)
 {
     Buffer = buffer;
     View   = view;
 }
 /// <summary>
 ///   Binds a depth-stencil buffer, a set of unordered access views, and a set of render targets to the output-merger stage.
 /// </summary>
 /// <param name = "depthStencilView">A view of the depth-stencil buffer to bind.</param>
 /// <param name = "startSlot">Index into a zero-based array to begin setting unordered access views.</param>
 /// <param name = "unorderedAccessViews">A set of unordered access views to bind.</param>
 /// <param name = "renderTargetViews">A set of render target views to bind.</param>
 /// <param name = "initialLengths">An array of Append/Consume buffer offsets. A value of -1 indicates the current offset should be kept. Any other values set the hidden counter for that Appendable/Consumable UAV.</param>
 /// <msdn-id>ff476465</msdn-id>	
 /// <unmanaged>void ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews([In] unsigned int NumRTVs,[In, Buffer, Optional] const ID3D11RenderTargetView** ppRenderTargetViews,[In, Optional] ID3D11DepthStencilView* pDepthStencilView,[In] unsigned int UAVStartSlot,[In] unsigned int NumUAVs,[In, Buffer, Optional] const ID3D11UnorderedAccessView** ppUnorderedAccessViews,[In, Buffer, Optional] const unsigned int* pUAVInitialCounts)</unmanaged>	
 /// <unmanaged-short>ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews</unmanaged-short>	
 public void SetTargets(
     DepthStencilView depthStencilView,
     int startSlot,
     UnorderedAccessView[] unorderedAccessViews,
     int[] initialLengths,
     params RenderTargetView[] renderTargetViews)
 {
     SetRenderTargetsAndUnorderedAccessViews(
         renderTargetViews.Length,
         renderTargetViews,
         depthStencilView,
         startSlot,
         unorderedAccessViews.Length,
         unorderedAccessViews,
         initialLengths);
 }
 private void DebugCount(string src, DeviceContext context, UnorderedAccessView uav)
 {
     if (elapsedSinceGenerator > 2)
     {
         elapsedSinceGenerator = 0;
         context.CopyStructureCount(particleCountStaging, 0, uav);
         DataStream ds;
         var db = context.MapSubresource(particleCountStaging, MapMode.Read, SharpDX.Direct3D11.MapFlags.None, out ds);
         CurrentParticleCount = ds.ReadInt();
         System.Diagnostics.Debug.WriteLine("{0}: {1},{2},{3},{4}", src, CurrentParticleCount, (uint)ds.ReadInt(), (uint)ds.ReadInt(), (uint)ds.ReadInt());
         context.UnmapSubresource(particleCountStaging, 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);
        }
        private void GenerateCS(string name, UnorderedAccessView append)
        {
            var context = this.DeviceManager.Direct3DContext;

            // Compile the shader if it isn't already
            if (!computeShaders.ContainsKey(name))
            {
                int oldThreadsX = ThreadsX;
                int oldThreadsY = ThreadsY;
                ThreadsX = GeneratorThreadsX;
                ThreadsY = 1;
                CompileComputeShader(name);
                ThreadsX = oldThreadsX;
                ThreadsY = oldThreadsY;
            }

            // Set the shader to run
            context.ComputeShader.Set(computeShaders[name]);

            clock.Restart();
            // Dispatch the compute shader thread groups
            context.Dispatch((int)Math.Ceiling(ParticlesPerBatch / 16.0), 1, 1);
            LastDispatchTicks = clock.ElapsedTicks;

            DebugCount("Gen-append", context, append);
        }
        internal MyRWStructuredBuffer(int elements, int stride)
        {
            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_UAV = new UnorderedAccessView(MyRender11.Device, m_resource);
            m_SRV = new ShaderResourceView(MyRender11.Device, m_resource);
        }
        private void UpdateCS(string name, UnorderedAccessView append, UnorderedAccessView consume)
        {
            int width, height;
            height = 1;
            width = this.Constants.MaxParticles;
            var context = this.DeviceManager.Direct3DContext;
            // Compile the shader if it isn't already
            if (!computeShaders.ContainsKey(name))
            {
                CompileComputeShader(name);
            }

            // Set the shader to run
            context.ComputeShader.Set(computeShaders[name]);

            //DebugCount("Update-consume-1", context, consume);
            clock.Restart();
            // Dispatch the compute shader thread groups
            context.Dispatch((int)Math.Ceiling(width / (double)ThreadsX), (int)Math.Ceiling(height / (double)ThreadsY), 1);
            LastDispatchTicks = clock.ElapsedTicks;
            //DebugCount("Update-consume-2", context, consume);
        }
 /// <summary>	
 /// Gets an array of views for an unordered resource.	
 /// </summary>	
 /// <remarks>	
 /// Any returned interfaces will have their reference count incremented by one. Applications should call IUnknown::Release on the returned interfaces when they are no longer needed to avoid memory leaks. 	
 /// </remarks>	
 /// <param name="startSlot">Index of the first element in the zero-based array to return (ranges from 0 to D3D11_PS_CS_UAV_REGISTER_COUNT - 1). </param>
 /// <param name="count">Number of views to get (ranges from 0 to D3D11_PS_CS_UAV_REGISTER_COUNT - StartSlot). </param>
 /// <unmanaged>void CSGetUnorderedAccessViews([In] int StartSlot,[In] int NumUAVs,[Out, Buffer] ID3D11UnorderedAccessView** ppUnorderedAccessViews)</unmanaged>
 public UnorderedAccessView[] GetUnorderedAccessViews(int startSlot, int count)
 {
     var temp = new UnorderedAccessView[count];
     GetUnorderedAccessViews(startSlot, count, temp);
     return temp;
 }
Example #42
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";
        }