@@ -289,6 +289,8 @@ void RenderDetailTextureGPUTask::prepare(GPUTaskContext &ctx) {
289
289
290
290
// Make compute list
291
291
292
+ _uniform_sets_to_free.reserve (5 + modifiers.size ());
293
+
292
294
const int compute_list_id = rd.compute_list_begin ();
293
295
294
296
// Gather hits
@@ -310,6 +312,7 @@ void RenderDetailTextureGPUTask::prepare(GPUTaskContext &ctx) {
310
312
gather_hits_uniforms[5 ] = hit_positions_uniform;
311
313
312
314
const RID gather_hits_uniform_set_rid = uniform_set_create (rd, gather_hits_uniforms, gather_hits_shader_rid, 0 );
315
+ _uniform_sets_to_free.push_back (gather_hits_uniform_set_rid);
313
316
314
317
rd.compute_list_bind_compute_pipeline (compute_list_id, _gather_hits_pipeline_rid);
315
318
rd.compute_list_bind_uniform_set (compute_list_id, gather_hits_uniform_set_rid, 0 );
@@ -350,6 +353,7 @@ void RenderDetailTextureGPUTask::prepare(GPUTaskContext &ctx) {
350
353
}
351
354
352
355
const RID detail_generator_uniform_set = uniform_set_create (rd, detail_generator_uniforms, shader_rid, 0 );
356
+ _uniform_sets_to_free.push_back (detail_generator_uniform_set);
353
357
354
358
rd.compute_list_bind_compute_pipeline (compute_list_id, _detail_generator_pipeline_rid);
355
359
rd.compute_list_bind_uniform_set (compute_list_id, detail_generator_uniform_set, 0 );
@@ -402,6 +406,7 @@ void RenderDetailTextureGPUTask::prepare(GPUTaskContext &ctx) {
402
406
403
407
const RID detail_modifier_uniform_set =
404
408
uniform_set_create (rd, detail_modifier_uniforms, modifier_shader_rid, 0 );
409
+ _uniform_sets_to_free.push_back (detail_modifier_uniform_set);
405
410
406
411
const RID pipeline_rid = _detail_modifier_pipelines[modifier_index];
407
412
rd.compute_list_bind_compute_pipeline (compute_list_id, pipeline_rid);
@@ -440,6 +445,7 @@ void RenderDetailTextureGPUTask::prepare(GPUTaskContext &ctx) {
440
445
441
446
const RID detail_normalmap_uniform_set_rid =
442
447
uniform_set_create (rd, detail_normalmap_uniforms, detail_normalmap_shader_rid, 0 );
448
+ _uniform_sets_to_free.push_back (detail_normalmap_uniform_set_rid);
443
449
444
450
rd.compute_list_bind_compute_pipeline (compute_list_id, _detail_normalmap_pipeline_rid);
445
451
rd.compute_list_bind_uniform_set (compute_list_id, detail_normalmap_uniform_set_rid, 0 );
@@ -470,6 +476,7 @@ void RenderDetailTextureGPUTask::prepare(GPUTaskContext &ctx) {
470
476
dilation_uniforms[1 ] = image1_uniform;
471
477
dilation_uniforms[2 ] = dilation_params_uniform;
472
478
const RID dilation_uniform_set_rid = uniform_set_create (rd, dilation_uniforms, dilation_shader_rid, 0 );
479
+ _uniform_sets_to_free.push_back (dilation_uniform_set_rid);
473
480
474
481
rd.compute_list_bind_compute_pipeline (compute_list_id, _normalmap_dilation_pipeline_rid);
475
482
rd.compute_list_bind_uniform_set (compute_list_id, dilation_uniform_set_rid, 0 );
@@ -506,6 +513,7 @@ void RenderDetailTextureGPUTask::prepare(GPUTaskContext &ctx) {
506
513
dilation_uniforms[2 ] = dilation_params_uniform;
507
514
// TODO Do I really have to create a new uniform set every time I modify just one of the passed values?
508
515
const RID dilation_uniform_set_rid = uniform_set_create (rd, dilation_uniforms, dilation_shader_rid, 0 );
516
+ _uniform_sets_to_free.push_back (dilation_uniform_set_rid);
509
517
510
518
rd.compute_list_bind_uniform_set (compute_list_id, dilation_uniform_set_rid, 0 );
511
519
@@ -550,6 +558,14 @@ PackedByteArray RenderDetailTextureGPUTask::collect_texture_and_cleanup(
550
558
free_rendering_device_rid (rd, rid);
551
559
}
552
560
561
+ // This is not documented: from dev source, uniform sets are "automatically freed by their dependencies". So
562
+ // apparently we don't *have* to free them. However, I got a bug report where RID limit got exceeded after
563
+ // several minutes, unless those RIDs get freed after use... something odd is going on, but absence of
564
+ // documentation on the automatic behavior doesn't help.
565
+ for (RID rid : _uniform_sets_to_free) {
566
+ free_rendering_device_rid (rd, rid);
567
+ }
568
+
553
569
storage_buffer_pool.recycle (_mesh_vertices_sb);
554
570
storage_buffer_pool.recycle (_mesh_indices_sb);
555
571
storage_buffer_pool.recycle (_cell_triangles_sb);
0 commit comments