summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolai Hähnle <nicolai.haehnle@amd.com>2017-06-09 17:47:34 +0200
committerNicolai Hähnle <nicolai.haehnle@amd.com>2017-07-13 13:26:51 +0200
commitcf4fea3961b73bf18feef01e0f4a713cd6f94eb0 (patch)
treed7ca0c61eb616ba7fe8ece1d8a7da6e04726c61f
parent28893c95a0858ea8bd40f5daeff332effacbc8de (diff)
ac/nir: add image and write parameter to ac_shader_abi::load_sampler_desc
-rw-r--r--src/amd/common/ac_nir_to_llvm.c43
-rw-r--r--src/amd/common/ac_shader_abi.h4
-rw-r--r--src/gallium/drivers/radeonsi/si_shader_nir.c3
3 files changed, 30 insertions, 20 deletions
diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index c70abb8267..1c23053c62 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -188,7 +188,8 @@ nir_to_llvm_context_from_abi(struct ac_shader_abi *abi)
static LLVMValueRef get_sampler_desc(struct ac_nir_context *ctx,
const nir_deref_var *deref,
- enum ac_descriptor_type desc_type);
+ enum ac_descriptor_type desc_type,
+ bool image, bool write);
static unsigned radeon_llvm_reg_index_soa(unsigned index, unsigned chan)
{
@@ -3297,7 +3298,7 @@ static LLVMValueRef get_image_coords(struct ac_nir_context *ctx,
fmask_load_address[1],
fmask_load_address[2],
sample_index,
- get_sampler_desc(ctx, instr->variables[0], AC_DESC_FMASK));
+ get_sampler_desc(ctx, instr->variables[0], AC_DESC_FMASK, true, false));
}
if (count == 1) {
if (instr->src[0].ssa->num_components)
@@ -3346,7 +3347,7 @@ static LLVMValueRef visit_image_load(struct ac_nir_context *ctx,
type = glsl_without_array(type);
if (glsl_get_sampler_dim(type) == GLSL_SAMPLER_DIM_BUF) {
- params[0] = get_sampler_desc(ctx, instr->variables[0], AC_DESC_BUFFER);
+ params[0] = get_sampler_desc(ctx, instr->variables[0], AC_DESC_BUFFER, true, false);
params[1] = LLVMBuildExtractElement(ctx->ac.builder, get_src(ctx, instr->src[0]),
ctx->ac.i32_0, ""); /* vindex */
params[2] = ctx->ac.i32_0; /* voffset */
@@ -3365,7 +3366,7 @@ static LLVMValueRef visit_image_load(struct ac_nir_context *ctx,
LLVMValueRef slc = i1false;
params[0] = get_image_coords(ctx, instr);
- params[1] = get_sampler_desc(ctx, instr->variables[0], AC_DESC_IMAGE);
+ params[1] = get_sampler_desc(ctx, instr->variables[0], AC_DESC_IMAGE, true, false);
params[2] = LLVMConstInt(ctx->ac.i32, 15, false); /* dmask */
if (HAVE_LLVM <= 0x0309) {
params[3] = i1false; /* r128 */
@@ -3407,7 +3408,7 @@ static void visit_image_store(struct ac_nir_context *ctx,
if (glsl_get_sampler_dim(type) == GLSL_SAMPLER_DIM_BUF) {
params[0] = to_float(&ctx->ac, get_src(ctx, instr->src[2])); /* data */
- params[1] = get_sampler_desc(ctx, instr->variables[0], AC_DESC_BUFFER);
+ params[1] = get_sampler_desc(ctx, instr->variables[0], AC_DESC_BUFFER, true, true);
params[2] = LLVMBuildExtractElement(ctx->ac.builder, get_src(ctx, instr->src[0]),
ctx->ac.i32_0, ""); /* vindex */
params[3] = ctx->ac.i32_0; /* voffset */
@@ -3424,7 +3425,7 @@ static void visit_image_store(struct ac_nir_context *ctx,
params[0] = to_float(&ctx->ac, get_src(ctx, instr->src[2]));
params[1] = get_image_coords(ctx, instr); /* coords */
- params[2] = get_sampler_desc(ctx, instr->variables[0], AC_DESC_IMAGE);
+ params[2] = get_sampler_desc(ctx, instr->variables[0], AC_DESC_IMAGE, true, true);
params[3] = LLVMConstInt(ctx->ac.i32, 15, false); /* dmask */
if (HAVE_LLVM <= 0x0309) {
params[4] = i1false; /* r128 */
@@ -3502,7 +3503,8 @@ static LLVMValueRef visit_image_atomic(struct ac_nir_context *ctx,
params[param_count++] = get_src(ctx, instr->src[2]);
if (glsl_get_sampler_dim(type) == GLSL_SAMPLER_DIM_BUF) {
- params[param_count++] = get_sampler_desc(ctx, instr->variables[0], AC_DESC_BUFFER);
+ params[param_count++] = get_sampler_desc(ctx, instr->variables[0], AC_DESC_BUFFER,
+ true, true);
params[param_count++] = LLVMBuildExtractElement(ctx->ac.builder, get_src(ctx, instr->src[0]),
ctx->ac.i32_0, ""); /* vindex */
params[param_count++] = ctx->ac.i32_0; /* voffset */
@@ -3517,7 +3519,8 @@ static LLVMValueRef visit_image_atomic(struct ac_nir_context *ctx,
glsl_get_sampler_dim(type) == GLSL_SAMPLER_DIM_CUBE;
LLVMValueRef coords = params[param_count++] = get_image_coords(ctx, instr);
- params[param_count++] = get_sampler_desc(ctx, instr->variables[0], AC_DESC_IMAGE);
+ params[param_count++] = get_sampler_desc(ctx, instr->variables[0], AC_DESC_IMAGE,
+ true, true);
params[param_count++] = i1false; /* r128 */
params[param_count++] = da ? i1true : i1false; /* da */
params[param_count++] = i1false; /* slc */
@@ -3545,13 +3548,15 @@ static LLVMValueRef visit_image_size(struct ac_nir_context *ctx,
type = instr->variables[0]->deref.child->type;
if (glsl_get_sampler_dim(type) == GLSL_SAMPLER_DIM_BUF)
- return get_buffer_size(ctx, get_sampler_desc(ctx, instr->variables[0], AC_DESC_BUFFER), true);
+ return get_buffer_size(ctx,
+ get_sampler_desc(ctx, instr->variables[0],
+ AC_DESC_BUFFER, true, false), true);
struct ac_image_args args = { 0 };
args.da = da;
args.dmask = 0xf;
- args.resource = get_sampler_desc(ctx, instr->variables[0], AC_DESC_IMAGE);
+ args.resource = get_sampler_desc(ctx, instr->variables[0], AC_DESC_IMAGE, true, false);
args.opcode = ac_image_get_resinfo;
args.addr = ctx->ac.i32_0;
@@ -4122,7 +4127,8 @@ static LLVMValueRef radv_get_sampler_desc(struct ac_shader_abi *abi,
unsigned base_index,
unsigned constant_index,
LLVMValueRef index,
- enum ac_descriptor_type desc_type)
+ enum ac_descriptor_type desc_type,
+ bool image, bool write)
{
struct nir_to_llvm_context *ctx = nir_to_llvm_context_from_abi(abi);
LLVMValueRef list = ctx->descriptor_sets[descriptor_set];
@@ -4194,7 +4200,8 @@ static LLVMValueRef radv_get_sampler_desc(struct ac_shader_abi *abi,
static LLVMValueRef get_sampler_desc(struct ac_nir_context *ctx,
const nir_deref_var *deref,
- enum ac_descriptor_type desc_type)
+ enum ac_descriptor_type desc_type,
+ bool image, bool write)
{
LLVMValueRef index = NULL;
unsigned constant_index = 0;
@@ -4230,7 +4237,7 @@ static LLVMValueRef get_sampler_desc(struct ac_nir_context *ctx,
deref->var->data.descriptor_set,
deref->var->data.binding,
constant_index, index,
- desc_type);
+ desc_type, image, write);
}
static void set_tex_fetch_args(struct ac_llvm_context *ctx,
@@ -4303,20 +4310,20 @@ static void tex_fetch_ptrs(struct ac_nir_context *ctx,
LLVMValueRef *fmask_ptr)
{
if (instr->sampler_dim == GLSL_SAMPLER_DIM_BUF)
- *res_ptr = get_sampler_desc(ctx, instr->texture, AC_DESC_BUFFER);
+ *res_ptr = get_sampler_desc(ctx, instr->texture, AC_DESC_BUFFER, false, false);
else
- *res_ptr = get_sampler_desc(ctx, instr->texture, AC_DESC_IMAGE);
+ *res_ptr = get_sampler_desc(ctx, instr->texture, AC_DESC_IMAGE, false, false);
if (samp_ptr) {
if (instr->sampler)
- *samp_ptr = get_sampler_desc(ctx, instr->sampler, AC_DESC_SAMPLER);
+ *samp_ptr = get_sampler_desc(ctx, instr->sampler, AC_DESC_SAMPLER, false, false);
else
- *samp_ptr = get_sampler_desc(ctx, instr->texture, AC_DESC_SAMPLER);
+ *samp_ptr = get_sampler_desc(ctx, instr->texture, AC_DESC_SAMPLER, false, false);
if (instr->sampler_dim < GLSL_SAMPLER_DIM_RECT)
*samp_ptr = sici_fix_sampler_aniso(ctx, *res_ptr, *samp_ptr);
}
if (fmask_ptr && !instr->sampler && (instr->op == nir_texop_txf_ms ||
instr->op == nir_texop_samples_identical))
- *fmask_ptr = get_sampler_desc(ctx, instr->texture, AC_DESC_FMASK);
+ *fmask_ptr = get_sampler_desc(ctx, instr->texture, AC_DESC_FMASK, false, false);
}
static LLVMValueRef apply_round_slice(struct ac_llvm_context *ctx,
diff --git a/src/amd/common/ac_shader_abi.h b/src/amd/common/ac_shader_abi.h
index 63d31c82b5..fe804cf5c8 100644
--- a/src/amd/common/ac_shader_abi.h
+++ b/src/amd/common/ac_shader_abi.h
@@ -67,13 +67,15 @@ struct ac_shader_abi {
* sampler variable is not an array)
* \param index non-constant part of an array index (may be NULL)
* \param desc_type the type of descriptor to load
+ * \param image whether the descriptor is loaded for an image operation
*/
LLVMValueRef (*load_sampler_desc)(struct ac_shader_abi *abi,
unsigned descriptor_set,
unsigned base_index,
unsigned constant_index,
LLVMValueRef index,
- enum ac_descriptor_type desc_type);
+ enum ac_descriptor_type desc_type,
+ bool image, bool write);
};
#endif /* AC_SHADER_ABI_H */
diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c b/src/gallium/drivers/radeonsi/si_shader_nir.c
index a278ef218b..9ad68f401b 100644
--- a/src/gallium/drivers/radeonsi/si_shader_nir.c
+++ b/src/gallium/drivers/radeonsi/si_shader_nir.c
@@ -346,7 +346,8 @@ static LLVMValueRef
si_nir_load_sampler_desc(struct ac_shader_abi *abi,
unsigned descriptor_set, unsigned base_index,
unsigned constant_index, LLVMValueRef dynamic_index,
- enum ac_descriptor_type desc_type)
+ enum ac_descriptor_type desc_type, bool image,
+ bool write)
{
struct si_shader_context *ctx = si_shader_context_from_abi(abi);
LLVMBuilderRef builder = ctx->ac.builder;