radeonsi: upload shader rodata after updating scratch relocations
authorMarek Olšák <marek.olsak@amd.com>
Fri, 10 Jul 2015 21:35:55 +0000 (23:35 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 22 Jul 2015 22:59:24 +0000 (00:59 +0200)
Cc: 10.5 10.6 <mesa-stable@lists.freedesktop.org>
Reviewed-by: Tom Stellard <thomas.stellard@amd.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
src/gallium/drivers/radeonsi/si_shader.c
src/gallium/drivers/radeonsi/si_shader.h
src/gallium/drivers/radeonsi/si_state_shaders.c

index b988f6d2c1067da0aff2050ec7893da658ade113..955e780faf2b67f85b262ed74817b1aa4181bd43 100644 (file)
@@ -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;
 }
 
index 1e8b52b8e58356308b44a3c41d2cf4f5654a5d77..c12782f288cb20436f2475f61287125392668a1a 100644 (file)
@@ -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,
index 78be4d9baf24afd7a40584403bd819ee127c5025..b153228fb2ca0a3bcde39ee58c6ebe9b92171e18 100644 (file)
@@ -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);