#include "util/u_half.h"
#include "util/u_helpers.h"
#include "util/u_math.h"
-#include "util/u_mm.h"
#include "util/u_memory.h"
#include "util/u_pack_color.h"
#include "util/u_transfer.h"
uint32_t blend_control = 0; /* R300_RB3D_CBLEND: 0x4e04 */
uint32_t blend_control_noclamp = 0; /* R300_RB3D_CBLEND: 0x4e04 */
uint32_t blend_control_noalpha = 0; /* R300_RB3D_CBLEND: 0x4e04 */
+ uint32_t blend_control_noalpha_noclamp = 0; /* R300_RB3D_CBLEND: 0x4e04 */
uint32_t alpha_blend_control = 0; /* R300_RB3D_ABLEND: 0x4e08 */
uint32_t alpha_blend_control_noclamp = 0; /* R300_RB3D_ABLEND: 0x4e08 */
uint32_t alpha_blend_control_noalpha = 0; /* R300_RB3D_ABLEND: 0x4e08 */
+ uint32_t alpha_blend_control_noalpha_noclamp = 0; /* R300_RB3D_ABLEND: 0x4e08 */
uint32_t rop = 0; /* R300_RB3D_ROPCNTL: 0x4e18 */
uint32_t dither = 0; /* R300_RB3D_DITHER_CTL: 0x4e50 */
int i;
/* Get blending register values. */
if (state->rt[0].blend_enable) {
- unsigned blend_eq;
+ unsigned blend_eq, blend_eq_noclamp;
/* despite the name, ALPHA_BLEND_ENABLE has nothing to do with alpha,
* this is just the crappy D3D naming */
( r300_translate_blend_factor(srcRGB) << R300_SRC_BLEND_SHIFT) |
( r300_translate_blend_factor(dstRGB) << R300_DST_BLEND_SHIFT);
- blend_control_noalpha =
+ blend_control_noalpha = blend_control_noalpha_noclamp =
R300_ALPHA_BLEND_ENABLE |
( r300_translate_blend_factor(srcRGBX) << R300_SRC_BLEND_SHIFT) |
( r300_translate_blend_factor(dstRGBX) << R300_DST_BLEND_SHIFT);
blend_eq = r300_translate_blend_function(eqRGB, TRUE);
+ blend_eq_noclamp = r300_translate_blend_function(eqRGB, FALSE);
+
blend_control |= blend_eq;
blend_control_noalpha |= blend_eq;
- blend_control_noclamp |= r300_translate_blend_function(eqRGB, FALSE);
+ blend_control_noclamp |= blend_eq_noclamp;
+ blend_control_noalpha_noclamp |= blend_eq_noclamp;
/* Optimization: some operations do not require the destination color. */
blend_control |= blend_read_enable(eqRGB, eqA, dstRGB, dstA,
srcRGB, srcA, FALSE);
blend_control_noalpha |= blend_read_enable(eqRGB, eqA, dstRGBX, dstA,
srcRGBX, srcA, r300screen->caps.is_r500);
+ blend_control_noalpha_noclamp |= blend_read_enable(eqRGB, eqA, dstRGBX, dstA,
+ srcRGBX, srcA, FALSE);
/* Optimization: discard pixels which don't change the colorbuffer.
* It cannot be used with FP16 AA. */
}
if (srcA != srcRGBX || dstA != dstRGBX || eqA != eqRGB) {
blend_control_noalpha |= R300_SEPARATE_ALPHA_ENABLE;
+ blend_control_noalpha_noclamp |= R300_SEPARATE_ALPHA_ENABLE;
- alpha_blend_control_noalpha =
+ alpha_blend_control_noalpha = alpha_blend_control_noalpha_noclamp =
(r300_translate_blend_factor(srcA) << R300_SRC_BLEND_SHIFT) |
- (r300_translate_blend_factor(dstA) << R300_DST_BLEND_SHIFT) |
- r300_translate_blend_function(eqA, TRUE);
+ (r300_translate_blend_factor(dstA) << R300_DST_BLEND_SHIFT);
+ alpha_blend_control_noalpha |= r300_translate_blend_function(eqA, TRUE);
+ alpha_blend_control_noalpha_noclamp |= r300_translate_blend_function(eqA, FALSE);
}
}
}
}
- /* Build a command buffer (for FP16). */
+ /* Build a command buffer (for RGBA16F). */
BEGIN_CB(blend->cb_noclamp, 8);
OUT_CB_REG(R300_RB3D_ROPCNTL, rop);
OUT_CB_REG_SEQ(R300_RB3D_CBLEND, 3);
OUT_CB_REG(R300_RB3D_DITHER_CTL, dither);
END_CB;
+ /* Build a command buffer (for RGB16F). */
+ BEGIN_CB(blend->cb_noclamp_noalpha, 8);
+ OUT_CB_REG(R300_RB3D_ROPCNTL, rop);
+ OUT_CB_REG_SEQ(R300_RB3D_CBLEND, 3);
+ OUT_CB(blend_control_noalpha_noclamp);
+ OUT_CB(alpha_blend_control_noalpha_noclamp);
+ OUT_CB(rgba_cmask(state->rt[0].colormask));
+ OUT_CB_REG(R300_RB3D_DITHER_CTL, dither);
+ END_CB;
+
/* The same as above, but with no colorbuffer reads and writes. */
BEGIN_CB(blend->cb_no_readwrite, 8);
OUT_CB_REG(R300_RB3D_ROPCNTL, rop);
struct r300_blend_color_state *state =
(struct r300_blend_color_state*)r300->blend_color_state.state;
struct pipe_blend_color c;
- enum pipe_format format = fb->nr_cbufs ? fb->cbufs[0]->format : 0;
+ struct pipe_surface *cb;
float tmp;
CB_LOCALS;
state->state = *color; /* Save it, so that we can reuse it in set_fb_state */
c = *color;
+ cb = fb->nr_cbufs ? r300_get_nonnull_cb(fb, 0) : NULL;
/* The blend color is dependent on the colorbuffer format. */
- if (fb->nr_cbufs) {
- switch (format) {
+ if (cb) {
+ switch (cb->format) {
case PIPE_FORMAT_R8_UNORM:
case PIPE_FORMAT_L8_UNORM:
case PIPE_FORMAT_I8_UNORM:
break;
case PIPE_FORMAT_L8A8_UNORM:
+ case PIPE_FORMAT_R8A8_UNORM:
c.color[2] = c.color[3];
break;
BEGIN_CB(state->cb, 3);
OUT_CB_REG_SEQ(R500_RB3D_CONSTANT_COLOR_AR, 2);
- switch (format) {
+ switch (cb ? cb->format : 0) {
case PIPE_FORMAT_R16G16B16A16_FLOAT:
+ case PIPE_FORMAT_R16G16B16X16_FLOAT:
OUT_CB(util_float_to_half(c.color[2]) |
(util_float_to_half(c.color[3]) << 16));
OUT_CB(util_float_to_half(c.color[0]) |
util_pack_color(c.color, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
BEGIN_CB(state->cb, 2);
- OUT_CB_REG(R300_RB3D_BLEND_COLOR, uc.ui);
+ OUT_CB_REG(R300_RB3D_BLEND_COLOR, uc.ui[0]);
END_CB;
}
r300_mark_atom_dirty(r300, &r300->dsa_state);
}
-static void r300_tex_set_tiling_flags(struct r300_context *r300,
- struct r300_resource *tex,
- unsigned level)
-{
- /* Check if the macrotile flag needs to be changed.
- * Skip changing the flags otherwise. */
- if (tex->tex.macrotile[tex->surface_level] !=
- tex->tex.macrotile[level]) {
- r300->rws->buffer_set_tiling(tex->buf, r300->cs,
- tex->tex.microtile, tex->tex.macrotile[level],
- 0, 0, 0, 0, 0,
- tex->tex.stride_in_bytes[0]);
-
- tex->surface_level = level;
- }
-}
-
-/* This switcheroo is needed just because of goddamned MACRO_SWITCH. */
-static void r300_fb_set_tiling_flags(struct r300_context *r300,
- const struct pipe_framebuffer_state *state)
-{
- unsigned i;
-
- /* Set tiling flags for new surfaces. */
- for (i = 0; i < state->nr_cbufs; i++) {
- r300_tex_set_tiling_flags(r300,
- r300_resource(state->cbufs[i]->texture),
- state->cbufs[i]->u.tex.level);
- }
- if (state->zsbuf) {
- r300_tex_set_tiling_flags(r300,
- r300_resource(state->zsbuf->texture),
- state->zsbuf->u.tex.level);
- }
-}
-
static void r300_print_fb_surf_info(struct pipe_surface *surf, unsigned index,
const char *binding)
{
/* The size of the rest of atoms stays the same. */
}
-static unsigned r300_get_num_samples(struct r300_context *r300)
-{
- struct pipe_framebuffer_state* fb =
- (struct pipe_framebuffer_state*)r300->fb_state.state;
- unsigned i, num_samples;
-
- if (!fb->nr_cbufs && !fb->zsbuf)
- return 1;
-
- num_samples = 6;
-
- for (i = 0; i < fb->nr_cbufs; i++)
- num_samples = MIN2(num_samples, fb->cbufs[i]->texture->nr_samples);
-
- if (fb->zsbuf)
- num_samples = MIN2(num_samples, fb->zsbuf->texture->nr_samples);
-
- if (!num_samples)
- num_samples = 1;
-
- return num_samples;
-}
-
static void
r300_set_framebuffer_state(struct pipe_context* pipe,
const struct pipe_framebuffer_state* state)
{
struct r300_context* r300 = r300_context(pipe);
struct r300_aa_state *aa = (struct r300_aa_state*)r300->aa_state.state;
- struct pipe_framebuffer_state *old_state = r300->fb_state.state;
+ struct pipe_framebuffer_state *current_state = r300->fb_state.state;
unsigned max_width, max_height, i;
uint32_t zbuffer_bpp = 0;
boolean unlock_zbuffer = FALSE;
return;
}
- if (old_state->zsbuf && r300->zmask_in_use && !r300->locked_zbuffer) {
+ if (current_state->zsbuf && r300->zmask_in_use && !r300->locked_zbuffer) {
/* There is a zmask in use, what are we gonna do? */
if (state->zsbuf) {
- if (!pipe_surface_equal(old_state->zsbuf, state->zsbuf)) {
+ if (!pipe_surface_equal(current_state->zsbuf, state->zsbuf)) {
/* Decompress the currently bound zbuffer before we bind another one. */
r300_decompress_zmask(r300);
r300->hiz_in_use = FALSE;
}
} else {
/* We don't bind another zbuffer, so lock the current one. */
- pipe_surface_reference(&r300->locked_zbuffer, old_state->zsbuf);
+ pipe_surface_reference(&r300->locked_zbuffer, current_state->zsbuf);
}
} else if (r300->locked_zbuffer) {
/* We have a locked zbuffer now, what are we gonna do? */
}
assert(state->zsbuf || (r300->locked_zbuffer && !unlock_zbuffer) || !r300->zmask_in_use);
+ /* If zsbuf is set from NULL to non-NULL or vice versa.. */
+ if (!!current_state->zsbuf != !!state->zsbuf) {
+ r300_mark_atom_dirty(r300, &r300->dsa_state);
+ }
+
+ util_copy_framebuffer_state(r300->fb_state.state, state);
+
+ /* Remove trailing NULL colorbuffers. */
+ while (current_state->nr_cbufs && !current_state->cbufs[current_state->nr_cbufs-1])
+ current_state->nr_cbufs--;
+
/* Set whether CMASK can be used. */
r300->cmask_in_use =
- state->nr_cbufs == 1 &&
+ state->nr_cbufs == 1 && state->cbufs[0] &&
r300->screen->cmask_resource == state->cbufs[0]->texture;
/* Need to reset clamping or colormask. */
/* Re-swizzle the blend color. */
r300_set_blend_color(pipe, &((struct r300_blend_color_state*)r300->blend_color_state.state)->state);
- /* If zsbuf is set from NULL to non-NULL or vice versa.. */
- if (!!old_state->zsbuf != !!state->zsbuf) {
- r300_mark_atom_dirty(r300, &r300->dsa_state);
- }
-
- if (r300->screen->info.drm_minor < 12) {
- /* The tiling flags are dependent on the surface miplevel, unfortunately.
- * This workarounds a bad design decision in old kernels which were
- * rewriting tile fields in registers. */
- r300_fb_set_tiling_flags(r300, state);
- }
-
- util_copy_framebuffer_state(r300->fb_state.state, state);
-
if (unlock_zbuffer) {
pipe_surface_reference(&r300->locked_zbuffer, NULL);
}
}
}
- r300->num_samples = r300_get_num_samples(r300);
+ r300->num_samples = util_framebuffer_get_num_samples(state);
/* Set up AA config. */
if (r300->num_samples > 1) {
if (DBG_ON(r300, DBG_FB)) {
fprintf(stderr, "r300: set_framebuffer_state:\n");
for (i = 0; i < state->nr_cbufs; i++) {
- r300_print_fb_surf_info(state->cbufs[i], i, "CB");
+ if (state->cbufs[i])
+ r300_print_fb_surf_info(state->cbufs[i], i, "CB");
}
if (state->zsbuf) {
r300_print_fb_surf_info(state->zsbuf, 0, "ZB");
struct r300_context* r300 = r300_context(pipe);
struct r300_fragment_shader* fs = (struct r300_fragment_shader*)shader;
- if (fs == NULL) {
+ if (!fs) {
r300->fs.state = NULL;
return;
}
static void r300_set_polygon_stipple(struct pipe_context* pipe,
const struct pipe_poly_stipple* state)
{
- /* XXX no idea how to set this up, but not terribly important */
}
/* Create a new rasterizer state based on the CSO rasterizer state.
if (r300_screen(pipe->screen)->caps.has_tcl) {
vap_clip_cntl = (state->clip_plane_enable & 63) |
- R300_PS_UCP_MODE_CLIP_AS_TRIFAN |
- (state->depth_clip ? 0 : R300_CLIP_DISABLE);
+ R300_PS_UCP_MODE_CLIP_AS_TRIFAN;
} else {
vap_clip_cntl = R300_CLIP_DISABLE;
}
boolean last_two_sided_color = r300->two_sided_color;
boolean last_msaa_enable = r300->msaa_enable;
boolean last_flatshade = r300->flatshade;
+ boolean last_clip_halfz = r300->clip_halfz;
if (r300->draw && rs) {
draw_set_rasterizer_state(r300->draw, &rs->rs_draw, state);
r300->two_sided_color = rs->rs.light_twoside;
r300->msaa_enable = rs->rs.multisample;
r300->flatshade = rs->rs.flatshade;
+ r300->clip_halfz = rs->rs.clip_halfz;
} else {
r300->polygon_offset_enabled = FALSE;
r300->sprite_coord_enable = 0;
r300->two_sided_color = FALSE;
r300->msaa_enable = FALSE;
r300->flatshade = FALSE;
+ r300->clip_halfz = FALSE;
}
UPDATE_STATE(state, r300->rs_state);
r300->fs_status = FRAGMENT_SHADER_MAYBE_DIRTY;
}
}
+
+ if (r300->screen->caps.has_tcl && last_clip_halfz != r300->clip_halfz) {
+ r300_mark_atom_dirty(r300, &r300->vs_state);
+ }
}
/* Free rasterizer state. */
}
static void r300_bind_sampler_states(struct pipe_context* pipe,
- unsigned count,
+ enum pipe_shader_type shader,
+ unsigned start, unsigned count,
void** states)
{
struct r300_context* r300 = r300_context(pipe);
(struct r300_textures_state*)r300->textures_state.state;
unsigned tex_units = r300->screen->caps.num_tex_units;
- if (count > tex_units) {
- return;
- }
+ assert(start == 0);
+
+ if (shader != PIPE_SHADER_FRAGMENT)
+ return;
+
+ if (count > tex_units)
+ return;
memcpy(state->sampler_states, states, sizeof(void*) * count);
state->sampler_state_count = count;
r300_mark_atom_dirty(r300, &r300->textures_state);
}
-static void r300_lacks_vertex_textures(struct pipe_context* pipe,
- unsigned count,
- void** states)
-{
-}
-
static void r300_delete_sampler_state(struct pipe_context* pipe, void* state)
{
FREE(state);
return R300_TX_CACHE(num + index);
}
-static void r300_set_fragment_sampler_views(struct pipe_context* pipe,
- unsigned count,
- struct pipe_sampler_view** views)
+static void r300_set_sampler_views(struct pipe_context* pipe,
+ enum pipe_shader_type shader,
+ unsigned start, unsigned count,
+ struct pipe_sampler_view** views)
{
struct r300_context* r300 = r300_context(pipe);
struct r300_textures_state* state =
unsigned tex_units = r300->screen->caps.num_tex_units;
boolean dirty_tex = FALSE;
+ if (shader != PIPE_SHADER_FRAGMENT)
+ return;
+
+ assert(start == 0); /* non-zero not handled yet */
+
if (count > tex_units) {
return;
}
r300_mark_atom_dirty(r300, &r300->sample_mask);
}
-static void r300_set_scissor_state(struct pipe_context* pipe,
- const struct pipe_scissor_state* state)
+static void r300_set_scissor_states(struct pipe_context* pipe,
+ unsigned start_slot,
+ unsigned num_scissors,
+ const struct pipe_scissor_state* state)
{
struct r300_context* r300 = r300_context(pipe);
r300_mark_atom_dirty(r300, &r300->scissor_state);
}
-static void r300_set_viewport_state(struct pipe_context* pipe,
- const struct pipe_viewport_state* state)
+static void r300_set_viewport_states(struct pipe_context* pipe,
+ unsigned start_slot,
+ unsigned num_viewports,
+ const struct pipe_viewport_state* state)
{
struct r300_context* r300 = r300_context(pipe);
struct r300_viewport_state* viewport =
r300->viewport = *state;
if (r300->draw) {
- draw_set_viewport_state(r300->draw, state);
+ draw_set_viewport_states(r300->draw, start_slot, num_viewports, state);
viewport->vte_control = R300_VTX_XY_FMT | R300_VTX_Z_FMT;
return;
}
return;
for (i = 0; i < count; i++) {
- if (buffers[i].user_buffer) {
+ if (buffers[i].is_user_buffer) {
draw_set_mapped_vertex_buffer(r300->draw, start_slot + i,
- buffers[i].user_buffer);
- } else if (buffers[i].buffer) {
+ buffers[i].buffer.user, ~0);
+ } else if (buffers[i].buffer.resource) {
draw_set_mapped_vertex_buffer(r300->draw, start_slot + i,
- r300_resource(buffers[i].buffer)->malloced_buffer);
- }
- }
-}
-
-static void r300_set_index_buffer_hwtcl(struct pipe_context* pipe,
- const struct pipe_index_buffer *ib)
-{
- struct r300_context* r300 = r300_context(pipe);
-
- if (ib) {
- pipe_resource_reference(&r300->index_buffer.buffer, ib->buffer);
- memcpy(&r300->index_buffer, ib, sizeof(*ib));
- } else {
- pipe_resource_reference(&r300->index_buffer.buffer, NULL);
- }
-}
-
-static void r300_set_index_buffer_swtcl(struct pipe_context* pipe,
- const struct pipe_index_buffer *ib)
-{
- struct r300_context* r300 = r300_context(pipe);
-
- if (ib) {
- const void *buf = NULL;
- if (ib->user_buffer) {
- buf = ib->user_buffer;
- } else if (ib->buffer) {
- buf = r300_resource(ib->buffer)->malloced_buffer;
+ r300_resource(buffers[i].buffer.resource)->malloced_buffer, ~0);
}
- draw_set_indexes(r300->draw,
- (const ubyte *) buf + ib->offset,
- ib->index_size);
}
}
struct r300_context *r300 = r300_context(pipe);
struct r300_vertex_element_state *velems = state;
- if (velems == NULL) {
+ if (!velems) {
return;
}
struct r300_context* r300 = r300_context(pipe);
struct r300_vertex_shader* vs = (struct r300_vertex_shader*)shader;
- if (vs == NULL) {
+ if (!vs) {
r300->vs_state.state = NULL;
return;
}
}
static void r300_set_constant_buffer(struct pipe_context *pipe,
- uint shader, uint index,
- struct pipe_constant_buffer *cb)
+ enum pipe_shader_type shader, uint index,
+ const struct pipe_constant_buffer *cb)
{
struct r300_context* r300 = r300_context(pipe);
struct r300_constant_buffer *cbuf;
uint32_t *mapped;
- if (!cb)
+ if (!cb || (!cb->buffer && !cb->user_buffer))
return;
switch (shader) {
}
}
-static void r300_texture_barrier(struct pipe_context *pipe)
+static void r300_texture_barrier(struct pipe_context *pipe, unsigned flags)
{
struct r300_context *r300 = r300_context(pipe);
r300_mark_atom_dirty(r300, &r300->texture_cache_inval);
}
+static void r300_memory_barrier(struct pipe_context *pipe, unsigned flags)
+{
+}
+
void r300_init_state_functions(struct r300_context* r300)
{
r300->context.create_blend_state = r300_create_blend_state;
r300->context.delete_rasterizer_state = r300_delete_rs_state;
r300->context.create_sampler_state = r300_create_sampler_state;
- r300->context.bind_fragment_sampler_states = r300_bind_sampler_states;
- r300->context.bind_vertex_sampler_states = r300_lacks_vertex_textures;
+ r300->context.bind_sampler_states = r300_bind_sampler_states;
r300->context.delete_sampler_state = r300_delete_sampler_state;
- r300->context.set_fragment_sampler_views = r300_set_fragment_sampler_views;
+ r300->context.set_sampler_views = r300_set_sampler_views;
r300->context.create_sampler_view = r300_create_sampler_view;
r300->context.sampler_view_destroy = r300_sampler_view_destroy;
- r300->context.set_scissor_state = r300_set_scissor_state;
+ r300->context.set_scissor_states = r300_set_scissor_states;
- r300->context.set_viewport_state = r300_set_viewport_state;
+ r300->context.set_viewport_states = r300_set_viewport_states;
if (r300->screen->caps.has_tcl) {
r300->context.set_vertex_buffers = r300_set_vertex_buffers_hwtcl;
- r300->context.set_index_buffer = r300_set_index_buffer_hwtcl;
} else {
r300->context.set_vertex_buffers = r300_set_vertex_buffers_swtcl;
- r300->context.set_index_buffer = r300_set_index_buffer_swtcl;
}
r300->context.create_vertex_elements_state = r300_create_vertex_elements_state;
r300->context.delete_vs_state = r300_delete_vs_state;
r300->context.texture_barrier = r300_texture_barrier;
+ r300->context.memory_barrier = r300_memory_barrier;
}