diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..5524ea4b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,176 @@ +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so + +# Packages # +############ +# it's better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +# Logs and databases # +###################### +*.log +*.sql +*.sqlite + +# OS generated files # +###################### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Python +__pycache__ +*.pyc + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ + +# TAgs +tags +tags.* + +# Visual Studio 2015 user specific files +.vs/ + +# Visual Studio 2015 database file +*.VC.db + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app +*.ipa + +# These project files can be generated by the engine +*.xcodeproj +*.xcworkspace +*.sln +*.suo +*.opensdf +*.sdf +*.VC.db +*.VC.opendb + +# Precompiled Assets +SourceArt/**/*.png +SourceArt/**/*.tga + +# Binary Files +Binaries/* +Plugins/*/Binaries/* + +# Builds +Build/* + +# Whitelist PakBlacklist-.txt files +!Build/*/ +Build/*/** +!Build/*/PakBlacklist*.txt + +# Don't ignore icon files in Build +!Build/**/*.ico + +# Built data for maps +*_BuiltData.uasset + +# Configuration files generated by the Editor +Saved/* + +# Compiled source files for the engine to use +Intermediate/* +Plugins/*/Intermediate/* + +# Cache files for the editor to use +DerivedDataCache/* + +# Starter Content Ignored + +Content/StarterContent/* + +# VSCode Files +/.vscode/* +BuildingEscape.code-workspace + +compile_commands.json + +.clangd/ + +# Project files +bin/ + diff --git a/Makefile b/Makefile index 23f3f11e6..4695ce0e0 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,33 @@ +####### SRC Build Params ####### + +CC=/c/Users/axsau/scoop/apps/gcc/current/bin/g++.exe + +####### Shader Build Params ####### -build: - /c/Users/axsau/scoop/apps/gcc/current/bin/g++.exe \ - -std=c++17 \ - -c src/main.cpp \ - -I"./external" \ - -I"C:\\VulkanSDK\\1.2.141.2\\Include" \ - -L"C:\\VulkanSDK\\1.2.141.2\\Lib\\vulkan-1.lib" \ - -o main.exe +SCMP=/c/VulkanSDK/1.2.141.2/Bin32/glslangValidator.exe + + +####### Main Target Rules ####### + +build: build_shaders + $(CC) \ + -Wall \ + src/* \ + -std=c++11 \ + -I"./src/" \ + -I"C:\\VulkanSDK\\1.2.141.2\\Include\\" \ + -L"C:\\VulkanSDK\\1.2.141.2\\Lib\\" \ + -lvulkan-1 \ + -o ./bin/main.exe + +build_shaders: + $(SCMP) -V shaders/glsl/computeheadless.comp -o shaders/glsl/computeheadless.comp.spv clean: - rm ./game; + rm ./bin/main.exe; run: - ./game; + cd bin && ./main.exe; diff --git a/shaders/glsl/computeheadless.comp b/shaders/glsl/computeheadless.comp new file mode 100644 index 000000000..869415659 --- /dev/null +++ b/shaders/glsl/computeheadless.comp @@ -0,0 +1,33 @@ +#version 450 + +layout(binding = 0) buffer Pos { + uint values[ ]; +}; + +layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in; + +layout (constant_id = 0) const uint BUFFER_ELEMENTS = 32; + +uint fibonacci(uint n) { + if(n <= 1){ + return n; + } + uint curr = 1; + uint prev = 1; + for(uint i = 2; i < n; ++i) { + uint temp = curr; + curr += prev; + prev = temp; + } + return curr; +} + +void main() +{ + uint index = gl_GlobalInvocationID.x; + if (index >= BUFFER_ELEMENTS) + return; + values[index] = fibonacci(values[index]); +} + + diff --git a/shaders/glsl/computeheadless.comp.spv b/shaders/glsl/computeheadless.comp.spv new file mode 100755 index 000000000..0c88bfe72 Binary files /dev/null and b/shaders/glsl/computeheadless.comp.spv differ diff --git a/shaders/hlsl/computeheadless.comp b/shaders/hlsl/computeheadless.comp new file mode 100644 index 000000000..ee3cd024f --- /dev/null +++ b/shaders/hlsl/computeheadless.comp @@ -0,0 +1,29 @@ +// Copyright 2020 Google LLC + +RWStructuredBuffer values : register(u0); +[[vk::constant_id(0)]] const uint BUFFER_ELEMENTS = 32; + +uint fibonacci(uint n) { + if(n <= 1){ + return n; + } + uint curr = 1; + uint prev = 1; + for(uint i = 2; i < n; ++i) { + uint temp = curr; + curr += prev; + prev = temp; + } + return curr; +} + +[numthreads(1, 1, 1)] +void main(uint3 GlobalInvocationID : SV_DispatchThreadID) +{ + uint index = GlobalInvocationID.x; + if (index >= BUFFER_ELEMENTS) + return; + values[index] = fibonacci(values[index]); +} + + diff --git a/src/VulkanTools.cpp b/src/VulkanTools.cpp index 5eb394299..f6dad8da1 100644 --- a/src/VulkanTools.cpp +++ b/src/VulkanTools.cpp @@ -13,7 +13,7 @@ const std::string getAssetPath() #if defined(VK_EXAMPLE_DATA_DIR) return VK_EXAMPLE_DATA_DIR; #else - return "./../data/"; + return "./../"; #endif } diff --git a/src/main.cpp b/src/main.cpp index 16d0262a2..a09a62ac3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -327,13 +327,14 @@ public: // TODO: There is no command line arguments parsing (nor Android settings) for this // example, so we have no way of picking between GLSL or HLSL shaders. // Hard-code to glsl for now. - const std::string shadersPath = getAssetPath() + "shaders/glsl/computeheadless/"; + const std::string shadersPath = getAssetPath() + "shaders/glsl/"; + std::cout << "Shader path: " << shadersPath << std::endl; VkPipelineShaderStageCreateInfo shaderStage = {}; shaderStage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; shaderStage.stage = VK_SHADER_STAGE_COMPUTE_BIT; - shaderStage.module = vks::tools::loadShader((shadersPath + "headless.comp.spv").c_str(), device); + shaderStage.module = vks::tools::loadShader((shadersPath + "computeheadless.comp.spv").c_str(), device); shaderStage.pName = "main"; shaderStage.pSpecializationInfo = &specializationInfo;