Ejemplo n.º 1
0
 public static VkResult vkMergePipelineCaches(VkDevice device, VkPipelineCache dstCache, ReadOnlySpan <VkPipelineCache> srcCaches)
 {
     fixed(VkPipelineCache *srcCachesPtr = srcCaches)
     {
         return(vkMergePipelineCaches(device, dstCache, (uint)srcCaches.Length, srcCachesPtr));
     }
 }
Ejemplo n.º 2
0
        public static ComputePipeline[] CreatePipelines(Device device, ComputePipelineCreateInfo[] infos, PipelineCache cache)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }
            if (infos == null)
            {
                throw new ArgumentNullException(nameof(infos));
            }

            VkPipelineCache nativeCache = VkPipelineCache.Null;

            if (cache != null)
            {
                nativeCache = cache.Native;
            }

            var pipelines = new ComputePipeline[infos.Length];
            var natives   = ComputePipeline.CreatePipelinesInternal(device, infos, nativeCache);

            for (int i = 0; i < infos.Length; i++)
            {
                pipelines[i] = new ComputePipeline(device, natives[i]);
            }

            return(pipelines);
        }
Ejemplo n.º 3
0
        //graphics
        public static Pipeline[] CreatePipelines(Device device, GraphicsPipelineCreateInfo[] infos, PipelineCache cache)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }
            if (infos == null)
            {
                throw new ArgumentNullException(nameof(infos));
            }
            for (int i = 0; i < infos.Length; i++)
            {
                if (infos[i] == null)
                {
                    throw new ArgumentNullException(string.Format("Element {0} of {1} is null", i, nameof(infos)));
                }
            }

            VkPipelineCache nativeCache = VkPipelineCache.Null;

            if (cache != null)
            {
                nativeCache = cache.Native;
            }

            var pipelines = new Pipeline[infos.Length];
            var natives   = CreatePipelinesInternal(device, infos, nativeCache);

            for (int i = 0; i < infos.Length; i++)
            {
                pipelines[i] = new Pipeline(device, natives[i]);
            }

            return(pipelines);
        }
Ejemplo n.º 4
0
        public static VkResult vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, VkComputePipelineCreateInfo createInfo, out VkPipeline pipeline)
        {
            VkPipeline pinPipeline;
            var        result = vkCreateComputePipelines(device, pipelineCache, 1, &createInfo, null, &pinPipeline);

            pipeline = pinPipeline;
            return(result);
        }
Ejemplo n.º 5
0
 public static extern VkResult CreateComputePipelines(
     VkDevice device,
     VkPipelineCache pipelineCache,
     uint createInfoCount,
     IntPtr pCreateInfos,
     IntPtr pAllocator,
     IntPtr pPipelines
     );
Ejemplo n.º 6
0
        private void CreatePipelineCache()
        {
            VkPipelineCacheCreateInfo pipelineCacheCreateInfo = new VkPipelineCacheCreateInfo();

            pipelineCacheCreateInfo.sType = PipelineCacheCreateInfo;
            VkPipelineCache cache;

            vkCreatePipelineCache(device, &pipelineCacheCreateInfo, null, &cache);
            this._pipelineCache = cache;
        }
Ejemplo n.º 7
0
        public static VkResult vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, int createInfoCount, VkGraphicsPipelineCreateInfo[] pCreateInfos, VkAllocationCallbacks pAllocator, VkPipeline[] pPipelines)
        {
            VkPreconditions.CheckNull(device, nameof(device));
            VkPreconditions.CheckNull(device, nameof(pCreateInfos));
            VkPreconditions.CheckNull(device, nameof(pPipelines));

            VkPreconditions.CheckRange(createInfoCount, 1, int.MaxValue, nameof(createInfoCount));
            VkPreconditions.CheckRange(pCreateInfos.Length < createInfoCount, nameof(pCreateInfos.Length));

            return(GetDevice(device).CreateGraphicsPipelines(pipelineCache, createInfoCount, pCreateInfos, pPipelines));
        }
