From: Marek Olšák <marek.ol...@amd.com>

Cc: 10.5 10.6 <mesa-sta...@lists.freedesktop.org>
---
 src/gallium/drivers/radeonsi/si_shader.c        | 49 ++++++++++++++-----------
 src/gallium/drivers/radeonsi/si_shader.h        |  1 +
 src/gallium/drivers/radeonsi/si_state_shaders.c |  8 +---
 3 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader.c 
b/src/gallium/drivers/radeonsi/si_shader.c
index b988f6d..955e780 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -2686,16 +2686,41 @@ void si_shader_apply_scratch_relocs(struct si_context 
*sctx,
        }
 }
 
+int si_shader_binary_upload(struct si_screen *sscreen, struct si_shader 
*shader)
+{
+       const struct radeon_shader_binary *binary = &shader->binary;
+       unsigned code_size = binary->code_size + binary->rodata_size;
+       unsigned char *ptr;
+
+       r600_resource_reference(&shader->bo, NULL);
+       shader->bo = si_resource_create_custom(&sscreen->b.b,
+                                              PIPE_USAGE_IMMUTABLE,
+                                              code_size);
+       if (!shader->bo)
+               return -ENOMEM;
+
+       ptr = sscreen->b.ws->buffer_map(shader->bo->cs_buf, NULL,
+                                       PIPE_TRANSFER_READ_WRITE);
+       util_memcpy_cpu_to_le32(ptr, binary->code, binary->code_size);
+       if (binary->rodata_size > 0) {
+               ptr += binary->code_size;
+               util_memcpy_cpu_to_le32(ptr, binary->rodata,
+                                       binary->rodata_size);
+       }
+
+       sscreen->b.ws->buffer_unmap(shader->bo->cs_buf);
+       return 0;
+}
+
 int si_shader_binary_read(struct si_screen *sscreen, struct si_shader *shader)
 {
        const struct radeon_shader_binary *binary = &shader->binary;
        unsigned i;
-       unsigned code_size;
-       unsigned char *ptr;
        bool dump  = r600_can_dump_shader(&sscreen->b,
                shader->selector ? shader->selector->tokens : NULL);
 
        si_shader_binary_read_config(sscreen, shader, 0);
+       si_shader_binary_upload(sscreen, shader);
 
        if (dump) {
                if (!binary->disassembled) {
@@ -2713,26 +2738,6 @@ int si_shader_binary_read(struct si_screen *sscreen, 
struct si_shader *shader)
                        shader->num_sgprs, shader->num_vgprs, binary->code_size,
                        shader->lds_size, shader->scratch_bytes_per_wave);
        }
-
-       /* copy new shader */
-       code_size = binary->code_size + binary->rodata_size;
-       r600_resource_reference(&shader->bo, NULL);
-       shader->bo = si_resource_create_custom(&sscreen->b.b, 
PIPE_USAGE_IMMUTABLE,
-                                              code_size);
-       if (shader->bo == NULL) {
-               return -ENOMEM;
-       }
-
-
-       ptr = sscreen->b.ws->buffer_map(shader->bo->cs_buf, NULL, 
PIPE_TRANSFER_READ_WRITE);
-       util_memcpy_cpu_to_le32(ptr, binary->code, binary->code_size);
-       if (binary->rodata_size > 0) {
-               ptr += binary->code_size;
-               util_memcpy_cpu_to_le32(ptr, binary->rodata, 
binary->rodata_size);
-       }
-
-       sscreen->b.ws->buffer_unmap(shader->bo->cs_buf);
-
        return 0;
 }
 
diff --git a/src/gallium/drivers/radeonsi/si_shader.h 
b/src/gallium/drivers/radeonsi/si_shader.h
index 1e8b52b..c12782f 100644
--- a/src/gallium/drivers/radeonsi/si_shader.h
+++ b/src/gallium/drivers/radeonsi/si_shader.h
@@ -191,6 +191,7 @@ int si_compile_llvm(struct si_screen *sscreen, struct 
si_shader *shader,
                    LLVMTargetMachineRef tm, LLVMModuleRef mod);
 void si_shader_destroy(struct pipe_context *ctx, struct si_shader *shader);
 unsigned si_shader_io_get_unique_index(unsigned semantic_name, unsigned index);
+int si_shader_binary_upload(struct si_screen *sscreen, struct si_shader 
*shader);
 int si_shader_binary_read(struct si_screen *sscreen, struct si_shader *shader);
 void si_shader_apply_scratch_relocs(struct si_context *sctx,
                        struct si_shader *shader,
diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c 
b/src/gallium/drivers/radeonsi/si_state_shaders.c
index a842d9d..12bce9a 100644
--- a/src/gallium/drivers/radeonsi/si_state_shaders.c
+++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
@@ -749,7 +749,6 @@ static unsigned si_update_scratch_buffer(struct si_context 
*sctx,
 {
        struct si_shader *shader;
        uint64_t scratch_va = sctx->scratch_buffer->gpu_address;
-       unsigned char *ptr;
 
        if (!sel)
                return 0;
@@ -770,12 +769,7 @@ static unsigned si_update_scratch_buffer(struct si_context 
*sctx,
        si_shader_apply_scratch_relocs(sctx, shader, scratch_va);
 
        /* Replace the shader bo with a new bo that has the relocs applied. */
-       r600_resource_reference(&shader->bo, NULL);
-       shader->bo = si_resource_create_custom(&sctx->screen->b.b, 
PIPE_USAGE_IMMUTABLE,
-                                              shader->binary.code_size);
-       ptr = sctx->screen->b.ws->buffer_map(shader->bo->cs_buf, NULL, 
PIPE_TRANSFER_WRITE);
-       util_memcpy_cpu_to_le32(ptr, shader->binary.code, 
shader->binary.code_size);
-       sctx->screen->b.ws->buffer_unmap(shader->bo->cs_buf);
+       si_shader_binary_upload(sctx->screen, shader);
 
        /* Update the shader state to use the new shader bo. */
        si_shader_init_pm4_state(shader);
-- 
2.1.0

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

Reply via email to