Mesa (master): util/u_atomic: Add new macro p_atomic_add
Module: Mesa Branch: master Commit: b16de0b713fb4d5d1c5600d126e4ce945fc27303 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=b16de0b713fb4d5d1c5600d126e4ce945fc27303 Author: Carl Worth Date: Thu Feb 5 15:36:59 2015 -0800 util/u_atomic: Add new macro p_atomic_add This provides for atomic addition, which will be used by an upcoming shader-cache patch. A simple test is added to "make check" as well. Note: The various O/S functions differ on whether they return the original value or the value after the addition, so I did not provide an add_return() macro which would be sensitive to that difference. Reviewed-by: Matt Turner Reviewed-by: Aaron Watry Reviewed-by: José Fonseca --- src/util/u_atomic.h | 16 src/util/u_atomic_test.c |5 + 2 files changed, 21 insertions(+) diff --git a/src/util/u_atomic.h b/src/util/u_atomic.h index cf7fff3..e123e17 100644 --- a/src/util/u_atomic.h +++ b/src/util/u_atomic.h @@ -39,6 +39,7 @@ #define p_atomic_dec_zero(v) (__sync_sub_and_fetch((v), 1) == 0) #define p_atomic_inc(v) (void) __sync_add_and_fetch((v), 1) #define p_atomic_dec(v) (void) __sync_sub_and_fetch((v), 1) +#define p_atomic_add(v, i) (void) __sync_add_and_fetch((v), (i)) #define p_atomic_inc_return(v) __sync_add_and_fetch((v), 1) #define p_atomic_dec_return(v) __sync_sub_and_fetch((v), 1) #define p_atomic_cmpxchg(v, old, _new) \ @@ -60,6 +61,7 @@ #define p_atomic_dec_zero(_v) (p_atomic_dec_return(_v) == 0) #define p_atomic_inc(_v) ((void) p_atomic_inc_return(_v)) #define p_atomic_dec(_v) ((void) p_atomic_dec_return(_v)) +#define p_atomic_add(_v, _i) (*(_v) = *(_v) + (_i)) #define p_atomic_inc_return(_v) (++(*(_v))) #define p_atomic_dec_return(_v) (--(*(_v))) #define p_atomic_cmpxchg(_v, _old, _new) (*(_v) == (_old) ? (*(_v) = (_new), (_old)) : *(_v)) @@ -144,6 +146,13 @@ char _InterlockedCompareExchange8(char volatile *Destination8, char Exchange8, c sizeof *(_v) == sizeof(__int64) ? InterlockedDecrement64 ((__int64 *)(_v)) : \ (assert(!"should not get here"), 0)) +#define p_atomic_add(_v, _i) (\ + sizeof *(_v) == sizeof(char)? _InterlockedExchangeAdd8 ((char *) (_v), (_i)) : \ + sizeof *(_v) == sizeof(short) ? _InterlockedExchangeAdd16((short *) (_v), (_i)) : \ + sizeof *(_v) == sizeof(long)? _InterlockedExchangeAdd ((long *) (_v), (_i)) : \ + sizeof *(_v) == sizeof(__int64) ? InterlockedExchangeAdd64((__int64 *)(_v), (_i)) : \ + (assert(!"should not get here"), 0)) + #define p_atomic_cmpxchg(_v, _old, _new) (\ sizeof *(_v) == sizeof(char)? _InterlockedCompareExchange8 ((char *) (_v), (char) (_new), (char) (_old)) : \ sizeof *(_v) == sizeof(short) ? _InterlockedCompareExchange16((short *) (_v), (short) (_new), (short) (_old)) : \ @@ -198,6 +207,13 @@ char _InterlockedCompareExchange8(char volatile *Destination8, char Exchange8, c sizeof(*v) == sizeof(uint64_t) ? atomic_dec_64_nv((uint64_t *)(v)) : \ (assert(!"should not get here"), 0)) +#define p_atomic_add(v, i) ((void) \ + sizeof(*v) == sizeof(uint8_t) ? atomic_add_8 ((uint8_t *)(v), (i)) : \ + sizeof(*v) == sizeof(uint16_t) ? atomic_add_16((uint16_t *)(v), (i)) : \ + sizeof(*v) == sizeof(uint32_t) ? atomic_add_32((uint32_t *)(v), (i)) : \ + sizeof(*v) == sizeof(uint64_t) ? atomic_add_64((uint64_t *)(v), (i)) : \ +(assert(!"should not get here"), 0)) + #define p_atomic_cmpxchg(v, old, _new) ((typeof(*v)) \ sizeof(*v) == sizeof(uint8_t) ? atomic_cas_8 ((uint8_t *)(v), (uint8_t )(old), (uint8_t )(_new)) : \ sizeof(*v) == sizeof(uint16_t) ? atomic_cas_16((uint16_t *)(v), (uint16_t)(old), (uint16_t)(_new)) : \ diff --git a/src/util/u_atomic_test.c b/src/util/u_atomic_test.c index 4845e75..c506275 100644 --- a/src/util/u_atomic_test.c +++ b/src/util/u_atomic_test.c @@ -97,6 +97,11 @@ assert(v == ones && "p_atomic_dec_return"); \ assert(r == v && "p_atomic_dec_return"); \ \ + v = 23; \ + p_atomic_add(&v, 42); \ + r = p_atomic_read(&v); \ + assert(r == 65 && "p_atomic_add"); \ + \ (void) r; \ (void) b; \ } ___ mesa-commit mailing list mesa-commit@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-commit
Mesa (master): i965: Fix integer border color on Haswell.
Module: Mesa Branch: master Commit: 08a06b6b891df456902f5e170f1d82236d0c73d2 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=08a06b6b891df456902f5e170f1d82236d0c73d2 Author: Kenneth Graunke Date: Fri Feb 6 03:39:20 2015 -0800 i965: Fix integer border color on Haswell. +82 Piglits - 100% of border color tests now pass on Haswell. Signed-off-by: Kenneth Graunke Reviewed-by: Jason Ekstrand Reviewed-by: Chris Forbes Cc: mesa-sta...@lists.freedesktop.org --- src/mesa/drivers/dri/i965/brw_defines.h |1 + src/mesa/drivers/dri/i965/brw_sampler_state.c | 62 + src/mesa/drivers/dri/i965/gen7_wm_surface_state.c |3 + 3 files changed, 66 insertions(+) diff --git a/src/mesa/drivers/dri/i965/brw_defines.h b/src/mesa/drivers/dri/i965/brw_defines.h index f02a0b8..a597d6b 100644 --- a/src/mesa/drivers/dri/i965/brw_defines.h +++ b/src/mesa/drivers/dri/i965/brw_defines.h @@ -551,6 +551,7 @@ #define BRW_SURFACE_PITCH_MASK INTEL_MASK(19, 3) #define BRW_SURFACE_TILED (1 << 1) #define BRW_SURFACE_TILED_Y(1 << 0) +#define HSW_SURFACE_IS_INTEGER_FORMAT (1 << 18) /* Surface state DW4 */ #define BRW_SURFACE_MIN_LOD_SHIFT 28 diff --git a/src/mesa/drivers/dri/i965/brw_sampler_state.c b/src/mesa/drivers/dri/i965/brw_sampler_state.c index d9a8eea..c532850 100644 --- a/src/mesa/drivers/dri/i965/brw_sampler_state.c +++ b/src/mesa/drivers/dri/i965/brw_sampler_state.c @@ -269,6 +269,68 @@ upload_default_color(struct brw_context *brw, uint32_t *sdc = brw_state_batch(brw, AUB_TRACE_SAMPLER_DEFAULT_COLOR, 4 * 4, 64, sdc_offset); memcpy(sdc, color.ui, 4 * 4); + } else if (brw->is_haswell && texObj->_IsIntegerFormat) { + /* Haswell's integer border color support is completely insane: + * SAMPLER_BORDER_COLOR_STATE is 20 DWords. The first four are + * for float colors. The next 12 DWords are MBZ and only exist to + * pad it out to a 64 byte cacheline boundary. DWords 16-19 then + * contain integer colors; these are only used if SURFACE_STATE + * has the "Integer Surface Format" bit set. Even then, the + * arrangement of the RGBA data devolves into madness. + */ + uint32_t *sdc = brw_state_batch(brw, AUB_TRACE_SAMPLER_DEFAULT_COLOR, + 20 * 4, 512, sdc_offset); + memset(sdc, 0, 20 * 4); + sdc = &sdc[16]; + + mesa_format format = firstImage->TexFormat; + int bits_per_channel = _mesa_get_format_bits(format, GL_RED_BITS); + + /* From the Haswell PRM, "Command Reference: Structures", Page 36: + * "If any color channel is missing from the surface format, + * corresponding border color should be programmed as zero and if + * alpha channel is missing, corresponding Alpha border color should + * be programmed as 1." + */ + unsigned c[4] = { 0, 0, 0, 1 }; + for (int i = 0; i < 4; i++) { + if (_mesa_format_has_color_component(format, i)) +c[i] = color.ui[i]; + } + + switch (bits_per_channel) { + case 8: + /* Copy RGBA in order. */ + for (int i = 0; i < 4; i++) +((uint8_t *) sdc)[i] = c[i]; + break; + case 10: + /* R10G10B10A2_UINT is treated like a 16-bit format. */ + case 16: + ((uint16_t *) sdc)[0] = c[0]; /* R -> DWord 0, bits 15:0 */ + ((uint16_t *) sdc)[1] = c[1]; /* G -> DWord 0, bits 31:16 */ + /* DWord 1 is Reserved/MBZ! */ + ((uint16_t *) sdc)[4] = c[2]; /* B -> DWord 2, bits 15:0 */ + ((uint16_t *) sdc)[5] = c[3]; /* A -> DWord 3, bits 31:16 */ + break; + case 32: + if (firstImage->_BaseFormat == GL_RG) { +/* Careful inspection of the tables reveals that for RG32 formats, + * the green channel needs to go where blue normally belongs. + */ +sdc[0] = c[0]; +sdc[2] = c[1]; +sdc[3] = 1; + } else { +/* Copy RGBA in order. */ +for (int i = 0; i < 4; i++) + sdc[i] = c[i]; + } + break; + default: + assert(!"Invalid number of bits per channel in integer format."); + break; + } } else if (brw->gen == 5 || brw->gen == 6) { struct gen5_sampler_default_color *sdc; diff --git a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c index 07db678..29553cd 100644 --- a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c +++ b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c @@ -321,6 +321,9 @@ gen7_update_texture_surface(struct gl_context *ctx, surf[3] = SET_FIELD(effective_depth - 1, BRW_SURFACE_DEPTH) | (mt->pitch - 1); + if (brw->is_haswell && tObj->_IsIntegerFormat) + surf[3] |= HSW_SURFACE_IS_INTEGER_FORMAT; + surf[4] = gen7_surface_msa
Mesa (master): i965: Override swizzles for integer luminance formats.
Module: Mesa Branch: master Commit: 8cb18760cccf2c89d94c50ff14b330ec2d5c4a3c URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=8cb18760cccf2c89d94c50ff14b330ec2d5c4a3c Author: Kenneth Graunke Date: Fri Feb 6 02:06:27 2015 -0800 i965: Override swizzles for integer luminance formats. The hardware's integer luminance formats are completely unusable; currently we fall back to RGBA. This means we need to override the texture swizzle to obtain the XXX1 values expected for luminance formats. Fixes spec/EXT_texture_integer/texwrap formats bordercolor [swizzled] on Broadwell - 100% of border color tests now pass on Broadwell. Signed-off-by: Kenneth Graunke Reviewed-by: Ian Romanick Reviewed-by: Chris Forbes Cc: mesa-sta...@lists.freedesktop.org --- src/mesa/drivers/dri/i965/brw_wm_surface_state.c |8 1 file changed, 8 insertions(+) diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c index 6456a61..5f81402 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c +++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c @@ -199,6 +199,14 @@ brw_get_texture_swizzle(const struct gl_context *ctx, swizzles[1] = SWIZZLE_ZERO; swizzles[2] = SWIZZLE_ZERO; break; + case GL_LUMINANCE: + if (t->_IsIntegerFormat) { + swizzles[0] = SWIZZLE_X; + swizzles[1] = SWIZZLE_X; + swizzles[2] = SWIZZLE_X; + swizzles[3] = SWIZZLE_ONE; + } + break; case GL_RED: case GL_RG: case GL_RGB: ___ mesa-commit mailing list mesa-commit@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-commit
Mesa (master): i965: Use a gl_color_union for sampler border color.
Module: Mesa Branch: master Commit: e1e73443c572b5432ef66a923fe64b73467f411b URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e1e73443c572b5432ef66a923fe64b73467f411b Author: Kenneth Graunke Date: Tue May 6 22:56:17 2014 -0700 i965: Use a gl_color_union for sampler border color. This should have no effect, but will make it easier to implement other bug fixes. v2: Eliminate "unsigned one" local; just use the value where necessary. Signed-off-by: Kenneth Graunke Reviewed-by: Ian Romanick Cc: mesa-sta...@lists.freedesktop.org --- src/mesa/drivers/dri/i965/brw_sampler_state.c | 105 - 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_sampler_state.c b/src/mesa/drivers/dri/i965/brw_sampler_state.c index 0fe0853..d9a8eea 100644 --- a/src/mesa/drivers/dri/i965/brw_sampler_state.c +++ b/src/mesa/drivers/dri/i965/brw_sampler_state.c @@ -208,7 +208,7 @@ upload_default_color(struct brw_context *brw, struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; struct gl_texture_object *texObj = texUnit->_Current; struct gl_texture_image *firstImage = texObj->Image[0][texObj->BaseLevel]; - float color[4]; + union gl_color_union color; switch (firstImage->_BaseFormat) { case GL_DEPTH_COMPONENT: @@ -216,40 +216,40 @@ upload_default_color(struct brw_context *brw, * R channel, while the hardware uses A. Spam R into all the * channels for safety. */ - color[0] = sampler->BorderColor.f[0]; - color[1] = sampler->BorderColor.f[0]; - color[2] = sampler->BorderColor.f[0]; - color[3] = sampler->BorderColor.f[0]; + color.ui[0] = sampler->BorderColor.ui[0]; + color.ui[1] = sampler->BorderColor.ui[0]; + color.ui[2] = sampler->BorderColor.ui[0]; + color.ui[3] = sampler->BorderColor.ui[0]; break; case GL_ALPHA: - color[0] = 0.0; - color[1] = 0.0; - color[2] = 0.0; - color[3] = sampler->BorderColor.f[3]; + color.ui[0] = 0u; + color.ui[1] = 0u; + color.ui[2] = 0u; + color.ui[3] = sampler->BorderColor.ui[3]; break; case GL_INTENSITY: - color[0] = sampler->BorderColor.f[0]; - color[1] = sampler->BorderColor.f[0]; - color[2] = sampler->BorderColor.f[0]; - color[3] = sampler->BorderColor.f[0]; + color.ui[0] = sampler->BorderColor.ui[0]; + color.ui[1] = sampler->BorderColor.ui[0]; + color.ui[2] = sampler->BorderColor.ui[0]; + color.ui[3] = sampler->BorderColor.ui[0]; break; case GL_LUMINANCE: - color[0] = sampler->BorderColor.f[0]; - color[1] = sampler->BorderColor.f[0]; - color[2] = sampler->BorderColor.f[0]; - color[3] = 1.0; + color.ui[0] = sampler->BorderColor.ui[0]; + color.ui[1] = sampler->BorderColor.ui[0]; + color.ui[2] = sampler->BorderColor.ui[0]; + color.ui[3] = float_as_int(1.0); break; case GL_LUMINANCE_ALPHA: - color[0] = sampler->BorderColor.f[0]; - color[1] = sampler->BorderColor.f[0]; - color[2] = sampler->BorderColor.f[0]; - color[3] = sampler->BorderColor.f[3]; + color.ui[0] = sampler->BorderColor.ui[0]; + color.ui[1] = sampler->BorderColor.ui[0]; + color.ui[2] = sampler->BorderColor.ui[0]; + color.ui[3] = sampler->BorderColor.ui[3]; break; default: - color[0] = sampler->BorderColor.f[0]; - color[1] = sampler->BorderColor.f[1]; - color[2] = sampler->BorderColor.f[2]; - color[3] = sampler->BorderColor.f[3]; + color.ui[0] = sampler->BorderColor.ui[0]; + color.ui[1] = sampler->BorderColor.ui[1]; + color.ui[2] = sampler->BorderColor.ui[2]; + color.ui[3] = sampler->BorderColor.ui[3]; break; } @@ -258,18 +258,17 @@ upload_default_color(struct brw_context *brw, * the border color alpha to 1.0 in that case. */ if (firstImage->_BaseFormat == GL_RGB) - color[3] = 1.0; + color.ui[3] = float_as_int(1.0); if (brw->gen >= 8) { /* On Broadwell, the border color is represented as four 32-bit floats, * integers, or unsigned values, interpreted according to the surface - * format. This matches the sampler->BorderColor union exactly. Since - * we use floats both here and in the above reswizzling code, we preserve - * the original bit pattern. So we actually handle all three formats. + * format. This matches the sampler->BorderColor union exactly; just + * memcpy the values. */ - float *sdc = brw_state_batch(brw, AUB_TRACE_SAMPLER_DEFAULT_COLOR, - 4 * 4, 64, sdc_offset); - COPY_4FV(sdc, color); + uint32_t *sdc = brw_state_batch(brw, AUB_TRACE_SAMPLER_DEFAULT_COLOR, + 4 * 4, 64, sdc_offset); + memcpy(sdc, color.ui, 4 * 4); } else if (brw->gen == 5 || brw->gen == 6) { struct gen5_sampler_default_color *sdc; @@ -278