private void InitializeVertexDescriptor(MgPipelineVertexInputStateCreateInfo vertexInput) { { var noOfBindings = vertexInput.VertexBindingDescriptions.Length; Layouts = new AmtGraphicsPipelineVertexLayoutBinding[noOfBindings]; for (var i = 0; i < noOfBindings; ++i) { var binding = vertexInput.VertexBindingDescriptions[i]; Layouts[i] = new AmtGraphicsPipelineVertexLayoutBinding { Index = (nint)i, StepFunction = TranslateStepFunction(binding.InputRate), Stride = (nuint)binding.Stride, }; } } { var noOfAttributes = vertexInput.VertexAttributeDescriptions.Length; Attributes = new AmtGraphicsPipelineVertexAttribute[noOfAttributes]; for (var i = 0; i < noOfAttributes; ++i) { var attribute = vertexInput.VertexAttributeDescriptions[i]; Attributes[i] = new AmtGraphicsPipelineVertexAttribute { Index = (nint)i, Offset = attribute.Offset, BufferIndex = (nuint)attribute.Binding, Format = AmtFormatExtensions.GetVertexFormat(attribute.Format), }; } } }
public void InitializeFormat(MTLRenderPipelineDescriptor dest) { nint colorAttachmentIndex = 0; foreach (var attachment in ColorAttachments) { dest.ColorAttachments[colorAttachmentIndex].PixelFormat = AmtFormatExtensions.GetPixelFormat(attachment.Format); ++colorAttachmentIndex; } if (DepthStencil != null) { dest.DepthAttachmentPixelFormat = AmtFormatExtensions.GetPixelFormat(DepthStencil.Format); dest.StencilAttachmentPixelFormat = AmtFormatExtensions.GetPixelFormat(DepthStencil.Format); } }
public AmtImageView(MgImageViewCreateInfo pCreateInfo) { if (pCreateInfo == null) { throw new ArgumentNullException(nameof(pCreateInfo)); } if (pCreateInfo.Image == null) { throw new ArgumentNullException(nameof(pCreateInfo.Image)); } var bImage = (AmtImage)pCreateInfo.Image; mImageView = bImage.OriginalTexture.CreateTextureView( AmtFormatExtensions.GetPixelFormat(pCreateInfo.Format), TranslateTextureType(pCreateInfo.ViewType), GenerateLevelRange(pCreateInfo.SubresourceRange), GenerateSliceRange(pCreateInfo.SubresourceRange)); }
public Result CreateImage(MgImageCreateInfo pCreateInfo, IMgAllocationCallbacks allocator, out IMgImage pImage) { Debug.Assert(pCreateInfo != null); var depth = (nuint)pCreateInfo.Extent.Depth; var height = (nuint)pCreateInfo.Extent.Height; var width = (nuint)pCreateInfo.Extent.Width; var arrayLayers = (nuint)pCreateInfo.ArrayLayers; var mipLevels = (nuint)pCreateInfo.MipLevels; //TODO : Figure this out var storageMode = MTLStorageMode.Shared; var resourceOptions = MTLResourceOptions.CpuCacheModeDefault; var cpuCacheMode = MTLCpuCacheMode.DefaultCache; var descriptor = new MTLTextureDescriptor { ArrayLength = arrayLayers, PixelFormat = AmtFormatExtensions.GetPixelFormat(pCreateInfo.Format), SampleCount = AmtSampleCountFlagBitExtensions.TranslateSampleCount(pCreateInfo.Samples), TextureType = TranslateTextureType(pCreateInfo.ImageType), StorageMode = storageMode, Width = width, Height = height, Depth = depth, MipmapLevelCount = mipLevels, Usage = TranslateUsage(pCreateInfo.Usage), ResourceOptions = resourceOptions, CpuCacheMode = cpuCacheMode, }; var texture = mDevice.CreateTexture(descriptor); pImage = new AmtImage(texture); return(Result.SUCCESS); }
public void Create(IMgCommandBuffer setupCmdBuffer, IMgSwapchainCollection swapchainCollection, MgGraphicsDeviceCreateInfo dsCreateInfo) { if (dsCreateInfo == null) { throw new ArgumentNullException(nameof(dsCreateInfo)); } if (swapchainCollection == null) { throw new ArgumentNullException(nameof(swapchainCollection)); } mDeviceCreated = false; var colorFormat = AmtFormatExtensions.GetPixelFormat(dsCreateInfo.Color); var depthFormat = AmtFormatExtensions.GetPixelFormat(dsCreateInfo.DepthStencil); var sampleCount = AmtSampleCountFlagBitExtensions.TranslateSampleCount(dsCreateInfo.Samples); ReleaseUnmanagedResources(); mApplicationView.SampleCount = sampleCount; // FIXME : RUNTIME ISSUE WITH SETTING COLOR FORMAT; SHOULD "FIGURE" OUT APPROPRIATE COLOR FORMAT SOMEHOW mApplicationView.ColorPixelFormat = colorFormat; mApplicationView.DepthStencilPixelFormat = depthFormat; CreateDepthStencilImageView(); CreateRenderpass(dsCreateInfo); var bSwapchainCollection = (AmtSwapchainCollection)swapchainCollection; bSwapchainCollection.Format = dsCreateInfo.Color; bSwapchainCollection.Create(setupCmdBuffer, dsCreateInfo.Width, dsCreateInfo.Height); mFramebuffers.Create( swapchainCollection, mRenderpass, mDepthStencilView, dsCreateInfo.Width, dsCreateInfo.Height); Scissor = new MgRect2D { Extent = new MgExtent2D { Width = dsCreateInfo.Width, Height = dsCreateInfo.Height }, Offset = new MgOffset2D { X = 0, Y = 0 }, }; // initialise viewport CurrentViewport = new MgViewport { Width = dsCreateInfo.Width, Height = dsCreateInfo.Height, X = 0, Y = 0, MinDepth = 0f, MaxDepth = 1f, }; mDeviceCreated = true; }
void CreateRenderpass(MgGraphicsDeviceCreateInfo createInfo) { bool isStencilFormat = AmtFormatExtensions.IsStencilFormat(createInfo.DepthStencil); var attachments = new[] { // Color attachment[0] new MgAttachmentDescription { Format = createInfo.Color, // TODO : multisampling Samples = createInfo.Samples, LoadOp = MgAttachmentLoadOp.CLEAR, StoreOp = MgAttachmentStoreOp.STORE, StencilLoadOp = MgAttachmentLoadOp.DONT_CARE, StencilStoreOp = MgAttachmentStoreOp.DONT_CARE, InitialLayout = MgImageLayout.COLOR_ATTACHMENT_OPTIMAL, FinalLayout = MgImageLayout.COLOR_ATTACHMENT_OPTIMAL, }, // Depth attachment[1] new MgAttachmentDescription { Format = createInfo.DepthStencil, // TODO : multisampling Samples = createInfo.Samples, LoadOp = MgAttachmentLoadOp.CLEAR, StoreOp = MgAttachmentStoreOp.STORE, // activate stencil if needed StencilLoadOp = isStencilFormat ? MgAttachmentLoadOp.CLEAR : MgAttachmentLoadOp.DONT_CARE, StencilStoreOp = isStencilFormat ? MgAttachmentStoreOp.STORE : MgAttachmentStoreOp.DONT_CARE, InitialLayout = MgImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL, FinalLayout = MgImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL, } }; var colorReference = new MgAttachmentReference { Attachment = 0, Layout = MgImageLayout.COLOR_ATTACHMENT_OPTIMAL, }; var depthReference = new MgAttachmentReference { Attachment = 1, Layout = MgImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL, }; var subpass = new MgSubpassDescription { PipelineBindPoint = MgPipelineBindPoint.GRAPHICS, Flags = 0, InputAttachments = null, ColorAttachmentCount = 1, ColorAttachments = new[] { colorReference }, ResolveAttachments = null, DepthStencilAttachment = depthReference, PreserveAttachments = null, }; var renderPassInfo = new MgRenderPassCreateInfo { Attachments = attachments, Subpasses = new[] { subpass }, Dependencies = null, }; Result err; IMgRenderPass renderPass; err = mConfiguration.Device.CreateRenderPass(renderPassInfo, null, out renderPass); Debug.Assert(err == Result.SUCCESS, err + " != Result.SUCCESS"); mRenderpass = renderPass; }