Updated to work with newer version of shaderc

This commit is contained in:
2022-05-27 17:11:31 +02:00
parent 87667f0618
commit 6729ad02e3
4 changed files with 41 additions and 9 deletions

View File

@@ -34,6 +34,7 @@ include(HandleLLVMOptions)
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/vendor/shaderc/CMakeLists.txt")
set(SHADERC_SKIP_TESTS ON)
set(SHADERC_ENABLE_WERROR_COMPILE OFF)
add_subdirectory(vendor/shaderc)
else()

View File

@@ -6,3 +6,15 @@ echo deb https://apt.llvm.org/bullseye llvm-toolchain-bullseye-14 main >/etc/apt
apt install llvm-14-tools clang build-essential cmake git \
llvm-14-dev libboost-log-dev spirv-headers spirv-tools
```
Clone the source, then in the source dir:
```shell
git submodule update --init vendor/shaderc
vendor/shaderc/utils/git-sync-deps
mkdir build
cd build
cmake -DCMAKE_BUILD_PROFILE=Release ..
# Note: just running `make` will fail with a link error in render_stub.c; ignore this.
make bluebell
```

View File

@@ -16,7 +16,7 @@ std::shared_ptr<std::vector<uint32_t>> pre_compile_shader(const std::string &src
// options.SetOptimizationLevel(shaderc_optimization_level_performance);
options.SetTargetSpirv(shaderc_spirv_version_1_0);
options.SetTargetEnvironment(
shaderc_target_env_opengl_compat,
shaderc_target_env_opengl,
shaderc_env_version::shaderc_env_version_opengl_4_5);

View File

@@ -18,6 +18,10 @@
#ifndef FRAME_COUNT
#define FRAME_COUNT 100
#endif
#ifndef MSAA
// Multisample anti-aliasing count (will actually sample MSAA^2 points)
#define MSAA 1
#endif
// render API:
struct Uniforms {
@@ -56,7 +60,6 @@ const char* PPM_HDR = "P6\n" STRINGIFY(FRAME_DIM) " " STRINGIFY(FRAME_DIM) "\n25
unsigned char frame_buf[FRAME_DIM][FRAME_DIM][3];
unsigned char linear_to_srgb(float lin) {
float srgb;
if (lin < 0) {
return 0;
} else if (lin > 1) {
@@ -64,7 +67,7 @@ unsigned char linear_to_srgb(float lin) {
} else if (lin < 0.0031308) {
return (unsigned char)(lin * 12.92);
} else {
float srgb = (powf(lin, 1.0f/2.4f) * 1.055f - 0.055f) * 256;
float srgb = (powf(lin, 1.0f/2.4f) * 1.055f - 0.055f) * 256.f;
if (srgb > 255.f) {
return 255;
} else {
@@ -72,6 +75,13 @@ unsigned char linear_to_srgb(float lin) {
}
}
}
float srgb_to_linear(float srgb) {
if (srgb < 0.04045f) {
return srgb/12.92f;
} else {
return powf((srgb+0.055f)/1.055f, 2.4f);
}
}
int main(int argc, char** argv) {
unsigned header_len = strlen(PPM_HDR);
@@ -87,14 +97,23 @@ int main(int argc, char** argv) {
for (int y = 0; y < FRAME_DIM; y++) {
for (int x = 0; x < FRAME_DIM; x++) {
float pixel[3];
float pixel_accum[3] = {0.f,0.f,0.f};
unsigned char *pxl_dst = frame_buf[y][x];
// printf("-- pixel %f,%f\n", (x+0.5f), (y+0.5f));
render_pixel(ctx, (x + 0.5f), (y + 0.5f), pixel);
for (int ss_x = 0; ss_x < MSAA; ss_x++) {
for (int ss_y = 0; ss_y < MSAA; ss_y++) {
float rx = (0.5f + (float)ss_x) / (float)MSAA + (float)x;
float ry = (0.5f + (float)ss_y) / (float)MSAA + (float)y;
render_pixel(ctx, rx, ry, pixel);
for (int i = 0; i < 3; i++) {
pixel_accum[i] += srgb_to_linear(pixel[i]);
}
}
}
for (int i = 0; i < 3; i++) {
pixel[i] *= 256;
if (pixel[i] < 0) { pixel[i] = 0; }
if (pixel[i] > 255) { pixel[i] = 255; }
pxl_dst[i] = (unsigned char) pixel[i];
// pixel_accum[i] *= 256;
// if (pixel_accum[i] < 0) { pixel_accum[i] = 0; }
// if (pixel_accum[i] > 255) { pixel_accum[i] = 255; }
pxl_dst[i] = linear_to_srgb(pixel_accum[i]/(float)(MSAA*MSAA));
}
}
}