iris: actually set KSP offsets
[mesa.git] / src / gallium / drivers / iris / iris_state.c
index 5d8837d31bedea697bb77d77ffffe3e0aaae4438..10b81859bd305dc86b0b724f97438eb58f572f48 100644 (file)
@@ -379,6 +379,8 @@ struct iris_blend_state {
    uint32_t blend_state[GENX(BLEND_STATE_length)];
    uint32_t blend_entries[BRW_MAX_DRAW_BUFFERS *
                           GENX(BLEND_STATE_ENTRY_length)];
+
+   bool alpha_to_coverage; /* for shader key */
 };
 
 static void *
@@ -387,6 +389,8 @@ iris_create_blend_state(struct pipe_context *ctx,
 {
    struct iris_blend_state *cso = malloc(sizeof(struct iris_blend_state));
 
+   cso->alpha_to_coverage = state->alpha_to_coverage;
+
    iris_pack_state(GENX(BLEND_STATE), cso->blend_state, bs) {
       bs.AlphaToCoverageEnable = state->alpha_to_coverage;
       bs.IndependentAlphaBlendEnable = state->independent_blend_enable;
@@ -530,6 +534,7 @@ struct iris_rasterizer_state {
    uint32_t line_stipple[GENX(3DSTATE_LINE_STIPPLE_length)];
 
    bool flatshade; /* for shader state */
+   bool clamp_fragment_color; /* for shader state */
    bool light_twoside; /* for shader state */
    bool rasterizer_discard; /* for 3DSTATE_STREAMOUT */
    bool half_pixel_center; /* for 3DSTATE_MULTISAMPLE */
@@ -559,6 +564,7 @@ iris_create_rasterizer_state(struct pipe_context *ctx,
    #endif
 
    cso->flatshade = state->flatshade;
+   cso->clamp_fragment_color = state->clamp_fragment_color;
    cso->light_twoside = state->light_twoside;
    cso->rasterizer_discard = state->rasterizer_discard;
    cso->half_pixel_center = state->half_pixel_center;
@@ -1364,13 +1370,82 @@ iris_bind_compute_state(struct pipe_context *ctx, void *state)
 {
 }
 
+static void
+iris_populate_vs_key(const struct iris_context *ice,
+                     struct brw_vs_prog_key *key)
+{
+   memset(key, 0, sizeof(*key));
+}
+
+static void
+iris_populate_tcs_key(const struct iris_context *ice,
+                      struct brw_tcs_prog_key *key)
+{
+   memset(key, 0, sizeof(*key));
+}
+
+static void
+iris_populate_tes_key(const struct iris_context *ice,
+                      struct brw_tes_prog_key *key)
+{
+   memset(key, 0, sizeof(*key));
+}
+
+static void
+iris_populate_gs_key(const struct iris_context *ice,
+                     struct brw_gs_prog_key *key)
+{
+   memset(key, 0, sizeof(*key));
+}
+
+static void
+iris_populate_fs_key(const struct iris_context *ice,
+                     struct brw_wm_prog_key *key)
+{
+   memset(key, 0, sizeof(*key));
+
+   /* XXX: dirty flags? */
+   struct pipe_framebuffer_state *fb = &ice->state.framebuffer;
+   struct iris_depth_stencil_alpha_state *zsa = ice->state.cso_zsa;
+   struct iris_rasterizer_state *rast = ice->state.cso_rast;
+   struct iris_blend_state *blend = ice->state.cso_blend;
+
+   key->nr_color_regions = fb->nr_cbufs;
+
+   key->clamp_fragment_color = rast->clamp_fragment_color;
+
+   key->replicate_alpha = fb->nr_cbufs > 1 &&
+      (zsa->alpha.enabled || blend->alpha_to_coverage);
+
+   // key->force_dual_color_blend for unigine
+#if 0
+   if (cso_rast->multisample) {
+      key->persample_interp =
+         ctx->Multisample.SampleShading &&
+         (ctx->Multisample.MinSampleShadingValue *
+          _mesa_geometric_samples(ctx->DrawBuffer) > 1);
+
+      key->multisample_fbo = fb->samples > 1;
+   }
+#endif
+
+   key->coherent_fb_fetch = true;
+}
+
    //pkt.SamplerCount =                                                     \
       //DIV_ROUND_UP(CLAMP(stage_state->sampler_count, 0, 16), 4);          \
    //pkt.PerThreadScratchSpace = prog_data->total_scratch == 0 ? 0 :        \
       //ffs(stage_state->per_thread_scratch) - 11;                          \
 
+static uint64_t
+KSP(const struct iris_compiled_shader *shader)
+{
+   struct iris_resource *res = (void *) shader->buffer;
+   return res->bo->gtt_offset + shader->offset;
+}
+
 #define INIT_THREAD_DISPATCH_FIELDS(pkt, prefix)                          \
-   pkt.KernelStartPointer = shader->prog_offset;                          \
+   pkt.KernelStartPointer = KSP(shader);                                  \
    pkt.BindingTableEntryCount = prog_data->binding_table.size_bytes / 4;  \
    pkt.FloatingPointMode = prog_data->use_alt_mode;                       \
                                                                           \
@@ -1542,11 +1617,11 @@ iris_set_fs_state(const struct gen_device_info *devinfo,
          brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data, ps, 2);
 
       ps.KernelStartPointer0 =
-         shader->prog_offset + brw_wm_prog_data_prog_offset(wm_prog_data, ps, 0);
+         KSP(shader) + brw_wm_prog_data_prog_offset(wm_prog_data, ps, 0);
       ps.KernelStartPointer1 =
-         shader->prog_offset + brw_wm_prog_data_prog_offset(wm_prog_data, ps, 1);
+         KSP(shader) + brw_wm_prog_data_prog_offset(wm_prog_data, ps, 1);
       ps.KernelStartPointer2 =
-         shader->prog_offset + brw_wm_prog_data_prog_offset(wm_prog_data, ps, 2);
+         KSP(shader) + brw_wm_prog_data_prog_offset(wm_prog_data, ps, 2);
    }
 
    iris_pack_command(GENX(3DSTATE_PS_EXTRA), psx_state, psx) {
@@ -1650,7 +1725,7 @@ iris_upload_render_state(struct iris_context *ice,
    /* XXX: L3 State */
 
    if (dirty & IRIS_DIRTY_URB) {
-      /* XXX: URB */
+      /* XXX: 3DSTATE_URB */
    }
 
    if (dirty & IRIS_DIRTY_BLEND_STATE) {
@@ -1682,6 +1757,12 @@ iris_upload_render_state(struct iris_context *ice,
    }
 
    // XXX: 3DSTATE_CONSTANT_XS
+   // Surfaces:
+   // - pull constants
+   // - ubos/ssbos/abos
+   // - images
+   // - textures
+   // - render targets - write and read
    // XXX: 3DSTATE_BINDING_TABLE_POINTERS_XS
 
    for (int stage = 0; stage <= MESA_SHADER_FRAGMENT; stage++) {
@@ -1744,7 +1825,10 @@ iris_upload_render_state(struct iris_context *ice,
       }
    }
 
-   // XXX: SOL and so on
+   // XXX: SOL:
+   // 3DSTATE_STREAMOUT
+   // 3DSTATE_SO_BUFFER
+   // 3DSTATE_SO_DECL_LIST
 
    if (dirty & IRIS_DIRTY_CLIP) {
       struct iris_rasterizer_state *cso_rast = ice->state.cso_rast;
@@ -1785,7 +1869,9 @@ iris_upload_render_state(struct iris_context *ice,
       iris_emit_merge(batch, cso->wm, dynamic_wm, ARRAY_SIZE(cso->wm));
    }
 
-   // XXX: SBE, SBE_SWIZ
+   // XXX: 3DSTATE_SBE, 3DSTATE_SBE_SWIZ
+   // -> iris_raster_state (point sprite texture coordinate origin)
+   // -> bunch of shader state...
 
    if (dirty & IRIS_DIRTY_PS_BLEND) {
       struct iris_blend_state *cso = ice->state.cso_blend;
@@ -1815,7 +1901,10 @@ iris_upload_render_state(struct iris_context *ice,
       }
    }
 
-   // XXX: 3DSTATE_DEPTH_BUFFER and friends
+   // XXX: 3DSTATE_DEPTH_BUFFER
+   // XXX: 3DSTATE_HIER_DEPTH_BUFFER
+   // XXX: 3DSTATE_STENCIL_BUFFER
+   // XXX: 3DSTATE_CLEAR_PARAMS
 
    if (dirty & IRIS_DIRTY_POLYGON_STIPPLE) {
       iris_emit_cmd(batch, GENX(3DSTATE_POLY_STIPPLE_PATTERN), poly) {
@@ -1917,44 +2006,8 @@ iris_upload_render_state(struct iris_context *ice,
 
       //prim.BaseVertexLocation = ...;
    }
-#if 0
-   l3 configuration
-
-   3DSTATE_URB_*
-     -> TODO
-
-   3DSTATE_CONSTANT_* - push constants
-     -> TODO
-
-   Surfaces:
-   - pull constants
-   - ubos/ssbos/abos
-   - images
-   - textures
-   - render targets - write and read
-   3DSTATE_BINDING_TABLE_POINTERS_*
-     -> TODO
-
-   3DSTATE_STREAMOUT
-   3DSTATE_SO_BUFFER
-   3DSTATE_SO_DECL_LIST
-
-   3DSTATE_SBE
-     -> iris_raster_state (point sprite texture coordinate origin)
-     -> bunch of shader state...
-   3DSTATE_SBE_SWIZ
-     -> FS state
-
-   3DSTATE_DEPTH_BUFFER
-   3DSTATE_HIER_DEPTH_BUFFER
-   3DSTATE_STENCIL_BUFFER
-   3DSTATE_CLEAR_PARAMS
-     -> iris_framebuffer_state?
-#endif
 }
 
-
-
 static void
 iris_destroy_state(struct iris_context *ice)
 {
@@ -2014,11 +2067,17 @@ genX(init_state)(struct iris_context *ice)
    ctx->stream_output_target_destroy = iris_stream_output_target_destroy;
    ctx->set_stream_output_targets = iris_set_stream_output_targets;
 
+   ice->state.destroy_state = iris_destroy_state;
    ice->state.init_render_context = iris_init_render_context;
    ice->state.upload_render_state = iris_upload_render_state;
    ice->state.derived_program_state_size = iris_derived_program_state_size;
    ice->state.set_derived_program_state = iris_set_derived_program_state;
-   ice->state.destroy_state = iris_destroy_state;
+   ice->state.populate_vs_key = iris_populate_vs_key;
+   ice->state.populate_tcs_key = iris_populate_tcs_key;
+   ice->state.populate_tes_key = iris_populate_tes_key;
+   ice->state.populate_gs_key = iris_populate_gs_key;
+   ice->state.populate_fs_key = iris_populate_fs_key;
+
 
    ice->state.dirty = ~0ull;
 }