#include "util/u_bitcast.h"
#include "util/u_memory.h"
#include "util/hash_table.h"
+#define XXH_INLINE_ALL
+#include "util/xxhash.h"
#include <stdbool.h>
#include <inttypes.h>
emit_decoration(b, target, SpvDecorationArrayStride, args, ARRAY_SIZE(args));
}
+void
+spirv_builder_emit_offset(struct spirv_builder *b, SpvId target,
+ uint32_t offset)
+{
+ uint32_t args[] = { offset };
+ emit_decoration(b, target, SpvDecorationOffset, args, ARRAY_SIZE(args));
+}
+
+void
+spirv_builder_emit_xfb_buffer(struct spirv_builder *b, SpvId target,
+ uint32_t buffer)
+{
+ uint32_t args[] = { buffer };
+ emit_decoration(b, target, SpvDecorationXfbBuffer, args, ARRAY_SIZE(args));
+}
+
+void
+spirv_builder_emit_xfb_stride(struct spirv_builder *b, SpvId target,
+ uint32_t stride)
+{
+ uint32_t args[] = { stride };
+ emit_decoration(b, target, SpvDecorationXfbStride, args, ARRAY_SIZE(args));
+}
+
+void
+spirv_builder_emit_index(struct spirv_builder *b, SpvId target, int index)
+{
+ uint32_t args[] = { index };
+ emit_decoration(b, target, SpvDecorationIndex, args, ARRAY_SIZE(args));
+}
+
static void
emit_member_decoration(struct spirv_builder *b, SpvId target, uint32_t member,
SpvDecoration decoration, const uint32_t extra_operands[],
SpvId bias,
SpvId dref,
SpvId dx,
- SpvId dy)
+ SpvId dy,
+ SpvId offset)
{
SpvId result = spirv_builder_new_id(b);
operands++;
}
- SpvImageOperandsMask operand_mask = 0;
- SpvId extra_operands[4];
- int num_extra_operands = SpvImageOperandsMaskNone;
+ SpvImageOperandsMask operand_mask = SpvImageOperandsMaskNone;
+ SpvId extra_operands[5];
+ int num_extra_operands = 0;
if (bias) {
extra_operands[++num_extra_operands] = bias;
operand_mask |= SpvImageOperandsBiasMask;
extra_operands[++num_extra_operands] = dy;
operand_mask |= SpvImageOperandsGradMask;
}
+ if (offset) {
+ extra_operands[++num_extra_operands] = offset;
+ operand_mask |= SpvImageOperandsOffsetMask;
+ }
/* finalize num_extra_operands / extra_operands */
if (num_extra_operands > 0) {
SpvId result_type,
SpvId image,
SpvId coordinate,
- SpvId lod)
+ SpvId lod,
+ SpvId sample)
{
SpvId result = spirv_builder_new_id(b);
- SpvId extra_operands[2];
+ SpvImageOperandsMask operand_mask = SpvImageOperandsMaskNone;
+ SpvId extra_operands[3];
int num_extra_operands = 0;
if (lod) {
- extra_operands[0] = SpvImageOperandsLodMask;
- extra_operands[1] = lod;
- num_extra_operands = 2;
+ extra_operands[++num_extra_operands] = lod;
+ operand_mask |= SpvImageOperandsLodMask;
+ }
+ if (sample) {
+ extra_operands[++num_extra_operands] = sample;
+ operand_mask |= SpvImageOperandsSampleMask;
+ }
+
+ /* finalize num_extra_operands / extra_operands */
+ if (num_extra_operands > 0) {
+ extra_operands[0] = operand_mask;
+ num_extra_operands++;
}
spirv_buffer_prepare(&b->instructions, 5 + num_extra_operands);
return result;
}
+SpvId
+spirv_builder_emit_image_query_size(struct spirv_builder *b,
+ SpvId result_type,
+ SpvId image,
+ SpvId lod)
+{
+ int opcode = SpvOpImageQuerySize;
+ int words = 4;
+ if (lod) {
+ words++;
+ opcode = SpvOpImageQuerySizeLod;
+ }
+
+ SpvId result = spirv_builder_new_id(b);
+ spirv_buffer_prepare(&b->instructions, words);
+ spirv_buffer_emit_word(&b->instructions, opcode | (words << 16));
+ spirv_buffer_emit_word(&b->instructions, result_type);
+ spirv_buffer_emit_word(&b->instructions, result);
+ spirv_buffer_emit_word(&b->instructions, image);
+
+ if (lod)
+ spirv_buffer_emit_word(&b->instructions, lod);
+
+ return result;
+}
+
SpvId
spirv_builder_emit_ext_inst(struct spirv_builder *b, SpvId result_type,
SpvId set, uint32_t instruction,
{
const struct spirv_type *type = arg;
- uint32_t hash = _mesa_fnv32_1a_offset_bias;
- hash = _mesa_fnv32_1a_accumulate(hash, type->op);
- hash = _mesa_fnv32_1a_accumulate_block(hash, type->args, sizeof(uint32_t) *
- type->num_args);
+ uint32_t hash = 0;
+ hash = XXH32(&type->op, sizeof(type->op), hash);
+ hash = XXH32(type->args, sizeof(uint32_t) * type->num_args, hash);
return hash;
}
{
const struct spirv_const *key = arg;
- uint32_t hash = _mesa_fnv32_1a_offset_bias;
- hash = _mesa_fnv32_1a_accumulate(hash, key->op);
- hash = _mesa_fnv32_1a_accumulate(hash, key->type);
- hash = _mesa_fnv32_1a_accumulate_block(hash, key->args, sizeof(uint32_t) *
- key->num_args);
+ uint32_t hash = 0;
+ hash = XXH32(&key->op, sizeof(key->op), hash);
+ hash = XXH32(&key->type, sizeof(key->type), hash);
+ hash = XXH32(key->args, sizeof(uint32_t) * key->num_args, hash);
return hash;
}