Added working compute example

This commit is contained in:
Alejandro Saucedo 2020-07-30 07:49:39 +01:00
parent ae12be78db
commit a012551d00
7 changed files with 267 additions and 13 deletions

176
.gitignore vendored Normal file
View file

@ -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-<BuildConfiguration>.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/

View file

@ -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;

View file

@ -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]);
}

Binary file not shown.

View file

@ -0,0 +1,29 @@
// Copyright 2020 Google LLC
RWStructuredBuffer<uint> 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]);
}

View file

@ -13,7 +13,7 @@ const std::string getAssetPath()
#if defined(VK_EXAMPLE_DATA_DIR)
return VK_EXAMPLE_DATA_DIR;
#else
return "./../data/";
return "./../";
#endif
}

View file

@ -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;