Ejemplo n.º 8
0
 public static VkResult vkCreateComputePipelines(
     VkDevice device,
     VkPipelineCache pipelineCache,
     ReadOnlySpan <VkComputePipelineCreateInfo> createInfos,
     Span <VkPipeline> pipelines)
 {
     fixed(VkComputePipelineCreateInfo *createInfosPtr = createInfos)
     {
         fixed(VkPipeline *pipelinesPtr = pipelines)
         {
             return(vkCreateComputePipelines(device, pipelineCache, (uint)createInfos.Length, createInfosPtr, null, pipelinesPtr));
         }
     }
 }
Ejemplo n.º 9
0
        public override VkResult CreateGraphicsPipelines(VkPipelineCache pipelineCache, int createInfoCount, VkGraphicsPipelineCreateInfo[] pCreateInfos, VkPipeline[] pPipelines)
        {
            VkResult result;

            for (int i = 0; i < createInfoCount; i++)
            {
                VkPipeline pipeline = null;
                result = CreateGraphicsPipelines(pCreateInfos[i], out pipeline);
                if (result != VkResult.VK_SUCCESS)
                {
                    return(result);
                }
                pPipelines[i] = pipeline;
            }
            return(VkResult.VK_SUCCESS);
        }
Ejemplo n.º 10
0
        public GraphicsPipeline(Device device, GraphicsPipelineCreateInfo info, PipelineCache cache)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            Device = device;

            VkPipelineCache nativeCache = VkPipelineCache.Null;

            if (cache != null)
            {
                nativeCache = cache.Native;
            }

            pipeline = CreatePipelinesInternal(device, new GraphicsPipelineCreateInfo[] { info }, nativeCache)[0];
        }
Ejemplo n.º 11
0
 public static VkResult vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, VkComputePipelineCreateInfo createInfo, out VkPipeline pipeline)
 {
     return(vkCreateComputePipelines(device, pipelineCache, 1, &createInfo, null, out pipeline));
 }
Ejemplo n.º 12
0
 public static VkResult vkMergePipelineCaches(VkDevice device, VkPipelineCache dstCache, VkPipelineCache srcCache)
 {
     return(vkMergePipelineCaches(device, dstCache, 1, &srcCache));
 }
