shader reflect testing
This commit is contained in:
@@ -48,6 +48,10 @@ class Buffer {
|
||||
}
|
||||
vk::DeviceSize getBufferSize() const { return bufferSize; }
|
||||
|
||||
vk::DeviceAddress getDeviceAddress() {
|
||||
return this->device.get()->getBufferAddress(this->buffer);
|
||||
}
|
||||
|
||||
private:
|
||||
static vk::DeviceSize getAlignment(vk::DeviceSize instanceSize,
|
||||
vk::DeviceSize minOffsetAlignment);
|
||||
|
||||
+70
-5
@@ -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;
|
||||
}
|
||||
|
||||
@@ -40,8 +40,14 @@ class Material {
|
||||
std::unique_ptr<GraphicsPipeline> pipeline;
|
||||
};
|
||||
|
||||
struct MaterialInstance {
|
||||
class MaterialInstance {
|
||||
public:
|
||||
void setBaseColor();
|
||||
|
||||
private:
|
||||
Material* material;
|
||||
|
||||
vec3 base_color = {};
|
||||
};
|
||||
|
||||
// !NOTE: eventually add ecs support for ecs
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user