struct r300_constant_buffer {
/* Buffer of constants */
- uint32_t constants[256][4];
- /* Total number of constants */
+ uint32_t *ptr;
+ /* Total number of vec4s */
unsigned count;
};
struct r300_fragment_shader *fs = r300_fs(r300);
struct r300_constant_buffer *buf = (struct r300_constant_buffer*)state;
unsigned count = fs->shader->externals_count * 4;
+ unsigned i, j;
CS_LOCALS(r300);
if (count == 0)
BEGIN_CS(size);
OUT_CS_REG_SEQ(R300_PFS_PARAM_0_X, count);
- OUT_CS_TABLE(buf->constants, count);
+ for (i = 0; i < count; i++)
+ for (j = 0; j < 4; j++)
+ OUT_CS(pack_float24(buf->ptr[i*4+j]));
END_CS;
}
unsigned count = fs->shader->rc_state_count;
unsigned first = fs->shader->externals_count;
unsigned end = constants->Count;
- uint32_t cdata[4];
unsigned j;
CS_LOCALS(r300);
const float *data =
get_rc_constant_state(r300, &constants->Constants[i]);
- for (j = 0; j < 4; j++)
- cdata[j] = pack_float24(data[j]);
-
OUT_CS_REG_SEQ(R300_PFS_PARAM_0_X + i * 16, 4);
- OUT_CS_TABLE(cdata, 4);
+ for (j = 0; j < 4; j++)
+ OUT_CS(pack_float24(data[j]));
}
}
END_CS;
BEGIN_CS(size);
OUT_CS_REG(R500_GA_US_VECTOR_INDEX, R500_GA_US_VECTOR_INDEX_TYPE_CONST);
OUT_CS_ONE_REG(R500_GA_US_VECTOR_DATA, count);
- OUT_CS_TABLE(buf->constants, count);
+ OUT_CS_TABLE(buf->ptr, count);
END_CS;
}
(r300->screen->caps.is_r500 ?
R500_PVS_CONST_START : R300_PVS_CONST_START));
OUT_CS_ONE_REG(R300_VAP_PVS_UPLOAD_DATA, count * 4);
- OUT_CS_TABLE(buf->constants, count * 4);
+ OUT_CS_TABLE(buf->ptr, count * 4);
END_CS;
}
struct r300_screen *r300screen = r300_screen(screen);
struct r300_buffer *rbuf = r300_buffer(buf);
+ if (rbuf->constant_buffer)
+ FREE(rbuf->constant_buffer);
+
r300_winsys_buffer_destroy(r300screen, rbuf);
FREE(rbuf);
}
if (rbuf->user_buffer)
return (uint8_t *) rbuf->user_buffer + transfer->box.x;
-
- if (rbuf->b.b.bind & PIPE_BIND_CONSTANT_BUFFER) {
- goto just_map;
- }
+ if (rbuf->constant_buffer)
+ return (uint8_t *) rbuf->constant_buffer + transfer->box.x;
/* check if the mapping is to a range we already flushed */
if (transfer->usage & PIPE_TRANSFER_DISCARD) {
}
}
-just_map:
map = rws->buffer_map(rws, rbuf->buf, r300->cs, transfer->usage);
if (map == NULL)
if (rbuf->user_buffer)
return;
-
- if (rbuf->b.b.bind & PIPE_BIND_CONSTANT_BUFFER)
- return;
+ if (rbuf->constant_buffer)
+ return;
/* mark the range as used */
for(i = 0; i < rbuf->num_ranges; ++i) {
rbuf->b.b.screen = screen;
rbuf->domain = R300_DOMAIN_GTT;
+ /* Alloc constant buffers in RAM. */
+ if (templ->bind & PIPE_BIND_CONSTANT_BUFFER) {
+ rbuf->constant_buffer = MALLOC(templ->width0);
+ return &rbuf->b.b;
+ }
+
rbuf->buf =
r300screen->rws->buffer_create(r300screen->rws,
rbuf->b.b.width0, alignment,
enum r300_buffer_domain domain;
void *user_buffer;
+ void *constant_buffer;
struct r300_buffer_range ranges[R300_BUFFER_MAX_RANGES];
unsigned num_ranges;
};
{
struct r300_context* r300 = r300_context(pipe);
struct r300_constant_buffer *cbuf;
- struct pipe_transfer *tr;
- float *mapped;
+ uint32_t *mapped = r300_buffer(buf)->user_buffer;
int max_size = 0, max_size_bytes = 0, clamped_size = 0;
switch (shader) {
max_size_bytes = max_size * 4 * sizeof(float);
if (buf == NULL || buf->width0 == 0 ||
- (mapped = pipe_buffer_map(pipe, buf, PIPE_TRANSFER_READ, &tr)) == NULL)
- {
+ (mapped = r300_buffer(buf)->constant_buffer) == NULL) {
cbuf->count = 0;
return;
}
clamped_size = MIN2(buf->width0, max_size_bytes);
cbuf->count = clamped_size / (4 * sizeof(float));
-
- if (shader == PIPE_SHADER_FRAGMENT && !r300->screen->caps.is_r500) {
- unsigned i,j;
-
- /* Convert constants to float24. */
- for (i = 0; i < cbuf->count; i++)
- for (j = 0; j < 4; j++)
- cbuf->constants[i][j] = pack_float24(mapped[i*4+j]);
- } else {
- memcpy(cbuf->constants, mapped, clamped_size);
- }
+ cbuf->ptr = mapped;
}
if (shader == PIPE_SHADER_VERTEX) {
} else if (shader == PIPE_SHADER_FRAGMENT) {
r300->fs_constants.dirty = TRUE;
}
-
- pipe_buffer_unmap(pipe, buf, tr);
}
void r300_init_state_functions(struct r300_context* r300)
desc.usage = get_pb_usage_from_create_flags(bind, usage, domain);
/* Assign a buffer manager. */
- if (bind & PIPE_BIND_CONSTANT_BUFFER)
- provider = ws->mman;
- else if (bind & (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER))
+ if (bind & (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER))
provider = ws->cman;
else
provider = ws->kman;
ws->cman->destroy(ws->cman);
ws->kman->destroy(ws->kman);
- ws->mman->destroy(ws->mman);
radeon_bo_manager_gem_dtor(ws->bom);
radeon_cs_manager_gem_dtor(ws->csm);
if (!ws->cman)
goto fail;
- ws->mman = pb_malloc_bufmgr_create();
- if (!ws->mman)
- goto fail;
-
ws->base.destroy = radeon_winsys_destroy;
ws->base.get_value = radeon_get_value;
ws->cman->destroy(ws->cman);
if (ws->kman)
ws->kman->destroy(ws->kman);
- if (ws->mman)
- ws->mman->destroy(ws->mman);
return FALSE;
}
struct pb_manager *cman;
- struct pb_manager *mman;
-
/* PCI ID */
uint32_t pci_id;