Skip to content
Snippets Groups Projects
Commit ec66e754 authored by Lars Hoerttrich's avatar Lars Hoerttrich
Browse files

[#91] very basic main.cpp, still has errors

parent 28efc953
No related branches found
No related tags found
1 merge request!79Draft: Resolve "Compute: First Network"
Pipeline #26346 passed
#version 450 core
#extension GL_ARB_separate_shader_objects : enable
layout(local_size_x = 1) in;
layout(std430, binding = 0) coherent buffer buffer_input
{
int bufferInput[];
};
layout( push_constant ) uniform constants{
int increment;
};
void main() {
uint id = gl_GlobalInvocationID.x;
bufferInput[id] += increment;
}
#include <iostream>
#include <vkcv/Core.hpp>
#include <GLFW/glfw3.h>
#include <vkcv/camera/CameraManager.hpp>
#include <chrono>
#include <vkcv/asset/asset_loader.hpp>
#include <vkcv/shader/GLSLCompiler.hpp>
#include <vkcv/scene/Scene.hpp>
int main(int argc, const char** argv) {
const char* applicationName = "Neural-Network";
uint32_t windowWidth = 800;
uint32_t windowHeight = 600;
vkcv::Window window = vkcv::Window::create(
applicationName,
windowWidth,
windowHeight,
true
);
vkcv::Core core = vkcv::Core::create(
window,
applicationName,
VK_MAKE_VERSION(0, 0, 1),
{ vk::QueueFlagBits::eTransfer, vk::QueueFlagBits::eGraphics, vk::QueueFlagBits::eCompute },
{},
{ "VK_KHR_swapchain" }
);
int input[64] = { 0 };
vkcv::Buffer<int> inputBuffer = core.createBuffer<int>(vkcv::BufferType::STORAGE, 64);
inputBuffer.fill(input);
vkcv::PassConfig computePassDefinition({});
vkcv::PassHandle computePass = core.createPass(computePassDefinition);
if (!computePass)
{
std::cout << "Error. Could not create renderpass. Exiting." << std::endl;
return EXIT_FAILURE;
}
// shader path
std::string shaderPathCompute = "resources/shaders/simpleShader.comp";
vkcv::shader::GLSLCompiler compiler;
vkcv::ShaderProgram computeShaderProgram{};
compiler.compile(vkcv::ShaderStage::COMPUTE, shaderPathCompute, [&](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) {
computeShaderProgram.addShader(shaderStage, path);
});
vkcv::DescriptorSetHandle computeDescriptorSet = core.createDescriptorSet(computeShaderProgram.getReflectedDescriptors()[0]);
vkcv::PipelineHandle computePipeline = core.createComputePipeline(computeShaderProgram, { core.getDescriptorSet(computeDescriptorSet).layout });
vkcv::DescriptorWrites computeWrites;
computeWrites.storageBufferWrites = { vkcv::StorageBufferDescriptorWrite(0,inputBuffer.getHandle()) };
core.writeDescriptorSet(computeDescriptorSet, computeWrites);
if (!computePipeline)
{
std::cout << "Error. Could not create compute pipeline. Exiting." << std::endl;
return EXIT_FAILURE;
}
auto cmdStream = core.createCommandStream(vkcv::QueueType::Compute);
uint32_t computeDispatchCount[3] = {inputBuffer.getSize(),1,1 };
vkcv::PushConstants pushConstantsCompute(sizeof(int));
pushConstantsCompute.appendDrawcall(1);
core.recordComputeDispatchToCmdStream(cmdStream,
computePipeline,
computeDispatchCount,
{ vkcv::DescriptorSetUsage(0,core.getDescriptorSet(computeDescriptorSet).vulkanHandle) },
pushConstantsCompute);
core.recordBufferMemoryBarrier(cmdStream, inputBuffer.getHandle());
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment