libs/vkd3d-shader: Factor out vkd3d_spirv_build_image_instruction() function.
This commit is contained in:
parent
d42f46cab6
commit
72b109d380
|
@ -1251,95 +1251,75 @@ static uint32_t vkd3d_spirv_build_op_image(struct vkd3d_spirv_builder *builder,
|
||||||
SpvOpImage, result_type, sampled_image_id);
|
SpvOpImage, result_type, sampled_image_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t vkd3d_spirv_build_op_image_sample(struct vkd3d_spirv_builder *builder,
|
static uint32_t vkd3d_spirv_build_image_instruction(struct vkd3d_spirv_builder *builder,
|
||||||
SpvOp op, uint32_t result_type, uint32_t sampled_image_id, uint32_t coordinate_id,
|
SpvOp op, uint32_t result_type, const uint32_t *operands, unsigned int operand_count,
|
||||||
uint32_t image_operands, const uint32_t *operands, unsigned int operand_count)
|
uint32_t image_operands_mask, const uint32_t *image_operands, unsigned int image_operand_count)
|
||||||
{
|
{
|
||||||
unsigned int i = 0, j;
|
unsigned int index = 0, i;
|
||||||
uint32_t w[10];
|
uint32_t w[10];
|
||||||
|
|
||||||
|
assert(operand_count <= ARRAY_SIZE(w));
|
||||||
|
for (i = 0; i < operand_count; ++i)
|
||||||
|
w[index++] = operands[i];
|
||||||
|
|
||||||
|
if (image_operands_mask)
|
||||||
|
{
|
||||||
|
assert(index + 1 + image_operand_count <= ARRAY_SIZE(w));
|
||||||
|
w[index++] = image_operands_mask;
|
||||||
|
for (i = 0; i < image_operand_count; ++i)
|
||||||
|
w[index++] = image_operands[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return vkd3d_spirv_build_op_trv(builder, &builder->function_stream,
|
||||||
|
op, result_type, w, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t vkd3d_spirv_build_op_image_sample(struct vkd3d_spirv_builder *builder,
|
||||||
|
SpvOp op, uint32_t result_type, uint32_t sampled_image_id, uint32_t coordinate_id,
|
||||||
|
uint32_t image_operands_mask, const uint32_t *image_operands, unsigned int image_operand_count)
|
||||||
|
{
|
||||||
|
const uint32_t operands[] = {sampled_image_id, coordinate_id};
|
||||||
|
|
||||||
if (op == SpvOpImageSampleExplicitLod)
|
if (op == SpvOpImageSampleExplicitLod)
|
||||||
assert(image_operands & SpvImageOperandsLodMask);
|
assert(image_operands_mask & SpvImageOperandsLodMask);
|
||||||
else
|
else
|
||||||
assert(op == SpvOpImageSampleImplicitLod);
|
assert(op == SpvOpImageSampleImplicitLod);
|
||||||
|
|
||||||
w[i++] = sampled_image_id;
|
return vkd3d_spirv_build_image_instruction(builder, op, result_type,
|
||||||
w[i++] = coordinate_id;
|
operands, ARRAY_SIZE(operands), image_operands_mask, image_operands, image_operand_count);
|
||||||
if (image_operands)
|
|
||||||
{
|
|
||||||
assert(i + 1 + operand_count <= ARRAY_SIZE(w));
|
|
||||||
w[i++] = image_operands;
|
|
||||||
for (j = 0; j < operand_count; ++j)
|
|
||||||
w[i++] = operands[j];
|
|
||||||
}
|
|
||||||
return vkd3d_spirv_build_op_trv(builder, &builder->function_stream,
|
|
||||||
op, result_type, w, i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t vkd3d_spirv_build_op_image_sample_dref(struct vkd3d_spirv_builder *builder,
|
static uint32_t vkd3d_spirv_build_op_image_sample_dref(struct vkd3d_spirv_builder *builder,
|
||||||
SpvOp op, uint32_t result_type, uint32_t sampled_image_id, uint32_t coordinate_id,
|
SpvOp op, uint32_t result_type, uint32_t sampled_image_id, uint32_t coordinate_id, uint32_t dref_id,
|
||||||
uint32_t dref_id, uint32_t image_operands, const uint32_t *operands, unsigned int operand_count)
|
uint32_t image_operands_mask, const uint32_t *image_operands, unsigned int image_operand_count)
|
||||||
{
|
{
|
||||||
unsigned int i = 0, j;
|
const uint32_t operands[] = {sampled_image_id, coordinate_id, dref_id};
|
||||||
uint32_t w[10];
|
|
||||||
|
|
||||||
if (op == SpvOpImageSampleDrefExplicitLod)
|
if (op == SpvOpImageSampleDrefExplicitLod)
|
||||||
assert(image_operands & SpvImageOperandsLodMask);
|
assert(image_operands_mask & SpvImageOperandsLodMask);
|
||||||
else
|
else
|
||||||
assert(op == SpvOpImageSampleDrefImplicitLod);
|
assert(op == SpvOpImageSampleDrefImplicitLod);
|
||||||
|
|
||||||
w[i++] = sampled_image_id;
|
return vkd3d_spirv_build_image_instruction(builder, op, result_type,
|
||||||
w[i++] = coordinate_id;
|
operands, ARRAY_SIZE(operands), image_operands_mask, image_operands, image_operand_count);
|
||||||
w[i++] = dref_id;
|
|
||||||
if (image_operands)
|
|
||||||
{
|
|
||||||
assert(i + 1 + operand_count <= ARRAY_SIZE(w));
|
|
||||||
w[i++] = image_operands;
|
|
||||||
for (j = 0; j < operand_count; ++j)
|
|
||||||
w[i++] = operands[j];
|
|
||||||
}
|
|
||||||
return vkd3d_spirv_build_op_trv(builder, &builder->function_stream,
|
|
||||||
op, result_type, w, i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t vkd3d_spirv_build_op_image_fetch(struct vkd3d_spirv_builder *builder,
|
static uint32_t vkd3d_spirv_build_op_image_fetch(struct vkd3d_spirv_builder *builder,
|
||||||
uint32_t result_type, uint32_t image_id, uint32_t coordinate_id,
|
uint32_t result_type, uint32_t image_id, uint32_t coordinate_id,
|
||||||
uint32_t image_operands, const uint32_t *operands, unsigned int operand_count)
|
uint32_t image_operands_mask, const uint32_t *image_operands, unsigned int image_operand_count)
|
||||||
{
|
{
|
||||||
unsigned int i = 0, j;
|
const uint32_t operands[] = {image_id, coordinate_id};
|
||||||
uint32_t w[10];
|
return vkd3d_spirv_build_image_instruction(builder, SpvOpImageFetch, result_type,
|
||||||
|
operands, ARRAY_SIZE(operands), image_operands_mask, image_operands, image_operand_count);
|
||||||
w[i++] = image_id;
|
|
||||||
w[i++] = coordinate_id;
|
|
||||||
if (image_operands)
|
|
||||||
{
|
|
||||||
assert(i + 1 + operand_count <= ARRAY_SIZE(w));
|
|
||||||
w[i++] = image_operands;
|
|
||||||
for (j = 0; j < operand_count; ++j)
|
|
||||||
w[i++] = operands[j];
|
|
||||||
}
|
|
||||||
return vkd3d_spirv_build_op_trv(builder, &builder->function_stream,
|
|
||||||
SpvOpImageFetch, result_type, w, i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t vkd3d_spirv_build_op_image_read(struct vkd3d_spirv_builder *builder,
|
static uint32_t vkd3d_spirv_build_op_image_read(struct vkd3d_spirv_builder *builder,
|
||||||
uint32_t result_type, uint32_t image_id, uint32_t coordinate_id,
|
uint32_t result_type, uint32_t image_id, uint32_t coordinate_id,
|
||||||
uint32_t image_operands, const uint32_t *operands, unsigned int operand_count)
|
uint32_t image_operands_mask, const uint32_t *image_operands, unsigned int image_operand_count)
|
||||||
{
|
{
|
||||||
unsigned int i = 0, j;
|
const uint32_t operands[] = {image_id, coordinate_id};
|
||||||
uint32_t w[10];
|
return vkd3d_spirv_build_image_instruction(builder, SpvOpImageRead, result_type,
|
||||||
|
operands, ARRAY_SIZE(operands), image_operands_mask, image_operands, image_operand_count);
|
||||||
w[i++] = image_id;
|
|
||||||
w[i++] = coordinate_id;
|
|
||||||
if (image_operands)
|
|
||||||
{
|
|
||||||
assert(i + 1 + operand_count <= ARRAY_SIZE(w));
|
|
||||||
w[i++] = image_operands;
|
|
||||||
for (j = 0; j < operand_count; ++j)
|
|
||||||
w[i++] = operands[j];
|
|
||||||
}
|
|
||||||
return vkd3d_spirv_build_op_trv(builder, &builder->function_stream,
|
|
||||||
SpvOpImageRead, result_type, w, i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vkd3d_spirv_build_op_image_write(struct vkd3d_spirv_builder *builder,
|
static void vkd3d_spirv_build_op_image_write(struct vkd3d_spirv_builder *builder,
|
||||||
|
|
Loading…
Reference in New Issue