diff options
author | Alyssa Rosenzweig <[email protected]> | 2019-08-01 10:30:40 -0700 |
---|---|---|
committer | Alyssa Rosenzweig <[email protected]> | 2019-08-01 14:31:56 -0700 |
commit | 898a18ea89ff29d5eb6fb9c6f0ddeae5de8ba7a7 (patch) | |
tree | 4a86c212f71ced3aec5e98727e77f3de8b4034ec /src/gallium/auxiliary/util/u_helpers.c | |
parent | 3e331732003ddbb9e707fa8b6eaabf8120c372f7 (diff) |
gallium/util: Add util_set_shader_buffers_mask helper
Conceptually follows util_set_vertex_buffers_mask but for SSBOs.
v2: Fix missing ~ when clearing mask. Adjust mask behaviour to match
freedreno/v3d when buffer == NULL.
Signed-off-by: Alyssa Rosenzweig <[email protected]>
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/util/u_helpers.c')
-rw-r--r-- | src/gallium/auxiliary/util/u_helpers.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_helpers.c b/src/gallium/auxiliary/util/u_helpers.c index 821242c0181..f28685f80d9 100644 --- a/src/gallium/auxiliary/util/u_helpers.c +++ b/src/gallium/auxiliary/util/u_helpers.c @@ -102,6 +102,43 @@ void util_set_vertex_buffers_count(struct pipe_vertex_buffer *dst, } /** + * This function is used to copy an array of pipe_shader_buffer structures, + * while properly referencing the pipe_shader_buffer::buffer member. + * + * \sa util_set_vertex_buffer_mask + */ +void util_set_shader_buffers_mask(struct pipe_shader_buffer *dst, + uint32_t *enabled_buffers, + const struct pipe_shader_buffer *src, + unsigned start_slot, unsigned count) +{ + unsigned i; + + dst += start_slot; + + if (src) { + for (i = 0; i < count; i++) { + pipe_resource_reference(&dst[i].buffer, src[i].buffer); + + if (src[i].buffer) + *enabled_buffers |= (1ull << (start_slot + i)); + else + *enabled_buffers &= ~(1ull << (start_slot + i)); + } + + /* Copy over the other members of pipe_shader_buffer. */ + memcpy(dst, src, count * sizeof(struct pipe_shader_buffer)); + } + else { + /* Unreference the buffers. */ + for (i = 0; i < count; i++) + pipe_resource_reference(&dst[i].buffer, NULL); + + *enabled_buffers &= ~(((1ull << count) - 1) << start_slot); + } +} + +/** * Given a user index buffer, save the structure to "saved", and upload it. */ bool |