From 911bb08314a71116b1b2fbf4291d475f40ef53e6 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 5 Jan 2021 11:12:11 -0800 Subject: [PATCH] gallium/tgsi_exec: Refactor to fix CS local memory overflow checks. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was OK because right now we only execute in the first channel of the CS, but if you wanted to extend that then you'd need to check each channel. We already had what we needed for SSBOs, so just reuse it. Reviewed-by: Marek Olšák Part-of: --- src/gallium/auxiliary/tgsi/tgsi_exec.c | 58 +++++++++----------------- 1 file changed, 19 insertions(+), 39 deletions(-) diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c index b5fa1d8f263..f17d61c2c7c 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_exec.c +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c @@ -3897,12 +3897,26 @@ exec_load_img(struct tgsi_exec_machine *mach, } static void -exec_load_buf(struct tgsi_exec_machine *mach, - const struct tgsi_full_instruction *inst) +exec_load_membuf(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) { uint32_t unit = fetch_sampler_unit(mach, inst, 0); + uint32_t size; - char *ptr = mach->Buffer->lookup(mach->Buffer, unit, &size); + char *ptr; + switch (inst->Src[0].Register.File) { + case TGSI_FILE_MEMORY: + ptr = mach->LocalMem; + size = mach->LocalMemSize; + break; + + case TGSI_FILE_BUFFER: + ptr = mach->Buffer->lookup(mach->Buffer, unit, &size); + break; + + default: + unreachable("unsupported TGSI_OPCODE_LOAD file"); + } union tgsi_exec_channel offset; IFETCH(&offset, 1, TGSI_CHAN_X); @@ -3926,48 +3940,14 @@ exec_load_buf(struct tgsi_exec_machine *mach, } } -static void -exec_load_mem(struct tgsi_exec_machine *mach, - const struct tgsi_full_instruction *inst) -{ - union tgsi_exec_channel r[4]; - uint chan; - char *ptr = mach->LocalMem; - uint32_t offset; - int j; - - IFETCH(&r[0], 1, TGSI_CHAN_X); - if (r[0].u[0] >= mach->LocalMemSize) - return; - - offset = r[0].u[0]; - ptr += offset; - - for (j = 0; j < TGSI_QUAD_SIZE; j++) { - for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) { - if (inst->Dst[0].Register.WriteMask & (1 << chan)) { - memcpy(&r[chan].u[j], ptr + (4 * chan), 4); - } - } - } - - for (chan = 0; chan < TGSI_NUM_CHANNELS; chan++) { - if (inst->Dst[0].Register.WriteMask & (1 << chan)) { - store_dest(mach, &r[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT); - } - } -} - static void exec_load(struct tgsi_exec_machine *mach, const struct tgsi_full_instruction *inst) { if (inst->Src[0].Register.File == TGSI_FILE_IMAGE) exec_load_img(mach, inst); - else if (inst->Src[0].Register.File == TGSI_FILE_BUFFER) - exec_load_buf(mach, inst); - else if (inst->Src[0].Register.File == TGSI_FILE_MEMORY) - exec_load_mem(mach, inst); + else + exec_load_membuf(mach, inst); } static uint