Skip to content

Commit 16f422c

Browse files
committed
aobench: port to vcc
1 parent f783b3f commit 16f422c

File tree

4 files changed

+66
-56
lines changed

4 files changed

+66
-56
lines changed

samples/aobench/CMakeLists.txt

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
find_program(CLANG_EXE "clang")
2-
find_program(LLVM-SPIRV_EXE "llvm-spirv")
3-
4-
if (CLANG_EXE AND LLVM-SPIRV_EXE)
1+
if (TARGET vcc)
52
add_executable(aobench_host ao_host.c ao_main.c)
3+
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ao.comp.c.ll COMMAND vcc ARGS ${CMAKE_CURRENT_SOURCE_DIR}/ao.comp.cpp --only-run-clang -o ${CMAKE_CURRENT_BINARY_DIR}/ao.comp.c.ll COMMENT ao.comp.c.ll DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ao.comp.cpp)
64

7-
add_custom_command(OUTPUT ao.cl.ll COMMAND clang ARGS ${CMAKE_CURRENT_SOURCE_DIR}/ao.cl -std=clc++2021 -emit-llvm -o ${CMAKE_CURRENT_BINARY_DIR}/ao.cl.ll -c -target spir64-unknown-unknown -O2 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ao.cl ${CMAKE_CURRENT_SOURCE_DIR}/ao.c)
8-
add_custom_command(OUTPUT ao.cl.spv COMMAND llvm-spirv ARGS ${CMAKE_CURRENT_BINARY_DIR}/ao.cl.ll -o ${CMAKE_CURRENT_BINARY_DIR}/ao.cl.spv DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ao.cl.ll)
9-
10-
set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/ao_main.c APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ao.cl.spv)
5+
set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/ao_main.c APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ao.comp.c.ll)
116
add_custom_command(TARGET aobench_host POST_BUILD
127
COMMAND ${CMAKE_COMMAND} -E copy
13-
${CMAKE_CURRENT_BINARY_DIR}/ao.cl.spv
14-
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ao.cl.spv)
8+
${CMAKE_CURRENT_BINARY_DIR}/ao.comp.c.ll
9+
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ao.comp.c.ll)
1510

1611
find_program(ISPC_EXE "ispc")
1712
if (ISPC_EXE)
1813
target_compile_definitions(aobench_host PUBLIC ENABLE_ISPC=1)
19-
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/aobench.ispc COMMAND slim ARGS ao.cl.spv --output ${CMAKE_CURRENT_BINARY_DIR}/aobench.ispc --entry-point aobench_kernel COMMENT generating aobench.ispc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ao.cl.spv)
14+
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/aobench.ispc COMMAND slim ARGS ${CMAKE_CURRENT_BINARY_DIR}/ao.comp.c.ll -o ${CMAKE_CURRENT_BINARY_DIR}/aobench.ispc --entry-point aobench_kernel COMMENT generating aobench.ispc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ao.comp.c.ll)
2015
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/aobench.ispc.o COMMAND ispc ARGS ${CMAKE_CURRENT_BINARY_DIR}/aobench.ispc -o ${CMAKE_CURRENT_BINARY_DIR}/aobench.ispc.o --pic -g -O2 -woff COMMENT generating aobench.ispc.o DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/aobench.ispc)
2116
add_library(aobench_ispc OBJECT ${CMAKE_CURRENT_BINARY_DIR}/aobench.ispc.o)
2217
set_target_properties(aobench_ispc PROPERTIES LINKER_LANGUAGE C)
@@ -25,5 +20,5 @@ if (CLANG_EXE AND LLVM-SPIRV_EXE)
2520

2621
target_link_libraries(aobench_host PRIVATE m shady runtime common)
2722
else()
28-
message("Clang and/or llvm-spirv not found. Skipping aobench.")
23+
message("Vcc not enabled. Skipping aobench.")
2924
endif()

samples/aobench/ao.cl

Lines changed: 0 additions & 43 deletions
This file was deleted.

samples/aobench/ao.comp.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <stdint.h>
2+
3+
#define compute_shader __attribute__((annotate("shady::entry_point::Compute")))
4+
5+
#define location(i) __attribute__((annotate("shady::location::"#i)))
6+
7+
#define input __attribute__((address_space(389)))
8+
#define output __attribute__((address_space(390)))
9+
#define global __attribute__((address_space(1)))
10+
11+
typedef uint32_t uvec4 __attribute__((ext_vector_type(4)));
12+
typedef float vec4 __attribute__((ext_vector_type(4)));
13+
14+
typedef uint32_t uvec3 __attribute__((ext_vector_type(3)));
15+
typedef float vec3 __attribute__((ext_vector_type(3)));
16+
17+
/*__attribute__((annotate("shady::builtin::FragCoord")))
18+
input vec4 fragCoord;
19+
20+
location(0) input vec3 fragColor;
21+
location(0) output vec4 outColor;*/
22+
23+
__attribute__((annotate("shady::builtin::WorkgroupId")))
24+
input uvec3 workgroup_id;
25+
26+
__attribute__((annotate("shady::builtin::GlobalInvocationId")))
27+
input uvec3 global_id;
28+
29+
float sqrtf(float) __asm__("shady::prim_op::sqrt");
30+
float sinf(float) __asm__("shady::prim_op::sin");
31+
float cosf(float) __asm__("shady::prim_op::cos");
32+
float fmodf(float, float) __asm__("shady::prim_op::mod");
33+
float fabsf(float) __asm__("shady::prim_op::abs");
34+
float floorf(float) __asm__("shady::prim_op::floor");
35+
#include "ao.c"
36+
37+
extern "C" __attribute__((annotate("shady::workgroup_size::16::16::1")))
38+
compute_shader void aobench_kernel(global unsigned char* out) {
39+
//outColor = (vec4) { fragColor[0], fragColor[1], fragColor[2], 1.0f };
40+
//outColor = (vec4) { fragCoord[0] / 1024, fragCoord[1] / 1024, 1.0f, 1.0f };
41+
42+
Ctx ctx = get_init_context();
43+
init_scene(&ctx);
44+
45+
int x = global_id.x;
46+
int y = global_id.y;
47+
//int x = (int) fragCoord.x % 1024;
48+
//int y = (int) fragCoord.y % 1024;
49+
50+
// unsigned int out[3]; // = { 55, 0, 0};
51+
out[0] = 255;
52+
out[1] = 255;
53+
render_pixel(&ctx, x + 3, y, WIDTH, HEIGHT, NSUBSAMPLES, (unsigned char*) out);
54+
//out[2] = 155;
55+
// out[0] = x / 4;
56+
// out[1] = y / 4;
57+
//outColor = (vec4) { ((int) out[0]) / 255.0f, ((int) out[1]) / 255.0f, ((int) out[2]) / 255.0f, 1.0f };
58+
}

samples/aobench/ao_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ int main(int argc, char **argv) {
180180
#endif
181181

182182
if (do_device || do_all) {
183-
render_device(&args, img, WIDTH, HEIGHT, NSUBSAMPLES, "./ao.cl.spv");
183+
render_device(&args, img, WIDTH, HEIGHT, NSUBSAMPLES, "./ao.comp.c.ll");
184184
saveppm("device.ppm", WIDTH, HEIGHT, img);
185185
}
186186

0 commit comments

Comments
 (0)