@@ -2854,6 +2854,7 @@ auto CAssetConverter::reserve(const SInputs& inputs) -> SReserveResult
2854
2854
{
2855
2855
const uint32_t * pPrimitiveCounts = as->getGeometryPrimitiveCounts ().data ();
2856
2856
// the code here is not pretty, but DRY-ing is of this is for later
2857
+ // TODO: ILogicalDevice needs code to query build sizes of ICPUBottomLevelAccelerationStructure geometries!
2857
2858
if (buildFlags.hasFlags (ICPUBottomLevelAccelerationStructure::BUILD_FLAGS::GEOMETRY_TYPE_IS_AABB_BIT))
2858
2859
{
2859
2860
const auto geoms = as->getAABBGeometries ();
@@ -4890,9 +4891,9 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
4890
4891
}
4891
4892
allocOffsets.resize (allocSizes.size (),scratch_allocator_t ::invalid_value);
4892
4893
// allocate out scratch or submit overflow, if fail then flush and keep trying till space is made
4893
- auto * const offsets = allocOffsets.data ()+allocOffsets.size ()-allocCount ;
4894
- const auto * const sizes = allocSizes.data ()+allocSizes.size ()-allocCount ;
4895
- for (uint32_t t=0 ; params.scratchForDeviceASBuild ->multi_allocate (allocCount ,offsets,sizes,alignments.data ())!=0 ; t++)
4894
+ auto * const offsets = allocOffsets.data ()+allocOffsets.size ()-alignments. size () ;
4895
+ const auto * const sizes = allocSizes.data ()+allocSizes.size ()-alignments. size () ;
4896
+ for (uint32_t t=0 ; params.scratchForDeviceASBuild ->multi_allocate (alignments. size () ,offsets,sizes,alignments.data ())!=0 ; t++)
4896
4897
if (t==1 ) // don't flush right away cause allocator not defragmented yet
4897
4898
{
4898
4899
recordBuildCommands ();
@@ -5007,6 +5008,7 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
5007
5008
{
5008
5009
buildInfo.geometryCount = canonical->getGeometryCount ();
5009
5010
const auto * offsetIt = offsets+1 ;
5011
+ const auto * sizeIt = sizes+1 ;
5010
5012
const auto primitiveCounts = canonical->getGeometryPrimitiveCounts ();
5011
5013
for (const auto count : primitiveCounts)
5012
5014
geometryRangeInfo.push_back ({
@@ -5015,14 +5017,17 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
5015
5017
.firstVertex = 0 ,
5016
5018
.transformByteOffset = 0
5017
5019
});
5018
- const uint32_t * pPrimitiveCounts = canonical->getGeometryPrimitiveCounts ().data ();
5020
+ const uint32_t * pPrimitiveCounts = primitiveCounts.data ();
5021
+ IUtilities::CMemcpyUpstreamingDataProducer memcpyCallback;
5019
5022
if (buildFlags.hasFlags (GeometryIsAABBFlag))
5020
5023
{
5021
5024
for (const auto & geom : canonical->getAABBGeometries ())
5022
5025
if (const auto aabbCount=*(pPrimitiveCounts++); aabbCount)
5023
5026
{
5024
5027
auto offset = *(offsetIt++);
5025
- // TODO: stream in the data
5028
+ memcpyCallback.data = reinterpret_cast <const uint8_t *>(geom.data .buffer ->getPointer ())+geom.data .offset ;
5029
+ if (!streamDataToScratch (offset,*(sizeIt++),memcpyCallback))
5030
+ break ;
5026
5031
aabbs.push_back ({
5027
5032
.data = {.offset =offset,.buffer =smart_refctd_ptr<const IGPUBuffer>(scratchBuffer)},
5028
5033
.stride = geom.stride ,
@@ -5038,19 +5043,24 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
5038
5043
{
5039
5044
auto & outGeom = triangles.emplace_back ();
5040
5045
auto offset = *(offsetIt++);
5041
- // TODO: stream in the data
5042
- outGeom.vertexData [0 ] = {.offset =offset,.buffer =smart_refctd_ptr<const IGPUBuffer>(scratchBuffer)};
5043
- offset += geom.vertexStride *geom.maxVertex ;
5044
- if (geom.vertexData [1 ])
5046
+ auto size = geom.vertexStride *geom.maxVertex ;
5047
+ for (auto i=0 ; i<2 ; i++)
5048
+ if (geom.vertexData [i]) // could assert that it must be true for i==0
5045
5049
{
5046
- outGeom.vertexData [1 ] = {.offset =offset,.buffer =smart_refctd_ptr<const IGPUBuffer>(scratchBuffer)};
5047
- offset += geom.vertexStride *geom.maxVertex ;
5050
+ outGeom.vertexData [i] = {.offset =offset,.buffer =smart_refctd_ptr<const IGPUBuffer>(scratchBuffer)};
5051
+ memcpyCallback.data = reinterpret_cast <const uint8_t *>(geom.vertexData [i].buffer ->getPointer ())+geom.vertexData [i].offset ;
5052
+ if (!streamDataToScratch (offset,size,memcpyCallback))
5053
+ break ;
5054
+ offset += size;
5048
5055
}
5049
5056
if (geom.hasTransform ())
5050
5057
{
5051
5058
offset = core::alignUp (offset,alignof (float ));
5052
5059
outGeom.transform = {.offset =offset,.buffer =smart_refctd_ptr<const IGPUBuffer>(scratchBuffer)};
5053
- offset += sizeof (hlsl::float32_t3x4);
5060
+ memcpyCallback.data = &geom.transform ;
5061
+ if (!streamDataToScratch (offset,sizeof (geom.transform ),memcpyCallback))
5062
+ break ;
5063
+ offset += sizeof (geom.transform );
5054
5064
}
5055
5065
switch (geom.indexType )
5056
5066
{
@@ -5060,11 +5070,16 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
5060
5070
const auto alignment = geom.indexType ==E_INDEX_TYPE::EIT_16BIT ? alignof (uint16_t ):alignof (uint32_t );
5061
5071
offset = core::alignUp (offset,alignment);
5062
5072
outGeom.indexData = {.offset =offset,.buffer =smart_refctd_ptr<const IGPUBuffer>(scratchBuffer)};
5073
+ size = triCount*3 *alignment;
5074
+ memcpyCallback.data = reinterpret_cast <const uint8_t *>(geom.indexData .buffer ->getPointer ())+geom.indexData .offset ;
5075
+ success = streamDataToScratch (offset,size,memcpyCallback);
5063
5076
break ;
5064
5077
}
5065
5078
default :
5066
5079
break ;
5067
5080
}
5081
+ if (!success)
5082
+ break ;
5068
5083
outGeom.maxVertex = geom.maxVertex ;
5069
5084
outGeom.vertexStride = geom.vertexStride ;
5070
5085
outGeom.vertexFormat = geom.vertexFormat ;
@@ -5073,8 +5088,8 @@ ISemaphore::future_t<IQueue::RESULT> CAssetConverter::convert_impl(SReserveResul
5073
5088
}
5074
5089
buildInfo.triangles = reinterpret_cast <const IGPUBottomLevelAccelerationStructure::Triangles<const IGPUBuffer>* const &>(trianglesOffset);
5075
5090
}
5091
+ success = pPrimitiveCounts==primitiveCounts.data ()+primitiveCounts.size ();
5076
5092
rangeInfos.push_back (reinterpret_cast <const IGPUBottomLevelAccelerationStructure::BuildRangeInfo* const &>(geometryRangeInfoOffset));
5077
- success = false ;
5078
5093
}
5079
5094
// current recording buffer may have changed
5080
5095
xferCmdBuf = params.transfer ->getCommandBufferForRecording ();
0 commit comments