From af34140d239182e22765c9f8e7fdd8f7886c227d Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Sun, 11 Jun 2017 04:37:26 -0700 Subject: [PATCH] compile performance benchmark works --- .gitignore | 1 + Makefile | 17 +++++++++++++++ shader.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index f7d2a05..4459f9b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ shader.bc shader.o +shader.ll diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ec66fef --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +.PHONY: all always_build clean + +all: shader.o + +always_build: + +INITIAL_OPT := -inline -mem2reg -sccp -dce -simplifycfg + +shader.bc: shader.cpp + clang++ -std=c++14 -march=corei7 -Wall -o shader.ll shader.cpp -emit-llvm -S && opt $(INITIAL_OPT) shader.ll > shader.bc && llvm-dis shader.bc + +shader.o: shader.bc always_build + time -p bash -c 'for i in {1..10}; do echo $$i; opt -O3 < shader.bc | llc -filetype=obj -O3 -o shader.o; done' + +clean: + rm -f shader.bc shader.o shader.ll + diff --git a/shader.cpp b/shader.cpp index 0e93206..573d470 100644 --- a/shader.cpp +++ b/shader.cpp @@ -1,8 +1,61 @@ +#ifndef RECURSIVE_INVOCATION +#define UNIQUEIFY3(v, c) v ## _ ## c +#define UNIQUEIFY2(v, c) UNIQUEIFY3(v, c) +#define UNIQUEIFY(v) UNIQUEIFY2(v, __COUNTER__) +// following is code to include the body of this file pow(2, 7) times +#define RECURSIVE_INVOCATION 1 +#include "shader.cpp" +#undef RECURSIVE_INVOCATION +#define RECURSIVE_INVOCATION 1 +#include "shader.cpp" +#elif RECURSIVE_INVOCATION == 1 +#undef RECURSIVE_INVOCATION +#define RECURSIVE_INVOCATION 2 +#include "shader.cpp" +#undef RECURSIVE_INVOCATION +#define RECURSIVE_INVOCATION 2 +#include "shader.cpp" +#elif RECURSIVE_INVOCATION == 2 +#undef RECURSIVE_INVOCATION +#define RECURSIVE_INVOCATION 3 +#include "shader.cpp" +#undef RECURSIVE_INVOCATION +#define RECURSIVE_INVOCATION 3 +#include "shader.cpp" +#elif RECURSIVE_INVOCATION == 3 +#undef RECURSIVE_INVOCATION +#define RECURSIVE_INVOCATION 4 +#include "shader.cpp" +#undef RECURSIVE_INVOCATION +#define RECURSIVE_INVOCATION 4 +#include "shader.cpp" +#elif RECURSIVE_INVOCATION == 4 +#undef RECURSIVE_INVOCATION +#define RECURSIVE_INVOCATION 5 +#include "shader.cpp" +#undef RECURSIVE_INVOCATION +#define RECURSIVE_INVOCATION 5 +#include "shader.cpp" +#elif RECURSIVE_INVOCATION == 5 +#undef RECURSIVE_INVOCATION +#define RECURSIVE_INVOCATION 6 +#include "shader.cpp" +#undef RECURSIVE_INVOCATION +#define RECURSIVE_INVOCATION 6 +#include "shader.cpp" +#elif RECURSIVE_INVOCATION == 6 +#undef RECURSIVE_INVOCATION +#define RECURSIVE_INVOCATION 7 +#include "shader.cpp" +#undef RECURSIVE_INVOCATION +#define RECURSIVE_INVOCATION 7 +#include "shader.cpp" +#elif RECURSIVE_INVOCATION == 7 #include #include #include -namespace shader +namespace UNIQUEIFY(shader) { constexpr float max(float a, float b) noexcept { @@ -540,7 +593,7 @@ static void loop(int i, SHb += DirToSh(RSM_to_RH_dir, color.b()); } -extern "C" void shader_main(void) noexcept +void shader_main(void) noexcept { vec3 normalizedRHCenter = 2.f * vec3(gl_FragCoord.xy(), slice) / resolution - 1.f; vec3 RHcenter = (RHMatrix * vec4(normalizedRHCenter * extents, 1.f)).xyz(); @@ -555,8 +608,8 @@ extern "C" void shader_main(void) noexcept vec4 SHg = vec4(0.f); vec4 SHb = vec4(0.f); - int x = int(gl_FragCoord.x), y = int(gl_FragCoord.y); - float phi = 30.f * (x ^ y) + 10.f * x * y; + //int x = int(gl_FragCoord.x), y = int(gl_FragCoord.y); + //float phi = 30.f * (x ^ y) + 10.f * x * y; loop(0, RHcenter, RHCellSize, RHuv, RHdepth, SHr, SHg, SHb); loop(1, RHcenter, RHCellSize, RHuv, RHdepth, SHr, SHg, SHb); @@ -584,3 +637,4 @@ extern "C" void shader_main(void) noexcept SHBlue = SHb; } } +#endif -- 2.30.2