Updated to include and work with cpp header shaders

This commit is contained in:
Alejandro Saucedo 2020-08-23 12:30:56 +01:00
parent fccacd0058
commit bb90806d79
9 changed files with 33 additions and 29 deletions

1
.ccls
View file

@ -11,6 +11,7 @@
%h c++-header
-DDEBUG=1
-DKOMPUTE_INCLUDE_FOR_SYNTAX
-I./external/

View file

@ -19,7 +19,6 @@ build: clean build_shaders
-std=c++17 \
-DDEBUG=1 \
-I"./external/" \
-I"./src/" \
-I"C:\\VulkanSDK\\1.2.141.2\\Include\\" \
-L"C:\\VulkanSDK\\1.2.141.2\\Lib\\" \
-lvulkan-1 \
@ -46,7 +45,7 @@ build_shaders:
python scripts/convert_shaders.py \
--shader-path shaders/glsl \
--shader-binary $(SCMP) \
--header-path src/shaders \
--header-path external/shaders \
-v
docker_seldon_run:
@ -80,6 +79,7 @@ format:
$(CF) -i -style="{BasedOnStyle: mozilla, IndentWidth: 4}" src/*.cpp src/*.hpp src/*.h
clean:
find src -name "*gch" -exec rm {} \; || "No ghc files"
rm ./bin/main.exe || echo "No main.exe"
run:

View file

@ -1,8 +1,9 @@
#pragma once
#ifndef SHADEROP_COMPUTEHEADLESS_HPP
#define SHADEROP_COMPUTEHEADLESS_HPP
namespace kp {
namespace shader_data {
unsigned char shaders_glsl_computeheadless_comp_spv[] = {
static unsigned const char shaders_glsl_computeheadless_comp_spv[] = {
0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x08, 0x00,
0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,
0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00,
@ -172,6 +173,7 @@ unsigned char shaders_glsl_computeheadless_comp_spv[] = {
0x12, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x02, 0x00, 0x13, 0x00, 0x00, 0x00,
0x38, 0x00, 0x01, 0x00
};
unsigned int shaders_glsl_computeheadless_comp_spv_len = 2008;
static unsigned const int shaders_glsl_computeheadless_comp_spv_len = 2008;
}
}
#endif // define SHADEROP_COMPUTEHEADLESS_HPP

View file

@ -1,8 +1,9 @@
#pragma once
#ifndef SHADEROP_MACHINELEARNING_HPP
#define SHADEROP_MACHINELEARNING_HPP
namespace kp {
namespace shader_data {
unsigned char shaders_glsl_machinelearning_comp_spv[] = {
static unsigned const char shaders_glsl_machinelearning_comp_spv[] = {
0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x08, 0x00,
0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,
0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00,
@ -122,6 +123,7 @@ unsigned char shaders_glsl_machinelearning_comp_spv[] = {
0x34, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00,
0x38, 0x00, 0x01, 0x00
};
unsigned int shaders_glsl_machinelearning_comp_spv_len = 1408;
static unsigned const int shaders_glsl_machinelearning_comp_spv_len = 1408;
}
}
#endif // define SHADEROP_MACHINELEARNING_HPP

View file

@ -1,8 +1,9 @@
#pragma once
#ifndef SHADEROP_OPMULT_HPP
#define SHADEROP_OPMULT_HPP
namespace kp {
namespace shader_data {
unsigned char shaders_glsl_opmult_comp_spv[] = {
static unsigned const char shaders_glsl_opmult_comp_spv[] = {
0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x08, 0x00,
0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,
0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00,
@ -113,6 +114,7 @@ unsigned char shaders_glsl_opmult_comp_spv[] = {
0x16, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x27, 0x00, 0x00, 0x00,
0x26, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00
};
unsigned int shaders_glsl_opmult_comp_spv_len = 1308;
static unsigned const int shaders_glsl_opmult_comp_spv_len = 1308;
}
}
#endif // define SHADEROP_OPMULT_HPP

View file

@ -79,18 +79,24 @@ def run_cli(
if header_path:
logger.debug(f"Header path provided. Converting bin files to hpp.")
logger.debug(f"Output header path: {shader_path}")
for file in spirv_files:
header_data = str(sh.xxd("-i", file))
# Ensuring the variable is a static unsigned const
header_data = header_data.replace("unsigned", "static unsigned const")
file_name = file.split("/")[-1]
header_file = file_name.replace(".comp.spv", ".hpp")
header_file_define = "SHADEROP_" + header_file.replace(".", "_").upper()
logger.debug(f"Converting to hpp: {file_name}")
with open(os.path.join(header_path, header_file), "w+") as fstream:
fstream.write("#pragma once\n\n")
fstream.write(f"#ifndef {header_file_define}\n")
fstream.write(f"#define {header_file_define}\n\n")
fstream.write("namespace kp {\n")
fstream.write("namespace shader_data {\n")
fstream.write(header_data)
fstream.write(f"{header_data}")
fstream.write("}\n")
fstream.write("}\n")
fstream.write(f"#endif // define {header_file_define}\n")
if __name__ == "__main__":

View file

@ -1,15 +1,15 @@
#ifndef OPMULT_CPP
#define OPMULT_CPP
#include "Tensor.hpp"
#include "shaders/opmult.hpp"
#include <shaders/opmult.hpp>
// Only defining hpp file for syntax validation in editors
#ifndef OPMULT_H
#ifndef OPMULT_HPP
#include "OpMult.hpp"
#endif
#ifndef OPMULT_CPP
#define OPMULT_CPP
namespace kp {
@ -99,8 +99,8 @@ OpMult<tX, tY, tZ>::init(std::vector<std::shared_ptr<Tensor>> tensors)
this->mCommandBuffer);
std::vector<char> shaderFileData(
kp::shader_data::shaders_glsl_opmult_comp_spv_len,
kp::shader_data::shaders_glsl_opmult_comp_spv + kp::shader_data::shaders_glsl_opmult_comp_spv_len);
shader_data::shaders_glsl_opmult_comp_spv,
shader_data::shaders_glsl_opmult_comp_spv + shader_data::shaders_glsl_opmult_comp_spv_len);
this->mAlgorithm->init(shaderFileData, tensors);
}

View file

@ -1,6 +1,6 @@
// Defining OPMULT_H to ensure cpp class doesn't reimport
#define OPMULT_H
#pragma once
#define OPMULT_HPP
#include <vulkan/vulkan.h>
#include <vulkan/vulkan.hpp>
@ -15,8 +15,6 @@
#include "Algorithm.hpp"
#include "Tensor.hpp"
#include "shaders/opmult.hpp"
#include "OpBase.hpp"
namespace kp {

View file

@ -1,7 +0,0 @@
#include <string>
namespace kp {
namespace shader_data {
}
}