[Mesa-dev] [PATCH 2/6] radeonsi: fix is_oneway_access_only for image stores
Marek Olšák
maraeo at gmail.com
Tue Nov 20 04:09:38 UTC 2018
From: Marek Olšák <marek.olsak at amd.com>
---
.../drivers/radeonsi/si_shader_tgsi_mem.c | 49 ++++++++++++++-----
1 file changed, 37 insertions(+), 12 deletions(-)
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
index 2ba3f251ff8..81df73ea9b1 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
@@ -395,59 +395,83 @@ static void load_emit_memory(
* \param shader_buffers_reverse_access_mask
* For LOAD, set this to (store | atomic) slot usage in the shader.
* For STORE, set this to (load | atomic) slot usage in the shader.
* \param images_reverse_access_mask Same as above, but for images.
*/
static bool is_oneway_access_only(const struct tgsi_full_instruction *inst,
const struct tgsi_shader_info *info,
unsigned shader_buffers_reverse_access_mask,
unsigned images_reverse_access_mask)
{
+ enum tgsi_file_type resource_file;
+ unsigned resource_index;
+ bool resource_indirect;
+
+ if (inst->Instruction.Opcode == TGSI_OPCODE_STORE) {
+ resource_file = inst->Dst[0].Register.File;
+ resource_index = inst->Dst[0].Register.Index;
+ resource_indirect = inst->Dst[0].Register.Indirect;
+ } else {
+ resource_file = inst->Src[0].Register.File;
+ resource_index = inst->Src[0].Register.Index;
+ resource_indirect = inst->Src[0].Register.Indirect;
+ }
+
+ assert(resource_file == TGSI_FILE_BUFFER ||
+ resource_file == TGSI_FILE_IMAGE ||
+ /* bindless image */
+ resource_file == TGSI_FILE_INPUT ||
+ resource_file == TGSI_FILE_OUTPUT ||
+ resource_file == TGSI_FILE_CONSTANT ||
+ resource_file == TGSI_FILE_TEMPORARY ||
+ resource_file == TGSI_FILE_IMMEDIATE);
+
+ assert(resource_file != TGSI_FILE_BUFFER ||
+ inst->Memory.Texture == TGSI_TEXTURE_BUFFER);
+
/* RESTRICT means NOALIAS.
* If there are no writes, we can assume the accessed memory is read-only.
* If there are no reads, we can assume the accessed memory is write-only.
*/
if (inst->Memory.Qualifier & TGSI_MEMORY_RESTRICT) {
unsigned reverse_access_mask;
- if (inst->Src[0].Register.File == TGSI_FILE_BUFFER) {
+ if (resource_file == TGSI_FILE_BUFFER) {
reverse_access_mask = shader_buffers_reverse_access_mask;
} else if (inst->Memory.Texture == TGSI_TEXTURE_BUFFER) {
reverse_access_mask = info->images_buffers &
images_reverse_access_mask;
} else {
reverse_access_mask = ~info->images_buffers &
images_reverse_access_mask;
}
- if (inst->Src[0].Register.Indirect) {
+ if (resource_indirect) {
if (!reverse_access_mask)
return true;
} else {
if (!(reverse_access_mask &
- (1u << inst->Src[0].Register.Index)))
+ (1u << resource_index)))
return true;
}
}
/* If there are no buffer writes (for both shader buffers & image
* buffers), it implies that buffer memory is read-only.
* If there are no buffer reads (for both shader buffers & image
* buffers), it implies that buffer memory is write-only.
*
* Same for the case when there are no writes/reads for non-buffer
* images.
*/
- if (inst->Src[0].Register.File == TGSI_FILE_BUFFER ||
- (inst->Memory.Texture == TGSI_TEXTURE_BUFFER &&
- (inst->Src[0].Register.File == TGSI_FILE_IMAGE ||
- tgsi_is_bindless_image_file(inst->Src[0].Register.File)))) {
+ if (resource_file == TGSI_FILE_BUFFER ||
+ inst->Memory.Texture == TGSI_TEXTURE_BUFFER) {
if (!shader_buffers_reverse_access_mask &&
!(info->images_buffers & images_reverse_access_mask))
return true;
} else {
if (!(~info->images_buffers & images_reverse_access_mask))
return true;
}
return false;
}
@@ -643,37 +667,38 @@ static void store_emit(
const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
const struct tgsi_full_instruction * inst = emit_data->inst;
const struct tgsi_shader_info *info = &ctx->shader->selector->info;
struct tgsi_full_src_register resource_reg =
tgsi_full_src_register_from_dst(&inst->Dst[0]);
unsigned target = inst->Memory.Texture;
+
+ if (inst->Dst[0].Register.File == TGSI_FILE_MEMORY) {
+ store_emit_memory(ctx, emit_data);
+ return;
+ }
+
bool writeonly_memory = is_oneway_access_only(inst, info,
info->shader_buffers_load |
info->shader_buffers_atomic,
info->images_load |
info->images_atomic);
bool is_image = inst->Dst[0].Register.File == TGSI_FILE_IMAGE ||
tgsi_is_bindless_image_file(inst->Dst[0].Register.File);
LLVMValueRef chans[4], value;
LLVMValueRef vindex = ctx->i32_0;
LLVMValueRef voffset = ctx->i32_0;
struct ac_image_args args = {};
- if (inst->Dst[0].Register.File == TGSI_FILE_MEMORY) {
- store_emit_memory(ctx, emit_data);
- return;
- }
-
for (unsigned chan = 0; chan < 4; ++chan)
chans[chan] = lp_build_emit_fetch(bld_base, inst, 1, chan);
value = ac_build_gather_values(&ctx->ac, chans, 4);
if (inst->Dst[0].Register.File == TGSI_FILE_BUFFER) {
args.resource = shader_buffer_fetch_rsrc(ctx, &resource_reg, false);
voffset = ac_to_integer(&ctx->ac, lp_build_emit_fetch(bld_base, inst, 0, 0));
} else if (is_image) {
image_fetch_rsrc(bld_base, &resource_reg, true, target, &args.resource);
--
2.17.1
More information about the mesa-dev
mailing list