Commit 11e9fb39 authored by Igor Torrente's avatar Igor Torrente
Browse files

vrend: Add comments to some obscure operations on vrend_renderer



vrend_sampler_view_reference, vrend_shader_state_reference and
vrend_resource_reference have some obscure address calculation
that cause confusion for some that don't fully understand what is
happening there.

Adds new comments to explain what is happening in these codes
and why we aren't really de-referencing any NULL pointer.

Signed-off-by: Igor Torrente's avatarIgor Torrente <igor.torrente@collabora.com>
parent 30370bd6
Pipeline #612114 waiting for manual action with stages
......@@ -1153,6 +1153,13 @@ vrend_sampler_view_reference(struct vrend_sampler_view **ptr, struct vrend_sampl
{
struct vrend_sampler_view *old_view = *ptr;
/**
* While this construct looks unsafe and seems to constitute undefined behavior all
* relevant compilers translate the construct &view->reference to
* `view + offset_in_struct(reference)` and pass this as function parameter,
* and since "reference" is the first value in the struct, view being NULL will
* result in passing a NULL pointer that is then checked in the function.
*/
if (pipe_reference(&(*ptr)->reference, &view->reference))
vrend_destroy_sampler_view(old_view);
*ptr = view;
......@@ -1263,6 +1270,10 @@ vrend_shader_state_reference(struct vrend_shader_selector **ptr, struct vrend_sh
{
struct vrend_shader_selector *old_shader = *ptr;
/**
* We are are not acessing ptr memory here.
* Check the comment in vrend_sampler_view_reference for more information.
*/
if (pipe_reference(&(*ptr)->reference, &shader->reference))
vrend_destroy_shader_selector(old_shader);
*ptr = shader;
......
......@@ -428,6 +428,10 @@ vrend_resource_reference(struct vrend_resource **ptr, struct vrend_resource *tex
{
struct vrend_resource *old_tex = *ptr;
/**
* We are are not acessing ptr memory here.
* Check the comment in vrend_sampler_view_reference for more information.
*/
if (pipe_reference(&(*ptr)->base.reference, &tex->base.reference))
vrend_renderer_resource_destroy(old_tex);
*ptr = tex;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment