feat: add process logs to minimal test

This commit is contained in:
Kai Angulo 2024-10-23 23:24:05 -07:00
parent 0ecaf43ec6
commit 3be328b820

View file

@ -5,8 +5,12 @@
int main(void)
{
std::cout << "Initialize process" << std::endl;
glslang_initialize_process();
std::cout << "Initialized process" << std::endl;
glslang_stage_t stage = GLSLANG_STAGE_FRAGMENT;
const char* fileName = u8"ExampleShader.hlsl";
@ -74,8 +78,12 @@ float4 pixel(VertexOutput input) : SV_Target
.resource = glslang_default_resource(),
};
std::cout << "Setup default resource" << std::endl;
glslang_shader_t* shader = glslang_shader_create(&input);
std::cout << "Created shader" << std::endl;
if (!glslang_shader_preprocess(shader, &input)) {
printf("HLSL preprocessing failed %s\n", fileName);
printf("%s\n", glslang_shader_get_info_log(shader));
@ -85,6 +93,8 @@ float4 pixel(VertexOutput input) : SV_Target
return 1;
}
std::cout << "Preprocessed shader" << std::endl;
if (!glslang_shader_parse(shader, &input)) {
printf("HLSL parsing failed %s\n", fileName);
printf("%s\n", glslang_shader_get_info_log(shader));
@ -95,9 +105,16 @@ float4 pixel(VertexOutput input) : SV_Target
return 1;
}
std::cout << "Parsed shader" << std::endl;
glslang_program_t* program = glslang_program_create();
std::cout << "Created program" << std::endl;
glslang_program_add_shader(program, shader);
std::cout << "Add shader to program" << std::endl;
if (!glslang_program_link(program, GLSLANG_MSG_SPV_RULES_BIT | GLSLANG_MSG_VULKAN_RULES_BIT)) {
printf("HLSL linking failed %s\n", fileName);
printf("%s\n", glslang_program_get_info_log(program));
@ -108,21 +125,33 @@ float4 pixel(VertexOutput input) : SV_Target
return 1;
}
std::cout << "Linked program" << std::endl;
glslang_program_SPIRV_generate(program, stage);
std::cout << "Generate SPIRV" << std::endl;
size_t size = glslang_program_SPIRV_get_size(program);
uint32_t* words = static_cast<uint32_t*>(malloc(size * sizeof(uint32_t)));
glslang_program_SPIRV_get(program, words);
std::cout << "Got SPIRV" << std::endl;
const char* spirv_messages = glslang_program_SPIRV_get_messages(program);
if (spirv_messages)
printf("(%s) %s\b", fileName, spirv_messages);
std::cout << "Got messages" << std::endl;
glslang_program_delete(program);
glslang_shader_delete(shader);
std::cout << "Free program and shader" << std::endl;
char* disassembled = glslang_SPIRV_disassemble(words, size);
std::cout << "Disassemble SPIRV" << std::endl;
std::cout << "Generated " << size << " SPIR-V words" << std::endl;
std::cout << disassembled << std::endl;