/* Manually-created vertex buffers. */
pipe_resource_reference(&r300->dummy_vb, NULL);
pipe_resource_reference(&r300->vbo, NULL);
- pipe_resource_reference((struct pipe_resource**)&r300->vb_instanceid, NULL);
/* If there are any queries pending or not destroyed, remove them now. */
foreach_s(query, temp, &r300->query_list) {
r300->dummy_vb = screen->resource_create(screen, &vb);
}
- {
- int i, num = 128000;
- struct pipe_resource vb, *r;
- struct pipe_transfer *transfer;
- float *buf;
-
- memset(&vb, 0, sizeof(vb));
- vb.target = PIPE_BUFFER;
- vb.format = PIPE_FORMAT_R8_UNORM;
- vb.bind = PIPE_BIND_VERTEX_BUFFER;
- vb.usage = PIPE_USAGE_IMMUTABLE;
- vb.width0 = 4 * num;
- vb.height0 = 1;
- vb.depth0 = 1;
-
- r = screen->resource_create(screen, &vb);
-
- buf = pipe_buffer_map(&r300->context, r, PIPE_TRANSFER_WRITE, &transfer);
- for (i = 0; i < num; i++)
- buf[i] = i;
- pipe_buffer_unmap(&r300->context, transfer);
-
- r300->vb_instanceid = r300_resource(r);
- }
-
{
struct pipe_depth_stencil_alpha_state dsa;
memset(&dsa, 0, sizeof(dsa));
unsigned vertex_size_dwords;
struct r300_vertex_stream_state vertex_stream;
- struct r300_vertex_stream_state vertex_stream_instanced;
};
enum r300_hiz_func {
/* When no vertex buffer is set, this one is used instead to prevent
* hardlocks. */
struct pipe_resource *dummy_vb;
- /* Vertex buffer for InstanceID. */
- struct r300_resource *vb_instanceid;
/* The currently active query. */
struct r300_query *query_current;
struct r300_resource *buf;
int i;
unsigned vertex_array_count = r300->velems->count;
- unsigned real_vertex_array_count = vertex_array_count +
- (vertex_array_count == 16 || instance_id == -1 ? 0 : 1);
- unsigned packet_size = (real_vertex_array_count * 3 + 1) / 2;
+ unsigned packet_size = (vertex_array_count * 3 + 1) / 2;
struct pipe_vertex_buffer *vb1, *vb2;
unsigned *hw_format_size = r300->velems->format_size;
unsigned size1, size2, offset1, offset2, stride1, stride2;
CS_LOCALS(r300);
- BEGIN_CS(2 + packet_size + real_vertex_array_count * 2);
+ BEGIN_CS(2 + packet_size + vertex_array_count * 2);
OUT_CS_PKT3(R300_PACKET3_3D_LOAD_VBPNTR, packet_size);
- OUT_CS(real_vertex_array_count | (!indexed ? R300_VC_FORCE_PREFETCH : 0));
+ OUT_CS(vertex_array_count | (!indexed ? R300_VC_FORCE_PREFETCH : 0));
if (instance_id == -1) {
/* Non-instanced arrays. This ignores instance_divisor and instance_id. */
offset1 = vb1->buffer_offset + velem[i].src_offset + offset * vb1->stride;
}
- /* Insert vertex buffer containing InstanceID. */
- if (vertex_array_count < 16) {
- OUT_CS(R300_VBPNTR_SIZE0(size1) | R300_VBPNTR_STRIDE0(stride1) |
- R300_VBPNTR_SIZE1(4));
- OUT_CS(offset1);
- OUT_CS(4 * instance_id);
- } else {
- OUT_CS(R300_VBPNTR_SIZE0(size1) | R300_VBPNTR_STRIDE0(stride1));
- OUT_CS(offset1);
- }
- } else if (vertex_array_count < 16) {
- /* Insert vertex buffer containing InstanceID. */
- OUT_CS(R300_VBPNTR_SIZE0(4));
- OUT_CS(4 * instance_id);
+ OUT_CS(R300_VBPNTR_SIZE0(size1) | R300_VBPNTR_STRIDE0(stride1));
+ OUT_CS(offset1);
}
for (i = 0; i < vertex_array_count; i++) {
buf = r300_resource(valid_vbuf[velem[i].vertex_buffer_index]);
OUT_CS_RELOC(buf);
}
- if (vertex_array_count < 16)
- OUT_CS_RELOC(r300->vb_instanceid);
}
END_CS;
}
void r300_emit_vertex_stream_state(struct r300_context* r300,
unsigned size, void* state)
{
- struct r300_vertex_element_state *velems =
- (struct r300_vertex_element_state*)state;
- struct r300_vertex_stream_state *streams;
+ struct r300_vertex_stream_state *streams =
+ (struct r300_vertex_stream_state*)state;
unsigned i;
CS_LOCALS(r300);
- if (r300->screen->caps.has_tcl && r300->instancing_enabled) {
- streams = &velems->vertex_stream_instanced;
- } else {
- streams = &velems->vertex_stream;
- }
-
if (DBG_ON(r300, DBG_PSC)) {
fprintf(stderr, "r300: PSC emit:\n");
}
}
- BEGIN_CS((1 + streams->count) * 2);
+ BEGIN_CS(size);
OUT_CS_REG_SEQ(R300_VAP_PROG_STREAM_CNTL_0, streams->count);
OUT_CS_TABLE(streams->vap_prog_stream_cntl, streams->count);
OUT_CS_REG_SEQ(R300_VAP_PROG_STREAM_CNTL_EXT_0, streams->count);
r300->rws->cs_add_reloc(r300->cs, r300_resource(*buf)->cs_buf,
r300_resource(*buf)->domain, 0);
}
- if (r300->instancing_enabled) {
- r300->rws->cs_add_reloc(r300->cs, r300->vb_instanceid->cs_buf,
- r300->vb_instanceid->domain, 0);
- }
}
/* ...and index buffer for HWTCL path. */
if (index_buffer)
int index_bias,
int instance_id)
{
- /* Update vertex elements for InstanceID here. */
- boolean instancing_enabled = instance_id != -1;
-
- if (r300->screen->caps.has_tcl &&
- (flags & PREP_EMIT_AOS) &&
- instancing_enabled != r300->instancing_enabled) {
- r300->instancing_enabled = instancing_enabled;
- r300_mark_atom_dirty(r300, &r300->vertex_stream_state);
- r300->vertex_arrays_dirty = TRUE;
- flags |= PREP_EMIT_STATES;
- }
-
/* Make sure there is enough space in the command stream and emit states. */
if (r300_reserve_cs_dwords(r300, flags, cs_dwords))
flags |= PREP_EMIT_STATES;
}
/* Initialize the PSC tables. */
-static void r300_vertex_psc(struct r300_vertex_element_state *velems,
- struct r300_vertex_stream_state *vstream,
- boolean insert_instance_id_attrib)
+static void r300_vertex_psc(struct r300_vertex_element_state *velems)
{
+ struct r300_vertex_stream_state *vstream = &velems->vertex_stream;
uint16_t type, swizzle;
enum pipe_format format;
unsigned i;
}
}
- /* Insert attrib emulating InstanceID. */
- if (i < 15 && insert_instance_id_attrib) {
- format = PIPE_FORMAT_R32_FLOAT;
-
- type = r300_translate_vertex_data_type(format);
- assert(type != R300_INVALID_FORMAT);
-
- type |= i << R300_DST_VEC_LOC_SHIFT;
- swizzle = r300_translate_vertex_data_swizzle(format);
-
- if (i & 1) {
- vstream->vap_prog_stream_cntl[i >> 1] |= type << 16;
- vstream->vap_prog_stream_cntl_ext[i >> 1] |= swizzle << 16;
- } else {
- vstream->vap_prog_stream_cntl[i >> 1] |= type;
- vstream->vap_prog_stream_cntl_ext[i >> 1] |= swizzle;
- }
-
- i++;
- }
-
/* Set the last vector in the PSC. */
if (i) {
i -= 1;
if (r300_screen(pipe->screen)->caps.has_tcl) {
/* Setup PSC.
* The unused components will be replaced by (..., 0, 1). */
- r300_vertex_psc(velems, &velems->vertex_stream, FALSE);
- r300_vertex_psc(velems, &velems->vertex_stream_instanced, TRUE);
+ r300_vertex_psc(velems);
for (i = 0; i < count; i++) {
velems->format_size[i] =
return;
}
- UPDATE_STATE(velems, r300->vertex_stream_state);
- r300->vertex_stream_state.size = (1 + velems->vertex_stream_instanced.count) * 2;
+ UPDATE_STATE(&velems->vertex_stream, r300->vertex_stream_state);
+ r300->vertex_stream_state.size = (1 + velems->vertex_stream.count) * 2;
r300->vertex_arrays_dirty = TRUE;
}
/* Update the PSC tables for SW TCL, using Draw. */
static void r300_swtcl_vertex_psc(struct r300_context *r300)
{
- struct r300_vertex_element_state *velems =
- (struct r300_vertex_element_state*)r300->vertex_stream_state.state;
- struct r300_vertex_stream_state *vstream = &velems->vertex_stream;
+ struct r300_vertex_stream_state *vstream = r300->vertex_stream_state.state;
struct vertex_info *vinfo = &r300->vertex_info;
uint16_t type, swizzle;
enum pipe_format format;
#include "radeon_compiler.h"
#include "radeon_program.h"
-#include "util/u_math.h"
#include "tgsi/tgsi_info.h"
#include "tgsi/tgsi_parse.h"
#include "tgsi/tgsi_scan.h"
/* fall-through */
case TGSI_FILE_TEMPORARY: return RC_FILE_TEMPORARY;
case TGSI_FILE_ADDRESS: return RC_FILE_ADDRESS;
- case TGSI_FILE_SYSTEM_VALUE: return RC_FILE_INPUT;
}
}
if (file == TGSI_FILE_IMMEDIATE)
return ttr->immediate_offset + index;
- if (file == TGSI_FILE_SYSTEM_VALUE) {
- if (index == ttr->instance_id) {
- return ttr->num_inputs;
- } else {
- fprintf(stderr, "Unknown system value semantic index: %i\n",
- index);
- ttr->error = TRUE;
- return 0;
- }
- }
-
return index;
}
dst->U.I.TexSwizzle = RC_SWIZZLE_XYZW;
}
-static void transform_instruction(struct tgsi_to_rc * ttr,
- struct tgsi_full_instruction * src)
+static void transform_instruction(struct tgsi_to_rc * ttr, struct tgsi_full_instruction * src)
{
struct rc_instruction * dst;
int i;
}
}
-static void handle_declaration(struct tgsi_to_rc *ttr,
- struct tgsi_full_declaration *decl)
-{
- switch (decl->Declaration.File) {
- case TGSI_FILE_INPUT:
- ttr->num_inputs = MAX2(ttr->num_inputs, decl->Range.First + 1);
- break;
-
- case TGSI_FILE_SYSTEM_VALUE:
- if (decl->Semantic.Name == TGSI_SEMANTIC_INSTANCEID) {
- printf("Got instance id\n");
- ttr->instance_id = decl->Range.First;
- } else {
- fprintf(stderr, "Unknown system value semantic: %i.\n",
- decl->Semantic.Name);
- ttr->error = TRUE;
- }
- break;
- }
-}
-
void r300_tgsi_to_rc(struct tgsi_to_rc * ttr,
const struct tgsi_token * tokens)
{
unsigned imm_index = 0;
int i;
- ttr->num_inputs = 0;
- ttr->instance_id = -1;
ttr->error = FALSE;
/* Allocate constants placeholders.
switch (parser.FullToken.Token.Type) {
case TGSI_TOKEN_TYPE_DECLARATION:
- handle_declaration(ttr, &parser.FullToken.FullDeclaration);
- if (ttr->error)
- goto end_while;
break;
-
case TGSI_TOKEN_TYPE_IMMEDIATE:
handle_immediate(ttr, &parser.FullToken.FullImmediate, imm_index);
imm_index++;
break;
-
case TGSI_TOKEN_TYPE_INSTRUCTION:
inst = &parser.FullToken.FullInstruction;
if (inst->Instruction.Opcode == TGSI_OPCODE_END) {
- goto end_while;
+ break;
}
transform_instruction(ttr, inst);
- if (ttr->error)
- goto end_while;
break;
}
}
-end_while:
tgsi_parse_free(&parser);
struct swizzled_imms * imms_to_swizzle;
unsigned imms_to_swizzle_count;
- int num_inputs;
- int instance_id;
-
/* Vertex shaders have no half swizzles, and no way to handle them, so
* until rc grows proper support, indicate if they're safe to use. */
boolean use_half_swizzles;
outputs->bcolor[1] != ATTR_UNUSED;
/* Fill in the input mapping */
- for (i = 0; i < info->num_inputs+1; i++)
+ for (i = 0; i < info->num_inputs; i++)
c->code->inputs[i] = i;
/* Position. */