Ejemplo n.º 13
0
        public FGraphicsPipeline(VkDevice device, VkPhysicalDevice physicalDevice, VkPipelineCache pipelineCache, VkRenderPass renderPass,
                                 string shaderPath, uint swapchainImageCount, FTexture textureArray)
        {
            this.device = device;
            this.swapchainImageCount = swapchainImageCount;
            this.renderPass          = renderPass;

            desclayout     = CreateDescriptorLayout(device, 1);
            descriptorPool = CreateDescriptorPool(device, swapchainImageCount, 7);
            descriptorSets = AllocateDescriptorSets(device, desclayout, descriptorPool,
                                                    swapchainImageCount);

            sampler = CreateSampler(device, textureArray.MipLevels);
            for (int i = 0; i < swapchainImageCount; i++)
            {
                VkDescriptorImageInfo imageInfo = new VkDescriptorImageInfo();
                imageInfo.imageLayout = VkImageLayout.ShaderReadOnlyOptimal;
                imageInfo.imageView   = textureArray.imageView;
                imageInfo.sampler     = sampler;

                VkWriteDescriptorSet[] writes = new VkWriteDescriptorSet[1];
                writes[0].dstSet          = descriptorSets[i];
                writes[0].dstBinding      = 0;
                writes[0].dstArrayElement = 0;
                writes[0].descriptorType  = VkDescriptorType.CombinedImageSampler;
                writes[0].descriptorCount = 1;
                writes[0].pImageInfo      = &imageInfo;

                fixed(VkWriteDescriptorSet *ptr = writes)
                vkUpdateDescriptorSets(device, (uint)writes.Length, ptr, 0, null);
            }

            uniformdata = CreateUniformBuffer(device, physicalDevice, 1);

            VkShaderModule vs = LoadShader(device, $"{shaderPath}.vert.spv");
            VkShaderModule fs = LoadShader(device, $"{shaderPath}.frag.spv");


            VkGraphicsPipelineCreateInfo pCreateInfo = VkGraphicsPipelineCreateInfo.New();

            pCreateInfo.flags = VkPipelineCreateFlags.DisableOptimization;

            VkPipelineShaderStageCreateInfo[] shaderStages = new VkPipelineShaderStageCreateInfo[2];
            shaderStages[0]        = VkPipelineShaderStageCreateInfo.New();
            shaderStages[0].stage  = VkShaderStageFlags.Vertex;
            shaderStages[0].module = vs;

            byte[] vsFuncName = Encoding.UTF8.GetBytes("main" + char.MinValue);

            fixed(byte *ptr = &(vsFuncName[0]))
            shaderStages[0].pName = ptr;

            shaderStages[1]        = VkPipelineShaderStageCreateInfo.New();
            shaderStages[1].stage  = VkShaderStageFlags.Fragment;
            shaderStages[1].module = fs;
            byte[] fsFuncName = Encoding.UTF8.GetBytes("main" + char.MinValue);

            fixed(byte *ptr = &(fsFuncName[0]))
            shaderStages[1].pName = ptr;

            fixed(VkPipelineShaderStageCreateInfo *ptr = shaderStages)
            pCreateInfo.pStages = ptr;

            pCreateInfo.stageCount = 2;

            VkVertexInputBindingDescription[] bindings = new VkVertexInputBindingDescription[4];
            bindings[0]           = new VkVertexInputBindingDescription();
            bindings[0].binding   = 0;
            bindings[0].stride    = (uint)sizeof(VoxelRenderer.VoxelVertex);
            bindings[0].inputRate = VkVertexInputRate.Vertex;

            bindings[1]           = new VkVertexInputBindingDescription();
            bindings[1].binding   = 1;
            bindings[1].stride    = (uint)sizeof(VoxelRenderer.VoxelVertex);
            bindings[1].inputRate = VkVertexInputRate.Vertex;

            bindings[2]           = new VkVertexInputBindingDescription();
            bindings[2].binding   = 2;
            bindings[2].stride    = (uint)sizeof(VoxelRenderer.VoxelVertex);
            bindings[2].inputRate = VkVertexInputRate.Vertex;

            bindings[3]           = new VkVertexInputBindingDescription();
            bindings[3].binding   = 3;
            bindings[3].stride    = (uint)sizeof(VoxelRenderer.VoxelVertex);
            bindings[3].inputRate = VkVertexInputRate.Vertex;

            VkVertexInputAttributeDescription[] attribs = new VkVertexInputAttributeDescription[4];
            attribs[0].binding  = 0;
            attribs[0].location = 0;
            attribs[0].format   = VkFormat.R32g32b32Sfloat;
            attribs[0].offset   = 0;

            attribs[1].binding  = 1;
            attribs[1].location = 1;
            attribs[1].format   = VkFormat.R32g32b32Sfloat;
            attribs[1].offset   = 0;

            attribs[2].binding  = 2;
            attribs[2].location = 2;
            attribs[2].format   = VkFormat.R32g32b32Sfloat;
            attribs[2].offset   = 0;

            attribs[3].binding  = 3;
            attribs[3].location = 3;
            attribs[3].format   = VkFormat.R32Uint;
            attribs[3].offset   = 0;

            VkPipelineVertexInputStateCreateInfo vertexInput = VkPipelineVertexInputStateCreateInfo.New();

            fixed(VkVertexInputBindingDescription *ptr = bindings)
            vertexInput.pVertexBindingDescriptions = ptr;

            vertexInput.vertexBindingDescriptionCount = (uint)bindings.Length;

            fixed(VkVertexInputAttributeDescription *ptr = attribs)
            vertexInput.pVertexAttributeDescriptions = ptr;

            vertexInput.vertexAttributeDescriptionCount = (uint)attribs.Length;
            pCreateInfo.pVertexInputState = &vertexInput;

            VkPipelineInputAssemblyStateCreateInfo inputAssembly = VkPipelineInputAssemblyStateCreateInfo.New();

            inputAssembly.topology          = VkPrimitiveTopology.TriangleList;
            pCreateInfo.pInputAssemblyState = &inputAssembly;

            VkPipelineViewportStateCreateInfo viewportState = VkPipelineViewportStateCreateInfo.New();

            viewportState.viewportCount = 1;
            viewportState.scissorCount  = 1;
            pCreateInfo.pViewportState  = &viewportState;

            VkPipelineRasterizationStateCreateInfo rasterizationState = VkPipelineRasterizationStateCreateInfo.New();

            rasterizationState.lineWidth    = 1;
            rasterizationState.frontFace    = VkFrontFace.Clockwise;
            rasterizationState.cullMode     = VkCullModeFlags.Back;
            rasterizationState.polygonMode  = VkPolygonMode.Fill;//TODO add line debug render
            pCreateInfo.pRasterizationState = &rasterizationState;

            VkPipelineMultisampleStateCreateInfo multisampleState = VkPipelineMultisampleStateCreateInfo.New();

            multisampleState.rasterizationSamples = VkSampleCountFlags.Count1;
            pCreateInfo.pMultisampleState         = &multisampleState;

            VkPipelineDepthStencilStateCreateInfo depthState = VkPipelineDepthStencilStateCreateInfo.New();

            depthState.depthTestEnable     = VkBool32.True;
            depthState.depthWriteEnable    = VkBool32.True;
            depthState.depthCompareOp      = VkCompareOp.Less;
            pCreateInfo.pDepthStencilState = &depthState;

            VkPipelineColorBlendAttachmentState colourAttachment = new VkPipelineColorBlendAttachmentState();

            colourAttachment.colorWriteMask = VkColorComponentFlags.R | VkColorComponentFlags.G | VkColorComponentFlags.B | VkColorComponentFlags.A;

            VkPipelineColorBlendStateCreateInfo colourState = VkPipelineColorBlendStateCreateInfo.New();

            colourState.pAttachments     = &colourAttachment;
            colourState.attachmentCount  = 1;
            pCreateInfo.pColorBlendState = &colourState;

            VkDynamicState[] dynamicStates = new VkDynamicState[2];
            dynamicStates[0] = VkDynamicState.Viewport;
            dynamicStates[1] = VkDynamicState.Scissor;

            VkPipelineDynamicStateCreateInfo dynamicState = VkPipelineDynamicStateCreateInfo.New();

            dynamicState.dynamicStateCount = (uint)dynamicStates.Length;

            fixed(VkDynamicState *ptr = &(dynamicStates[0]))
            dynamicState.pDynamicStates = ptr;

            pCreateInfo.pDynamicState = &dynamicState;

            this.pipelineLayout    = CreatePipelineLayout(device, desclayout);
            pCreateInfo.layout     = this.pipelineLayout;
            pCreateInfo.renderPass = renderPass;
            pCreateInfo.subpass    = 0;


            VkPipeline pipeline = VkPipeline.Null;

            Assert(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pCreateInfo, null, &pipeline));
            this.pipeline = pipeline;
        }
