示例#1
0
        /// <summary>
        /// Function to initialize the example and prepare the required components.
        /// </summary>
        private static void Initialize()
        {
            // We will need to access the graphics device in order to use compute functionality, so we'll use the first usable device in the system.
            // Find out which devices we have installed in the system.
            IReadOnlyList <IGorgonVideoAdapterInfo> deviceList = GorgonGraphics.EnumerateAdapters();

            Console.WriteLine("Enumerating video devices...");

            IGorgonVideoAdapterInfo firstDevice = deviceList.FirstOrDefault(item => item.FeatureSet >= FeatureSet.Level_12_0);

            // If a device with a feature set of at least 12.0 not found, then we cannot run this example. The compute engine requires a minimum
            // of feature level 12.0 to run.
            if (firstDevice == null)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("No Level 12.0 or better adapters found in the system. This example requires a FeatureLevel 12.0 or better adapter.");
                Console.ResetColor();
                return;
            }

            Console.WriteLine($"Using the '{firstDevice.Name}' video device.\n");

            // We have to create a graphics interface to allow the compute engine to communicate with the GPU.
            _graphics = new GorgonGraphics(firstDevice);

            // We will also need to compile a compute shader so we can actually perform the work.
            Console.WriteLine("Compiling the compute shader (SimpleCompute)...");
            _computeShader = GorgonShaderFactory.Compile <GorgonComputeShader>(_graphics, Resources.ComputeShader, "SimpleCompute");

            // Finally, the star of the show, the compute engine.
            Console.WriteLine("Creating compute engine...");
            _engine = new GorgonComputeEngine(_graphics);
        }
示例#2
0
文件: Sobel.cs 项目: ishkang/Gorgon
        /// <summary>
        /// Initializes a new instance of the <see cref="Sobel"/> class.
        /// </summary>
        /// <param name="graphics">The graphics interface to use.</param>
        /// <param name="sobelShader">The shader for sobel edge detection.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="graphics"/>, or the <paramref name="sobelShader"/> parameter is <b>null</b>.</exception>
        public Sobel(GorgonGraphics graphics, GorgonComputeShader sobelShader)
        {
            if (sobelShader == null)
            {
                throw new ArgumentNullException(nameof(sobelShader));
            }

            _compute   = new GorgonComputeEngine(graphics);
            _sobelData = new GorgonConstantBuffer(graphics,
                                                  new GorgonConstantBufferInfo("SobelData")
            {
                Usage       = ResourceUsage.Dynamic,
                SizeInBytes = 16
            });

            _dispatchBuilder = new GorgonDispatchCallBuilder();
            _dispatchBuilder.ConstantBuffer(_sobelData.GetView())
            .ComputeShader(sobelShader);
        }