Updated tests to not use namespaace for compileShader

This commit is contained in:
Alejandro Saucedo 2021-07-21 20:30:21 +01:00
parent b7fd1b4d79
commit 15346ee505
10 changed files with 36 additions and 57 deletions

View file

@ -1,20 +0,0 @@
#include "kompute/Kompute.hpp"
#include "kompute_test/Shader.hpp"
namespace kp_test_utils {
std::vector<uint32_t>
Shader::compileSource(
const std::string& source)
{
if (system(std::string("glslangValidator --stdin -S comp -V -o tmp_kp_shader.comp.spv << END\n" + source + "\nEND").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 {(uint32_t*)buffer.data(), (uint32_t*)(buffer.data() + buffer.size())};
}
}

View file

@ -2,26 +2,26 @@
#include <iostream>
#include <vector>
namespace kp_test_utils {
#include <fstream>
/**
Shader utily class with functions to compile and process glsl files.
*/
class Shader
* 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/EthicalML/vulkan-kompute/pull/235
*
* @param source An individual raw glsl shader in string format
* @return The compiled SPIR-V binary in unsigned int32 format
*/
static
std::vector<uint32_t>
compileSource(
const std::string& source)
{
public:
/**
* 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/EthicalML/vulkan-kompute/pull/235
*
* @param source An individual raw glsl shader in string format
* @return The compiled SPIR-V binary in unsigned int32 format
*/
static std::vector<uint32_t> compileSource(
const std::string& source);
};
if (system(std::string("glslangValidator --stdin -S comp -V -o tmp_kp_shader.comp.spv << END\n" + source + "\nEND").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 {(uint32_t*)buffer.data(), (uint32_t*)(buffer.data() + buffer.size())};
}