Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/shady/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,15 @@
{ "name": "values", "class": "value", "list": true }
]
},
{
"name": "DebugMarker",
"class": "annotation",
"type": false,
"ops": [
{ "name": "name", "class": "string" },
{ "name": "marker", "class": "value" }
]
},
{
"name": "BasicBlock",
"recursive": true,
Expand Down
7 changes: 7 additions & 0 deletions src/backend/spirv/emit_spv.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ SpvId spv_emit_decl(Emitter* emitter, const Node* decl) {
size_t loc = shd_get_int_literal_value(*shd_resolve_to_int_literal(shd_get_annotation_value(a)), false);
assert(loc >= 0);
spvb_decorate(emitter->file_builder, given_id, SpvDecorationBinding, 1, (uint32_t[]) { loc });
} else if (a->tag == DebugMarker_TAG) {
String debug_marker = shd_get_string_literal(emitter->arena, a->payload.debug_marker.marker);
assert(debug_marker);
spvb_name(emitter->file_builder, given_id, shd_fmt_string_irarena(emitter->arena, "DEBUG_%s", debug_marker));
String debugged_node_name = shd_get_node_name_safe(a);
shd_log_fmt(DEBUGVV, "Emitting debug marker '%s' for SPIR-V ID '%d' for node '%s'\n", debug_marker,
given_id, debugged_node_name);
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/frontend/llvm/l2s_annotations.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ void l2s_process_llvm_annotations(Parser* p, LLVMValueRef global) {
.value = shd_int32_literal(a, as)
})
});
} else if (strcmp(keyword, "debug_marker") == 0) {
char *marker_name = strtok(NULL, "::");
if (marker_name) {
shd_log_fmt(DEBUGVV, "Adding DebugMarker '%s' to '%s' (type: %s)\n", marker_name,
shd_get_node_name_safe(target),
shd_get_node_tag_string(target->tag));

add_annotation(p, target, (ParsedAnnotation) {
.payload = debug_marker(a, (DebugMarker) {
.name = "DebugMarker",
.marker = string_lit_helper(a, marker_name),
})
});
}
} else {
shd_error_print("Unrecognised shady annotation '%s'\n", keyword);
shd_error_die();
Expand Down
10 changes: 10 additions & 0 deletions src/shady/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,16 @@ static void print_annotation(PrinterCtx* ctx, const Node* node) {
print_args_list(ctx, annotation->values);
break;
}
case DebugMarker_TAG: {
const DebugMarker* debug_marker = &node->payload.debug_marker;
printf(ANNOTATION_COLOR);
printf("@%s", debug_marker->name);
printf(RESET);
printf("(");
print_node(debug_marker->marker);
printf(")");
break;
}
case NotAnAnnotation: SHADY_UNKNOWN_ENUM("annotation node, tag = %s", shd_get_node_tag_string(node->tag));
}
}
Expand Down
1 change: 1 addition & 0 deletions test/vcc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ shady_unit_test(COMPILER vcc NAME vcc_simple_frag FILES simple.frag.c ARGS ${VCC
shady_unit_test(COMPILER vcc NAME vcc_flat_decoration_frag FILES flat_decoration.frag.c ARGS ${VCC_TEST_ARGS} --entry-point main --execution-model Fragment VALSPV SPV_VAL_ARGS ${SHADY_SPV_VAL_VK_ARGS})
shady_unit_test(COMPILER vcc NAME vcc_checker_frag FILES checkerboard.frag.c ARGS ${VCC_TEST_ARGS} --entry-point main --execution-model Fragment VALSPV SPV_VAL_ARGS ${SHADY_SPV_VAL_VK_ARGS})
shady_unit_test(COMPILER vcc NAME vcc_textured_frag FILES textured.frag.c ARGS ${VCC_TEST_ARGS} --entry-point main --execution-model Fragment VALSPV SPV_VAL_ARGS ${SHADY_SPV_VAL_VK_ARGS})
shady_unit_test(COMPILER vcc NAME vcc_debug_marker_frag FILES debug_marker.frag.c ARGS ${VCC_TEST_ARGS} --entry-point main --execution-model Fragment VALSPV SPV_VAL_ARGS ${SHADY_SPV_VAL_VK_ARGS})

shady_unit_test(COMPILER vcc NAME vcc_linkage FILES linkage.frag.c lib.c ARGS ${VCC_TEST_ARGS} --entry-point main --execution-model Fragment VALSPV SPV_VAL_ARGS ${SHADY_SPV_VAL_VK_ARGS})
shady_unit_test(COMPILER vcc NAME vcc_linkage_type FILES linkage2.frag.c lib2.c ARGS ${VCC_TEST_ARGS} --entry-point main --execution-model Fragment VALSPV SPV_VAL_ARGS ${SHADY_SPV_VAL_VK_ARGS})
Expand Down
13 changes: 13 additions & 0 deletions test/vcc/debug_marker.frag.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <stdint.h>
#include <shady.h>

descriptor_set(0) descriptor_binding(1) uniform_constant sampler2D texSampler;

location(0) input native_vec3 fragColor;
debug_marker(albedo_texture) location(1) input native_vec2 fragTexCoord;

location(0) output native_vec4 outColor;

fragment_shader void main() {
outColor = texture2D(texSampler, fragTexCoord) * (native_vec4) { fragColor.x * 2.5f, fragColor.y * 2.5f, fragColor.z * 2.5f, 1.0f };
}
2 changes: 2 additions & 0 deletions vcc/include/shady.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace vcc {
#define descriptor_binding(i) __attribute__((annotate("shady::descriptor_binding::"#i)))
#define local_size(x, y, z) __attribute__((annotate("shady::workgroup_size::"#x"::"#y"::"#z)))

#define debug_marker(name) __attribute__((annotate("shady::debug_marker::"#name)))

#define input __attribute__((annotate("shady::io::389")))
#define output __attribute__((annotate("shady::io::390")))
// maybe deprecate it ?
Expand Down