当前位置: 首页>>代码示例>>C++>>正文


C++ CommandContext::GetCommandList方法代码示例

本文整理汇总了C++中CommandContext::GetCommandList方法的典型用法代码示例。如果您正苦于以下问题:C++ CommandContext::GetCommandList方法的具体用法?C++ CommandContext::GetCommandList怎么用?C++ CommandContext::GetCommandList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommandContext的用法示例。


在下文中一共展示了CommandContext::GetCommandList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GenerateMips

void GenerateMipsHelper::GenerateMips(RenderDeviceD3D12Impl *pRenderDeviceD3D12, TextureViewD3D12Impl *pTexView, CommandContext& Ctx)
{
    auto &ComputeCtx = Ctx.AsComputeContext();
    ComputeCtx.SetRootSignature(m_pGenerateMipsRS);
    auto *pTexture = pTexView->GetTexture();
    auto *pTexD3D12 = ValidatedCast<TextureD3D12Impl>( pTexture );
    auto &TexDesc = pTexture->GetDesc();
    auto *pSRV = pTexture->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE);
    auto *pSRVD3D12Impl = ValidatedCast<TextureViewD3D12Impl>(pSRV);
    auto SRVDescriptorHandle = pSRVD3D12Impl->GetCPUDescriptorHandle();

    Ctx.TransitionResource(pTexD3D12, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
    auto *pd3d12Device = pRenderDeviceD3D12->GetD3D12Device();

    for (uint32_t TopMip = 0; TopMip < TexDesc.MipLevels-1; )
    {
        uint32_t SrcWidth = TexDesc.Width >> TopMip;
        uint32_t SrcHeight = TexDesc.Height >> TopMip;
        uint32_t DstWidth = SrcWidth >> 1;
        uint32_t DstHeight = SrcHeight >> 1;

        // Determine if the first downsample is more than 2:1.  This happens whenever
        // the source width or height is odd.
        uint32_t NonPowerOfTwo = (SrcWidth & 1) | (SrcHeight & 1) << 1;
        if (TexDesc.Format == TEX_FORMAT_RGBA8_UNORM_SRGB)
            ComputeCtx.SetPipelineState(m_pGenerateMipsGammaPSO[NonPowerOfTwo]);
        else
            ComputeCtx.SetPipelineState(m_pGenerateMipsLinearPSO[NonPowerOfTwo]);

        // We can downsample up to four times, but if the ratio between levels is not
        // exactly 2:1, we have to shift our blend weights, which gets complicated or
        // expensive.  Maybe we can update the code later to compute sample weights for
        // each successive downsample.  We use _BitScanForward to count number of zeros
        // in the low bits.  Zeros indicate we can divide by two without truncating.
        uint32_t AdditionalMips;
        _BitScanForward((unsigned long*)&AdditionalMips, DstWidth | DstHeight);
        uint32_t NumMips = 1 + (AdditionalMips > 3 ? 3 : AdditionalMips);
        if (TopMip + NumMips > TexDesc.MipLevels-1)
            NumMips = TexDesc.MipLevels-1 - TopMip;

        // These are clamped to 1 after computing additional mips because clamped
        // dimensions should not limit us from downsampling multiple times.  (E.g.
        // 16x1 -> 8x1 -> 4x1 -> 2x1 -> 1x1.)
        if (DstWidth == 0)
            DstWidth = 1;
        if (DstHeight == 0)
            DstHeight = 1;

        D3D12_DESCRIPTOR_HEAP_TYPE HeapType = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
        auto DescriptorAlloc = Ctx.AllocateDynamicGPUVisibleDescriptor(HeapType, 5);
        CommandContext::ShaderDescriptorHeaps Heaps(DescriptorAlloc.GetDescriptorHeap());
        ComputeCtx.SetDescriptorHeaps(Heaps);
        Ctx.GetCommandList()->SetComputeRootDescriptorTable(1, DescriptorAlloc.GetGpuHandle(0));
        Ctx.GetCommandList()->SetComputeRootDescriptorTable(2, DescriptorAlloc.GetGpuHandle(1));
        struct RootCBData
        {
            Uint32 SrcMipLevel;	    // Texture level of source mip
            Uint32 NumMipLevels;	// Number of OutMips to write: [1, 4]
            float TexelSize[2];	    // 1.0 / OutMip1.Dimensions
        } CBData = {TopMip, NumMips, 1.0f / static_cast<float>(DstWidth), 1.0f / static_cast<float>(DstHeight)};
        Ctx.GetCommandList()->SetComputeRoot32BitConstants(0, 4, &CBData, 0);

        // TODO: Shouldn't we transition top mip to shader resource state?
        D3D12_CPU_DESCRIPTOR_HANDLE DstDescriptorRange = DescriptorAlloc.GetCpuHandle();
        UINT DstRangeSize = 1+NumMips;
        D3D12_CPU_DESCRIPTOR_HANDLE SrcDescriptorRanges[5] = {};
        SrcDescriptorRanges[0] = SRVDescriptorHandle;
        UINT SrcRangeSizes[5] = {1,1,1,1,1};
        for(Uint32 u=0; u < NumMips; ++u)
            SrcDescriptorRanges[1+u] = pTexD3D12->GetUAVDescriptorHandle(TopMip+u+1, 0);

        pd3d12Device->CopyDescriptors(1, &DstDescriptorRange, &DstRangeSize, 1+NumMips, SrcDescriptorRanges, SrcRangeSizes, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);

        ComputeCtx.Dispatch((DstWidth+7)/8, (DstHeight+7)/8);

        Ctx.InsertUAVBarrier(*pTexD3D12, *pTexD3D12);

        TopMip += NumMips;
    }
}
开发者ID:DiligentGraphics,项目名称:DiligentCore,代码行数:80,代码来源:GenerateMips.cpp


注:本文中的CommandContext::GetCommandList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。