[Mesa-dev] [PATCH 03/88] glsl: Add initial functions to

Eric Anholt eric at anholt.net
Mon Sep 26 15:42:50 UTC 2016


Timothy Arceri <timothy.arceri at collabora.com> writes:

> On Sun, 2016-09-25 at 13:26 -0700, Eric Anholt wrote:
>> Timothy Arceri <timothy.arceri at collabora.com> writes:
>> > +static void
>> > +test_put_key_and_get_key(void)
>> > +{
>> > +   struct program_cache *cache;
>> > +   bool result;
>> > +
>> > +   uint8_t key_a[20] = {  0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
>> > +			 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
>> > +   uint8_t key_b[20] = { 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
>> > +			 30, 33, 32, 33, 34, 35, 36, 37, 38, 39};
>> > +   uint8_t key_a_collide[20] =
>> > +                        { 0,  1, 42, 43, 44, 45, 46, 47, 48, 49,
>> > +			 50, 55, 52, 53, 54, 55, 56, 57, 58, 59};
>> > +
>> > +   cache = cache_create();
>> > +
>> > +   /* First test that cache_has_key returns false before
>> > cache_put_key */
>> > +   result = cache_has_key(cache, key_a);
>> > +   expect_equal(result, 0, "cache_has_key before key added");
>> > +
>> > +   /* Then a couple of tests of cache_put_key followed by
>> > cache_has_key */
>> > +   cache_put_key(cache, key_a);
>> > +   result = cache_has_key(cache, key_a);
>> > +   expect_equal(result, 1, "cache_has_key after key added");
>> > +
>> > +   cache_put_key(cache, key_b);
>> > +   result = cache_has_key(cache, key_b);
>> > +   expect_equal(result, 1, "2nd cache_has_key after key added");
>> > +
>> > +   /* Test that a key with the same two bytes as an existing key
>> > +    * forces an eviction.
>> > +    */
>> > +   cache_put_key(cache, key_a_collide);
>> > +   result = cache_has_key(cache, key_a_collide);
>> > +   expect_equal(result, 1, "put_key of a colliding key lands in
>> > the cache");
>> > +
>> > +   result = cache_has_key(cache, key_a);
>> > +   expect_equal(result, 0, "put_key of a colliding key evicts from
>> > the cache");
>> > +
>> > +   /* And finally test that we can re-add the original key to re-
>> > evict
>> > +    * the colliding key.
>> > +    */
>> > +   cache_put_key(cache, key_a);
>> > +   result = cache_has_key(cache, key_a);
>> > +   expect_equal(result, 1, "put_key of original key lands again");
>> > +
>> > +   result = cache_has_key(cache, key_a_collide);
>> > +   expect_equal(result, 0, "put_key of oiginal key evicts the
>> > colliding key");
>> 
>> "original"
>> 
>> I haven't yet figured out what the purpose of
>> cache_put_key()/cache_has_key() are.  I suppose I'll find out later
>> in
>> the series.
>
> Since we cache a program rather than individual shaders we set a cache
> key for each shader and opportunistically skip compiling it next time
> we see the shader.
>
> If we happen to be using the shader to create a program we haven't seen
> before we end up having to fall back to compiling the shader later. 

That works out better than just always skipping shader compile until
link time and you find that you need it?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 800 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160926/0b3ba410/attachment-0001.sig>


More information about the mesa-dev mailing list