aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/ilo/core
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2015-06-15 12:01:29 +0800
committerChia-I Wu <[email protected]>2015-06-15 15:06:11 +0800
commit7cb853d52ae795b76adec41c98870166b41c9e6f (patch)
treec778b642f47df0ec77c985b0331b679eacfa7f2a /src/gallium/drivers/ilo/core
parent8f37e8e64fc897180603a7247e2fd47bf0ffb834 (diff)
ilo: add ilo_state_sample_pattern
Move sample pattern initialization from ilo_render to ilo_state_sample_pattern.
Diffstat (limited to 'src/gallium/drivers/ilo/core')
-rw-r--r--src/gallium/drivers/ilo/core/ilo_builder_3d_bottom.h37
-rw-r--r--src/gallium/drivers/ilo/core/ilo_state_raster.c143
-rw-r--r--src/gallium/drivers/ilo/core/ilo_state_raster.h42
3 files changed, 204 insertions, 18 deletions
diff --git a/src/gallium/drivers/ilo/core/ilo_builder_3d_bottom.h b/src/gallium/drivers/ilo/core/ilo_builder_3d_bottom.h
index 7c1825b6b13..cc1ece3ed14 100644
--- a/src/gallium/drivers/ilo/core/ilo_builder_3d_bottom.h
+++ b/src/gallium/drivers/ilo/core/ilo_builder_3d_bottom.h
@@ -450,9 +450,13 @@ gen7_3DSTATE_SAMPLER_STATE_POINTERS_PS(struct ilo_builder *builder,
static inline void
gen6_3DSTATE_MULTISAMPLE(struct ilo_builder *builder,
const struct ilo_state_raster *rs,
- const uint32_t *pattern, int pattern_len)
+ const struct ilo_state_sample_pattern *pattern,
+ uint8_t sample_count)
{
const uint8_t cmd_len = (ilo_dev_gen(builder->dev) >= ILO_GEN(7)) ? 4 : 3;
+ const uint32_t *packed = (const uint32_t *)
+ ilo_state_sample_pattern_get_packed_offsets(pattern,
+ builder->dev, sample_count);
uint32_t *dw;
ILO_DEV_ASSERT(builder->dev, 6, 7.5);
@@ -463,10 +467,10 @@ gen6_3DSTATE_MULTISAMPLE(struct ilo_builder *builder,
/* see raster_set_gen8_3DSTATE_MULTISAMPLE() */
dw[1] = rs->sample[0];
- assert(pattern_len == 1 || pattern_len == 2);
- dw[2] = pattern[0];
+ /* see sample_pattern_set_gen8_3DSTATE_SAMPLE_PATTERN() */
+ dw[2] = (sample_count >= 4) ? packed[0] : 0;
if (ilo_dev_gen(builder->dev) >= ILO_GEN(7))
- dw[3] = (pattern_len == 2) ? pattern[1] : 0;
+ dw[3] = (sample_count >= 8) ? packed[1] : 0;
}
static inline void
@@ -487,11 +491,7 @@ gen8_3DSTATE_MULTISAMPLE(struct ilo_builder *builder,
static inline void
gen8_3DSTATE_SAMPLE_PATTERN(struct ilo_builder *builder,
- const uint32_t *pattern_1x,
- const uint32_t *pattern_2x,
- const uint32_t *pattern_4x,
- const uint32_t *pattern_8x,
- const uint32_t *pattern_16x)
+ const struct ilo_state_sample_pattern *pattern)
{
const uint8_t cmd_len = 9;
uint32_t *dw;
@@ -501,15 +501,16 @@ gen8_3DSTATE_SAMPLE_PATTERN(struct ilo_builder *builder,
ilo_builder_batch_pointer(builder, cmd_len, &dw);
dw[0] = GEN8_RENDER_CMD(3D, 3DSTATE_SAMPLE_PATTERN) | (cmd_len - 2);
- dw[1] = pattern_16x[3];
- dw[2] = pattern_16x[2];
- dw[3] = pattern_16x[1];
- dw[4] = pattern_16x[0];
- dw[5] = pattern_8x[1];
- dw[6] = pattern_8x[0];
- dw[7] = pattern_4x[0];
- dw[8] = pattern_1x[0] << 16 |
- pattern_2x[0];
+ dw[1] = 0;
+ dw[2] = 0;
+ dw[3] = 0;
+ dw[4] = 0;
+ /* see sample_pattern_set_gen8_3DSTATE_SAMPLE_PATTERN() */
+ dw[5] = ((const uint32_t *) pattern->pattern_8x)[1];
+ dw[6] = ((const uint32_t *) pattern->pattern_8x)[0];
+ dw[7] = ((const uint32_t *) pattern->pattern_4x)[0];
+ dw[8] = pattern->pattern_1x[0] << 16 |
+ ((const uint16_t *) pattern->pattern_2x)[0];
}
static inline void
diff --git a/src/gallium/drivers/ilo/core/ilo_state_raster.c b/src/gallium/drivers/ilo/core/ilo_state_raster.c
index a33812d7638..a93eaad154c 100644
--- a/src/gallium/drivers/ilo/core/ilo_state_raster.c
+++ b/src/gallium/drivers/ilo/core/ilo_state_raster.c
@@ -862,6 +862,69 @@ raster_set_gen8_3dstate_wm_hz_op(struct ilo_state_raster *rs,
return true;
}
+static bool
+sample_pattern_get_gen6_packed_offsets(const struct ilo_dev *dev,
+ uint8_t sample_count,
+ const struct ilo_state_sample_pattern_offset_info *in,
+ uint8_t *out)
+{
+ uint8_t max_dist, i;
+
+ ILO_DEV_ASSERT(dev, 6, 8);
+
+ max_dist = 0;
+ for (i = 0; i < sample_count; i++) {
+ const int8_t dist_x = (int8_t) in[i].x - 8;
+ const int8_t dist_y = (int8_t) in[i].y - 8;
+ const uint8_t dist = dist_x * dist_x + dist_y * dist_y;
+
+ /*
+ * From the Sandy Bridge PRM, volume 2 part 1, page 305:
+ *
+ * "Programming Note: When programming the sample offsets (for
+ * NUMSAMPLES_4 or _8 and MSRASTMODE_xxx_PATTERN), the order of the
+ * samples 0 to 3 (or 7 for 8X) must have monotonically increasing
+ * distance from the pixel center. This is required to get the
+ * correct centroid computation in the device."
+ */
+ assert(dist >= max_dist);
+ max_dist = dist;
+
+ assert(in[i].x < 16);
+ assert(in[i].y < 16);
+
+ out[i] = in[i].x << 4 | in[i].y;
+ }
+
+ return true;
+}
+
+static bool
+sample_pattern_set_gen8_3DSTATE_SAMPLE_PATTERN(struct ilo_state_sample_pattern *pattern,
+ const struct ilo_dev *dev,
+ const struct ilo_state_sample_pattern_info *info)
+{
+ ILO_DEV_ASSERT(dev, 6, 8);
+
+ STATIC_ASSERT(ARRAY_SIZE(pattern->pattern_1x) >= 1);
+ STATIC_ASSERT(ARRAY_SIZE(pattern->pattern_2x) >= 2);
+ STATIC_ASSERT(ARRAY_SIZE(pattern->pattern_4x) >= 4);
+ STATIC_ASSERT(ARRAY_SIZE(pattern->pattern_8x) >= 8);
+ STATIC_ASSERT(ARRAY_SIZE(pattern->pattern_16x) >= 16);
+
+ return (sample_pattern_get_gen6_packed_offsets(dev, 1,
+ info->pattern_1x, pattern->pattern_1x) &&
+ sample_pattern_get_gen6_packed_offsets(dev, 2,
+ info->pattern_2x, pattern->pattern_2x) &&
+ sample_pattern_get_gen6_packed_offsets(dev, 4,
+ info->pattern_4x, pattern->pattern_4x) &&
+ sample_pattern_get_gen6_packed_offsets(dev, 8,
+ info->pattern_8x, pattern->pattern_8x) &&
+ sample_pattern_get_gen6_packed_offsets(dev, 16,
+ info->pattern_16x, pattern->pattern_16x));
+
+}
+
bool
ilo_state_raster_init(struct ilo_state_raster *rs,
const struct ilo_dev *dev,
@@ -1027,3 +1090,83 @@ ilo_state_raster_get_delta(const struct ilo_state_raster *rs,
delta->dirty |= ILO_STATE_RASTER_3DSTATE_WM_HZ_OP;
}
}
+
+bool
+ilo_state_sample_pattern_init(struct ilo_state_sample_pattern *pattern,
+ const struct ilo_dev *dev,
+ const struct ilo_state_sample_pattern_info *info)
+{
+ bool ret = true;
+
+ ret &= sample_pattern_set_gen8_3DSTATE_SAMPLE_PATTERN(pattern, dev, info);
+
+ assert(ret);
+
+ return ret;
+}
+
+bool
+ilo_state_sample_pattern_init_default(struct ilo_state_sample_pattern *pattern,
+ const struct ilo_dev *dev)
+{
+ static const struct ilo_state_sample_pattern_info default_info = {
+ .pattern_1x = {
+ { 8, 8 },
+ },
+
+ .pattern_2x = {
+ { 4, 4 }, { 12, 12 },
+ },
+
+ .pattern_4x = {
+ { 6, 2 }, { 14, 6 }, { 2, 10 }, { 10, 14 },
+ },
+
+ /* \see brw_multisample_positions_8x */
+ .pattern_8x = {
+ { 7, 9 }, { 9, 13 }, { 11, 3 }, { 13, 11 },
+ { 1, 7 }, { 5, 1 }, { 15, 5 }, { 3, 15 },
+ },
+
+ .pattern_16x = {
+ { 8, 10 }, { 11, 8 }, { 5, 6 }, { 6, 4 },
+ { 12, 11 }, { 13, 9 }, { 14, 7 }, { 10, 2 },
+ { 4, 13 }, { 3, 3 }, { 7, 1 }, { 15, 5 },
+ { 1, 12 }, { 9, 0 }, { 2, 14 }, { 0, 15 },
+ },
+ };
+
+ return ilo_state_sample_pattern_init(pattern, dev, &default_info);
+}
+
+const uint8_t *
+ilo_state_sample_pattern_get_packed_offsets(const struct ilo_state_sample_pattern *pattern,
+ const struct ilo_dev *dev,
+ uint8_t sample_count)
+{
+ switch (sample_count) {
+ case 1: return pattern->pattern_1x;
+ case 2: return pattern->pattern_2x;
+ case 4: return pattern->pattern_4x;
+ case 8: return pattern->pattern_8x;
+ case 16: return pattern->pattern_16x;
+ default:
+ assert(!"unknown sample count");
+ return NULL;
+ }
+}
+
+void
+ilo_state_sample_pattern_get_offset(const struct ilo_state_sample_pattern *pattern,
+ const struct ilo_dev *dev,
+ uint8_t sample_count, uint8_t sample_index,
+ uint8_t *x, uint8_t *y)
+{
+ const const uint8_t *packed =
+ ilo_state_sample_pattern_get_packed_offsets(pattern, dev, sample_count);
+
+ assert(sample_index < sample_count);
+
+ *x = (packed[sample_index] >> 4) & 0xf;
+ *y = packed[sample_index] & 0xf;
+}
diff --git a/src/gallium/drivers/ilo/core/ilo_state_raster.h b/src/gallium/drivers/ilo/core/ilo_state_raster.h
index add26cd0a48..e4697bc383f 100644
--- a/src/gallium/drivers/ilo/core/ilo_state_raster.h
+++ b/src/gallium/drivers/ilo/core/ilo_state_raster.h
@@ -197,6 +197,28 @@ struct ilo_state_raster_delta {
uint32_t dirty;
};
+struct ilo_state_sample_pattern_offset_info {
+ /* in U0.4 */
+ uint8_t x;
+ uint8_t y;
+};
+
+struct ilo_state_sample_pattern_info {
+ struct ilo_state_sample_pattern_offset_info pattern_1x[1];
+ struct ilo_state_sample_pattern_offset_info pattern_2x[2];
+ struct ilo_state_sample_pattern_offset_info pattern_4x[4];
+ struct ilo_state_sample_pattern_offset_info pattern_8x[8];
+ struct ilo_state_sample_pattern_offset_info pattern_16x[16];
+};
+
+struct ilo_state_sample_pattern {
+ uint8_t pattern_1x[1];
+ uint8_t pattern_2x[2];
+ uint8_t pattern_4x[4];
+ uint8_t pattern_8x[8];
+ uint8_t pattern_16x[16];
+};
+
bool
ilo_state_raster_init(struct ilo_state_raster *rs,
const struct ilo_dev *dev,
@@ -230,4 +252,24 @@ ilo_state_raster_get_delta(const struct ilo_state_raster *rs,
const struct ilo_state_raster *old,
struct ilo_state_raster_delta *delta);
+bool
+ilo_state_sample_pattern_init(struct ilo_state_sample_pattern *pattern,
+ const struct ilo_dev *dev,
+ const struct ilo_state_sample_pattern_info *info);
+
+bool
+ilo_state_sample_pattern_init_default(struct ilo_state_sample_pattern *pattern,
+ const struct ilo_dev *dev);
+
+const uint8_t *
+ilo_state_sample_pattern_get_packed_offsets(const struct ilo_state_sample_pattern *pattern,
+ const struct ilo_dev *dev,
+ uint8_t sample_count);
+
+void
+ilo_state_sample_pattern_get_offset(const struct ilo_state_sample_pattern *pattern,
+ const struct ilo_dev *dev,
+ uint8_t sample_count, uint8_t sample_index,
+ uint8_t *x, uint8_t *y);
+
#endif /* ILO_STATE_RASTER_H */