#include "util/u_memory.h"
-#include "../radeon/r600_cs.h"
+#include "radeon/r600_cs.h"
#include "si_pipe.h"
#include "si_shader.h"
#include "sid.h"
-#include "radeon_llvm_util.h"
+#include "radeon/radeon_llvm_util.h"
#define MAX_GLOBAL_BUFFERS 20
#if HAVE_LLVM < 0x0305
#define NUM_USER_SGPRS 4
#endif
-struct si_pipe_compute {
+struct si_compute {
struct si_context *ctx;
unsigned local_size;
unsigned private_size;
unsigned input_size;
unsigned num_kernels;
- struct si_pipe_shader *kernels;
+ struct si_shader *kernels;
unsigned num_user_sgprs;
- struct pipe_resource *global_buffers[MAX_GLOBAL_BUFFERS];
+ struct r600_resource *input_buffer;
+ struct pipe_resource *global_buffers[MAX_GLOBAL_BUFFERS];
LLVMContextRef llvm_ctx;
};
const struct pipe_compute_state *cso)
{
struct si_context *sctx = (struct si_context *)ctx;
- struct si_pipe_compute *program =
- CALLOC_STRUCT(si_pipe_compute);
+ struct si_compute *program = CALLOC_STRUCT(si_compute);
const struct pipe_llvm_program_header *header;
const unsigned char *code;
unsigned i;
program->num_kernels = radeon_llvm_get_num_kernels(program->llvm_ctx, code,
header->num_bytes);
- program->kernels = CALLOC(sizeof(struct si_pipe_shader),
+ program->kernels = CALLOC(sizeof(struct si_shader),
program->num_kernels);
for (i = 0; i < program->num_kernels; i++) {
LLVMModuleRef mod = radeon_llvm_get_kernel_module(program->llvm_ctx, i,
code, header->num_bytes);
- si_compile_llvm(sctx, &program->kernels[i], mod);
+ si_compile_llvm(sctx->screen, &program->kernels[i], mod);
LLVMDisposeModule(mod);
}
+ program->input_buffer = si_resource_create_custom(sctx->b.b.screen,
+ PIPE_USAGE_IMMUTABLE, program->input_size);
+
return program;
}
static void si_bind_compute_state(struct pipe_context *ctx, void *state)
{
struct si_context *sctx = (struct si_context*)ctx;
- sctx->cs_shader_state.program = (struct si_pipe_compute*)state;
+ sctx->cs_shader_state.program = (struct si_compute*)state;
}
static void si_set_global_binding(
{
unsigned i;
struct si_context *sctx = (struct si_context*)ctx;
- struct si_pipe_compute *program = sctx->cs_shader_state.program;
+ struct si_compute *program = sctx->cs_shader_state.program;
if (!resources) {
for (i = first; i < first + n; i++) {
uint32_t pc, const void *input)
{
struct si_context *sctx = (struct si_context*)ctx;
- struct si_pipe_compute *program = sctx->cs_shader_state.program;
+ struct radeon_winsys_cs *cs = sctx->b.rings.gfx.cs;
+ struct si_compute *program = sctx->cs_shader_state.program;
struct si_pm4_state *pm4 = CALLOC_STRUCT(si_pm4_state);
- struct r600_resource *kernel_args_buffer = NULL;
+ struct r600_resource *input_buffer = program->input_buffer;
unsigned kernel_args_size;
unsigned num_work_size_bytes = 36;
uint32_t kernel_args_offset = 0;
uint64_t shader_va;
unsigned arg_user_sgpr_count = NUM_USER_SGPRS;
unsigned i;
- struct si_pipe_shader *shader = &program->kernels[pc];
+ struct si_shader *shader = &program->kernels[pc];
unsigned lds_blocks;
unsigned num_waves_for_scratch;
- pm4->compute_pkt = true;
- si_cmd_context_control(pm4);
+ radeon_emit(cs, PKT3(PKT3_CONTEXT_CONTROL, 1, 0) | PKT3_SHADER_TYPE_S(1));
+ radeon_emit(cs, 0x80000000);
+ radeon_emit(cs, 0x80000000);
- si_pm4_cmd_begin(pm4, PKT3_EVENT_WRITE);
- si_pm4_cmd_add(pm4, EVENT_TYPE(EVENT_TYPE_CACHE_FLUSH) |
- EVENT_INDEX(0x7) |
- EVENT_WRITE_INV_L2);
- si_pm4_cmd_end(pm4, false);
+ sctx->b.flags |= R600_CONTEXT_INV_TEX_CACHE |
+ R600_CONTEXT_INV_SHADER_CACHE |
+ R600_CONTEXT_INV_CONST_CACHE |
+ R600_CONTEXT_FLUSH_WITH_INV_L2 |
+ R600_CONTEXT_FLAG_COMPUTE;
+ si_emit_cache_flush(&sctx->b, NULL);
- si_pm4_inval_texture_cache(pm4);
- si_pm4_inval_shader_cache(pm4);
- si_cmd_surface_sync(pm4, pm4->cp_coher_cntl);
+ pm4->compute_pkt = true;
/* Upload the kernel arguments */
/* The extra num_work_size_bytes are for work group / work item size information */
kernel_args_size = program->input_size + num_work_size_bytes + 8 /* For scratch va */;
- kernel_args = MALLOC(kernel_args_size);
+ kernel_args = sctx->b.ws->buffer_map(input_buffer->cs_buf,
+ sctx->b.rings.gfx.cs, PIPE_TRANSFER_WRITE);
for (i = 0; i < 3; i++) {
kernel_args[i] = grid_layout[i];
kernel_args[i + 3] = grid_layout[i] * block_layout[i];
kernel_args[i]);
}
- si_upload_const_buffer(sctx, &kernel_args_buffer, (uint8_t*)kernel_args,
- kernel_args_size, &kernel_args_offset);
- kernel_args_va = kernel_args_buffer->gpu_address;
+ sctx->b.ws->buffer_unmap(input_buffer->cs_buf);
+
+ kernel_args_va = input_buffer->gpu_address;
kernel_args_va += kernel_args_offset;
- si_pm4_add_bo(pm4, kernel_args_buffer, RADEON_USAGE_READ, RADEON_PRIO_SHADER_DATA);
+ si_pm4_add_bo(pm4, input_buffer, RADEON_USAGE_READ,
+ RADEON_PRIO_SHADER_DATA);
si_pm4_set_reg(pm4, R_00B900_COMPUTE_USER_DATA_0, kernel_args_va);
si_pm4_set_reg(pm4, R_00B900_COMPUTE_USER_DATA_0 + 4, S_008F04_BASE_ADDRESS_HI (kernel_args_va >> 32) | S_008F04_STRIDE(0));
si_pm4_cmd_add(pm4, 1); /* DISPATCH_INITIATOR */
si_pm4_cmd_end(pm4, false);
- si_pm4_cmd_begin(pm4, PKT3_EVENT_WRITE);
- si_pm4_cmd_add(pm4, EVENT_TYPE(V_028A90_CS_PARTIAL_FLUSH | EVENT_INDEX(0x4)));
- si_pm4_cmd_end(pm4, false);
-
- si_pm4_inval_texture_cache(pm4);
- si_pm4_inval_shader_cache(pm4);
- si_cmd_surface_sync(pm4, pm4->cp_coher_cntl);
-
si_pm4_emit(sctx, pm4);
#if 0
}
#endif
- FREE(kernel_args);
si_pm4_free_state(sctx, pm4, ~0);
+
+ sctx->b.flags |= R600_CONTEXT_CS_PARTIAL_FLUSH |
+ R600_CONTEXT_INV_TEX_CACHE |
+ R600_CONTEXT_INV_SHADER_CACHE |
+ R600_CONTEXT_INV_CONST_CACHE |
+ R600_CONTEXT_FLAG_COMPUTE;
+ si_emit_cache_flush(&sctx->b, NULL);
}
static void si_delete_compute_state(struct pipe_context *ctx, void* state){
- struct si_pipe_compute *program = (struct si_pipe_compute *)state;
+ struct si_compute *program = (struct si_compute *)state;
if (!state) {
return;
if (program->kernels) {
for (int i = 0; i < program->num_kernels; i++){
if (program->kernels[i].bo){
- si_pipe_shader_destroy(ctx, &program->kernels[i]);
+ si_shader_destroy(ctx, &program->kernels[i]);
}
}
-
FREE(program->kernels);
}
if (program->llvm_ctx){
LLVMContextDispose(program->llvm_ctx);
}
+ pipe_resource_reference(
+ (struct pipe_resource **)&program->input_buffer, NULL);
//And then free the program itself.
FREE(program);