const struct tgsi_full_instruction * inst = emit_data->inst;
unsigned opcode = inst->Instruction.Opcode;
unsigned target = inst->Texture.Texture;
- unsigned sampler_src, sampler_index;
LLVMValueRef coords[4];
LLVMValueRef address[16];
int ref_pos;
unsigned num_coords = tgsi_util_get_texture_coord_dim(target, &ref_pos);
unsigned count = 0;
unsigned chan;
+ unsigned sampler_src = emit_data->inst->Instruction.NumSrcRegs - 1;
+ unsigned sampler_index = emit_data->inst->Src[sampler_src].Register.Index;
+
+ if (target == TGSI_TEXTURE_BUFFER) {
+ LLVMTypeRef i128 = LLVMIntTypeInContext(gallivm->context, 128);
+ LLVMTypeRef v2i128 = LLVMVectorType(i128, 2);
+ LLVMTypeRef i8 = LLVMInt8TypeInContext(gallivm->context);
+ LLVMTypeRef v16i8 = LLVMVectorType(i8, 16);
+
+ /* Truncate v32i8 to v16i8. */
+ LLVMValueRef res = si_shader_ctx->resources[sampler_index];
+ res = LLVMBuildBitCast(gallivm->builder, res, v2i128, "");
+ res = LLVMBuildExtractElement(gallivm->builder, res, bld_base->uint_bld.zero, "");
+ res = LLVMBuildBitCast(gallivm->builder, res, v16i8, "");
+
+ emit_data->dst_type = LLVMVectorType(bld_base->base.elem_type, 4);
+ emit_data->args[0] = res;
+ emit_data->args[1] = bld_base->uint_bld.zero;
+ emit_data->args[2] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, 0);
+ emit_data->arg_count = 3;
+ return;
+ }
/* Fetch and project texture coordinates */
coords[3] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, TGSI_CHAN_W);
"");
}
- sampler_src = emit_data->inst->Instruction.NumSrcRegs - 1;
- sampler_index = emit_data->inst->Src[sampler_src].Register.Index;
-
/* Adjust the sample index according to FMASK.
*
* For uncompressed MSAA surfaces, FMASK should return 0x76543210,
struct lp_build_context * base = &bld_base->base;
char intr_name[127];
+ if (emit_data->inst->Texture.Texture == TGSI_TEXTURE_BUFFER) {
+ emit_data->output[emit_data->chan] = build_intrinsic(
+ base->gallivm->builder,
+ "llvm.SI.vs.load.input", emit_data->dst_type,
+ emit_data->args, emit_data->arg_count,
+ LLVMReadNoneAttribute | LLVMNoUnwindAttribute);
+ return;
+ }
+
sprintf(intr_name, "%sv%ui32", action->intr_name,
LLVMGetVectorSize(LLVMTypeOf(emit_data->args[0])));
{
struct si_shader_context *si_shader_ctx = si_shader_context(bld_base);
const struct tgsi_full_instruction *inst = emit_data->inst;
+ struct gallivm_state *gallivm = bld_base->base.gallivm;
+
+ if (inst->Texture.Texture == TGSI_TEXTURE_BUFFER) {
+ LLVMTypeRef i32 = LLVMInt32TypeInContext(gallivm->context);
+ LLVMTypeRef v8i32 = LLVMVectorType(i32, 8);
+
+ /* Read the size from the buffer descriptor directly. */
+ LLVMValueRef size = si_shader_ctx->resources[inst->Src[1].Register.Index];
+ size = LLVMBuildBitCast(gallivm->builder, size, v8i32, "");
+ size = LLVMBuildExtractElement(gallivm->builder, size,
+ lp_build_const_int32(gallivm, 2), "");
+ emit_data->args[0] = size;
+ return;
+ }
/* Mip level */
emit_data->args[0] = lp_build_emit_fetch(bld_base, inst, 0, TGSI_CHAN_X);
4);
}
+static void build_txq_intrinsic(const struct lp_build_tgsi_action * action,
+ struct lp_build_tgsi_context * bld_base,
+ struct lp_build_emit_data * emit_data)
+{
+ if (emit_data->inst->Texture.Texture == TGSI_TEXTURE_BUFFER) {
+ /* Just return the buffer size. */
+ emit_data->output[emit_data->chan] = emit_data->args[0];
+ return;
+ }
+
+ build_tgsi_intrinsic_nomem(action, bld_base, emit_data);
+}
+
#if HAVE_LLVM >= 0x0304
static void si_llvm_emit_ddxy(
static const struct lp_build_tgsi_action txq_action = {
.fetch_args = txq_fetch_args,
- .emit = build_tgsi_intrinsic_nomem,
+ .emit = build_txq_intrinsic,
.intr_name = "llvm.SI.resinfo"
};
util_format_get_first_non_void_channel(format)) != ~0U;
}
-static uint32_t si_translate_vertexformat(struct pipe_screen *screen,
- enum pipe_format format,
- const struct util_format_description *desc,
- int first_non_void)
+static uint32_t si_translate_buffer_dataformat(struct pipe_screen *screen,
+ const struct util_format_description *desc,
+ int first_non_void)
{
unsigned type = desc->channel[first_non_void].type;
int i;
return V_008F0C_BUF_DATA_FORMAT_INVALID;
}
+static uint32_t si_translate_buffer_numformat(struct pipe_screen *screen,
+ const struct util_format_description *desc,
+ int first_non_void)
+{
+ switch (desc->channel[first_non_void].type) {
+ case UTIL_FORMAT_TYPE_SIGNED:
+ if (desc->channel[first_non_void].normalized)
+ return V_008F0C_BUF_NUM_FORMAT_SNORM;
+ else if (desc->channel[first_non_void].pure_integer)
+ return V_008F0C_BUF_NUM_FORMAT_SINT;
+ else
+ return V_008F0C_BUF_NUM_FORMAT_SSCALED;
+ break;
+ case UTIL_FORMAT_TYPE_UNSIGNED:
+ if (desc->channel[first_non_void].normalized)
+ return V_008F0C_BUF_NUM_FORMAT_UNORM;
+ else if (desc->channel[first_non_void].pure_integer)
+ return V_008F0C_BUF_NUM_FORMAT_UINT;
+ else
+ return V_008F0C_BUF_NUM_FORMAT_USCALED;
+ break;
+ case UTIL_FORMAT_TYPE_FLOAT:
+ default:
+ return V_008F0C_BUF_NUM_FORMAT_FLOAT;
+ }
+}
+
static bool si_is_vertex_format_supported(struct pipe_screen *screen, enum pipe_format format)
{
const struct util_format_description *desc;
desc = util_format_description(format);
first_non_void = util_format_get_first_non_void_channel(format);
- data_format = si_translate_vertexformat(screen, format, desc, first_non_void);
+ data_format = si_translate_buffer_dataformat(screen, desc, first_non_void);
return data_format != V_008F0C_BUF_DATA_FORMAT_INVALID;
}
/* initialize base object */
view->base = *state;
view->base.texture = NULL;
- pipe_reference(NULL, &texture->reference);
- view->base.texture = texture;
+ pipe_resource_reference(&view->base.texture, texture);
view->base.reference.count = 1;
view->base.context = ctx;
+ view->resource = &tmp->resource;
+
+ /* Buffer resource. */
+ if (texture->target == PIPE_BUFFER) {
+ unsigned stride;
+
+ desc = util_format_description(state->format);
+ first_non_void = util_format_get_first_non_void_channel(state->format);
+ stride = desc->block.bits / 8;
+ va = r600_resource_va(ctx->screen, texture) + state->u.buf.first_element*stride;
+ format = si_translate_buffer_dataformat(ctx->screen, desc, first_non_void);
+ num_format = si_translate_buffer_numformat(ctx->screen, desc, first_non_void);
+
+ view->state[0] = va;
+ view->state[1] = S_008F04_BASE_ADDRESS_HI(va >> 32) |
+ S_008F04_STRIDE(stride);
+ view->state[2] = state->u.buf.last_element + 1 - state->u.buf.first_element;
+ view->state[3] = S_008F0C_DST_SEL_X(si_map_swizzle(desc->swizzle[0])) |
+ S_008F0C_DST_SEL_Y(si_map_swizzle(desc->swizzle[1])) |
+ S_008F0C_DST_SEL_Z(si_map_swizzle(desc->swizzle[2])) |
+ S_008F0C_DST_SEL_W(si_map_swizzle(desc->swizzle[3])) |
+ S_008F0C_NUM_FORMAT(num_format) |
+ S_008F0C_DATA_FORMAT(format);
+ return &view->base;
+ }
state_swizzle[0] = state->swizzle_r;
state_swizzle[1] = state->swizzle_g;
format = 0;
}
- view->resource = &tmp->resource;
-
/* not supported any more */
//endian = si_colorformat_endian_swap(format);
assert(start == 0);
for (i = 0; i < count; i++) {
- if (views[i]) {
+ if (!views[i]) {
+ samplers->depth_texture_mask &= ~(1 << i);
+ samplers->compressed_colortex_mask &= ~(1 << i);
+ si_set_sampler_view(rctx, shader, i, NULL, NULL);
+ si_set_sampler_view(rctx, shader, FMASK_TEX_OFFSET + i,
+ NULL, NULL);
+ continue;
+ }
+
+ si_set_sampler_view(rctx, shader, i, views[i], rviews[i]->state);
+
+ if (views[i]->texture->target != PIPE_BUFFER) {
struct r600_texture *rtex =
(struct r600_texture*)views[i]->texture;
samplers->compressed_colortex_mask &= ~(1 << i);
}
- si_set_sampler_view(rctx, shader, i, views[i], rviews[i]->state);
-
if (rtex->fmask.size) {
si_set_sampler_view(rctx, shader, FMASK_TEX_OFFSET + i,
views[i], rviews[i]->fmask_state);
si_set_sampler_view(rctx, shader, FMASK_TEX_OFFSET + i,
NULL, NULL);
}
- } else {
- samplers->depth_texture_mask &= ~(1 << i);
- samplers->compressed_colortex_mask &= ~(1 << i);
- si_set_sampler_view(rctx, shader, i, NULL, NULL);
- si_set_sampler_view(rctx, shader, FMASK_TEX_OFFSET + i,
- NULL, NULL);
}
}
for (; i < samplers->n_views; i++) {
desc = util_format_description(elements[i].src_format);
first_non_void = util_format_get_first_non_void_channel(elements[i].src_format);
- data_format = si_translate_vertexformat(ctx->screen, elements[i].src_format,
- desc, first_non_void);
-
- switch (desc->channel[first_non_void].type) {
- case UTIL_FORMAT_TYPE_FIXED:
- num_format = V_008F0C_BUF_NUM_FORMAT_USCALED; /* XXX */
- break;
- case UTIL_FORMAT_TYPE_SIGNED:
- if (desc->channel[first_non_void].normalized)
- num_format = V_008F0C_BUF_NUM_FORMAT_SNORM;
- else if (desc->channel[first_non_void].pure_integer)
- num_format = V_008F0C_BUF_NUM_FORMAT_SINT;
- else
- num_format = V_008F0C_BUF_NUM_FORMAT_SSCALED;
- break;
- case UTIL_FORMAT_TYPE_UNSIGNED:
- if (desc->channel[first_non_void].normalized)
- num_format = V_008F0C_BUF_NUM_FORMAT_UNORM;
- else if (desc->channel[first_non_void].pure_integer)
- num_format = V_008F0C_BUF_NUM_FORMAT_UINT;
- else
- num_format = V_008F0C_BUF_NUM_FORMAT_USCALED;
- break;
- case UTIL_FORMAT_TYPE_FLOAT:
- default:
- num_format = V_008F14_IMG_NUM_FORMAT_FLOAT;
- }
+ data_format = si_translate_buffer_dataformat(ctx->screen, desc, first_non_void);
+ num_format = si_translate_buffer_numformat(ctx->screen, desc, first_non_void);
v->rsrc_word3[i] = S_008F0C_DST_SEL_X(si_map_swizzle(desc->swizzle[0])) |
S_008F0C_DST_SEL_Y(si_map_swizzle(desc->swizzle[1])) |