Ejemplo n.º 1
0
        /// <summary>
        /// Function to execute the compute shader with the compute engine.
        /// </summary>
        /// <returns>An array of <see cref="OutputData"/> values.  These contain the results from the compute engine.</returns>
        private static OutputData[] Execute()
        {
            // The first step is to provide the compute shader with the information it needs to do its job.
            GorgonDispatchCall dispatch = _dispatchBuilder.ShaderResource(_intBuffer.GetShaderResourceView(BufferFormat.R32_SInt))
                                          .ShaderResource(_floatBuffer.GetShaderResourceView(BufferFormat.R32_Float), 1)
                                          .ReadWriteView(new GorgonReadWriteViewBinding(_outputBuffer.GetStructuredReadWriteView()))
                                          .ComputeShader(_computeShader)
                                          .Build();

            // Now, we execute the shader with MaxValues threads for the first thread group.
            _engine.Execute(dispatch, MaxValues, 1, 1);

            // Finally, let's turn this into some meaningful data structures rather than raw buffer data.
            // This will enable us handle the data better in our code.
            return(_outputBuffer.GetData <OutputData>());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Function to process a texture into the output texture.
        /// </summary>
        /// <param name="texture">The texture to process.</param>
        /// <param name="outputTexture">The output texture that will receive the processed texture.</param>
        /// <param name="thickness">The thickness of the sobel lines.</param>
        /// <param name="threshold">The threshold used to determine an edge.</param>
        public void Process(GorgonTexture2DView texture, GorgonTexture2DReadWriteView outputTexture, int thickness, float threshold)
        {
            if ((texture == null) ||
                (outputTexture == null))
            {
                return;
            }

            if ((_dispatch == null) || (_dispatch.ShaderResources[0] != texture) || (_dispatch.ReadWriteViews[0].ReadWriteView != outputTexture))
            {
                _dispatch = _dispatchBuilder.ReadWriteView(new GorgonReadWriteViewBinding(outputTexture))
                            .ShaderResource(texture)
                            .Build();
            }

            _sobelOptions[0] = thickness;
            _sobelOptions[1] = threshold;
            _sobelData.SetData(_sobelOptions);

            // Send 32 threads per group.
            _compute.Execute(_dispatch, (int)(texture.Width / 32.0f).FastCeiling(), (int)(texture.Height / 32.0f).FastCeiling(), 1);
        }