[10/15] gallium: add blob field to pipe_llvm_program_header

Submitted by Karol Herbst on May 11, 2019, 2:07 p.m.

Details

Message ID 20190511140712.27095-11-kherbst@redhat.com
State New
Headers show
Series "Clover: support CL through SPIR-V" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Karol Herbst May 11, 2019, 2:07 p.m.
makes it easier to consume a IR_NATIVE binary

Signed-off-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
---
 src/gallium/drivers/r600/evergreen_compute.c           | 4 +---
 src/gallium/drivers/radeonsi/si_compute.c              | 4 +---
 src/gallium/include/pipe/p_state.h                     | 1 +
 src/gallium/state_trackers/clover/spirv/invocation.cpp | 3 +--
 4 files changed, 4 insertions(+), 8 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/gallium/drivers/r600/evergreen_compute.c b/src/gallium/drivers/r600/evergreen_compute.c
index 1536210c7ef..34e5755696f 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -411,7 +411,6 @@  static void *evergreen_create_compute_state(struct pipe_context *ctx,
 	struct r600_pipe_compute *shader = CALLOC_STRUCT(r600_pipe_compute);
 #ifdef HAVE_OPENCL
 	const struct pipe_llvm_program_header *header;
-	const char *code;
 	void *p;
 	boolean use_kill;
 #endif
@@ -430,9 +429,8 @@  static void *evergreen_create_compute_state(struct pipe_context *ctx,
 #ifdef HAVE_OPENCL
 	COMPUTE_DBG(rctx->screen, "*** evergreen_create_compute_state\n");
 	header = cso->prog;
-	code = cso->prog + sizeof(struct pipe_llvm_program_header);
 	radeon_shader_binary_init(&shader->binary);
-	r600_elf_read(code, header->num_bytes, &shader->binary);
+	r600_elf_read(header->blob, header->num_bytes, &shader->binary);
 	r600_create_shader(&shader->bc, &shader->binary, &use_kill);
 
 	/* Upload code + ROdata */
diff --git a/src/gallium/drivers/radeonsi/si_compute.c b/src/gallium/drivers/radeonsi/si_compute.c
index f1a433b72df..ae10709f2f1 100644
--- a/src/gallium/drivers/radeonsi/si_compute.c
+++ b/src/gallium/drivers/radeonsi/si_compute.c
@@ -233,11 +233,9 @@  static void *si_create_compute_state(
 					    program, si_create_compute_state_async);
 	} else {
 		const struct pipe_llvm_program_header *header;
-		const char *code;
 		header = cso->prog;
-		code = cso->prog + sizeof(struct pipe_llvm_program_header);
 
-		ac_elf_read(code, header->num_bytes, &program->shader.binary);
+		ac_elf_read(header->blob, header->num_bytes, &program->shader.binary);
 		if (program->use_code_object_v2) {
 			const amd_kernel_code_t *code_object =
 				si_compute_get_code_object(program, 0);
diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h
index b7fa76a803a..27350091b82 100644
--- a/src/gallium/include/pipe/p_state.h
+++ b/src/gallium/include/pipe/p_state.h
@@ -884,6 +884,7 @@  struct pipe_grid_info
 struct pipe_llvm_program_header
 {
    uint32_t num_bytes; /**< Number of bytes in the LLVM bytecode program. */
+   char blob[];
 };
 
 struct pipe_compute_state
diff --git a/src/gallium/state_trackers/clover/spirv/invocation.cpp b/src/gallium/state_trackers/clover/spirv/invocation.cpp
index 6100fca0065..2fd5a876a32 100644
--- a/src/gallium/state_trackers/clover/spirv/invocation.cpp
+++ b/src/gallium/state_trackers/clover/spirv/invocation.cpp
@@ -649,8 +649,7 @@  clover::spirv::link_program(const std::vector<module> &modules,
          assert(false);
       }
 
-      const auto c_il = msec->data.data() +
-                        sizeof(struct pipe_llvm_program_header);
+      const auto c_il = ((struct pipe_llvm_program_header*)msec->data.data())->blob;
       const auto length = msec->size;
 
       sections.push_back(reinterpret_cast<const uint32_t *>(c_il));