예제 #1
0
    internal GraphicsRenderTarget(GraphicsSwapchain swapchain, int index) : base(swapchain)
    {
        _index = index;

        _d3d12RtvDescriptorHandle = GetD3D12RtvDescriptorHandle();

        var d3d12RtvResource = CreateD3D12RtvResource(out _d3d12RtvResourceVersion);

        _d3d12RtvResource.Attach(d3d12RtvResource);

        ID3D12Resource *CreateD3D12RtvResource(out uint d3d12RtvResourceVersion)
        {
            var d3d12RenderTargetViewDesc = new D3D12_RENDER_TARGET_VIEW_DESC {
                Format        = swapchain.RenderTargetFormat.AsDxgiFormat(),
                ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D,
                Texture2D     = new D3D12_TEX2D_RTV()
            };

            ID3D12Resource *d3d12RtvResource;

            ThrowExternalExceptionIfFailed(swapchain.DxgiSwapchain->GetBuffer((uint)_index, __uuidof <ID3D12Resource>(), (void **)&d3d12RtvResource));

            swapchain.Device.D3D12Device->CreateRenderTargetView(d3d12RtvResource, &d3d12RenderTargetViewDesc, _d3d12RtvDescriptorHandle);
            return(GetLatestD3D12Resource(d3d12RtvResource, out d3d12RtvResourceVersion));
        }

        D3D12_CPU_DESCRIPTOR_HANDLE GetD3D12RtvDescriptorHandle()
        {
            var d3d12RtvDescriptorHandleIncrementSize = Device.D3D12RtvDescriptorSize;
            var d3d12RtvDescriptorHandleForHeapStart  = Swapchain.D3D12RtvDescriptorHeap->GetCPUDescriptorHandleForHeapStart();

            D3D12_CPU_DESCRIPTOR_HANDLE.InitOffsetted(out var d3d12RtvDescriptorHandle, d3d12RtvDescriptorHandleForHeapStart, _index, d3d12RtvDescriptorHandleIncrementSize);
            return(d3d12RtvDescriptorHandle);
        }
    }
 /// <summary>Initializes a new instance of the <see cref="GraphicsSwapchainObject" /> class.</summary>
 /// <param name="swapchain">The swapchain for which the object is being created.</param>
 /// <param name="name">The name of the object or <c>null</c> to use <see cref="MemberInfo.Name" />.</param>
 /// <exception cref="ArgumentNullException"><paramref name="swapchain" /> is <c>null</c>.</exception>
 protected GraphicsSwapchainObject(GraphicsSwapchain swapchain, string?name = null) : base(swapchain.RenderPass, name)
 {
     _swapchain = swapchain;
 }