Compare commits

..

2 Commits

Author SHA1 Message Date
burkkyy 17fe9de756 using engine types 2026-10-25 22:46:35 -07:00
burkkyy 2f5268fef6 shader reflect testing 2026-10-22 07:12:25 +00:00
5 changed files with 128 additions and 8 deletions
+2 -2
View File
@@ -11,7 +11,7 @@ namespace sophia {
struct TagComponent { struct TagComponent {
std::string tag; // entt::hashed_string ? std::string tag; // entt::hashed_string ?
uint32_t mask = 0; u32 mask = 0;
}; };
struct TransformComponent { struct TransformComponent {
@@ -100,7 +100,7 @@ struct CameraComponent {
float farPlane = 100.f; float farPlane = 100.f;
}; };
enum class Projection { Orthographic, Perspective }; enum class Projection : u8 { Orthographic, Perspective };
Projection projection = Projection::Orthographic; Projection projection = Projection::Orthographic;
Orthographic ortho; Orthographic ortho;
+4
View File
@@ -48,6 +48,10 @@ class Buffer {
} }
vk::DeviceSize getBufferSize() const { return bufferSize; } vk::DeviceSize getBufferSize() const { return bufferSize; }
vk::DeviceAddress getDeviceAddress() {
return this->device.get()->getBufferAddress(this->buffer);
}
private: private:
static vk::DeviceSize getAlignment(vk::DeviceSize instanceSize, static vk::DeviceSize getAlignment(vk::DeviceSize instanceSize,
vk::DeviceSize minOffsetAlignment); vk::DeviceSize minOffsetAlignment);
+70 -5
View File
@@ -1,8 +1,10 @@
#define GLFW_INCLUDE_VULKAN #define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <spirv_reflect.h>
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
#include <iostream>
#include <sophia/components.hpp> #include <sophia/components.hpp>
#include <sophia/scene_registry.hpp> #include <sophia/scene_registry.hpp>
#include <sophia/scene_view.hpp> #include <sophia/scene_view.hpp>
@@ -18,6 +20,9 @@
#include "vulkan/shader.hpp" #include "vulkan/shader.hpp"
#include "window.hpp" #include "window.hpp"
// local includes
#include "material.hpp"
constexpr uint32_t WIDTH = 1280; constexpr uint32_t WIDTH = 1280;
constexpr uint32_t HEIGHT = 720; constexpr uint32_t HEIGHT = 720;
constexpr const char* NAME = "sandbox"; constexpr const char* NAME = "sandbox";
@@ -29,9 +34,7 @@ void immediate_submit(sophia::Device& device,
device.endSingleTimeCommands(command); device.endSingleTimeCommands(command);
} }
#include "material.hpp" void triangle_test() {
int main() {
sophia::Window window{WIDTH, HEIGHT, NAME}; sophia::Window window{WIDTH, HEIGHT, NAME};
sophia::Device device{&window}; sophia::Device device{&window};
sophia::RenderContext renderContext{window, device}; sophia::RenderContext renderContext{window, device};
@@ -89,8 +92,7 @@ int main() {
triangleBuffer.writeToBuffer(verticies); triangleBuffer.writeToBuffer(verticies);
vk::DeviceAddress address = vk::DeviceAddress address = triangleBuffer.getDeviceAddress();
device.get()->getBufferAddress({triangleBuffer.getBuffer()});
while (!window.shouldClose()) { while (!window.shouldClose()) {
glfwPollEvents(); glfwPollEvents();
@@ -151,6 +153,69 @@ int main() {
} }
device.waitIdle(); 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; return EXIT_SUCCESS;
} }
+7 -1
View File
@@ -40,8 +40,14 @@ class Material {
std::unique_ptr<GraphicsPipeline> pipeline; std::unique_ptr<GraphicsPipeline> pipeline;
}; };
struct MaterialInstance { class MaterialInstance {
public:
void setBaseColor();
private:
Material* material; Material* material;
vec3 base_color = {};
}; };
// !NOTE: eventually add ecs support for ecs // !NOTE: eventually add ecs support for ecs
+45
View File
@@ -0,0 +1,45 @@
#version 450
#extension GL_EXT_buffer_reference : require
struct TriangleVertex {
vec4 vertex;
vec4 color;
};
layout(buffer_reference, std430) readonly buffer TriangleVertexBuffer {
TriangleVertex vertices[];
};
layout( push_constant ) uniform constants {
TriangleVertexBuffer triangleBuffer;
vec2 padding;
vec4 data1;
vec4 data2;
vec4 data3;
} PushConstants;
layout (location = 0) out vec3 outColor;
void main()
{
//const array of positions for the triangle
const vec3 positions[3] = vec3[3](
vec3(-1.f,1.f, 0.0f),
vec3(1.f,1.f, 0.0f),
vec3(0.f,-1.f, 0.0f)
);
//const array of colors for the triangle
const vec3 colors[3] = vec3[3](
vec3(1.0f, 0.0f, 0.0f), //red
vec3(0.0f, 1.0f, 0.0f), //green
vec3(00.f, 0.0f, 1.0f) //blue
);
// Load vertex data from device address
TriangleVertex v = PushConstants.triangleBuffer.vertices[gl_VertexIndex];
// output the position of each vertex
gl_Position = vec4(v.vertex.xyz, 1.0);
outColor = vec3(v.color.xyz);
}