Ejemplo n.º 14
0
 public static extern VkResult MergePipelineCaches(
     VkDevice device,
     VkPipelineCache dstCache,
     uint srcCacheCount,
     IntPtr pSrcCaches
     );
Ejemplo n.º 15
0
 public static extern VkResult GetPipelineCacheData(
     VkDevice device,
     VkPipelineCache pipelineCache,
     ref ulong pDataSize,
     IntPtr pData
     );
Ejemplo n.º 16
0
 public static extern void DestroyPipelineCache(
     VkDevice device,
     VkPipelineCache pipelineCache,
     IntPtr pAllocator
     );
Ejemplo n.º 17
0
 public static extern VkResult CreatePipelineCache(
     VkDevice device,
     ref VkPipelineCacheCreateInfo pCreateInfo,
     IntPtr pAllocator,
     out VkPipelineCache pPipelineCache
     );
Ejemplo n.º 18
0
 public override VkResult CreateGraphicsPipelines(VkPipelineCache pipelineCache, int createInfoCount, VkGraphicsPipelineCreateInfo[] pCreateInfos, VkPipeline[] pPipelines)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            Console.WriteLine(AppContext.GetData("NATIVE_DLL_SEARCH_DIRECTORIES").ToString());
            Console.WriteLine($"Hello Vulkan!");
            Init();

            if (!GLFW.Vulkan.IsSupported)
            {
                Console.Error.WriteLine("GLFW says that vulkan is not supported.");
                return;
            }

            WindowHint(Hint.ClientApi, ClientApi.None);
            NativeWindow window = new GLFW.NativeWindow(width, height, "Fabricor");

            Glfw.SetKeyCallback(window, (a, b, c, d, e) => {
                GLFWInput.KeyCallback(a, b, c, d, e);
            });

            FInstance      finst      = new FInstance();
            VkSurfaceKHR   surface    = CreateSurface(finst.instance, window);
            VkDevice       device     = CreateDevice(finst.instance, out var physicalDevice, surface, out var queueFamilyIndex);
            VkSwapchainKHR swapchain  = CreateSwapchain(VkSwapchainKHR.Null, finst.instance, device, physicalDevice, surface, queueFamilyIndex);
            VkRenderPass   renderPass = CreateRenderPass(device);

            uint swapchainImageCount = 0;

            Assert(vkGetSwapchainImagesKHR(device, swapchain, &swapchainImageCount, null));////////////IMAGES
            VkImage[] swapchainImages = new VkImage[swapchainImageCount];

            fixed(VkImage *ptr = &swapchainImages[0])
            Assert(vkGetSwapchainImagesKHR(device, swapchain, &swapchainImageCount, ptr));

            CommandPoolManager.Init(device, queueFamilyIndex);
            int poolId = CommandPoolManager.CreateCommandPool(VkCommandPoolCreateFlags.ResetCommandBuffer);


            VkSemaphoreCreateInfo pCreateInfo = VkSemaphoreCreateInfo.New();

            VkSemaphore acquireSemaphore = new VkSemaphore();

            vkCreateSemaphore(device, &pCreateInfo, null, &acquireSemaphore);

            VkSemaphore releaseSemaphore = new VkSemaphore();

            vkCreateSemaphore(device, &pCreateInfo, null, &releaseSemaphore);

            VkQueue graphicsQueue = VkQueue.Null;

            vkGetDeviceQueue(device, queueFamilyIndex, 0, &graphicsQueue);

            string[] textures = new string[] {
                "res/Linus.png",
                "res/Alex.png",
                "res/Victor.png",
                "res/Alex2.png",
                //"res/Cyan.png",
                "res/Alex3.png",
                //"res/Red.png",
            };

            FTexture texture = new FTexture(device, physicalDevice, poolId, graphicsQueue, textures, VkFormat.R8g8b8a8Unorm,
                                            512, 512, (uint)(Math.Log(512) / Math.Log(2)) + 1);

            VkPipelineCache   pipelineCache = VkPipelineCache.Null;//This is critcal for performance.
            FGraphicsPipeline voxelPipeline =
                new FGraphicsPipeline(device, physicalDevice, pipelineCache, renderPass, "shaders/voxel", swapchainImageCount, texture);

            voxelPipeline.CreateDepthBuffer(physicalDevice, (uint)width, (uint)height);

            VkImageView[] swapchainImageViews = new VkImageView[swapchainImageCount];
            for (int i = 0; i < swapchainImageCount; i++)
            {
                swapchainImageViews[i] = FTexture.CreateColourImageView(device, swapchainImages[i], surfaceFormat.format);
            }
            VkFramebuffer[] frambuffers = new VkFramebuffer[swapchainImageCount];
            for (int i = 0; i < swapchainImageCount; i++)
            {
                frambuffers[i] = CreateFramebuffer(device, renderPass, swapchainImageViews[i], voxelPipeline.depthImageView);
            }

            MeshWrapper <VoxelVertex> mesh = VoxelMeshFactory.GenerateMesh(device, physicalDevice);

            Action updateMesh = delegate {
                VoxelMeshFactory.UpdateMesh(device, physicalDevice, mesh);
            };

            GLFWInput.Subscribe(Keys.U, updateMesh, InputState.Press);

            Action changeTexture = delegate
            {
                Span <VoxelVertex> span = mesh.Mesh.vertices.Map();
                for (int j = 0; j < span.Length; j++)
                {
                    span[j].textureId++;
                }
                span = mesh.Mesh.vertices.UnMap();
            };

            GLFWInput.Subscribe(Keys.F, changeTexture, InputState.Press);

            FCommandBuffer[] cmdBuffers = new FCommandBuffer[swapchainImageCount];
            VkFence[]        fences     = new VkFence[swapchainImageCount];
            for (int i = 0; i < swapchainImageCount; i++)
            {
                cmdBuffers[i] = new FCommandBuffer(device, poolId);

                VkFenceCreateInfo createInfo = VkFenceCreateInfo.New();
                createInfo.flags = VkFenceCreateFlags.Signaled;
                VkFence fence = VkFence.Null;
                Assert(vkCreateFence(device, &createInfo, null, &fence));
                fences[i] = fence;
            }

            FCamera camera = new FCamera();

            camera.AspectWidth  = width;
            camera.AspectHeight = height;
            camera.position.Z   = -1f;
            //camera.rotation=Quaternion.CreateFromYawPitchRoll(MathF.PI,0,0);

            double lastTime = Glfw.Time;
            int    nbFrames = 0;

            while (!WindowShouldClose(window))
            {
                PollEvents();
                GLFWInput.Update();

                // Measure speed
                double currentTime = Glfw.Time;
                nbFrames++;
                if (currentTime - lastTime >= 1.0)
                { // If last prinf() was more than 1 sec ago
                  // printf and reset timer
                    Console.WriteLine($"ms/frame: {1000.0 / nbFrames}");
                    nbFrames  = 0;
                    lastTime += 1.0;
                }

                if (GLFWInput.TimeKeyPressed(Keys.D) > 0)
                {
                    camera.position += Vector3.Transform(Vector3.UnitX * 0.00015f, camera.rotation);
                }
                if (GLFWInput.TimeKeyPressed(Keys.A) > 0)
                {
                    camera.position -= Vector3.Transform(Vector3.UnitX * 0.00015f, camera.rotation);
                }

                if (GLFWInput.TimeKeyPressed(Keys.W) > 0)
                {
                    camera.position += Vector3.Transform(Vector3.UnitZ * 0.00015f, camera.rotation);
                }
                if (GLFWInput.TimeKeyPressed(Keys.S) > 0)
                {
                    camera.position -= Vector3.Transform(Vector3.UnitZ * 0.00015f, camera.rotation);
                }

                if (GLFWInput.TimeKeyPressed(Keys.Space) > 0)
                {
                    camera.position += Vector3.Transform(Vector3.UnitY * 0.00015f, camera.rotation);
                }
                if (GLFWInput.TimeKeyPressed(Keys.LeftShift) > 0)
                {
                    camera.position -= Vector3.Transform(Vector3.UnitY * 0.00015f, camera.rotation);
                }

                if (GLFWInput.TimeKeyPressed(Keys.Right) > 0)
                {
                    camera.rotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitY, 0.00015f);
                }
                if (GLFWInput.TimeKeyPressed(Keys.Left) > 0)
                {
                    camera.rotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitY, -0.00015f);
                }


                uint imageIndex = 0;

                Assert(vkAcquireNextImageKHR(device, swapchain, ulong.MaxValue, acquireSemaphore, VkFence.Null, &imageIndex));


                VkCommandBufferBeginInfo beginInfo = VkCommandBufferBeginInfo.New();
                beginInfo.flags = VkCommandBufferUsageFlags.OneTimeSubmit;

                voxelPipeline.swapchainFramebuffer = frambuffers[imageIndex];
                voxelPipeline.swapchainImage       = swapchainImages[imageIndex];
                voxelPipeline.swapchainImageIndex  = imageIndex;

                voxelPipeline.mesh   = mesh;
                voxelPipeline.camera = camera;

                fixed(VkFence *ptr = &(fences[imageIndex]))
                {
                    vkWaitForFences(device, 1, ptr, VkBool32.False, ulong.MaxValue);
                    vkResetFences(device, 1, ptr);
                }

                cmdBuffers[imageIndex].RecordCommandBuffer(new Action <VkCommandBuffer>[] {
                    voxelPipeline.Execute,
                });

                VkPipelineStageFlags submitStageMask = VkPipelineStageFlags.ColorAttachmentOutput;

                VkSubmitInfo submitInfo = VkSubmitInfo.New();
                submitInfo.waitSemaphoreCount = 1;
                submitInfo.pWaitSemaphores    = &acquireSemaphore;
                submitInfo.pWaitDstStageMask  = &submitStageMask;
                submitInfo.commandBufferCount = 1;

                fixed(VkCommandBuffer *ptr = &(cmdBuffers[imageIndex].buffer))
                submitInfo.pCommandBuffers = ptr;

                submitInfo.signalSemaphoreCount = 1;
                submitInfo.pSignalSemaphores    = &releaseSemaphore;

                Assert(vkQueueSubmit(graphicsQueue, 1, &submitInfo, fences[imageIndex]));

                VkPresentInfoKHR presentInfoKHR = VkPresentInfoKHR.New();
                presentInfoKHR.swapchainCount = 1;
                presentInfoKHR.pSwapchains    = &swapchain;
                presentInfoKHR.pImageIndices  = &imageIndex;

                presentInfoKHR.waitSemaphoreCount = 1;
                presentInfoKHR.pWaitSemaphores    = &releaseSemaphore;

                Assert(vkQueuePresentKHR(graphicsQueue, &presentInfoKHR));
                vkDeviceWaitIdle(device);
            }
            finst.Destroy();
            DestroyWindow(window);
            Terminate();
        }
