2023-03-08 14:02:51 +08:00
|
|
|
|
#ifndef HGL_GLSL_COMPILER_INCLUDE
|
|
|
|
|
#define HGL_GLSL_COMPILER_INCLUDE
|
|
|
|
|
|
|
|
|
|
#include<hgl/type/String.h>
|
|
|
|
|
#include<hgl/type/Map.h>
|
|
|
|
|
#include<stdint.h>
|
2023-03-17 21:06:05 +08:00
|
|
|
|
#include<hgl/graph/VKShaderStage.h>
|
2023-03-08 14:02:51 +08:00
|
|
|
|
|
|
|
|
|
namespace hgl
|
|
|
|
|
{
|
|
|
|
|
namespace io
|
|
|
|
|
{
|
|
|
|
|
class MemoryOutputStream;
|
|
|
|
|
class DataOutputStream;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace glsl_compiler
|
|
|
|
|
{
|
|
|
|
|
using namespace hgl;
|
2023-03-17 21:06:05 +08:00
|
|
|
|
using namespace hgl::graph;
|
2023-03-08 14:02:51 +08:00
|
|
|
|
|
|
|
|
|
enum class DescriptorType //等同VkDescriptorType
|
|
|
|
|
{
|
|
|
|
|
SAMPLER = 0,
|
|
|
|
|
COMBINED_IMAGE_SAMPLER,
|
|
|
|
|
SAMPLED_IMAGE,
|
|
|
|
|
STORAGE_IMAGE,
|
|
|
|
|
UNIFORM_TEXEL_BUFFER,
|
|
|
|
|
STORAGE_TEXEL_BUFFER,
|
|
|
|
|
UNIFORM_BUFFER,
|
|
|
|
|
STORAGE_BUFFER,
|
|
|
|
|
UNIFORM_BUFFER_DYNAMIC,
|
|
|
|
|
STORAGE_BUFFER_DYNAMIC,
|
|
|
|
|
INPUT_ATTACHMENT,
|
|
|
|
|
|
|
|
|
|
ENUM_CLASS_RANGE(SAMPLER,INPUT_ATTACHMENT)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Descriptor
|
|
|
|
|
{
|
|
|
|
|
char name[SHADER_RESOURCE_NAME_MAX_LENGTH];
|
|
|
|
|
uint8_t set;
|
|
|
|
|
uint8_t binding;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct PushConstant
|
|
|
|
|
{
|
|
|
|
|
char name[SHADER_RESOURCE_NAME_MAX_LENGTH];
|
|
|
|
|
uint8_t offset;
|
|
|
|
|
uint8_t size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SubpassInput
|
|
|
|
|
{
|
|
|
|
|
char name[SHADER_RESOURCE_NAME_MAX_LENGTH];
|
|
|
|
|
uint8_t input_attachment_index;
|
|
|
|
|
uint8_t binding;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
struct ShaderResourceData
|
|
|
|
|
{
|
|
|
|
|
uint32_t count;
|
|
|
|
|
T *items;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using ShaderDescriptorResource=ShaderResourceData<Descriptor>[size_t(DescriptorType::RANGE_SIZE)];
|
|
|
|
|
|
|
|
|
|
struct SPVData
|
|
|
|
|
{
|
|
|
|
|
bool result;
|
|
|
|
|
char *log;
|
|
|
|
|
char *debug_log;
|
|
|
|
|
|
|
|
|
|
uint32_t *spv_data;
|
|
|
|
|
uint32_t spv_length;
|
|
|
|
|
|
2023-03-17 21:06:05 +08:00
|
|
|
|
ShaderStageIO stage_io;
|
2023-03-08 14:02:51 +08:00
|
|
|
|
ShaderDescriptorResource resource;
|
|
|
|
|
ShaderResourceData<PushConstant> push_constant;
|
|
|
|
|
ShaderResourceData<SubpassInput> subpass_input;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool Init();
|
|
|
|
|
void Close();
|
|
|
|
|
|
|
|
|
|
void AddGLSLIncludePath(const char *);
|
|
|
|
|
void RebuildGLSLIncludePath();
|
|
|
|
|
|
|
|
|
|
uint32_t GetType (const char *ext_name);
|
|
|
|
|
|
|
|
|
|
SPVData * Compile (const uint32_t type,const char *source);
|
|
|
|
|
void Free (SPVData *spv_data);
|
|
|
|
|
}//namespace glsl_compiler
|
|
|
|
|
#endif//HGL_GLSL_COMPILER_INCLUDE
|