Example #1
0
        static void CreateResources()
        {
            factory     = device.ResourceFactory;
            commandList = factory.CreateCommandList();
            Vertex[] quadVertices = Logic.ScreenQuads;
            ushort[] quadIndices  = { 0, 1, 2, 3 };

            imGuiRenderer = new ImGuiRenderer(device,
                                              device.SwapchainFramebuffer.OutputDescription, window.Width, window.Height);


            renderTexture = MakeTexture(Round(window.Width, Logic.GroupSize), Round(window.Height, Logic.GroupSize));//var resultTBuffer = factory.CreateTextureView(new TextureViewDescription(renderTexture));
            var drawUBuffer = MakeBuffer(new Info[] { Logic.State }, BufferUsage.UniformBuffer);

            var renderDesc = new VertFragUnit.Description()
            {
                Vertex   = LoadShader(ShaderStages.Vertex),
                Fragment = LoadShader("DisplayFrag", ShaderStages.Fragment),

                VertexBuffer = MakeBuffer(quadVertices, BufferUsage.VertexBuffer),
                IndexBuffer  = MakeBuffer(quadIndices, BufferUsage.IndexBuffer),
                Topology     = PrimitiveTopology.TriangleStrip,
                Output       = device.SwapchainFramebuffer.OutputDescription
            };

            renderDesc.AddResource("texture", ResourceKind.TextureReadOnly, renderTexture);
            renderDesc.AddResource("info", ResourceKind.UniformBuffer, drawUBuffer);
            renderer = new VertFragUnit(factory, renderDesc);

            var infoUBuffer = MakeBuffer(new Info[] { Logic.State }, BufferUsage.UniformBuffer);

            var compDesc = new ComputeUnit.Description(LoadShader("Compute", ShaderStages.Compute))
            {
                xGroupSize = Logic.GroupSize,
                yGroupSize = Logic.GroupSize
            };

            compDesc.AddResource("sampler", ResourceKind.Sampler, device.LinearSampler);
            //compDesc.AddResource("values", ResourceKind.StructuredBufferReadOnly, model.ValueBuffer());
            compDesc.AddResource("values", ResourceKind.TextureReadOnly, model.ValueTexture());
            compDesc.AddResource("data", ResourceKind.StructuredBufferReadOnly, model.StructBuffer());
            compDesc.AddResource("info", ResourceKind.UniformBuffer, infoUBuffer);
            compDesc.AddResource("result", ResourceKind.TextureReadWrite, renderTexture);
            compute = new ComputeUnit(factory, compDesc);


            ushort[] debugIndices = { 0, 1, 2, 3, 4, 5 };
            var      uiDesc       = new VertFragUnit.Description()
            {
                Vertex       = LoadShader(ShaderStages.Vertex),
                Fragment     = LoadShader("Plain", ShaderStages.Fragment),
                VertexBuffer = MakeBuffer(Logic.DebugUtils, BufferUsage.VertexBuffer),
                IndexBuffer  = MakeBuffer(debugIndices, BufferUsage.IndexBuffer),
                Topology     = PrimitiveTopology.LineList,
                Output       = device.SwapchainFramebuffer.OutputDescription
            };

            uiRenderer = new VertFragUnit(factory, uiDesc);
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.SetOut(Logic.console);
            Trace.Listeners.Add(new TextWriterTraceListener(Logic.console));

            model = Logic.MakeData(args[0]);

            window = Utilities.MakeWindow(720, 720);
            Logic.Init(window);
            window.Resized += Resize;

            FPS fpsCounter = new FPS();

            device = VeldridStartup.CreateGraphicsDevice(window, new GraphicsDeviceOptions(DebugMode, null, false, ResourceBindingModel.Improved));
            CreateResources();
            DateTime start = DateTime.Now;
            TimeSpan delta = TimeSpan.FromSeconds(0);

            Logic.Heading      = Logic.Heading;
            Logic.Position     = Logic.Position;
            window.WindowState = WindowState.Maximized;

            while (window.Exists)
            {
                if (loader != null && loader.IsCompleted)
                {
                    model             = loader.Result;
                    compute["data"]   = model.StructBuffer();
                    compute["values"] = model.ValueTexture();
                    compute.Update(factory);
                    loader = null;
                }
                delta = DateTime.Now - start;
                start = DateTime.Now;

                var input = window.PumpEvents();
                Logic.Update(delta, input);
                Logic.MakeGUI(fpsCounter.Frames);
                Draw();
                fpsCounter.Frame();
            }
            ImGui.DestroyContext();
            DisposeResources();
        }