On 19.12.2016 09:11, Michel Dänzer wrote:
On 16/12/16 08:22 PM, Nicolai Hähnle wrote:
On 16.12.2016 10:52, Michel Dänzer wrote:
From: Michel Dänzer <michel.daen...@amd.com>

Only copy/memset the pointers that actually need to be.

Signed-off-by: Michel Dänzer <michel.daen...@amd.com>
---
 src/gallium/auxiliary/cso_cache/cso_context.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c
b/src/gallium/auxiliary/cso_cache/cso_context.c
index f52969d366..03f78eea53 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -1267,8 +1267,10 @@ cso_save_fragment_samplers(struct cso_context
*ctx)
    struct sampler_info *saved = &ctx->fragment_samplers_saved;

    saved->nr_samplers = info->nr_samplers;
-   memcpy(saved->cso_samplers, info->cso_samplers,
sizeof(info->cso_samplers));
-   memcpy(saved->samplers, info->samplers, sizeof(info->samplers));
+   memcpy(saved->cso_samplers, info->cso_samplers, info->nr_samplers *
+          sizeof(*info->cso_samplers));
+   memcpy(saved->samplers, info->samplers, info->nr_samplers *
+          sizeof(*info->samplers));
 }


@@ -1277,9 +1279,20 @@ cso_restore_fragment_samplers(struct
cso_context *ctx)
 {
    struct sampler_info *info = &ctx->samplers[PIPE_SHADER_FRAGMENT];
    struct sampler_info *saved = &ctx->fragment_samplers_saved;
+   int delta = info->nr_samplers - saved->nr_samplers;
+
+   memcpy(info->cso_samplers, saved->cso_samplers,
+          saved->nr_samplers * sizeof(*info->cso_samplers));
+   memcpy(info->samplers, saved->samplers,
+          saved->nr_samplers * sizeof(*info->samplers));
+
+   if (delta > 0) {

I'd be more comfortable with an explicit info->nr_samplers >
saved->nr_samplers given that nr_samplers is an unsigned.

How about:

   int delta = (int)info->nr_samplers - saved->nr_samplers;

This generates identical code as without the cast, whereas with the
explicit comparison the ELF text section grows by 48 bytes.

Yes, that sounds good.





Apart from that, patches 1-3:

Reviewed-by: Nicolai Hähnle <nicolai.haeh...@amd.com>

Thanks!


_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to