Added initial implementation of shaders as hpp files

This commit is contained in:
Alejandro Saucedo 2020-08-23 10:56:14 +01:00
parent 2561ace8b7
commit f3b28e6b08
9 changed files with 30 additions and 38 deletions

View file

@ -30,14 +30,14 @@ Algorithm::~Algorithm()
}
void
Algorithm::init(std::string shaderFilePath,
Algorithm::init(const std::vector<char>& shaderFileData,
std::vector<std::shared_ptr<Tensor>> tensorParams)
{
SPDLOG_DEBUG("Kompute Algorithm init started");
// TODO: Move to util function
this->createParameters(tensorParams);
this->createShaderModule(shaderFilePath);
this->createShaderModule(shaderFileData);
this->createPipeline();
}
@ -103,22 +103,6 @@ Algorithm::createParameters(std::vector<std::shared_ptr<Tensor>>& tensorParams)
this->mDevice->allocateDescriptorSets(&descriptorSetAllocateInfo,
this->mDescriptorSet.get());
////std::vector<vk::DescriptorBufferInfo> descriptorBufferInfos;
////for (size_t i = 0; i < tensorParams.size(); i++) {
//// descriptorBufferInfos.push_back(tensorParams[i]->constructDescriptorBufferInfo());
////}
////std::vector<vk::WriteDescriptorSet> computeWriteDescriptorSets;
////computeWriteDescriptorSets.push_back(
//// vk::WriteDescriptorSet(*this->mDescriptorSet,
//// 0, // Destination binding
//// 0, // Destination array element
//// 1, // Descriptor count
//// vk::DescriptorType::eStorageBuffer,
//// nullptr, // Descriptor image info
//// descriptorBufferInfos.data()
//// ));
// TODO: Explore design exposing the destination array element
for (size_t i = 0; i < tensorParams.size(); i++) {
std::vector<vk::WriteDescriptorSet> computeWriteDescriptorSets;
@ -146,24 +130,15 @@ Algorithm::createParameters(std::vector<std::shared_ptr<Tensor>>& tensorParams)
}
void
Algorithm::createShaderModule(std::string shaderFilePath)
Algorithm::createShaderModule(const std::vector<char>& shaderFileData)
{
SPDLOG_DEBUG("Kompute Algorithm createShaderModule started");
std::ifstream fileStream(shaderFilePath,
std::ios::binary | std::ios::in | std::ios::ate);
size_t shaderFileSize = fileStream.tellg();
fileStream.seekg(0, std::ios::beg);
char* shaderFileData = new char[shaderFileSize];
fileStream.read(shaderFileData, shaderFileSize);
fileStream.close();
vk::ShaderModuleCreateInfo shaderModuleInfo(
vk::ShaderModuleCreateFlags(), shaderFileSize, (uint32_t*)shaderFileData);
vk::ShaderModuleCreateFlags(), shaderFileData.size(), (uint32_t*)shaderFileData.data());
SPDLOG_DEBUG("Kompute Algorithm Creating shader module. ShaderFileSize: {}",
shaderFileSize);
shaderFileData.size());
this->mFreeShaderModule = true;
this->mShaderModule = std::make_shared<vk::ShaderModule>();
this->mDevice->createShaderModule(

View file

@ -24,7 +24,7 @@ class Algorithm
// TODO: Add specialisation data
// TODO: Explore other ways of passing shader (ie raw bytes)
void init(std::string shaderFilePath,
void init(const std::vector<char>& shaderFileData,
std::vector<std::shared_ptr<Tensor>> tensorParams);
~Algorithm();
@ -55,7 +55,7 @@ class Algorithm
bool mFreePipeline = false;
// Create util functions
void createShaderModule(std::string shaderFilePath);
void createShaderModule(const std::vector<char>& shaderFileData);
void createPipeline();
// Parameters
void createParameters(std::vector<std::shared_ptr<Tensor>>& tensorParams);

View file

@ -1,9 +1,8 @@
#include <chrono>
#include <thread>
#include "Tensor.hpp"
#include "shaders/opmult.hpp"
// Only defining hpp file for syntax validation in editors
#ifndef OPMULT_H
#include "OpMult.hpp"
@ -99,8 +98,10 @@ OpMult<tX, tY, tZ>::init(std::vector<std::shared_ptr<Tensor>> tensors)
this->mDevice,
this->mCommandBuffer);
// TODO: Make this path configurable
this->mAlgorithm->init("shaders/glsl/opmult.comp.spv", tensors);
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);
this->mAlgorithm->init(shaderFileData, tensors);
}
template<uint32_t tX, uint32_t tY, uint32_t tZ>

View file

@ -15,6 +15,8 @@
#include "Algorithm.hpp"
#include "Tensor.hpp"
#include "shaders/opmult.hpp"
#include "OpBase.hpp"
namespace kp {

View file

@ -1,3 +1,5 @@
#pragma once
namespace kp {
namespace shader_data {
unsigned char shaders_glsl_computeheadless_comp_spv[] = {

View file

@ -1,3 +1,5 @@
#pragma once
namespace kp {
namespace shader_data {
unsigned char shaders_glsl_machinelearning_comp_spv[] = {

View file

@ -1,3 +1,5 @@
#pragma once
namespace kp {
namespace shader_data {
unsigned char shaders_glsl_opmult_comp_spv[] = {

View file

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