Beispiel #1
0
        protected virtual ID3D12Resource *CreateDepthStencil()
        {
            ID3D12Resource *depthStencil;

            var heapProperties = new D3D12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);

            var resourceDesc = D3D12_RESOURCE_DESC.Tex2D(DepthBufferFormat, (uint)Size.Width, (uint)Size.Height, mipLevels: 1);

            resourceDesc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;

            var clearValue = new D3D12_CLEAR_VALUE(DepthBufferFormat, 1.0f, 0);

            var iid = IID_ID3D12Resource;

            ThrowIfFailed(nameof(ID3D12Device.CreateCommittedResource), D3DDevice->CreateCommittedResource(&heapProperties, D3D12_HEAP_FLAG_NONE, &resourceDesc, D3D12_RESOURCE_STATE_DEPTH_WRITE, &clearValue, &iid, (void **)&depthStencil));

            var dsvDesc = new D3D12_DEPTH_STENCIL_VIEW_DESC {
                Format        = DepthBufferFormat,
                ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D,
            };

            D3DDevice->CreateDepthStencilView(depthStencil, &dsvDesc, DSVHeap->GetCPUDescriptorHandleForHeapStart());

            return(depthStencil);
        }
Beispiel #2
0
        private Pointer <ID3D12Resource> CreateD3D12Resource()
        {
            _state.ThrowIfDisposedOrDisposing();

            ID3D12Resource *d3d12Resource;

            var textureDesc = Kind switch {
                GraphicsTextureKind.OneDimensional => D3D12_RESOURCE_DESC.Tex1D(DXGI_FORMAT_R8G8B8A8_UNORM, Width, mipLevels: 1),
                GraphicsTextureKind.TwoDimensional => D3D12_RESOURCE_DESC.Tex2D(DXGI_FORMAT_R8G8B8A8_UNORM, Width, Height, mipLevels: 1),
                GraphicsTextureKind.ThreeDimensional => D3D12_RESOURCE_DESC.Tex3D(DXGI_FORMAT_R8G8B8A8_UNORM, Width, Height, Depth, mipLevels: 1),
                _ => default,
    protected override ID3D12Resource *CreateDepthStencil()
    {
        ID3D12Resource *depthStencil;

        var heapProperties = new D3D12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);

        var resourceDesc = D3D12_RESOURCE_DESC.Tex2D(DepthBufferFormat, (uint)Size.Width, (uint)Size.Height, 1, 1, _msaaDesc.Count, _msaaDesc.Quality);

        resourceDesc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;

        var clearValue = new D3D12_CLEAR_VALUE(DepthBufferFormat, 1.0f, 0);

        ThrowIfFailed(D3DDevice->CreateCommittedResource(&heapProperties, D3D12_HEAP_FLAG_NONE, &resourceDesc, D3D12_RESOURCE_STATE_DEPTH_WRITE, &clearValue, __uuidof <ID3D12Resource>(), (void **)&depthStencil));

        var dsvDesc = new D3D12_DEPTH_STENCIL_VIEW_DESC {
            Format        = DepthBufferFormat,
            ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DMS
        };

        D3DDevice->CreateDepthStencilView(depthStencil, &dsvDesc, DSVHeap->GetCPUDescriptorHandleForHeapStart());

        return(depthStencil);
    }
Beispiel #4
0
 /// <summary>
 /// Creates a new <see cref="GpuResourceFormat"/> representing a depth stencil
 /// </summary>
 /// <param name="format">The format of the depth stencil</param>
 /// <param name="width">The width of the depth stencil</param>
 /// <param name="height">The height of the depth stencil</param>
 /// <returns>A new <see cref="GpuResourceFormat"/> representing a depth stencil</returns>
 public static GpuResourceFormat DepthStencil(DXGI_FORMAT format, ulong width, uint height)
 {
     return(new GpuResourceFormat(D3D12_RESOURCE_DESC.Tex2D(format, width, height, mipLevels: 1, flags: D3D12_RESOURCE_FLAGS.D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)));
 }