public override Framebuffer CreateFramebuffer(ref FramebufferDescription description) { Framebuffer fb = Factory.CreateFramebuffer(ref description); DisposeCollector.Add(fb); return(fb); }
private void CreateFramebuffers() { if (_scFramebuffers != null) { for (int i = 0; i < _scFramebuffers.Length; i++) { _scFramebuffers[i]?.Dispose(); _scFramebuffers[i] = null; } Array.Clear(_scFramebuffers, 0, _scFramebuffers.Length); } Util.EnsureArrayMinimumSize(ref _scFramebuffers, (uint)_scImages.Length); Util.EnsureArrayMinimumSize(ref _scColorTextures, (uint)_scImages.Length); for (uint i = 0; i < _scImages.Length; i++) { VkTexture colorTex = new VkTexture( _gd, Math.Max(1, _scExtent.width), Math.Max(1, _scExtent.height), 1, 1, _scImageFormat, TextureUsage.RenderTarget, TextureSampleCount.Count1, _scImages[i]); FramebufferDescription desc = new FramebufferDescription(_depthAttachment?.Target, colorTex); VkFramebuffer fb = new VkFramebuffer(_gd, ref desc, true); _scFramebuffers[i] = fb; _scColorTextures[i] = new FramebufferAttachment[] { new FramebufferAttachment(colorTex, 0) }; } }
public D3D11Framebuffer(Device device, ref FramebufferDescription description) : base(description.DepthTarget, description.ColorTargets) { if (description.DepthTarget != null) { D3D11Texture d3dDepthTarget = Util.AssertSubtype <Texture, D3D11Texture>(description.DepthTarget); DepthStencilViewDescription dsvDesc = new DepthStencilViewDescription() { Dimension = DepthStencilViewDimension.Texture2D, Format = D3D11Formats.GetDepthFormat(d3dDepthTarget.Format) }; DepthStencilView = new DepthStencilView(device, d3dDepthTarget.DeviceTexture, dsvDesc); } if (description.ColorTargets != null && description.ColorTargets.Length > 0) { RenderTargetViews = new RenderTargetView[description.ColorTargets.Length]; for (int i = 0; i < RenderTargetViews.Length; i++) { D3D11Texture d3dColorTarget = Util.AssertSubtype <Texture, D3D11Texture>(description.ColorTargets[i]); RenderTargetViewDescription rtvDesc = new RenderTargetViewDescription { Format = D3D11Formats.ToDxgiFormat(d3dColorTarget.Format, false), Dimension = RenderTargetViewDimension.Texture2D, }; RenderTargetViews[i] = new RenderTargetView(device, d3dColorTarget.DeviceTexture, rtvDesc); } } else { RenderTargetViews = Array.Empty <RenderTargetView>(); } }
public static Framebuffer CreateFramebuffer(GraphicsDevice device, uint resolutionX, uint resolutionY, PixelFormat pixelFormat) { var drawTrgt = device.ResourceFactory.CreateTexture( new TextureDescription(resolutionX, resolutionY, 1, 1, 1, pixelFormat, TextureUsage.RenderTarget | TextureUsage.Sampled | TextureUsage.Storage, TextureType.Texture2D) ); var depthTrgt = device.ResourceFactory.CreateTexture( new TextureDescription(resolutionY, resolutionY, 1, 1, 1, PixelFormat.R32_Float, TextureUsage.DepthStencil, TextureType.Texture2D) ); FramebufferAttachmentDescription[] cltTrgs = new FramebufferAttachmentDescription[1] { new FramebufferAttachmentDescription() { ArrayLayer = 0, MipLevel = 0, Target = drawTrgt } }; FramebufferAttachmentDescription depTrg = new FramebufferAttachmentDescription() { ArrayLayer = 0, MipLevel = 0, Target = depthTrgt }; var frameBuffDesc = new FramebufferDescription() { ColorTargets = cltTrgs, //DepthTarget = depTrg }; var offscreenBuffer = device.ResourceFactory.CreateFramebuffer(frameBuffDesc); return(offscreenBuffer); }
protected override Framebuffer CreateFramebuffer(global::Veldrid.GraphicsDevice device) { if (device == null) { throw new System.ArgumentNullException(nameof(device)); } Depth.DeviceTexture = device.ResourceFactory.CreateTexture(new TextureDescription( Width, Height, 1, 1, 1, global::Veldrid.PixelFormat.R32_Float, TextureUsage.DepthStencil, TextureType.Texture2D)); Depth.DeviceTexture.Name = Depth.Name; Color.DeviceTexture = device.ResourceFactory.CreateTexture(new TextureDescription( Width, Height, 1, 1, 1, global::Veldrid.PixelFormat.B8_G8_R8_A8_UNorm, TextureUsage.RenderTarget | TextureUsage.Sampled, TextureType.Texture2D)); Color.DeviceTexture.Name = Color.Name; var description = new FramebufferDescription(Depth.DeviceTexture, Color.DeviceTexture); var framebuffer = device.ResourceFactory.CreateFramebuffer(ref description); framebuffer.Name = Name; return(framebuffer); }
private void RecreateSwapchainFramebuffer(int width, int height) { // NOTE: Perhaps this should be deferred until all CommandLists naturally remove their references to the swapchain. // The actual resize could be done in ExecuteCommands() when it is found that this list is empty. foreach (D3D11CommandList d3dCL in CommandListsReferencingSwapchain) { d3dCL.Reset(); } _swapChainFramebuffer?.Dispose(); _swapChain.ResizeBuffers(2, width, height, Format.B8G8R8A8_UNorm, SwapChainFlags.None); // Get the backbuffer from the swapchain using (SharpDX.Direct3D11.Texture2D backBufferTexture = _swapChain.GetBackBuffer <SharpDX.Direct3D11.Texture2D>(0)) using (SharpDX.Direct3D11.Texture2D depthBufferTexture = new SharpDX.Direct3D11.Texture2D( _device, new Texture2DDescription() { Format = Format.D16_UNorm, ArraySize = 1, MipLevels = 1, Width = backBufferTexture.Description.Width, Height = backBufferTexture.Description.Height, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, BindFlags = BindFlags.DepthStencil, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None })) { D3D11Texture backBufferVdTexture = new D3D11Texture(backBufferTexture); D3D11Texture depthVdTexture = new D3D11Texture(depthBufferTexture); FramebufferDescription desc = new FramebufferDescription(depthVdTexture, backBufferVdTexture); _swapChainFramebuffer = new D3D11Framebuffer(_device, ref desc); _swapChainFramebuffer.IsSwapchainFramebuffer = true; } }
private void CreateFramebuffers() { if (_scFramebuffers != null) { for (int i = 0; i < _scFramebuffers.Length; i++) { _scFramebuffers[i]?.Dispose(); _scFramebuffers[i] = null; } Array.Clear(_scFramebuffers, 0, _scFramebuffers.Length); } EnsureSize(ref _scFramebuffers, _scImages.Length); EnsureSize(ref _scColorTextures, _scImages.Length); for (uint i = 0; i < _scImages.Length; i++) { VkTexture colorTex = new VkTexture(_gd, _scExtent.width, _scExtent.height, 1, 1, _scImageFormat, TextureUsage.RenderTarget, _scImages[i]); FramebufferDescription desc = new FramebufferDescription(_depthTexture, colorTex); VkFramebuffer fb = (VkFramebuffer)_gd.ResourceFactory.CreateFramebuffer(ref desc); _scFramebuffers[i] = fb; _scColorTextures[i] = new VkTexture[] { colorTex }; } }
/// <summary> /// Creates a new <see cref="Framebuffer"/>. /// </summary> /// <param name="description">The desired properties of the created object.</param> /// <returns>A new <see cref="Framebuffer"/>.</returns> public abstract Framebuffer CreateFramebuffer(ref FramebufferDescription description);
public override Framebuffer CreateFramebuffer(ref FramebufferDescription description) { return(new OpenGLFramebuffer(_gd, ref description)); }
internal void RecreateWindowSizedResources(GraphicsDevice gd, CommandList cl) { MainSceneColorTexture?.Dispose(); MainSceneDepthTexture?.Dispose(); MainSceneResolvedColorTexture?.Dispose(); MainSceneResolvedColorView?.Dispose(); MainSceneViewResourceSet?.Dispose(); MainSceneFramebuffer?.Dispose(); DuplicatorTarget0?.Dispose(); DuplicatorTarget1?.Dispose(); DuplicatorTargetView0?.Dispose(); DuplicatorTargetView1?.Dispose(); DuplicatorTargetSet0?.Dispose(); DuplicatorTargetSet1?.Dispose(); DuplicatorFramebuffer?.Dispose(); ResourceFactory factory = gd.ResourceFactory; TextureSampleCount mainSceneSampleCountCapped = (TextureSampleCount)Math.Min( (int)gd.GetSampleCountLimit(PixelFormat.R8_G8_B8_A8_UNorm, false), (int)MainSceneSampleCount); TextureDescription mainColorDesc = TextureDescription.Texture2D( gd.SwapchainFramebuffer.Width, gd.SwapchainFramebuffer.Height, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.RenderTarget | TextureUsage.Sampled, mainSceneSampleCountCapped); MainSceneColorTexture = factory.CreateTexture(ref mainColorDesc); if (mainSceneSampleCountCapped != TextureSampleCount.Count1) { mainColorDesc.SampleCount = TextureSampleCount.Count1; MainSceneResolvedColorTexture = factory.CreateTexture(ref mainColorDesc); } else { MainSceneResolvedColorTexture = MainSceneColorTexture; } MainSceneResolvedColorView = factory.CreateTextureView(MainSceneResolvedColorTexture); MainSceneDepthTexture = factory.CreateTexture(TextureDescription.Texture2D( gd.SwapchainFramebuffer.Width, gd.SwapchainFramebuffer.Height, 1, 1, PixelFormat.R16_UNorm, TextureUsage.DepthStencil, mainSceneSampleCountCapped)); MainSceneFramebuffer = factory.CreateFramebuffer(new FramebufferDescription(MainSceneDepthTexture, MainSceneColorTexture)); MainSceneViewResourceSet = factory.CreateResourceSet(new ResourceSetDescription(TextureSamplerResourceLayout, MainSceneResolvedColorView, gd.PointSampler)); TextureDescription colorTargetDesc = TextureDescription.Texture2D( gd.SwapchainFramebuffer.Width, gd.SwapchainFramebuffer.Height, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.RenderTarget | TextureUsage.Sampled); DuplicatorTarget0 = factory.CreateTexture(ref colorTargetDesc); DuplicatorTargetView0 = factory.CreateTextureView(DuplicatorTarget0); DuplicatorTarget1 = factory.CreateTexture(ref colorTargetDesc); DuplicatorTargetView1 = factory.CreateTextureView(DuplicatorTarget1); DuplicatorTargetSet0 = factory.CreateResourceSet(new ResourceSetDescription(TextureSamplerResourceLayout, DuplicatorTargetView0, gd.PointSampler)); DuplicatorTargetSet1 = factory.CreateResourceSet(new ResourceSetDescription(TextureSamplerResourceLayout, DuplicatorTargetView1, gd.PointSampler)); FramebufferDescription fbDesc = new FramebufferDescription(null, DuplicatorTarget0, DuplicatorTarget1); DuplicatorFramebuffer = factory.CreateFramebuffer(ref fbDesc); }
/// <summary> /// Creates a new <see cref="Framebuffer"/>. /// </summary> /// <param name="description">The desired properties of the created object.</param> /// <returns>A new <see cref="Framebuffer"/>.</returns> public Framebuffer CreateFramebuffer(FramebufferDescription description) => CreateFramebuffer(ref description);
public D3D11Framebuffer(Device device, ref FramebufferDescription description) : base(description.DepthTarget, description.ColorTargets) { if (description.DepthTarget != null) { D3D11Texture d3dDepthTarget = Util.AssertSubtype <Texture, D3D11Texture>(description.DepthTarget.Value.Target); DepthStencilViewDescription dsvDesc = new DepthStencilViewDescription() { Format = D3D11Formats.GetDepthFormat(d3dDepthTarget.Format), }; if (d3dDepthTarget.ArrayLayers == 1) { if (d3dDepthTarget.SampleCount == TextureSampleCount.Count1) { dsvDesc.Dimension = DepthStencilViewDimension.Texture2D; dsvDesc.Texture2D.MipSlice = (int)description.DepthTarget.Value.MipLevel; } else { dsvDesc.Dimension = DepthStencilViewDimension.Texture2DMultisampled; } } else { if (d3dDepthTarget.SampleCount == TextureSampleCount.Count1) { dsvDesc.Dimension = DepthStencilViewDimension.Texture2DArray; dsvDesc.Texture2DArray.FirstArraySlice = (int)description.DepthTarget.Value.ArrayLayer; dsvDesc.Texture2DArray.ArraySize = 1; dsvDesc.Texture2DArray.MipSlice = (int)description.DepthTarget.Value.MipLevel; } else { dsvDesc.Dimension = DepthStencilViewDimension.Texture2DMultisampledArray; dsvDesc.Texture2DMSArray.FirstArraySlice = (int)description.DepthTarget.Value.ArrayLayer; dsvDesc.Texture2DMSArray.ArraySize = 1; } } DepthStencilView = new DepthStencilView(device, d3dDepthTarget.DeviceTexture, dsvDesc); } if (description.ColorTargets != null && description.ColorTargets.Length > 0) { RenderTargetViews = new RenderTargetView[description.ColorTargets.Length]; for (int i = 0; i < RenderTargetViews.Length; i++) { D3D11Texture d3dColorTarget = Util.AssertSubtype <Texture, D3D11Texture>(description.ColorTargets[i].Target); RenderTargetViewDescription rtvDesc = new RenderTargetViewDescription { Format = D3D11Formats.ToDxgiFormat(d3dColorTarget.Format, false), }; if (d3dColorTarget.ArrayLayers > 1 || (d3dColorTarget.Usage & TextureUsage.Cubemap) != 0) { if (d3dColorTarget.SampleCount == TextureSampleCount.Count1) { rtvDesc.Dimension = RenderTargetViewDimension.Texture2DArray; rtvDesc.Texture2DArray = new RenderTargetViewDescription.Texture2DArrayResource { ArraySize = 1, FirstArraySlice = (int)description.ColorTargets[i].ArrayLayer, MipSlice = (int)description.ColorTargets[i].MipLevel }; } else { rtvDesc.Dimension = RenderTargetViewDimension.Texture2DMultisampledArray; rtvDesc.Texture2DMSArray = new RenderTargetViewDescription.Texture2DMultisampledArrayResource { ArraySize = 1, FirstArraySlice = (int)description.ColorTargets[i].ArrayLayer }; } } else { if (d3dColorTarget.SampleCount == TextureSampleCount.Count1) { rtvDesc.Dimension = RenderTargetViewDimension.Texture2D; rtvDesc.Texture2D.MipSlice = (int)description.ColorTargets[i].MipLevel; } else { rtvDesc.Dimension = RenderTargetViewDimension.Texture2DMultisampled; } } RenderTargetViews[i] = new RenderTargetView(device, d3dColorTarget.DeviceTexture, rtvDesc); } } else { RenderTargetViews = Array.Empty <RenderTargetView>(); } }
public VkFramebuffer(VkGraphicsDevice gd, ref FramebufferDescription description, bool isPresented) : base(description.DepthTarget, description.ColorTargets) { _gd = gd; VkRenderPassCreateInfo renderPassCI = VkRenderPassCreateInfo.New(); StackList <VkAttachmentDescription> attachments = new StackList <VkAttachmentDescription>(); uint colorAttachmentCount = (uint)ColorTargets.Count; StackList <VkAttachmentReference> colorAttachmentRefs = new StackList <VkAttachmentReference>(); for (int i = 0; i < colorAttachmentCount; i++) { VkTexture vkColorTex = Util.AssertSubtype <Texture, VkTexture>(ColorTargets[i].Target); VkAttachmentDescription colorAttachmentDesc = new VkAttachmentDescription(); colorAttachmentDesc.format = vkColorTex.VkFormat; colorAttachmentDesc.samples = vkColorTex.VkSampleCount; colorAttachmentDesc.loadOp = VkAttachmentLoadOp.DontCare; colorAttachmentDesc.storeOp = VkAttachmentStoreOp.Store; colorAttachmentDesc.stencilLoadOp = VkAttachmentLoadOp.DontCare; colorAttachmentDesc.stencilStoreOp = VkAttachmentStoreOp.DontCare; colorAttachmentDesc.initialLayout = VkImageLayout.Undefined; colorAttachmentDesc.finalLayout = VkImageLayout.ColorAttachmentOptimal; attachments.Add(colorAttachmentDesc); VkAttachmentReference colorAttachmentRef = new VkAttachmentReference(); colorAttachmentRef.attachment = (uint)i; colorAttachmentRef.layout = VkImageLayout.ColorAttachmentOptimal; colorAttachmentRefs.Add(colorAttachmentRef); } VkAttachmentDescription depthAttachmentDesc = new VkAttachmentDescription(); VkAttachmentReference depthAttachmentRef = new VkAttachmentReference(); if (DepthTarget != null) { VkTexture vkDepthTex = Util.AssertSubtype <Texture, VkTexture>(DepthTarget.Value.Target); bool hasStencil = FormatHelpers.IsStencilFormat(vkDepthTex.Format); depthAttachmentDesc.format = vkDepthTex.VkFormat; depthAttachmentDesc.samples = vkDepthTex.VkSampleCount; depthAttachmentDesc.loadOp = VkAttachmentLoadOp.DontCare; depthAttachmentDesc.storeOp = VkAttachmentStoreOp.Store; depthAttachmentDesc.stencilLoadOp = VkAttachmentLoadOp.DontCare; depthAttachmentDesc.stencilStoreOp = hasStencil ? VkAttachmentStoreOp.Store : VkAttachmentStoreOp.DontCare; depthAttachmentDesc.initialLayout = VkImageLayout.Undefined; depthAttachmentDesc.finalLayout = VkImageLayout.DepthStencilAttachmentOptimal; depthAttachmentRef.attachment = (uint)description.ColorTargets.Length; depthAttachmentRef.layout = VkImageLayout.DepthStencilAttachmentOptimal; } VkSubpassDescription subpass = new VkSubpassDescription(); subpass.pipelineBindPoint = VkPipelineBindPoint.Graphics; if (ColorTargets.Count > 0) { subpass.colorAttachmentCount = colorAttachmentCount; subpass.pColorAttachments = (VkAttachmentReference *)colorAttachmentRefs.Data; } if (DepthTarget != null) { subpass.pDepthStencilAttachment = &depthAttachmentRef; attachments.Add(depthAttachmentDesc); } VkSubpassDependency subpassDependency = new VkSubpassDependency(); subpassDependency.srcSubpass = SubpassExternal; subpassDependency.srcStageMask = VkPipelineStageFlags.ColorAttachmentOutput; subpassDependency.dstStageMask = VkPipelineStageFlags.ColorAttachmentOutput; subpassDependency.dstAccessMask = VkAccessFlags.ColorAttachmentRead | VkAccessFlags.ColorAttachmentWrite; if (DepthTarget != null) { subpassDependency.dstAccessMask |= VkAccessFlags.DepthStencilAttachmentRead | VkAccessFlags.DepthStencilAttachmentWrite; } renderPassCI.attachmentCount = attachments.Count; renderPassCI.pAttachments = (VkAttachmentDescription *)attachments.Data; renderPassCI.subpassCount = 1; renderPassCI.pSubpasses = &subpass; renderPassCI.dependencyCount = 1; renderPassCI.pDependencies = &subpassDependency; VkResult creationResult = vkCreateRenderPass(_gd.Device, ref renderPassCI, null, out _renderPassNoClear); CheckResult(creationResult); for (int i = 0; i < colorAttachmentCount; i++) { attachments[i].loadOp = VkAttachmentLoadOp.Load; attachments[i].initialLayout = VkImageLayout.ColorAttachmentOptimal; } if (DepthTarget != null) { attachments[attachments.Count - 1].loadOp = VkAttachmentLoadOp.Load; attachments[attachments.Count - 1].initialLayout = VkImageLayout.DepthStencilAttachmentOptimal; bool hasStencil = FormatHelpers.IsStencilFormat(DepthTarget.Value.Target.Format); if (hasStencil) { attachments[attachments.Count - 1].stencilLoadOp = VkAttachmentLoadOp.Load; } } creationResult = vkCreateRenderPass(_gd.Device, ref renderPassCI, null, out _renderPassNoClearLoad); CheckResult(creationResult); // Load version if (DepthTarget != null) { attachments[attachments.Count - 1].loadOp = VkAttachmentLoadOp.Clear; attachments[attachments.Count - 1].initialLayout = VkImageLayout.Undefined; bool hasStencil = FormatHelpers.IsStencilFormat(DepthTarget.Value.Target.Format); if (hasStencil) { attachments[attachments.Count - 1].stencilLoadOp = VkAttachmentLoadOp.Clear; } } for (int i = 0; i < colorAttachmentCount; i++) { attachments[i].loadOp = VkAttachmentLoadOp.Clear; attachments[i].initialLayout = VkImageLayout.Undefined; } creationResult = vkCreateRenderPass(_gd.Device, ref renderPassCI, null, out _renderPassClear); CheckResult(creationResult); VkFramebufferCreateInfo fbCI = VkFramebufferCreateInfo.New(); uint fbAttachmentsCount = (uint)description.ColorTargets.Length; if (description.DepthTarget != null) { fbAttachmentsCount += 1; } VkImageView *fbAttachments = stackalloc VkImageView[(int)fbAttachmentsCount]; for (int i = 0; i < colorAttachmentCount; i++) { VkTexture vkColorTarget = Util.AssertSubtype <Texture, VkTexture>(description.ColorTargets[i].Target); VkImageViewCreateInfo imageViewCI = VkImageViewCreateInfo.New(); imageViewCI.image = vkColorTarget.OptimalDeviceImage; imageViewCI.format = vkColorTarget.VkFormat; imageViewCI.viewType = VkImageViewType.Image2D; imageViewCI.subresourceRange = new VkImageSubresourceRange( VkImageAspectFlags.Color, description.ColorTargets[i].MipLevel, 1, description.ColorTargets[i].ArrayLayer, 1); VkImageView *dest = (fbAttachments + i); VkResult result = vkCreateImageView(_gd.Device, ref imageViewCI, null, dest); CheckResult(result); _attachmentViews.Add(*dest); } // Depth if (description.DepthTarget != null) { VkTexture vkDepthTarget = Util.AssertSubtype <Texture, VkTexture>(description.DepthTarget.Value.Target); bool hasStencil = FormatHelpers.IsStencilFormat(vkDepthTarget.Format); VkImageViewCreateInfo depthViewCI = VkImageViewCreateInfo.New(); depthViewCI.image = vkDepthTarget.OptimalDeviceImage; depthViewCI.format = vkDepthTarget.VkFormat; depthViewCI.viewType = description.DepthTarget.Value.Target.ArrayLayers == 1 ? VkImageViewType.Image2D : VkImageViewType.Image2DArray; depthViewCI.subresourceRange = new VkImageSubresourceRange( hasStencil ? VkImageAspectFlags.Depth | VkImageAspectFlags.Stencil : VkImageAspectFlags.Depth, description.DepthTarget.Value.MipLevel, 1, description.DepthTarget.Value.ArrayLayer, 1); VkImageView *dest = (fbAttachments + (fbAttachmentsCount - 1)); VkResult result = vkCreateImageView(_gd.Device, ref depthViewCI, null, dest); CheckResult(result); _attachmentViews.Add(*dest); } Texture dimTex; uint mipLevel; if (ColorTargets.Count > 0) { dimTex = ColorTargets[0].Target; mipLevel = ColorTargets[0].MipLevel; } else { Debug.Assert(DepthTarget != null); dimTex = DepthTarget.Value.Target; mipLevel = DepthTarget.Value.MipLevel; } Util.GetMipDimensions( dimTex, mipLevel, out uint mipWidth, out uint mipHeight, out _); fbCI.width = mipWidth; fbCI.height = mipHeight; fbCI.attachmentCount = fbAttachmentsCount; fbCI.pAttachments = fbAttachments; fbCI.layers = 1; fbCI.renderPass = _renderPassNoClear; creationResult = vkCreateFramebuffer(_gd.Device, ref fbCI, null, out _deviceFramebuffer); CheckResult(creationResult); if (DepthTarget != null) { AttachmentCount += 1; } AttachmentCount += (uint)ColorTargets.Count; }
public Framebuffer CreateFramebuffer(FramebufferDescription framebufferDescription) => RawFactory?.CreateFramebuffer(framebufferDescription);
public WindowSizedSceneContext(GraphicsDevice gd, TextureSampleCount sampleCount) { _disposer.DisposeAll(); ResourceFactory factory = new DisposingResourceFactoryFacade(gd.ResourceFactory, _disposer); TextureSamplerResourceLayout = factory.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription( "SourceTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription( "SourceSampler", ResourceKind.Sampler, ShaderStages.Fragment))); TextureSamplerResourceLayout.Name = "RL_TextureSampler"; gd.GetPixelFormatSupport( PixelFormat.R16_G16_B16_A16_Float, TextureType.Texture2D, TextureUsage.RenderTarget, out PixelFormatProperties properties); while (!properties.IsSampleCountSupported(sampleCount)) { sampleCount--; } TextureDescription mainColorDesc = TextureDescription.Texture2D( gd.SwapchainFramebuffer.Width, gd.SwapchainFramebuffer.Height, 1, 1, PixelFormat.R16_G16_B16_A16_Float, TextureUsage.RenderTarget | TextureUsage.Sampled, sampleCount); MainSceneColorTexture = factory.CreateTexture(ref mainColorDesc); MainSceneColorTexture.Name = "T_MainSceneColor"; if (sampleCount != TextureSampleCount.Count1) { mainColorDesc.SampleCount = TextureSampleCount.Count1; MainSceneResolvedColorTexture = factory.CreateTexture(ref mainColorDesc); MainSceneResolvedColorTexture.Name = "T_MainSceneResolvedColor"; } else { MainSceneResolvedColorTexture = MainSceneColorTexture; } MainSceneResolvedColorView = factory.CreateTextureView(MainSceneResolvedColorTexture); MainSceneDepthTexture = factory.CreateTexture(TextureDescription.Texture2D( gd.SwapchainFramebuffer.Width, gd.SwapchainFramebuffer.Height, 1, 1, PixelFormat.R32_Float, TextureUsage.DepthStencil, sampleCount)); MainSceneFramebuffer = factory.CreateFramebuffer(new FramebufferDescription(MainSceneDepthTexture, MainSceneColorTexture)); MainSceneViewResourceSet = factory.CreateResourceSet( new ResourceSetDescription( TextureSamplerResourceLayout, MainSceneResolvedColorView, gd.PointSampler)); MainSceneResolvedColorView.Name = "TV_MainSceneResolvedColor"; MainSceneDepthTexture.Name = "T_MainSceneDepth"; MainSceneFramebuffer.Name = "FB_MainFrame"; MainSceneViewResourceSet.Name = "RS_MainFrame"; TextureDescription colorTargetDesc = TextureDescription.Texture2D( gd.SwapchainFramebuffer.Width, gd.SwapchainFramebuffer.Height, 1, 1, PixelFormat.R16_G16_B16_A16_Float, TextureUsage.RenderTarget | TextureUsage.Sampled); DuplicatorTarget0 = factory.CreateTexture(ref colorTargetDesc); DuplicatorTargetView0 = factory.CreateTextureView(DuplicatorTarget0); DuplicatorTargetSet0 = factory.CreateResourceSet(new ResourceSetDescription(TextureSamplerResourceLayout, DuplicatorTargetView0, gd.PointSampler)); DuplicatorTarget0.Name = "T_DuplicatorTarget"; DuplicatorTargetView0.Name = "TV_DuplicatorTarget"; DuplicatorTargetSet0.Name = "RS_DuplicatorTarget"; FramebufferDescription fbDesc = new FramebufferDescription(null, DuplicatorTarget0); DuplicatorFramebuffer = factory.CreateFramebuffer(ref fbDesc); DuplicatorFramebuffer.Name = "FB_Duplicator"; }
public MTLFramebufferBase(MTLGraphicsDevice gd, ref FramebufferDescription description) : base(description.DepthTarget, description.ColorTargets) { }
public override Framebuffer CreateFramebuffer(ref FramebufferDescription description) => Track(_factory.CreateFramebuffer(description));
public override Framebuffer CreateFramebuffer(ref FramebufferDescription description) { return(new VkFramebuffer(_gd, ref description, false)); }
public MTLFramebuffer(MTLGraphicsDevice gd, ref FramebufferDescription description) : base(gd, ref description) { }
protected override Framebuffer GetFramebuffer() { var framebufferDesc = new FramebufferDescription(null, _texture); return(_factory.CreateFramebuffer(ref framebufferDesc)); }
public VkFramebuffer(VkGraphicsDevice gd, ref FramebufferDescription description) : base(description.DepthTarget, description.ColorTargets) { _gd = gd; VkRenderPassCreateInfo renderPassCI = VkRenderPassCreateInfo.New(); StackList <VkAttachmentDescription> attachments = new StackList <VkAttachmentDescription>(); uint colorAttachmentCount = (uint)ColorTextures.Count; StackList <VkAttachmentDescription> colorAttachmentDescriptions = new StackList <VkAttachmentDescription>(); StackList <VkAttachmentReference> colorAttachmentRefs = new StackList <VkAttachmentReference>(); for (int i = 0; i < colorAttachmentCount; i++) { VkTexture vkColorTex = Util.AssertSubtype <Texture, VkTexture>(ColorTextures[i]); VkAttachmentDescription colorAttachmentDesc = new VkAttachmentDescription(); colorAttachmentDesc.format = vkColorTex.VkFormat; colorAttachmentDesc.samples = VkSampleCountFlags.Count1; colorAttachmentDesc.loadOp = VkAttachmentLoadOp.DontCare; colorAttachmentDesc.storeOp = VkAttachmentStoreOp.Store; colorAttachmentDesc.stencilLoadOp = VkAttachmentLoadOp.DontCare; colorAttachmentDesc.stencilStoreOp = VkAttachmentStoreOp.DontCare; colorAttachmentDesc.initialLayout = VkImageLayout.Undefined; colorAttachmentDesc.finalLayout = VkImageLayout.PresentSrcKHR; colorAttachmentDescriptions.Add(colorAttachmentDesc); attachments.Add(colorAttachmentDesc); VkAttachmentReference colorAttachmentRef = new VkAttachmentReference(); colorAttachmentRef.attachment = (uint)i; colorAttachmentRef.layout = VkImageLayout.ColorAttachmentOptimal; colorAttachmentRefs.Add(colorAttachmentRef); } VkTexture vkDepthTex = Util.AssertSubtype <Texture, VkTexture>(DepthTexture); VkAttachmentDescription depthAttachmentDesc = new VkAttachmentDescription(); VkAttachmentReference depthAttachmentRef = new VkAttachmentReference(); if (vkDepthTex != null) { depthAttachmentDesc.format = vkDepthTex.VkFormat; depthAttachmentDesc.samples = VkSampleCountFlags.Count1; depthAttachmentDesc.loadOp = VkAttachmentLoadOp.DontCare; depthAttachmentDesc.storeOp = VkAttachmentStoreOp.Store; depthAttachmentDesc.stencilLoadOp = VkAttachmentLoadOp.DontCare; depthAttachmentDesc.stencilStoreOp = VkAttachmentStoreOp.DontCare; depthAttachmentDesc.initialLayout = VkImageLayout.Undefined; depthAttachmentDesc.finalLayout = VkImageLayout.ShaderReadOnlyOptimal; depthAttachmentRef.attachment = (uint)description.ColorTargets.Length; depthAttachmentRef.layout = VkImageLayout.DepthStencilAttachmentOptimal; } VkSubpassDescription subpass = new VkSubpassDescription(); subpass.pipelineBindPoint = VkPipelineBindPoint.Graphics; if (ColorTextures.Count > 0) { subpass.colorAttachmentCount = colorAttachmentCount; subpass.pColorAttachments = (VkAttachmentReference *)colorAttachmentRefs.Data; } if (DepthTexture != null) { subpass.pDepthStencilAttachment = &depthAttachmentRef; attachments.Add(depthAttachmentDesc); } VkSubpassDependency subpassDependency = new VkSubpassDependency(); subpassDependency.srcSubpass = SubpassExternal; subpassDependency.srcStageMask = VkPipelineStageFlags.ColorAttachmentOutput; subpassDependency.dstStageMask = VkPipelineStageFlags.ColorAttachmentOutput; subpassDependency.dstAccessMask = VkAccessFlags.ColorAttachmentRead | VkAccessFlags.ColorAttachmentWrite; if (DepthTexture != null) { subpassDependency.dstAccessMask |= VkAccessFlags.DepthStencilAttachmentRead | VkAccessFlags.DepthStencilAttachmentWrite; } renderPassCI.attachmentCount = attachments.Count; renderPassCI.pAttachments = (VkAttachmentDescription *)attachments.Data; renderPassCI.subpassCount = 1; renderPassCI.pSubpasses = &subpass; renderPassCI.dependencyCount = 1; renderPassCI.pDependencies = &subpassDependency; VkResult creationResult = vkCreateRenderPass(_gd.Device, ref renderPassCI, null, out _renderPass); CheckResult(creationResult); VkFramebufferCreateInfo fbCI = VkFramebufferCreateInfo.New(); uint fbAttachmentsCount = (uint)description.ColorTargets.Length; if (description.DepthTarget != null) { fbAttachmentsCount += 1; } VkImageView *fbAttachments = stackalloc VkImageView[(int)fbAttachmentsCount]; for (int i = 0; i < fbAttachmentsCount - 1; i++) { Texture colorTarget = description.ColorTargets[i]; VkTexture vkColorTarget = Util.AssertSubtype <Texture, VkTexture>(colorTarget); VkImageViewCreateInfo imageViewCI = VkImageViewCreateInfo.New(); imageViewCI.image = vkColorTarget.DeviceImage; imageViewCI.format = vkColorTarget.VkFormat; imageViewCI.viewType = VkImageViewType.Image2D; imageViewCI.subresourceRange = new VkImageSubresourceRange(VkImageAspectFlags.Color, 0, 1, 0, 1); VkImageView *dest = (fbAttachments + i); VkResult result = vkCreateImageView(_gd.Device, ref imageViewCI, null, dest); CheckResult(result); _attachmentViews.Add(*dest); } // Depth if (description.DepthTarget != null) { VkTexture vkDepthTarget = Util.AssertSubtype <Texture, VkTexture>(description.DepthTarget); VkImageViewCreateInfo depthViewCI = VkImageViewCreateInfo.New(); depthViewCI.image = vkDepthTarget.DeviceImage; depthViewCI.format = vkDepthTarget.VkFormat; depthViewCI.viewType = VkImageViewType.Image2D; depthViewCI.subresourceRange = new VkImageSubresourceRange(VkImageAspectFlags.Depth, 0, 1, 0, 1); VkImageView *dest = (fbAttachments + (fbAttachmentsCount - 1)); VkResult result = vkCreateImageView(_gd.Device, ref depthViewCI, null, dest); CheckResult(result); _attachmentViews.Add(*dest); } if (ColorTextures.Count > 0) { fbCI.width = ColorTextures[0].Width; fbCI.height = ColorTextures[0].Height; } else if (vkDepthTex != null) { fbCI.width = vkDepthTex.Width; fbCI.height = vkDepthTex.Height; } fbCI.attachmentCount = fbAttachmentsCount; fbCI.pAttachments = fbAttachments; fbCI.layers = 1; fbCI.renderPass = _renderPass; creationResult = vkCreateFramebuffer(_gd.Device, ref fbCI, null, out _deviceFramebuffer); CheckResult(creationResult); }
internal void RecreateWindowSizedResources(GraphicsDevice gd, CommandList cl) { MainSceneColorTexture?.Dispose(); MainSceneDepthTexture?.Dispose(); MainSceneResolvedColorTexture?.Dispose(); MainSceneResolvedColorView?.Dispose(); MainSceneViewResourceSet?.Dispose(); MainSceneFramebuffer?.Dispose(); DuplicatorTarget0?.Dispose(); DuplicatorTarget1?.Dispose(); DuplicatorTargetView0?.Dispose(); DuplicatorTargetView1?.Dispose(); DuplicatorTargetSet0?.Dispose(); DuplicatorTargetSet1?.Dispose(); DuplicatorFramebuffer?.Dispose(); ResourceFactory factory = gd.ResourceFactory; gd.GetPixelFormatSupport( PixelFormat.R8_G8_B8_A8_UNorm, TextureType.Texture2D, TextureUsage.RenderTarget, out PixelFormatProperties properties); TextureSampleCount sampleCount = MainSceneSampleCount; while (!properties.IsSampleCountSupported(sampleCount)) { sampleCount = (TextureSampleCount)(sampleCount - 1); } TextureDescription mainColorDesc = TextureDescription.Texture2D( gd.SwapchainFramebuffer.Width, gd.SwapchainFramebuffer.Height, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.RenderTarget | TextureUsage.Sampled, sampleCount); MainSceneColorTexture = factory.CreateTexture(ref mainColorDesc); if (sampleCount != TextureSampleCount.Count1) { mainColorDesc.SampleCount = TextureSampleCount.Count1; MainSceneResolvedColorTexture = factory.CreateTexture(ref mainColorDesc); } else { MainSceneResolvedColorTexture = MainSceneColorTexture; } MainSceneResolvedColorView = factory.CreateTextureView(MainSceneResolvedColorTexture); MainSceneDepthTexture = factory.CreateTexture(TextureDescription.Texture2D( gd.SwapchainFramebuffer.Width, gd.SwapchainFramebuffer.Height, 1, 1, PixelFormat.R32_Float, TextureUsage.DepthStencil, sampleCount)); MainSceneFramebuffer = factory.CreateFramebuffer(new FramebufferDescription(MainSceneDepthTexture, MainSceneColorTexture)); MainSceneViewResourceSet = factory.CreateResourceSet(new ResourceSetDescription(TextureSamplerResourceLayout, MainSceneResolvedColorView, gd.PointSampler)); TextureDescription colorTargetDesc = TextureDescription.Texture2D( gd.SwapchainFramebuffer.Width, gd.SwapchainFramebuffer.Height, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.RenderTarget | TextureUsage.Sampled); DuplicatorTarget0 = factory.CreateTexture(ref colorTargetDesc); DuplicatorTargetView0 = factory.CreateTextureView(DuplicatorTarget0); DuplicatorTarget1 = factory.CreateTexture(ref colorTargetDesc); DuplicatorTargetView1 = factory.CreateTextureView(DuplicatorTarget1); DuplicatorTargetSet0 = factory.CreateResourceSet(new ResourceSetDescription(TextureSamplerResourceLayout, DuplicatorTargetView0, gd.PointSampler)); DuplicatorTargetSet1 = factory.CreateResourceSet(new ResourceSetDescription(TextureSamplerResourceLayout, DuplicatorTargetView1, gd.PointSampler)); FramebufferDescription fbDesc = new FramebufferDescription(null, DuplicatorTarget0, DuplicatorTarget1); DuplicatorFramebuffer = factory.CreateFramebuffer(ref fbDesc); }
public override Framebuffer CreateFramebuffer(ref FramebufferDescription description) { return(new D3D11Framebuffer(_device, ref description)); }
public Framebuffer CreateFramebuffer(FramebufferDescription framebufferDescription) => _factory.CreateFramebuffer(framebufferDescription);