r600g: implement seamless_cube_map on r600-r700
authorMarek Olšák <maraeo@gmail.com>
Sun, 19 Jun 2011 21:41:02 +0000 (23:41 +0200)
committerMarek Olšák <maraeo@gmail.com>
Sun, 19 Jun 2011 22:19:07 +0000 (00:19 +0200)
st/mesa guarantees that all bound sampler states have the same value
in seamless_cube_map.

src/gallium/drivers/r600/r600_pipe.c
src/gallium/drivers/r600/r600_pipe.h
src/gallium/drivers/r600/r600_state.c

index 16fe6c54a15380312fe693440b3954f4b15c4186..a0d145d71782651378d8ca555391751a563d8dc3 100644 (file)
@@ -376,6 +376,7 @@ static int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
        case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
        case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
        case PIPE_CAP_SM3:
+       case PIPE_CAP_SEAMLESS_CUBE_MAP:
                return 1;
 
        /* Supported except the original R600. */
@@ -385,7 +386,6 @@ static int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
                return family == CHIP_R600 ? 0 : 1;
 
        /* Supported on Evergreen. */
-       case PIPE_CAP_SEAMLESS_CUBE_MAP:
        case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
                return family >= CHIP_CEDAR ? 1 : 0;
 
index 84a45bec05dedf16929a8c7f85b68cfedaf3056d..9941bbf0e3c01a5c1b51ad47e3863e63bc6be9e3 100644 (file)
@@ -50,6 +50,7 @@ enum r600_pipe_state_id {
        R600_PIPE_STATE_BLEND = 0,
        R600_PIPE_STATE_BLEND_COLOR,
        R600_PIPE_STATE_CONFIG,
+       R600_PIPE_STATE_SEAMLESS_CUBEMAP,
        R600_PIPE_STATE_CLIP,
        R600_PIPE_STATE_SCISSOR,
        R600_PIPE_STATE_VIEWPORT,
@@ -126,6 +127,11 @@ struct r600_pipe_shader {
        struct r600_vertex_element      vertex_elements;
 };
 
+struct r600_pipe_sampler_state {
+       struct r600_pipe_state          rstate;
+       boolean seamless_cube_map;
+};
+
 /* needed for blitter save */
 #define NUM_TEX_UNITS 16
 
index 4ce17403ba2b0ce6e3256030d0638a268ba6b232..91da7c55f4bda8946e0f026ecba6c5400312735b 100644 (file)
@@ -369,14 +369,17 @@ static void *r600_create_rs_state(struct pipe_context *ctx,
 static void *r600_create_sampler_state(struct pipe_context *ctx,
                                        const struct pipe_sampler_state *state)
 {
-       struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state);
+       struct r600_pipe_sampler_state *ss = CALLOC_STRUCT(r600_pipe_sampler_state);
+       struct r600_pipe_state *rstate;
        union util_color uc;
        unsigned aniso_flag_offset = state->max_anisotropy > 1 ? 4 : 0;
 
-       if (rstate == NULL) {
+       if (ss == NULL) {
                return NULL;
        }
 
+       ss->seamless_cube_map = state->seamless_cube_map;
+       rstate = &ss->rstate;
        rstate->id = R600_PIPE_STATE_SAMPLER;
        util_pack_color(state->border_color, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
        r600_pipe_state_add_reg_noblock(rstate, R_03C000_SQ_TEX_SAMPLER_WORD0_0,
@@ -559,27 +562,57 @@ static void r600_set_ps_sampler_view(struct pipe_context *ctx, unsigned count,
        rctx->ps_samplers.n_views = count;
 }
 
+static void r600_set_seamless_cubemap(struct r600_pipe_context *rctx, boolean enable)
+{
+       struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state);
+       if (rstate == NULL)
+               return;
+
+       rstate->id = R600_PIPE_STATE_SEAMLESS_CUBEMAP;
+       r600_pipe_state_add_reg(rstate, R_009508_TA_CNTL_AUX,
+                               (enable ? 0 : S_009508_DISABLE_CUBE_WRAP(1)),
+                               1, NULL);
+
+       free(rctx->states[R600_PIPE_STATE_SEAMLESS_CUBEMAP]);
+       rctx->states[R600_PIPE_STATE_SEAMLESS_CUBEMAP] = rstate;
+       r600_context_pipe_state_set(&rctx->ctx, rstate);
+}
+
 static void r600_bind_ps_sampler(struct pipe_context *ctx, unsigned count, void **states)
 {
        struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
-       struct r600_pipe_state **rstates = (struct r600_pipe_state **)states;
+       struct r600_pipe_sampler_state **sstates = (struct r600_pipe_sampler_state **)states;
+       int seamless = -1;
 
        memcpy(rctx->ps_samplers.samplers, states, sizeof(void*) * count);
        rctx->ps_samplers.n_samplers = count;
 
        for (int i = 0; i < count; i++) {
-               r600_context_pipe_state_set_ps_sampler(&rctx->ctx, rstates[i], i);
+               r600_context_pipe_state_set_ps_sampler(&rctx->ctx, &sstates[i]->rstate, i);
+
+               if (sstates[i])
+                       seamless = sstates[i]->seamless_cube_map;
        }
+
+       if (seamless != -1)
+               r600_set_seamless_cubemap(rctx, seamless);
 }
 
 static void r600_bind_vs_sampler(struct pipe_context *ctx, unsigned count, void **states)
 {
        struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
-       struct r600_pipe_state **rstates = (struct r600_pipe_state **)states;
+       struct r600_pipe_sampler_state **sstates = (struct r600_pipe_sampler_state **)states;
+       int seamless = -1;
 
        for (int i = 0; i < count; i++) {
-               r600_context_pipe_state_set_vs_sampler(&rctx->ctx, rstates[i], i);
+               r600_context_pipe_state_set_vs_sampler(&rctx->ctx, &sstates[i]->rstate, i);
+
+               if (sstates[i])
+                       seamless = sstates[i]->seamless_cube_map;
        }
+
+       if (seamless != -1)
+               r600_set_seamless_cubemap(rctx, seamless);
 }
 
 static void r600_set_clip_state(struct pipe_context *ctx,