語法
void BuildRaytracingAccelerationStructureBatched2X(
UINT NumBuildDescs,
const D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_BATCHED_DESC2* pDescs
)
參數
NumBuildDescs _In_類型:UINT 建置描述的數目 pDescs _In_
類型:D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_BATCHED_DESC2* 建置描述
傳回值
類型:void備註
範例 1. 執行階段建置器範例:設定多個 ExtraOptions 值,並配置正確數量的暫存空間。D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC topLevelAccelerationStructureDesc = {};
D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS& topLevelInputs = topLevelAccelerationStructureDesc.Inputs;
// The BuildRaytracingAccelerationStructureBatched2X API can build BLASes, TLASes, or both.
// Some ExtraOptions parameters only apply to one type of build and will be ignored in the other.
topLevelInputs.Type = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL;
topLevelInputs.NumDescs = UINT(instanceDescs.size());
topLevelInputs.InstanceDescs = m_instanceDescs.GetGpuVirtualAddress();
topLevelInputs.DescsLayout = D3D12_ELEMENTS_LAYOUT_ARRAY;
// NOTE: the flag chosen here will still have an effect for options which are left at defaults.
// Some options may override the behaviour from this flag.
topLevelInputs.Flags = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_PREFER_FAST_TRACE;
struct
{
D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_PARAMS1 params1;
D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_PARAMS2 params2;
D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_PARAMS3 params3;
} options;
// NOTE: D3D12XboxMakeDefault_* must be used here instead of zero-initializing these structs.
// Default values are not always zero and may contain special values to instruct the driver to rely on the topLevelInputs.Flags value instead.
D3D12XboxMakeDefault_D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_PARAMS1(&options.params1);
D3D12XboxMakeDefault_D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_PARAMS2(&options.params2);
D3D12XboxMakeDefault_D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_PARAMS3(&options.params3);
// Modify options relating to treelet reordering.
options.params1.TreeletFirstLevel = 1;
options.params1.TreeletNumLevels = 64;
options.params1.TreeletStepSizeBetweenRounds = 1;
options.params1.TreeletRoundsLimiter = 2; // Very expensive
// Increase the memory budget for splitting instances.
options.params3.NumExtraElementsForInstanceSplitting = (UINT)(instanceDescs.size() * 0.5f);
// Modify the percentage of extra memory devoted to splitting instances into 16 pieces instead of 4 pieces.
options.params3.InstanceSplit16Fraction = 0.3f;
// See the doc pages dedicated to D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_PARAMS* structs for more information and parameter descriptions.
D3D12XBOX_XDXR_STREAM_DESC streamDesc;
streamDesc.pXdxrStreamDesc = &options;
streamDesc.SizeInBytes = sizeof(options);
// NOTE: This function must be used in place of GetRaytracingAccelerationStructurePrebuildInfo when using ExtraOptions.
// Using GetRaytracingAccelerationStructurePrebuildInfo will result in heap corruption and hangs.
g_Device->GetRaytracingAccelerationStructurePrebuildInfoX(&topLevelInputs, &streamDesc, &m_topLevelPrebuildInfoCurrentFrame);
m_tlas.Create(L"TLAS", UINT(m_topLevelPrebuildInfoCurrentFrame.ResultDataMaxSizeInBytes), 1, nullptr, D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE);
m_tlasScratchBuffer.Create(L"Acceleration Structure Scratch Buffer", UINT(m_topLevelPrebuildInfoCurrentFrame.ScratchDataSizeInBytes), 1);
topLevelAccelerationStructureDesc.ScratchAccelerationStructureData = m_tlasScratchBuffer.GetGpuVirtualAddress();
topLevelAccelerationStructureDesc.DestAccelerationStructureData = m_tlas->GetGPUVirtualAddress();
D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_BATCHED_DESC2 desc = {};
desc.Desc = topLevelAccelerationStructureDesc;
desc.ExtraOptions = streamDesc;
pRaytracingCommandList->BuildRaytracingAccelerationStructureBatched2X(1, &desc);
D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_COMPACTED_SIZE_DESC sizeA;
D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_COMPACTED_SIZE_DESC sizeB;
D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC blasBuildInfo {};
blasBuildInfo.InfoType = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_COMPACTED_SIZE;
blasBuildInfo.DestBuffer = (D3D12_GPU_VIRTUAL_ADDRESS)&sizeA;
// Set special options
struct
{
D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_PARAMS1 params1;
D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_PARAMS2 params2;
} options;
D3D12XboxMakeDefault_D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_PARAMS1(&options.params1);
D3D12XboxMakeDefault_D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_PARAMS2(&options.params2);
options.params1.QuadJoinThreshold = 0; // Disallow quads
options.params2.TriangleSplitFactor = 3; // Huge split, may actually slow it down
// Access via a batched build
D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_BATCHED_DESC2 blasBatchedBuild {};
blasBatchedBuild.Desc = buildDesc;
blasBatchedBuild.NumPostbuildInfoDescs = 1;
blasBatchedBuild.pPostbuildInfoDescs = &blasBuildInfo;
blasBatchedBuild.ExtraOptions.SizeInBytes = sizeof(options);
blasBatchedBuild.ExtraOptions.pXdxrStreamDesc = &options;
// Build acceleration structure.
m_CommandList->BuildRaytracingAccelerationStructureBatched2X(1, &blasBatchedBuild);
SubmitPendingAndWait();
// Set it to smaller build
options.params1.QuadJoinThreshold = 2; // Allow generous quads (packs trees better)
options.params2.TriangleSplitFactor = 1; // Disallow splits (no extra nodes)
blasBuildInfo.DestBuffer = (D3D12_GPU_VIRTUAL_ADDRESS)&sizeB;
// Build acceleration structure.
m_CommandList->BuildRaytracingAccelerationStructureBatched2X(1, &blasBatchedBuild);
SubmitPendingAndWait();
需求
標頭: d3d12_xs.h 程式庫: d3d12_xs.lib支援的平台: XBOX Series 主機
另請參閱
D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_PARAMS1D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_PARAMS2
D3D12XBOX_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_PARAMS3
ID3D12GraphicsCommandList6
