nouveau/nir: Implement load_global_constant
[mesa.git] / src / gallium / drivers / r300 / r300_state.c
index 1d78134de6dc6a88ad574af0372a5b29bb27583f..2d8e5b1832ad115fcf629fab966c6fce6f5caf25 100644 (file)
 #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"
+#include "util/u_blend.h"
 
 #include "tgsi/tgsi_parse.h"
 
@@ -285,15 +285,8 @@ static unsigned blend_read_enable(unsigned eqRGB, unsigned eqA,
         eqRGB == PIPE_BLEND_MAX || eqA == PIPE_BLEND_MAX ||
         dstRGB != PIPE_BLENDFACTOR_ZERO ||
         dstA != PIPE_BLENDFACTOR_ZERO ||
-        srcRGB == PIPE_BLENDFACTOR_DST_COLOR ||
-        srcRGB == PIPE_BLENDFACTOR_DST_ALPHA ||
-        srcRGB == PIPE_BLENDFACTOR_INV_DST_COLOR ||
-        srcRGB == PIPE_BLENDFACTOR_INV_DST_ALPHA ||
-        srcA == PIPE_BLENDFACTOR_DST_COLOR ||
-        srcA == PIPE_BLENDFACTOR_DST_ALPHA ||
-        srcA == PIPE_BLENDFACTOR_INV_DST_COLOR ||
-        srcA == PIPE_BLENDFACTOR_INV_DST_ALPHA ||
-        srcRGB == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE) {
+        util_blend_factor_uses_dest(srcRGB, false) ||
+        util_blend_factor_uses_dest(srcA, true)) {
         /* Enable reading from the colorbuffer. */
         blend_control |= R300_READ_ENABLE;
 
@@ -834,45 +827,6 @@ static void r300_set_stencil_ref(struct pipe_context* pipe,
     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, 0, 0,
-                tex->tex.stride_in_bytes[0], false);
-
-        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++) {
-        if (!state->cbufs[i])
-            continue;
-
-        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)
 {
@@ -1017,13 +971,6 @@ r300_set_framebuffer_state(struct pipe_context* pipe,
     /* Re-swizzle the blend color. */
     r300_set_blend_color(pipe, &((struct r300_blend_color_state*)r300->blend_color_state.state)->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);
-    }
-
     if (unlock_zbuffer) {
         pipe_surface_reference(&r300->locked_zbuffer, NULL);
     }
@@ -1204,7 +1151,7 @@ static void* r300_create_rs_state(struct pipe_context* pipe,
     rs->rs_draw.offset_tri = 0;
     rs->rs_draw.offset_clamp = 0;
 
-#ifdef PIPE_ARCH_LITTLE_ENDIAN
+#if UTIL_ARCH_LITTLE_ENDIAN
     vap_control_status = R300_VC_NO_SWAP;
 #else
     vap_control_status = R300_VC_32BIT_SWAP;
@@ -1515,7 +1462,7 @@ static void*
 }
 
 static void r300_bind_sampler_states(struct pipe_context* pipe,
-                                     unsigned shader,
+                                     enum pipe_shader_type shader,
                                      unsigned start, unsigned count,
                                      void** states)
 {
@@ -1568,7 +1515,8 @@ static uint32_t r300_assign_texture_cache_region(unsigned index, unsigned num)
         return R300_TX_CACHE(num + index);
 }
 
-static void r300_set_sampler_views(struct pipe_context* pipe, unsigned shader,
+static void r300_set_sampler_views(struct pipe_context* pipe,
+                                   enum pipe_shader_type shader,
                                    unsigned start, unsigned count,
                                    struct pipe_sampler_view** views)
 {
@@ -1818,44 +1766,13 @@ static void r300_set_vertex_buffers_swtcl(struct pipe_context* pipe,
         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, ~0);
-        } 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, ~0);
-        }
-    }
-}
-
-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, ~0);
     }
 }
 
@@ -2048,8 +1965,8 @@ static void r300_delete_vs_state(struct pipe_context* pipe, void* shader)
 }
 
 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;
@@ -2113,7 +2030,7 @@ static void r300_set_constant_buffer(struct pipe_context *pipe,
     }
 }
 
-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);
 
@@ -2170,10 +2087,8 @@ void r300_init_state_functions(struct r300_context* r300)
 
     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;