# HG changeset patch # User Sam # Date 1673412202 -25200 # Node ID 8f290112718a7534c5127b8e6804125ada91a7dc # Parent 71bbe11d8de8fea50de7beac800099423f81d177 fix: build from scratch not working, remove temp shader files from compilation diff -r 71bbe11d8de8 -r 8f290112718a Makefile --- a/Makefile Wed Jan 11 11:15:02 2023 +0700 +++ b/Makefile Wed Jan 11 11:43:22 2023 +0700 @@ -1,13 +1,19 @@ SOURCES := $(shell find src -name '*.nim') +# compilation requirements +examples/glslangValidator: thirdparty/bin/linux/glslangValidator + cp $< examples +examples/glslangValidator.exe: thirdparty/bin/windows/glslangValidator.exe + cp $< examples + # build hello_triangle -build/debug/linux/hello_triangle: ${SOURCES} thirdparty/bin/linux +build/debug/linux/hello_triangle: ${SOURCES} examples/glslangValidator nim build_linux_debug -o:$@ examples/hello_triangle.nim -build/release/linux/hello_triangle: ${SOURCES} thirdparty/bin/linux +build/release/linux/hello_triangle: ${SOURCES} examples/glslangValidator nim build_linux_release -o:$@ examples/hello_triangle.nim -build/debug/windows/hello_triangle.exe: ${SOURCES} thirdparty/bin/windows +build/debug/windows/hello_triangle.exe: ${SOURCES} examples/glslangValidator.exe nim build_windows_debug -o:$@ examples/hello_triangle.nim -build/release/windows/hello_triangle.exe: ${SOURCES} thirdparty/bin/windows +build/release/windows/hello_triangle.exe: ${SOURCES} examples/glslangValidator.exe nim build_windows_release -o:$@ examples/hello_triangle.nim build_all_linux_hello_triangle: build/debug/linux/hello_triangle build/release/linux/hello_triangle @@ -15,13 +21,13 @@ build_all_hello_triangle: build_all_linux_hello_triangle build_all_windows_hello_triangle # build alotof_triangles -build/debug/linux/alotof_triangles: ${SOURCES} thirdparty/bin/linux +build/debug/linux/alotof_triangles: ${SOURCES} examples/glslangValidator nim build_linux_debug -o:$@ examples/alotof_triangles.nim -build/release/linux/alotof_triangles: ${SOURCES} thirdparty/bin/linux +build/release/linux/alotof_triangles: ${SOURCES} examples/glslangValidator nim build_linux_release -o:$@ examples/alotof_triangles.nim -build/debug/windows/alotof_triangles.exe: ${SOURCES} thirdparty/bin/windows +build/debug/windows/alotof_triangles.exe: ${SOURCES} examples/glslangValidator.exe nim build_windows_debug -o:$@ examples/alotof_triangles.nim -build/release/windows/alotof_triangles.exe: ${SOURCES} thirdparty/bin/windows +build/release/windows/alotof_triangles.exe: ${SOURCES} examples/glslangValidator.exe nim build_windows_release -o:$@ examples/alotof_triangles.nim build_all_linux_alotof_triangles: build/debug/linux/alotof_triangles build/release/linux/alotof_triangles @@ -34,10 +40,6 @@ rm -rf thirdparty .PHONY: tests -.PHONY: glslang-master-linux-Debug.zip -.PHONY: glslang-master-linux-Release.zip -.PHONY: glslang-master-windows-x64-Debug.zip -.PHONY: glslang-master-windows-x64-Release.zip # tests tests: @@ -71,15 +73,15 @@ # download thirdparty-libraries -thirdparty/bin/linux: glslang-master-linux-Release.zip - mkdir -p $@ - cd $@ && wget https://github.com/KhronosGroup/glslang/releases/download/master-tot/$< - cd $@ && unzip $< - cd $@ && mv bin/* . - cd $@ && rm -rf $< bin lib include -thirdparty/bin/windows: glslang-master-windows-x64-Release.zip - mkdir -p $@ - cd $@ && wget https://github.com/KhronosGroup/glslang/releases/download/master-tot/$< - cd $@ && unzip $< - cd $@ && mv bin/* . - cd $@ && rm -rf $< bin lib include +thirdparty/bin/linux/glslangValidator: + mkdir -p $$( dirname $@ ) + cd $$( dirname $@ ) && wget https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-linux-Release.zip + cd $$( dirname $@ ) && unzip *.zip + cd $$( dirname $@ ) && mv bin/* . + cd $$( dirname $@ ) && rm -rf *.zip bin lib include +thirdparty/bin/windows/glslangValidator.exe: + mkdir -p $$( dirname $@ ) + cd $$( dirname $@ ) && wget https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-windows-x64-Release.zip + cd $$( dirname $@ ) && unzip *.zip + cd $$( dirname $@ ) && mv bin/* . + cd $$( dirname $@ ) && rm -rf *.zip bin lib include diff -r 71bbe11d8de8 -r 8f290112718a src/zamikongine/shader.nim --- a/src/zamikongine/shader.nim Wed Jan 11 11:15:02 2023 +0700 +++ b/src/zamikongine/shader.nim Wed Jan 11 11:43:22 2023 +0700 @@ -1,4 +1,3 @@ -import std/tempfiles import std/strformat import std/strutils import std/tables @@ -27,13 +26,22 @@ of VK_SHADER_STAGE_ALL: "" proc compileGLSLToSPIRV(stage: VkShaderStageFlagBits, shaderSource: string, entrypoint: string): seq[uint32] {.compileTime.} = + # TODO: compiles only on linux for now (because we don't have compile-time functionality in std/tempfile) let stagename = stage2string(stage) - let (tmpfile, tmpfilename) = createTempFile("shader", stage2string(stage)) - tmpfile.close() - let (output, exitCode) = gorgeEx(command=fmt"{querySetting(projectPath)}/glslangValidator --entry-point {entrypoint} -V --stdin -S {stagename} -o {tmpfilename}", input=shaderSource) + + let (tmpfile, exitCode) = gorgeEx(command=fmt"mktemp --tmpdir shader_XXXXXXX.{stagename}") if exitCode != 0: + raise newException(Exception, tmpfile) + + let (output, exitCode_glsl) = gorgeEx(command=fmt"{querySetting(projectPath)}/glslangValidator --entry-point {entrypoint} -V --stdin -S {stagename} -o {tmpfile}", input=shaderSource) + if exitCode_glsl != 0: raise newException(Exception, output) - let shaderbinary = staticRead tmpfilename + let shaderbinary = staticRead tmpfile + + let (output_rm, exitCode_rm) = gorgeEx(command=fmt"rm {tmpfile}") + if exitCode_rm != 0: + raise newException(Exception, output_rm) + var i = 0 while i < shaderbinary.len: result.add(