Skip to content

Commit 22e4cd5

Browse files
committed
Add storage images and support for querying image size
1 parent 0d37d8f commit 22e4cd5

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

src/backend/spirv/emit_spv_value.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,14 @@ static SpvId emit_ext_op(Emitter* emitter, FnBuilder* fn_builder, BBBuilder bb_b
287287
assert(operands.count == 1);
288288
break;
289289
}
290+
case SpvOpImageWrite: {
291+
spvb_capability(emitter->file_builder, SpvCapabilityStorageImageWriteWithoutFormat);
292+
break;
293+
}
294+
case SpvOpImageQuerySize: {
295+
spvb_capability(emitter->file_builder, SpvCapabilityImageQuery);
296+
break;
297+
}
290298
default: break;
291299
}
292300
LARRAY(SpvId, ops, operands.count);

src/frontend/llvm/l2s_instr.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,16 @@ const Node* l2s_convert_instruction(Parser* p, FnParseCtx* fn_ctx, Node* fn_or_b
627627
ShdScope shd_scope = parse_scope(scope_str);
628628
Nodes ops = convert_operands(p, num_args, instr);
629629
uint32_t op = strtol(opcode_str, NULL, 10);
630+
631+
const Type* result_t = NULL;
632+
if (t && t->tag == TupleType_TAG && t->payload.tuple_type.members.count == 0) {
633+
result_t = NULL;
634+
} else if (t) {
635+
result_t = qualified_type_helper(a, shd_scope, t);
636+
}
630637

631638
free(duped);
632-
return shd_bld_add_instruction(b, ext_instr_helper(a, shd_bld_mem(b), qualified_type_helper(a, shd_scope, t), set, op, ops));
639+
return shd_bld_add_instruction(b, ext_instr_helper(a, shd_bld_mem(b), result_t, set, op, ops));
633640
} else {
634641
shd_error_print("Unrecognised shady intrinsic '%s'\n", keyword);
635642
shd_error_die();

src/frontend/llvm/l2s_type.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,22 @@ const Type* l2s_convert_type(Parser* p, LLVMTypeRef t) {
8888
default: assert(false);
8989
}
9090
bool arrayed = (offset >> 6) & 1;
91-
92-
return sampled_image_type(a, (SampledImageType) {.image_type = image_type(a, (ImageType) {
91+
bool is_storage = (offset >> 8) & 1;
92+
93+
const Type* img_type = image_type(a, (ImageType) {
9394
//.sampled_type = pack_type(a, (PackType) { .element_type = float_type(a, (Float) { .width = FloatTy32 }), .width = 4 }),
9495
.sampled_type = sampled_type,
9596
.dim = dim,
9697
.depth = 0,
9798
.arrayed = arrayed,
9899
.ms = 0,
99-
.sampled = 1,
100+
.sampled = is_storage ? 2 : 1,
100101
.imageformat = 0
101-
})});
102+
});
103+
if (is_storage) {
104+
return img_type;
105+
}
106+
return sampled_image_type(a, (SampledImageType) {.image_type = img_type});
102107
}
103108
AddressSpace as = l2s_convert_llvm_address_space(llvm_as);
104109
const Type* pointee = NULL;

vcc/include/shady.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,21 @@ typedef __attribute__((address_space(0x1001))) struct __shady_builtin_sampler2D*
4848
typedef __attribute__((address_space(0x1002))) struct __shady_builtin_sampler3D* sampler3D;
4949
typedef __attribute__((address_space(0x1003))) struct __shady_builtin_sampler3D* samplerCube;
5050

51+
typedef __attribute__((address_space(0x1100))) struct __shady_builtin_image2D *image1D;
52+
typedef __attribute__((address_space(0x1101))) struct __shady_builtin_image2D *image2D;
53+
typedef __attribute__((address_space(0x1102))) struct __shady_builtin_image2D *image3D;
54+
typedef __attribute__((address_space(0x1103))) struct __shady_builtin_image2D *imageCube;
55+
5156
native_vec4 texture1D(const sampler1D, float) __asm__("shady::impure_op::spirv.core::87::Invocation");
5257
native_vec4 texture2D(const sampler2D, native_vec2) __asm__("shady::impure_op::spirv.core::87::Invocation");
5358
native_vec4 texture3D(const sampler3D, native_vec3) __asm__("shady::impure_op::spirv.core::87::Invocation");
5459
native_vec4 textureCube(const samplerCube, native_vec3) __asm__("shady::impure_op::spirv.core::87::Invocation");
5560

61+
native_ivec2 imageSize(image2D img) __asm__("shady::pure_op::spirv.core::104::Invocation");
62+
void imageStore(image2D img,
63+
native_ivec2 coord,
64+
native_vec4 data) __asm__("shady::impure_op::spirv.core::99::Invocation");
65+
5666
#if defined(__cplusplus)
5767
native_vec4 texture(const sampler1D, float) __asm__("shady::impure_op::spirv.core::87::Invocation");
5868
native_vec4 texture(const sampler2D, native_vec2) __asm__("shady::impure_op::spirv.core::87::Invocation");

0 commit comments

Comments
 (0)