public static ReadOnlySpan <VkRect2D> vkGetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface) { uint rectCount = 0; vkGetPhysicalDevicePresentRectanglesKHR(physicalDevice, surface, &rectCount, null).CheckResult(); ReadOnlySpan <VkRect2D> rects = new VkRect2D[rectCount]; fixed(VkRect2D *rectsPtr = rects) { vkGetPhysicalDevicePresentRectanglesKHR(physicalDevice, surface, &rectCount, rectsPtr).CheckResult(); } return(rects); }
public override void Draw(RenderContext rc, CommandBuffer cmd) { var view = View; if (view.Camera == null) { return; } UpdateCascades(view); UpdateUniformBuffers(view); casters[0].Clear(); casters[1].Clear(); casters[2].Clear(); shadowCasterQuery.Init(view.Camera, Drawable.DRAWABLE_ANY, view.ViewMask); view.Scene.GetDrawables(shadowCasterQuery, (drawable) => { if (drawable.CastShadows) { foreach (SourceBatch batch in drawable.Batches) { casters[batch.material.blendType].Add(batch); if (batch.frameNum != view.Frame.frameNumber) { batch.frameNum = view.Frame.frameNumber; batch.offset = FrameGraph.GetTransform(batch.worldTransform, (uint)batch.numWorldTransforms); } } } }); VkClearValue[] clearDepth = { new VkClearDepthStencilValue(1.0f, 0) }; if (RenderPass == null) { CreateRenderPass(); CreateRenderTargets(); } //todo:multi thread for (int i = 0; i < SHADOW_MAP_CASCADE_COUNT; i++) { VkViewport viewport = new VkViewport(0, 0, SHADOWMAP_DIM, SHADOWMAP_DIM, 0.0f, 1.0f); VkRect2D renderArea = new VkRect2D(0, 0, SHADOWMAP_DIM, SHADOWMAP_DIM); BeginRenderPass(cmd, cascades[i].frameBuffer, renderArea, clearDepth); cmd.SetViewport(viewport); cmd.SetScissor(renderArea); uint cascade = (uint)i; Span <ConstBlock> consts = stackalloc ConstBlock[] { new ConstBlock(VkShaderStageFlags.Vertex, 0, 4, Utilities.AsPointer(ref cascade)) }; foreach (var batch in casters[0]) { DrawBatch(cmd, passID, batch, consts, vsSet); } EndRenderPass(cmd); } } void DrawBatch(CommandBuffer cb, ulong passID, SourceBatch batch, Span <ConstBlock> pushConsts, DescriptorSet resourceSet) { var shader = batch.material.Shader; if ((passID & shader.passFlags) == 0) { return; } var pass = shader.GetPass(passID); var pipe = pass.GetGraphicsPipeline(RenderPass, 0, batch.geometry); cb.BindPipeline(VkPipelineBindPoint.Graphics, pipe); batch.Draw(cb, pushConsts, resourceSet, default, pass);
public static void vkCmdSetScissor(VkCommandBuffer commandBuffer, uint firstScissor, VkRect2D scissor) { vkCmdSetScissor(commandBuffer, firstScissor, 1, &scissor); }
public unsafe RenderPassBeginInfo(RenderPass renderPass, Framebuffer framebuffer, VkRect2D renderArea, Span <VkClearValue> clearValues) { this.renderPass = renderPass; fixed(VkClearValue *pClearValues = clearValues) { native = new VkRenderPassBeginInfo { sType = VkStructureType.RenderPassBeginInfo, renderPass = framebuffer.renderPass, framebuffer = framebuffer, renderArea = new VkRect2D(renderArea.offset, renderArea.extent), pClearValues = pClearValues, clearValueCount = (uint)clearValues.Length }; } }