shader reflect testing

This commit is contained in:
2026-10-22 07:12:25 +00:00
parent 09a6c0283a
commit 2f5268fef6
4 changed files with 126 additions and 6 deletions
+70 -5
View File
@@ -1,8 +1,10 @@
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include <spirv_reflect.h>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <sophia/components.hpp>
#include <sophia/scene_registry.hpp>
#include <sophia/scene_view.hpp>
@@ -18,6 +20,9 @@
#include "vulkan/shader.hpp"
#include "window.hpp"
// local includes
#include "material.hpp"
constexpr uint32_t WIDTH = 1280;
constexpr uint32_t HEIGHT = 720;
constexpr const char* NAME = "sandbox";
@@ -29,9 +34,7 @@ void immediate_submit(sophia::Device& device,
device.endSingleTimeCommands(command);
}
#include "material.hpp"
int main() {
void triangle_test() {
sophia::Window window{WIDTH, HEIGHT, NAME};
sophia::Device device{&window};
sophia::RenderContext renderContext{window, device};
@@ -89,8 +92,7 @@ int main() {
triangleBuffer.writeToBuffer(verticies);
vk::DeviceAddress address =
device.get()->getBufferAddress({triangleBuffer.getBuffer()});
vk::DeviceAddress address = triangleBuffer.getDeviceAddress();
while (!window.shouldClose()) {
glfwPollEvents();
@@ -151,6 +153,69 @@ int main() {
}
device.waitIdle();
}
int main() {
{
using namespace sophia;
auto shader = Shader::Builder()
.fromGLSL(SANDBOX_SHADER_DIR "/shader.comp")
.setStage(ShaderStage::VERTEX)
.build();
std::vector<u32> spirv = shader.get()->getSpirv();
size_t spirv_size = spirv.size() * sizeof(u32);
void* spirv_code = spirv.data();
SpvReflectShaderModule module;
SpvReflectResult result =
spvReflectCreateShaderModule(spirv_size, spirv_code, &module);
assert(result == SPV_REFLECT_RESULT_SUCCESS);
{
log::print();
log::info("Reflecting Input Variables");
uint32_t count = 0;
result = spvReflectEnumerateInputVariables(&module, &count, NULL);
assert(result == SPV_REFLECT_RESULT_SUCCESS);
SpvReflectInterfaceVariable** vars =
(SpvReflectInterfaceVariable**)malloc(
count * sizeof(SpvReflectInterfaceVariable*));
result = spvReflectEnumerateInputVariables(&module, &count, vars);
assert(result == SPV_REFLECT_RESULT_SUCCESS);
for (size_t i = 0; i < count; i++) {
SpvReflectInterfaceVariable* var = vars[i];
assert(var != nullptr);
std::cout << "{" << std::endl;
log::print("\tname: {},", var->name);
std::cout << "}" << std::endl;
std::cout << std::endl;
}
}
{
log::print();
log::info("Reflecting Output Variables");
u32 count = 0;
result = spvReflectEnumerateOutputVariables(&module, &count, NULL);
assert(result == SPV_REFLECT_RESULT_SUCCESS);
SpvReflectInterfaceVariable** vars =
(SpvReflectInterfaceVariable**)malloc(
count * sizeof(SpvReflectInterfaceVariable*));
result = spvReflectEnumerateOutputVariables(&module, &count, vars);
assert(result == SPV_REFLECT_RESULT_SUCCESS);
}
spvReflectDestroyShaderModule(&module);
}
// triangle_test();
return EXIT_SUCCESS;
}