Skip to content

Commit

Permalink
Fixes RenderingDevice::get_driver_resource will crash or give incor…
Browse files Browse the repository at this point in the history
…rect result with certain resources
  • Loading branch information
jsjtxietian committed Apr 8, 2024
1 parent e5b4ef8 commit 5a5453b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
16 changes: 10 additions & 6 deletions servers/rendering/rendering_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5224,28 +5224,32 @@ uint64_t RenderingDevice::get_driver_resource(DriverResource p_resource, RID p_r
case DRIVER_RESOURCE_LOGICAL_DEVICE:
case DRIVER_RESOURCE_PHYSICAL_DEVICE:
case DRIVER_RESOURCE_TOPMOST_OBJECT:
break;
case DRIVER_RESOURCE_COMMAND_QUEUE:
driver_id = main_queue.id;
break;
case DRIVER_RESOURCE_QUEUE_FAMILY:
driver_id = main_queue_family.id;
break;
case DRIVER_RESOURCE_TEXTURE:
case DRIVER_RESOURCE_TEXTURE_VIEW:
case DRIVER_RESOURCE_TEXTURE_DATA_FORMAT: {
Texture *tex = texture_owner.get_or_null(p_rid);
ERR_FAIL_NULL_V(tex, 0);

driver_id = tex->driver_id;
driver_id = tex->driver_id.id;
} break;
case DRIVER_RESOURCE_SAMPLER: {
RDD::SamplerID *sampler_driver_id = sampler_owner.get_or_null(p_rid);
ERR_FAIL_NULL_V(sampler_driver_id, 0);

driver_id = *sampler_driver_id;
driver_id = (*sampler_driver_id).id;
} break;
case DRIVER_RESOURCE_UNIFORM_SET: {
UniformSet *uniform_set = uniform_set_owner.get_or_null(p_rid);
ERR_FAIL_NULL_V(uniform_set, 0);

driver_id = uniform_set->driver_id;
driver_id = uniform_set->driver_id.id;
} break;
case DRIVER_RESOURCE_BUFFER: {
Buffer *buffer = nullptr;
Expand All @@ -5262,19 +5266,19 @@ uint64_t RenderingDevice::get_driver_resource(DriverResource p_resource, RID p_r
}
ERR_FAIL_NULL_V(buffer, 0);

driver_id = buffer->driver_id;
driver_id = buffer->driver_id.id;
} break;
case DRIVER_RESOURCE_COMPUTE_PIPELINE: {
ComputePipeline *compute_pipeline = compute_pipeline_owner.get_or_null(p_rid);
ERR_FAIL_NULL_V(compute_pipeline, 0);

driver_id = compute_pipeline->driver_id;
driver_id = compute_pipeline->driver_id.id;
} break;
case DRIVER_RESOURCE_RENDER_PIPELINE: {
RenderPipeline *render_pipeline = render_pipeline_owner.get_or_null(p_rid);
ERR_FAIL_NULL_V(render_pipeline, 0);

driver_id = render_pipeline->driver_id;
driver_id = render_pipeline->driver_id.id;
} break;
default: {
ERR_FAIL_V(0);
Expand Down
2 changes: 1 addition & 1 deletion servers/rendering/rendering_device_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class RenderingDeviceDriver : public RenderingDeviceCommons {

#define DEFINE_ID(m_name) \
struct m_name##ID : public ID { \
_ALWAYS_INLINE_ operator bool() const { return id != 0; } \
_ALWAYS_INLINE_ explicit operator bool() const { return id != 0; } \
_ALWAYS_INLINE_ m_name##ID &operator=(m_name##ID p_other) { \
id = p_other.id; \
return *this; \
Expand Down
6 changes: 3 additions & 3 deletions servers/rendering/rendering_device_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void RenderingDeviceGraph::_add_command_to_graph(ResourceTracker **p_resource_tr
}

if (resource_tracker->parent->usage == RESOURCE_USAGE_NONE) {
if (resource_tracker->parent->texture_driver_id != 0) {
if (resource_tracker->parent->texture_driver_id.id != 0) {
// If the resource is a texture, we transition it entirely to the layout determined by the first slice that uses it.
_add_texture_barrier_to_command(resource_tracker->parent->texture_driver_id, RDD::BarrierAccessBits(0), new_usage_access, RDG::RESOURCE_USAGE_NONE, new_resource_usage, resource_tracker->parent->texture_subresources, command_normalization_barriers, r_command->normalization_barrier_index, r_command->normalization_barrier_count);
}
Expand Down Expand Up @@ -324,7 +324,7 @@ void RenderingDeviceGraph::_add_command_to_graph(ResourceTracker **p_resource_tr
ERR_FAIL_MSG("Texture slices that overlap can't be used in the same command.");
} else {
// Delete the slice from the dirty list and revert it to the usage of the parent.
if (current_tracker->texture_driver_id != 0) {
if (current_tracker->texture_driver_id.id != 0) {
_add_texture_barrier_to_command(current_tracker->texture_driver_id, current_tracker->usage_access, new_usage_access, current_tracker->usage, resource_tracker->parent->usage, current_tracker->texture_subresources, command_normalization_barriers, r_command->normalization_barrier_index, r_command->normalization_barrier_count);

// Merge the area of the slice with the current tracking area of the command and indicate it's a write usage as well.
Expand Down Expand Up @@ -383,7 +383,7 @@ void RenderingDeviceGraph::_add_command_to_graph(ResourceTracker **p_resource_tr
while (current_tracker != nullptr) {
current_tracker->reset_if_outdated(tracking_frame);

if (current_tracker->texture_driver_id != 0) {
if (current_tracker->texture_driver_id.id != 0) {
// Transition all slices to the layout of the parent resource.
_add_texture_barrier_to_command(current_tracker->texture_driver_id, current_tracker->usage_access, new_usage_access, current_tracker->usage, resource_tracker->usage, current_tracker->texture_subresources, command_normalization_barriers, r_command->normalization_barrier_index, r_command->normalization_barrier_count);
}
Expand Down

0 comments on commit 5a5453b

Please sign in to comment.