MCPcopy Create free account
hub / github.com/GPUOpen-Effects/TressFX / CreateBindSet

Method CreateBindSet

src/DX12/DX12EngineInterfaceImpl.cpp:549–610  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

547}
548
549std::unique_ptr<EI_BindSet> EI_Device::CreateBindSet(EI_BindLayout* layout, EI_BindSetDescription& bindSet)
550{
551 EI_BindSet* result = new EI_BindSet;
552 assert(layout->layoutBindings.size() == bindSet.resources.size());
553
554 UINT numTotalSlotsNeededInDeScriptorTable = 0;
555 int numBindings = (int)layout->layoutBindings.size();
556
557 // On DX12, we can't mix samplers with other resource types, so validate that all resources in the bind set are all samplers, or all other
558 bool IsSamplerBindSet = (bindSet.resources[0]->m_ResourceType == EI_ResourceType::Sampler);
559
560 for (int i = 0; i < numBindings; i++)
561 {
562 UINT numSlotsNeededInDeScriptorTable = layout->layoutBindings[i].BaseShaderRegister + layout->layoutBindings[i].NumDescriptors;
563 if (numSlotsNeededInDeScriptorTable > numTotalSlotsNeededInDeScriptorTable)
564 numTotalSlotsNeededInDeScriptorTable = numSlotsNeededInDeScriptorTable;
565 assert(!IsSamplerBindSet || (IsSamplerBindSet && bindSet.resources[i]->m_ResourceType == EI_ResourceType::Sampler) && "Samplers cannot be mixed with other resource types. Please re-organize your layout/bindset");
566 }
567
568 if (!IsSamplerBindSet)
569 m_resourceViewHeaps.AllocCBV_SRV_UAVDescriptor(numTotalSlotsNeededInDeScriptorTable, static_cast<CAULDRON_DX12::CBV_SRV_UAV*>(&result->descriptorTable));
570 else
571 m_resourceViewHeaps.AllocSamplerDescriptor(numTotalSlotsNeededInDeScriptorTable, static_cast<CAULDRON_DX12::SAMPLER*>(&result->descriptorTable));
572
573 for (int i = 0; i < numBindings; i++)
574 {
575 assert(layout->layoutBindings[i].NumDescriptors == 1);
576 UINT descriptorIdx = i;
577 switch (layout->description.resources[i].type)
578 {
579 case EI_RESOURCETYPE_BUFFER_RW:
580 bindSet.resources[i]->m_pBuffer->CreateUAV(descriptorIdx, static_cast<CAULDRON_DX12::CBV_SRV_UAV*>(&result->descriptorTable));
581 break;
582 case EI_RESOURCETYPE_BUFFER_RO:
583 bindSet.resources[i]->m_pBuffer->CreateSRV(descriptorIdx, static_cast<CAULDRON_DX12::CBV_SRV_UAV*>(&result->descriptorTable));
584 break;
585 case EI_RESOURCETYPE_IMAGE_RW:
586 if (bindSet.resources[i]->m_ResourceType == EI_ResourceType::Buffer)
587 bindSet.resources[i]->m_pBuffer->CreateUAV(descriptorIdx, &result->descriptorTable); // Override the descriptor pointers used with our own which are properly allocated for clearing/writing
588 else
589 bindSet.resources[i]->m_pTexture->CreateUAV(descriptorIdx, static_cast<CAULDRON_DX12::CBV_SRV_UAV*>(&result->descriptorTable));
590 break;
591 case EI_RESOURCETYPE_IMAGE_RO:
592 if (bindSet.resources[i]->m_ResourceType == EI_ResourceType::Buffer)
593 bindSet.resources[i]->m_pBuffer->CreateSRV(descriptorIdx, &result->descriptorTable); // Override the descriptor pointers used with our own which are properly allocated for clearing/writing
594 else
595 bindSet.resources[i]->m_pTexture->CreateSRV(descriptorIdx, static_cast<CAULDRON_DX12::CBV_SRV_UAV*>(&result->descriptorTable), 0);
596 break;
597 case EI_RESOURCETYPE_UNIFORM:
598 bindSet.resources[i]->m_pBuffer->CreateCBV(descriptorIdx, static_cast<CAULDRON_DX12::CBV_SRV_UAV*>(&result->descriptorTable));
599 break;
600 case EI_RESOURCETYPE_SAMPLER:
601 m_device.GetDevice()->CreateSampler(&bindSet.resources[i]->samplerDesc, static_cast<CAULDRON_DX12::SAMPLER*>(&result->descriptorTable)->GetCPU());
602 break;
603 default:
604 assert(0);
605 break;
606 }

Callers

nothing calls this directly

Calls 4

CreateUAVMethod · 0.80
CreateSRVMethod · 0.80
CreateCBVMethod · 0.80
CreateSamplerMethod · 0.45

Tested by

no test coverage detected