Ejemplo n.º 20
0
 public abstract VkResult CreateGraphicsPipelines(VkPipelineCache pipelineCache, int createInfoCount, VkGraphicsPipelineCreateInfo[] pCreateInfos, VkPipeline[] pPipelines);
Ejemplo n.º 21
0
 public static VkResult vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint createInfoCount, VkComputePipelineCreateInfo *createInfos, VkAllocationCallbacks *allocator, out VkPipeline pipelines)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 22
0
        static internal VkPipeline[] CreatePipelinesInternal(Device device, GraphicsPipelineCreateInfo[] mInfos, VkPipelineCache cache)
        {
            int count            = mInfos.Length;
            var infosMarshalled  = new MarshalledArray <VkGraphicsPipelineCreateInfo>(count);
            var pipelineResults  = new VkPipeline[count];
            var marshalledArrays = new DisposableList <IDisposable>(count);

            for (int i = 0; i < count; i++)
            {
                VkGraphicsPipelineCreateInfo info = new VkGraphicsPipelineCreateInfo();
                var mInfo = mInfos[i];

                info.sType = VkStructureType.GraphicsPipelineCreateInfo;
                info.flags = mInfo.flags;

                int stagesCount      = mInfo.stages.Count;
                var stagesMarshalled = new MarshalledArray <VkPipelineShaderStageCreateInfo>(stagesCount);
                for (int j = 0; j < stagesCount; j++)
                {
                    stagesMarshalled[j] = mInfo.stages[j].GetNative(marshalledArrays);
                }

                info.stageCount = (uint)stagesCount;
                info.pStages    = stagesMarshalled.Address;

                marshalledArrays.Add(stagesMarshalled);

                if (mInfo.vertexInputState != null)
                {
                    var m = new Marshalled <VkPipelineVertexInputStateCreateInfo>(mInfo.vertexInputState.GetNative(marshalledArrays));
                    info.pVertexInputState = m.Address;
                    marshalledArrays.Add(m);
                }

                if (mInfo.inputAssemblyState != null)
                {
                    var m = new Marshalled <VkPipelineInputAssemblyStateCreateInfo>(mInfo.inputAssemblyState.GetNative());
                    info.pInputAssemblyState = m.Address;
                    marshalledArrays.Add(m);
                }

                if (mInfo.tessellationState != null)
                {
                    var m = new Marshalled <VkPipelineTessellationStateCreateInfo>(mInfo.tessellationState.GetNative());
                    info.pTessellationState = m.Address;
                    marshalledArrays.Add(m);
                }

                if (mInfo.viewportState != null)
                {
                    var m = new Marshalled <VkPipelineViewportStateCreateInfo>(mInfo.viewportState.GetNative(marshalledArrays));
                    info.pViewportState = m.Address;
                }

                if (mInfo.rasterizationState != null)
                {
                    var m = new Marshalled <VkPipelineRasterizationStateCreateInfo>(mInfo.rasterizationState.GetNative());
                    info.pRasterizationState = m.Address;
                    marshalledArrays.Add(m);
                }

                if (mInfo.multisampleState != null)
                {
                    var m = new Marshalled <VkPipelineMultisampleStateCreateInfo>(mInfo.multisampleState.GetNative());
                    info.pMultisampleState = m.Address;
                    marshalledArrays.Add(m);
                }

                if (mInfo.depthStencilState != null)
                {
                    var m = new Marshalled <VkPipelineDepthStencilStateCreateInfo>(mInfo.depthStencilState.GetNative());
                    info.pDepthStencilState = m.Address;
                    marshalledArrays.Add(m);
                }

                if (mInfo.colorBlendState != null)
                {
                    var m = new Marshalled <VkPipelineColorBlendStateCreateInfo>(mInfo.colorBlendState.GetNative(marshalledArrays));
                    info.pColorBlendState = m.Address;
                    marshalledArrays.Add(m);
                }

                if (mInfo.dynamicState != null)
                {
                    var m = new Marshalled <VkPipelineDynamicStateCreateInfo>(mInfo.dynamicState.GetNative(marshalledArrays));
                    info.pDynamicState = m.Address;
                    marshalledArrays.Add(m);
                }

                info.layout = mInfo.layout.Native;

                if (mInfo.renderPass != null)
                {
                    info.renderPass = mInfo.renderPass.Native;
                }

                info.subpass = mInfo.subpass;
                if (mInfo.basePipelineHandle != null)
                {
                    info.basePipelineHandle = mInfo.basePipelineHandle.Native;
                }
                info.basePipelineIndex = mInfo.basePipelineIndex;

                infosMarshalled[i] = info;
            }

            using (infosMarshalled)
                using (marshalledArrays)
                    using (var pipelinesMarshalled = new PinnedArray <VkPipeline>(pipelineResults)) {
                        var result = device.Commands.createGraphicsPiplines(
                            device.Native, cache,
                            (uint)count, infosMarshalled.Address,
                            device.Instance.AllocationCallbacks, pipelinesMarshalled.Address);

                        if (result != VkResult.Success)
                        {
                            throw new PipelineException(string.Format("Error creating pipeline: {0}", result));
                        }
                        return(pipelineResults);
                    }
        }
