spirv: Add support for using derefs for UBO/SSBO access
[mesa.git] / src / compiler / blob.c
index 5c94beed842f7273dbd95a212d7db404462f50ca..c89092e1cf3a98b0c2f9b9222cd23fd73e13d8df 100644 (file)
@@ -158,10 +158,10 @@ blob_write_bytes(struct blob *blob, const void *bytes, size_t to_write)
    return true;
 }
 
-ssize_t
+intptr_t
 blob_reserve_bytes(struct blob *blob, size_t to_write)
 {
-   ssize_t ret;
+   intptr_t ret;
 
    if (! grow_to_fit (blob, to_write))
       return -1;
@@ -172,14 +172,14 @@ blob_reserve_bytes(struct blob *blob, size_t to_write)
    return ret;
 }
 
-ssize_t
+intptr_t
 blob_reserve_uint32(struct blob *blob)
 {
    align_blob(blob, sizeof(uint32_t));
    return blob_reserve_bytes(blob, sizeof(uint32_t));
 }
 
-ssize_t
+intptr_t
 blob_reserve_intptr(struct blob *blob)
 {
    align_blob(blob, sizeof(intptr_t));
@@ -238,7 +238,7 @@ blob_write_string(struct blob *blob, const char *str)
 }
 
 void
-blob_reader_init(struct blob_reader *blob, const uint8_t *data, size_t size)
+blob_reader_init(struct blob_reader *blob, const void *data, size_t size)
 {
    blob->data = data;
    blob->end = blob->data + size;
@@ -256,7 +256,7 @@ ensure_can_read(struct blob_reader *blob, size_t size)
    if (blob->overrun)
       return false;
 
-   if (blob->current < blob->end && blob->end - blob->current >= size)
+   if (blob->current <= blob->end && blob->end - blob->current >= size)
       return true;
 
    blob->overrun = true;
@@ -280,9 +280,9 @@ blob_read_bytes(struct blob_reader *blob, size_t size)
 }
 
 void
-blob_copy_bytes(struct blob_reader *blob, uint8_t *dest, size_t size)
+blob_copy_bytes(struct blob_reader *blob, void *dest, size_t size)
 {
-   const uint8_t *bytes;
+   const void *bytes;
 
    bytes = blob_read_bytes(blob, size);
    if (bytes == NULL)
@@ -291,6 +291,13 @@ blob_copy_bytes(struct blob_reader *blob, uint8_t *dest, size_t size)
    memcpy(dest, bytes, size);
 }
 
+void
+blob_skip_bytes(struct blob_reader *blob, size_t size)
+{
+   if (ensure_can_read (blob, size))
+      blob->current += size;
+}
+
 /* These next three read functions have identical form. If we add any beyond
  * these first three we should probably switch to generating these with a
  * preprocessor macro.