[Mesa-dev] [PATCH 1/2] nvc0: handle NULL pointer in nvc0_get_compute_param()

Samuel Pitoiset samuel.pitoiset at gmail.com
Tue Nov 3 10:40:03 PST 2015



On 11/03/2015 07:26 PM, Ilia Mirkin wrote:
> On Tue, Nov 3, 2015 at 1:35 PM, Samuel Pitoiset
> <samuel.pitoiset at gmail.com> wrote:
>> To get the size (in bytes) of a compute parameter, clover first calls
>> get_compute_param() with a NULL data pointer. The RET() macro is based
>> on nv50.
>>
>> Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
>> ---
>>   src/gallium/drivers/nouveau/nvc0/nvc0_screen.c | 45 ++++++++++++--------------
>>   1 file changed, 21 insertions(+), 24 deletions(-)
>>
>> diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
>> index 6aa4f0b..ea317a5 100644
>> --- a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
>> +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
>> @@ -353,45 +353,42 @@ static int
>>   nvc0_screen_get_compute_param(struct pipe_screen *pscreen,
>>                                 enum pipe_compute_cap param, void *data)
>>   {
>> -   uint64_t *data64 = (uint64_t *)data;
>> -   uint32_t *data32 = (uint32_t *)data;
>>      const uint16_t obj_class = nvc0_screen(pscreen)->compute->oclass;
>>
>> +#define RET(x) do {                  \
>> +   if (data)                         \
>> +      memcpy(data, x, sizeof(x));    \
>> +   return sizeof(x);                 \
>> +} while (0)
>> +
>>      switch (param) {
>>      case PIPE_COMPUTE_CAP_GRID_DIMENSION:
>> -      data64[0] = 3;
>> -      return 8;
>> +      RET((uint64_t []) { 3ul });
>>      case PIPE_COMPUTE_CAP_MAX_GRID_SIZE:
>> -      data64[0] = (obj_class >= NVE4_COMPUTE_CLASS) ? 0x7fffffff : 65535;
>> -      data64[1] = 65535;
>> -      data64[2] = 65535;
>> -      return 24;
>> +      if (obj_class >= NVE4_COMPUTE_CLASS) {
>> +         RET(((uint64_t []) { 0x7fffffff, 65535ul, 65535ul }));
>
> Why the ul's everywhere? And why not on the 0x7ffff ?

Based on curro's branch for nv50 compute support, but I assume I can get 
rid of this.

>
>> +      } else {
>> +         RET(((uint64_t []) { 65535ul, 65535ul, 65535ul }));
>> +      }
>>      case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE:
>> -      data64[0] = 1024;
>> -      data64[1] = 1024;
>> -      data64[2] = 64;
>> -      return 24;
>> +      RET(((uint64_t []) { 1024ul, 1024ul, 64ul }));
>>      case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK:
>> -      data64[0] = 1024;
>> -      return 8;
>> +      RET((uint64_t []) { 1024ul });
>>      case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE: /* g[] */
>> -      data64[0] = (uint64_t)1 << 40;
>> -      return 8;
>> +      RET((uint64_t []) { 1ul << 40 });
>>      case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE: /* s[] */
>> -      data64[0] = 48 << 10;
>> -      return 8;
>> +      RET((uint64_t []) { 48ul << 10 });
>>      case PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE: /* l[] */
>> -      data64[0] = 512 << 10;
>> -      return 8;
>> +      RET((uint64_t []) { 512ul << 10 });
>>      case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE: /* c[], arbitrary limit */
>> -      data64[0] = 4096;
>> -      return 8;
>> +      RET((uint64_t []) { 4096ul });
>>      case PIPE_COMPUTE_CAP_SUBGROUP_SIZE:
>> -      data32[0] = 32;
>> -      return 4;
>> +      RET((uint32_t []) { 32u });
>>      default:
>>         return 0;
>>      }
>> +
>> +#undef RET
>>   }
>>
>>   static void
>> --
>> 2.5.3
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list