Ejemplo n.º 23
0
        static internal VkPipeline[] CreatePipelinesInternal(Device device, ComputePipelineCreateInfo[] mInfos, VkPipelineCache cache)
        {
            int count            = mInfos.Length;
            var infosMarshalled  = new MarshalledArray <VkComputePipelineCreateInfo>(count);
            var pipelineResults  = new VkPipeline[count];
            var marshalledArrays = new DisposableList <IDisposable>(count);

            for (int i = 0; i < count; i++)
            {
                var mInfo = mInfos[i];
                VkComputePipelineCreateInfo info = new VkComputePipelineCreateInfo();
                info.sType = VkStructureType.ComputePipelineCreateInfo;
                info.flags = mInfo.flags;

                info.stage = mInfo.stage.GetNative(marshalledArrays);

                info.layout = mInfo.layout.Native;
                if (mInfo.basePipelineHandle != null)
                {
                    info.basePipelineHandle = mInfo.basePipelineHandle.Native;
                }
                info.basePipelineIndex = mInfo.basePipelineIndex;

                infosMarshalled[i] = info;
            }

            using (infosMarshalled)
                using (marshalledArrays)
                    using (var pipelinesMarshalled = new PinnedArray <VkPipeline>(pipelineResults)) {
                        var result = device.Commands.createComputePipelines(
                            device.Native, cache,
                            (uint)count, infosMarshalled.Address,
                            device.Instance.AllocationCallbacks, pipelinesMarshalled.Address);

                        if (result != VkResult.Success)
                        {
                            throw new PipelineException(string.Format("Error creating pipeline: {0}", result));
                        }
                        return(pipelineResults);
                    }
        }