@@ -172,7 +172,6 @@ static bool extract_resources_layout(VkrSpecProgram* program, VkDescriptorSetLay
172
172
.as = as ,
173
173
.set = set ,
174
174
.binding = binding ,
175
- .host_owned = true,
176
175
};
177
176
growy_append_object (resources , res_info );
178
177
program -> resources .num_resources ++ ;
@@ -199,6 +198,11 @@ static bool extract_resources_layout(VkrSpecProgram* program, VkDescriptorSetLay
199
198
// TODO initial value
200
199
}
201
200
201
+ if (vkr_can_import_host_memory (program -> device ))
202
+ res_info -> host_backed_allocation = true;
203
+ else
204
+ res_info -> staging = calloc (1 , res_info -> size );
205
+
202
206
VkDescriptorSetLayoutBinding vk_binding = {
203
207
.binding = binding ,
204
208
.descriptorType = as_to_descriptor_type (as ),
@@ -366,11 +370,22 @@ static bool allocate_sets(VkrSpecProgram* program) {
366
370
return true;
367
371
}
368
372
373
+ static void flush_staged_data (VkrSpecProgram * program ) {
374
+ for (size_t i = 0 ; i < program -> resources .num_resources ; i ++ ) {
375
+ ProgramResourceInfo * resource = program -> resources .resources [i ];
376
+ if (resource -> staging ) {
377
+ copy_to_buffer (resource -> buffer , 0 , resource -> buffer , resource -> size );
378
+ free (resource -> staging );
379
+ }
380
+ }
381
+ }
382
+
369
383
static bool prepare_resources (VkrSpecProgram * program ) {
370
384
for (size_t i = 0 ; i < program -> resources .num_resources ; i ++ ) {
371
385
ProgramResourceInfo * resource = program -> resources .resources [i ];
372
386
373
- if (resource -> host_owned ) {
387
+ if (resource -> host_backed_allocation ) {
388
+ assert (vkr_can_import_host_memory (program -> device ));
374
389
resource -> host_ptr = alloc_aligned (resource -> size , program -> device -> caps .properties .external_memory_host .minImportedHostPointerAlignment );
375
390
resource -> buffer = import_buffer_host (program -> device , resource -> host_ptr , resource -> size );
376
391
} else {
@@ -384,12 +399,17 @@ static bool prepare_resources(VkrSpecProgram* program) {
384
399
free (zeroes );
385
400
386
401
if (resource -> parent ) {
387
- assert (resource -> parent -> host_ptr );
388
- char * parent = resource -> parent -> host_ptr ;
389
- * ((uint64_t * ) (parent + resource -> offset )) = get_buffer_device_pointer (resource -> buffer );
402
+ char * dst = resource -> parent -> host_ptr ;
403
+ if (!dst ) {
404
+ dst = resource -> parent -> staging ;
405
+ }
406
+ assert (dst );
407
+ * ((uint64_t * ) (dst + resource -> offset )) = get_buffer_device_pointer (resource -> buffer );
390
408
}
391
409
}
392
410
411
+ flush_staged_data (program );
412
+
393
413
return true;
394
414
}
395
415
@@ -436,7 +456,7 @@ void destroy_specialized_program(VkrSpecProgram* spec) {
436
456
ProgramResourceInfo * resource = spec -> resources .resources [i ];
437
457
if (resource -> buffer )
438
458
destroy_buffer (resource -> buffer );
439
- if (resource -> host_ptr && resource -> host_owned )
459
+ if (resource -> host_ptr && resource -> host_backed_allocation )
440
460
free_aligned (resource -> host_ptr );
441
461
}
442
462
free (spec -> resources .resources );
0 commit comments