First pass for rewriting the build system
* Refactored all CMake files * Started working on compiling shaders to header files in CMake Signed-off-by: Fabian Sauter <sauter.fabian@mailbox.org>
This commit is contained in:
parent
c6a2b022f9
commit
b95df8d0a0
33 changed files with 559 additions and 2712 deletions
8
test/shaders/CMakeLists.txt
Normal file
8
test/shaders/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
#######################
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
add_library(test_shaders "Utils.cpp"
|
||||
"Utils.hpp")
|
||||
|
||||
add_subdirectory(glsl)
|
||||
28
test/shaders/Utils.cpp
Normal file
28
test/shaders/Utils.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#include "Utils.hpp"
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
std::vector<uint32_t>
|
||||
compileSource(const std::string& source)
|
||||
{
|
||||
std::ofstream fileOut("tmp_kp_shader.comp");
|
||||
fileOut << source;
|
||||
fileOut.close();
|
||||
if (system(
|
||||
std::string(
|
||||
"glslangValidator -V tmp_kp_shader.comp -o tmp_kp_shader.comp.spv")
|
||||
.c_str())) {
|
||||
throw std::runtime_error("Error running glslangValidator command");
|
||||
}
|
||||
std::ifstream fileStream("tmp_kp_shader.comp.spv", std::ios::binary);
|
||||
std::vector<char> buffer;
|
||||
buffer.insert(
|
||||
buffer.begin(), std::istreambuf_iterator<char>(fileStream), {});
|
||||
return { reinterpret_cast<uint32_t*>(buffer.data()),
|
||||
reinterpret_cast<uint32_t*>(buffer.data() + buffer.size()) };
|
||||
}
|
||||
19
test/shaders/Utils.hpp
Normal file
19
test/shaders/Utils.hpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* Compile a single glslang source from string value. This is only meant
|
||||
* to be used for testing as it's non threadsafe, and it had to be removed
|
||||
* from the glslang dependency and now can only run the CLI directly due to
|
||||
* license issues: see https://github.com/KomputeProject/kompute/pull/235
|
||||
*
|
||||
* @param source An individual raw glsl shader in string format
|
||||
* @return The compiled SPIR-V binary in unsigned int32 format
|
||||
*/
|
||||
std::vector<uint32_t>
|
||||
compileSource(const std::string& source);
|
||||
22
test/shaders/glsl/CMakeLists.txt
Normal file
22
test/shaders/glsl/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
#######################
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
vulkan_compile_shader(INFILE test_logistic_regression.comp
|
||||
OUTFILE test_logistic_regression.hpp
|
||||
NAMESPACE "kp")
|
||||
|
||||
vulkan_compile_shader(INFILE test_op_custom_shader.comp
|
||||
OUTFILE test_op_custom_shader.hpp
|
||||
NAMESPACE "kp")
|
||||
|
||||
vulkan_compile_shader(INFILE test_workgroup.comp
|
||||
OUTFILE test_workgroup.hpp
|
||||
NAMESPACE "kp")
|
||||
|
||||
add_library(test_shaders_glsl "${CMAKE_CURRENT_BINARY_DIR}/test_logistic_regression.hpp"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/test_op_custom_shader.hpp"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/test_workgroup.hpp")
|
||||
|
||||
set_target_properties(test_shaders_glsl PROPERTIES LINKER_LANGUAGE CXX)
|
||||
target_include_directories(test_shaders_glsl PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue