Hello Guest

VK10.VK_VERSION_MAJOR can return negative values

  • 1 Replies
  • 5257 Views
VK10.VK_VERSION_MAJOR can return negative values
« on: March 16, 2020, 09:38:18 »

This appears to be a minor issue but came up with value range testing:

VK10.VK_VERSION_MAJOR can return negative integer. The assumption is all returned values are positive due to underlying C99 API using unsigned integers.

The following code will return signed value -512 instead of the expected value 512:

Code: [Select]
System.err.println(VK10.VK_VERSION_MAJOR(0x80000000));

> -512

Assuming we've not misunderstood the intended bit manipulation operations, the (decompiled) implementation of VK_VERSION_MAJOR should use Java's unsigned bit shift operation '>>>' instead of the signed right shift operation '>>':

Code: [Select]
  public static int VK_VERSION_MAJOR(@NativeType("uint32_t") int version)
  {
    return version >>> 22;
  }

Or alternatively use bit-wise AND mask to drop the signed bit:

Code: [Select]
  public static int VK_VERSION_MAJOR(@NativeType("uint32_t") int version)
  {
    return version >> 22 & 1023;
  }

Given the current code does yield 512 distinct *major* versions, this is probably not a high priority issue for anyone at the moment :-)



*

Offline spasi

  • *****
  • 2247
    • WebHotelier
Re: VK10.VK_VERSION_MAJOR can return negative values
« Reply #1 on: May 07, 2020, 21:37:59 »
Thanks! This will be fixed in the next 3.2.4 snapshot.