Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 119-graphicspipeline-refactoring
  • 129-projekte-und-assets-auslagern
  • 132-denoising-module
  • 143-ar-vr-support-via-openxr
  • 43-multi-threading
  • 91-compute-first-network
  • 95-arm64-raspberry-pi-4-support
  • develop
  • master
  • optimizations
  • 0.1.0
  • 0.2.0
12 results

Target

Select target project
  • vulkan2021/vkcv-framework
1 result
Select Git revision
  • 119-graphicspipeline-refactoring
  • 129-projekte-und-assets-auslagern
  • 132-denoising-module
  • 143-ar-vr-support-via-openxr
  • 43-multi-threading
  • 91-compute-first-network
  • 95-arm64-raspberry-pi-4-support
  • develop
  • master
  • optimizations
  • 0.1.0
  • 0.2.0
12 results
Show changes
Showing
with 151 additions and 292 deletions
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
%VULKAN_SDK%\Bin32\glslc.exe shader.vert -o vert.spv
%VULKAN_SDK%\Bin32\glslc.exe shader.frag -o frag.spv
pause
\ No newline at end of file
File deleted
File deleted
......@@ -4,17 +4,8 @@
#include <vkcv/camera/CameraManager.hpp>
#include <chrono>
#include <vkcv/asset/asset_loader.hpp>
#include <vkcv/Logger.hpp>
glm::mat4 arrayTo4x4Matrix(std::array<float,16> array){
glm::mat4 matrix;
for (int i = 0; i < 4; i++){
for (int j = 0; j < 4; j++){
matrix[i][j] = array[j * 4 + i];
}
}
return matrix;
}
#include <vkcv/shader/GLSLCompiler.hpp>
#include <vkcv/scene/Scene.hpp>
int main(int argc, const char** argv) {
const char* applicationName = "First Scene";
......@@ -32,8 +23,8 @@ int main(int argc, const char** argv) {
vkcv::camera::CameraManager cameraManager(window);
uint32_t camIndex0 = cameraManager.addCamera(vkcv::camera::ControllerType::PILOT);
uint32_t camIndex1 = cameraManager.addCamera(vkcv::camera::ControllerType::TRACKBALL);
cameraManager.getCamera(camIndex0).setPosition(glm::vec3(0, 0, -3));
cameraManager.getCamera(camIndex0).setPosition(glm::vec3(-8, 1, -0.5));
cameraManager.getCamera(camIndex0).setNearFar(0.1f, 30.0f);
cameraManager.getCamera(camIndex1).setNearFar(0.1f, 30.0f);
......@@ -46,66 +37,10 @@ int main(int argc, const char** argv) {
{},
{ "VK_KHR_swapchain" }
);
vkcv::asset::Scene scene;
const char* path = argc > 1 ? argv[1] : "resources/Sponza/Sponza.gltf";
int result = vkcv::asset::loadScene(path, scene);
if (result == 1) {
std::cout << "Mesh loading successful!" << std::endl;
}
else {
std::cout << "Mesh loading failed: " << result << std::endl;
return 1;
}
assert(!scene.vertexGroups.empty());
std::vector<std::vector<uint8_t>> vBuffers;
std::vector<std::vector<uint8_t>> iBuffers;
std::vector<vkcv::VertexBufferBinding> vBufferBindings;
std::vector<std::vector<vkcv::VertexBufferBinding>> vertexBufferBindings;
std::vector<vkcv::asset::VertexAttribute> vAttributes;
for (int i = 0; i < scene.vertexGroups.size(); i++) {
vBuffers.push_back(scene.vertexGroups[i].vertexBuffer.data);
iBuffers.push_back(scene.vertexGroups[i].indexBuffer.data);
auto& attributes = scene.vertexGroups[i].vertexBuffer.attributes;
std::sort(attributes.begin(), attributes.end(), [](const vkcv::asset::VertexAttribute& x, const vkcv::asset::VertexAttribute& y) {
return static_cast<uint32_t>(x.type) < static_cast<uint32_t>(y.type);
});
}
std::vector<vkcv::Buffer<uint8_t>> vertexBuffers;
for (const vkcv::asset::VertexGroup& group : scene.vertexGroups) {
vertexBuffers.push_back(core.createBuffer<uint8_t>(
vkcv::BufferType::VERTEX,
group.vertexBuffer.data.size()));
vertexBuffers.back().fill(group.vertexBuffer.data);
}
std::vector<vkcv::Buffer<uint8_t>> indexBuffers;
for (const auto& dataBuffer : iBuffers) {
indexBuffers.push_back(core.createBuffer<uint8_t>(
vkcv::BufferType::INDEX,
dataBuffer.size()));
indexBuffers.back().fill(dataBuffer);
}
int vertexBufferIndex = 0;
for (const auto& vertexGroup : scene.vertexGroups) {
for (const auto& attribute : vertexGroup.vertexBuffer.attributes) {
vAttributes.push_back(attribute);
vBufferBindings.push_back(vkcv::VertexBufferBinding(attribute.offset, vertexBuffers[vertexBufferIndex].getVulkanHandle()));
}
vertexBufferBindings.push_back(vBufferBindings);
vBufferBindings.clear();
vertexBufferIndex++;
}
vkcv::scene::Scene scene = vkcv::scene::Scene::load(core, std::filesystem::path(
argc > 1 ? argv[1] : "resources/Sponza/Sponza.gltf"
));
const vkcv::AttachmentDescription present_color_attachment(
vkcv::AttachmentOperation::STORE,
......@@ -127,9 +62,18 @@ int main(int argc, const char** argv) {
return EXIT_FAILURE;
}
vkcv::ShaderProgram sceneShaderProgram{};
sceneShaderProgram.addShader(vkcv::ShaderStage::VERTEX, std::filesystem::path("resources/shaders/vert.spv"));
sceneShaderProgram.addShader(vkcv::ShaderStage::FRAGMENT, std::filesystem::path("resources/shaders/frag.spv"));
vkcv::ShaderProgram sceneShaderProgram;
vkcv::shader::GLSLCompiler compiler;
compiler.compile(vkcv::ShaderStage::VERTEX, std::filesystem::path("resources/shaders/shader.vert"),
[&sceneShaderProgram](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) {
sceneShaderProgram.addShader(shaderStage, path);
});
compiler.compile(vkcv::ShaderStage::FRAGMENT, std::filesystem::path("resources/shaders/shader.frag"),
[&sceneShaderProgram](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) {
sceneShaderProgram.addShader(shaderStage, path);
});
const std::vector<vkcv::VertexAttachment> vertexAttachments = sceneShaderProgram.getVertexAttachments();
std::vector<vkcv::VertexBinding> bindings;
......@@ -138,41 +82,8 @@ int main(int argc, const char** argv) {
}
const vkcv::VertexLayout sceneLayout(bindings);
uint32_t setID = 0;
std::vector<vkcv::DescriptorBinding> descriptorBindings = { sceneShaderProgram.getReflectedDescriptors()[setID] };
vkcv::SamplerHandle sampler = core.createSampler(
vkcv::SamplerFilterType::LINEAR,
vkcv::SamplerFilterType::LINEAR,
vkcv::SamplerMipmapMode::LINEAR,
vkcv::SamplerAddressMode::REPEAT
);
std::vector<vkcv::Image> sceneImages;
std::vector<vkcv::DescriptorSetHandle> descriptorSets;
for (const auto& vertexGroup : scene.vertexGroups) {
descriptorSets.push_back(core.createDescriptorSet(descriptorBindings));
const auto& material = scene.materials[vertexGroup.materialIndex];
int baseColorIndex = material.baseColor;
if (baseColorIndex < 0) {
vkcv_log(vkcv::LogLevel::WARNING, "Material lacks base color");
baseColorIndex = 0;
}
vkcv::asset::Texture& sceneTexture = scene.textures[baseColorIndex];
sceneImages.push_back(core.createImage(vk::Format::eR8G8B8A8Srgb, sceneTexture.w, sceneTexture.h));
sceneImages.back().fill(sceneTexture.data.data());
vkcv::DescriptorWrites setWrites;
setWrites.sampledImageWrites = { vkcv::SampledImageDescriptorWrite(0, sceneImages.back().getHandle()) };
setWrites.samplerWrites = { vkcv::SamplerDescriptorWrite(1, sampler) };
core.writeDescriptorSet(descriptorSets.back(), setWrites);
}
const auto& material0 = scene.getMaterial(0);
const vkcv::PipelineConfig scenePipelineDefsinition{
sceneShaderProgram,
......@@ -180,7 +91,7 @@ int main(int argc, const char** argv) {
UINT32_MAX,
scenePass,
{sceneLayout},
{ core.getDescriptorSet(descriptorSets[0]).layout },
{ core.getDescriptorSet(material0.getDescriptorSet()).layout },
true };
vkcv::PipelineHandle scenePipeline = core.createGraphicsPipeline(scenePipelineDefsinition);
......@@ -192,26 +103,7 @@ int main(int argc, const char** argv) {
vkcv::ImageHandle depthBuffer = core.createImage(vk::Format::eD32Sfloat, windowWidth, windowHeight).getHandle();
const vkcv::ImageHandle swapchainInput = vkcv::ImageHandle::createSwapchainImageHandle();
std::vector<vkcv::DrawcallInfo> drawcalls;
for(int i = 0; i < scene.vertexGroups.size(); i++){
vkcv::Mesh renderMesh(vertexBufferBindings[i], indexBuffers[i].getVulkanHandle(), scene.vertexGroups[i].numIndices);
vkcv::DescriptorSetUsage descriptorUsage(0, core.getDescriptorSet(descriptorSets[i]).vulkanHandle);
drawcalls.push_back(vkcv::DrawcallInfo(renderMesh, {descriptorUsage},1));
}
std::vector<glm::mat4> modelMatrices;
modelMatrices.resize(scene.vertexGroups.size(), glm::mat4(1.f));
for (const auto &mesh : scene.meshes) {
const glm::mat4 m = arrayTo4x4Matrix(mesh.modelMatrix);
for (const auto &vertexGroupIndex : mesh.vertexGroups) {
modelMatrices[vertexGroupIndex] = m;
}
}
std::vector<glm::mat4> mvp;
auto start = std::chrono::system_clock::now();
while (window.isWindowOpen()) {
vkcv::Window::pollEvents();
......@@ -236,25 +128,24 @@ int main(int argc, const char** argv) {
start = end;
cameraManager.update(0.000001 * static_cast<double>(deltatime.count()));
glm::mat4 vp = cameraManager.getActiveCamera().getMVP();
mvp.clear();
for (const auto& m : modelMatrices) {
mvp.push_back(vp * m);
}
vkcv::PushConstantData pushConstantData((void*)mvp.data(), sizeof(glm::mat4));
const std::vector<vkcv::ImageHandle> renderTargets = { swapchainInput, depthBuffer };
auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics);
core.recordDrawcallsToCmdStream(
cmdStream,
scenePass,
scenePipeline,
pushConstantData,
drawcalls,
renderTargets);
auto recordMesh = [](const glm::mat4& MVP, const glm::mat4& M,
vkcv::PushConstants &pushConstants,
vkcv::DrawcallInfo& drawcallInfo) {
pushConstants.appendDrawcall(MVP);
};
scene.recordDrawcalls(cmdStream,
cameraManager.getActiveCamera(),
scenePass,
scenePipeline,
sizeof(glm::mat4),
recordMesh,
renderTargets);
core.prepareSwapchainImageForPresent(cmdStream);
core.submitCommandStream(cmdStream);
core.endFrame();
......
File deleted
%VULKAN_SDK%\Bin32\glslc.exe shader.vert -o vert.spv
%VULKAN_SDK%\Bin32\glslc.exe shader.frag -o frag.spv
%VULKAN_SDK%\Bin32\glslc.exe shader.comp -o comp.spv
pause
\ No newline at end of file
File deleted
#version 440
layout(std430, binding = 0) buffer testBuffer
{
float test1[10];
float test2[10];
float test3[10];
};
layout( push_constant ) uniform constants{
float pushConstant;
};
layout(local_size_x = 5) in;
void main(){
if(gl_GlobalInvocationID.x >= 10){
return;
}
test1[gl_GlobalInvocationID.x] = gl_GlobalInvocationID.x;
test2[gl_GlobalInvocationID.x] = 69; // nice!
test3[gl_GlobalInvocationID.x] = pushConstant;
}
\ No newline at end of file
File deleted
......@@ -2,10 +2,8 @@
#include <vkcv/Core.hpp>
#include <GLFW/glfw3.h>
#include <vkcv/camera/CameraManager.hpp>
#include <chrono>
#include <vkcv/shader/GLSLCompiler.hpp>
#include <vkcv/gui/GUI.hpp>
#include <chrono>
int main(int argc, const char** argv) {
const char* applicationName = "First Triangle";
......@@ -27,57 +25,11 @@ int main(int argc, const char** argv) {
{},
{ "VK_KHR_swapchain" }
);
vkcv::gui::GUI gui (core, window);
const auto& context = core.getContext();
const vk::Instance& instance = context.getInstance();
const vk::PhysicalDevice& physicalDevice = context.getPhysicalDevice();
const vk::Device& device = context.getDevice();
struct vec3 {
float x, y, z;
};
const size_t n = 5027;
auto testBuffer = core.createBuffer<vec3>(vkcv::BufferType::VERTEX, n, vkcv::BufferMemoryType::DEVICE_LOCAL);
vec3 vec_data[n];
for (size_t i = 0; i < n; i++) {
vec_data[i] = { 42, static_cast<float>(i), 7 };
}
testBuffer.fill(vec_data);
auto triangleIndexBuffer = core.createBuffer<uint16_t>(vkcv::BufferType::INDEX, n, vkcv::BufferMemoryType::DEVICE_LOCAL);
auto triangleIndexBuffer = core.createBuffer<uint16_t>(vkcv::BufferType::INDEX, 3, vkcv::BufferMemoryType::DEVICE_LOCAL);
uint16_t indices[3] = { 0, 1, 2 };
triangleIndexBuffer.fill(&indices[0], sizeof(indices));
/*vec3* m = buffer.map();
m[0] = { 0, 0, 0 };
m[1] = { 0, 0, 0 };
m[2] = { 0, 0, 0 };
buffer.unmap();*/
vkcv::SamplerHandle sampler = core.createSampler(
vkcv::SamplerFilterType::NEAREST,
vkcv::SamplerFilterType::NEAREST,
vkcv::SamplerMipmapMode::NEAREST,
vkcv::SamplerAddressMode::REPEAT
);
std::cout << "Physical device: " << physicalDevice.getProperties().deviceName << std::endl;
switch (physicalDevice.getProperties().vendorID) {
case 0x1002: std::cout << "Running AMD huh? You like underdogs, are you a Linux user?" << std::endl; break;
case 0x10DE: std::cout << "An NVidia GPU, how predictable..." << std::endl; break;
case 0x8086: std::cout << "Poor child, running on an Intel GPU, probably integrated..."
"or perhaps you are from the future with a dedicated one?" << std::endl; break;
case 0x13B5: std::cout << "ARM? What the hell are you running on, next thing I know you're trying to run Vulkan on a leg..." << std::endl; break;
default: std::cout << "Unknown GPU vendor?! Either you're on an exotic system or your driver is broken..." << std::endl;
}
// an example attachment for passes that output to the window
const vkcv::AttachmentDescription present_color_attachment(
vkcv::AttachmentOperation::STORE,
......@@ -93,7 +45,7 @@ int main(int argc, const char** argv) {
return EXIT_FAILURE;
}
vkcv::ShaderProgram triangleShaderProgram{};
vkcv::ShaderProgram triangleShaderProgram;
vkcv::shader::GLSLCompiler compiler;
compiler.compile(vkcv::ShaderStage::VERTEX, std::filesystem::path("shaders/shader.vert"),
......@@ -123,49 +75,9 @@ int main(int argc, const char** argv) {
std::cout << "Error. Could not create graphics pipeline. Exiting." << std::endl;
return EXIT_FAILURE;
}
// Compute Pipeline
vkcv::ShaderProgram computeShaderProgram{};
computeShaderProgram.addShader(vkcv::ShaderStage::COMPUTE, std::filesystem::path("shaders/comp.spv"));
// take care, assuming shader has exactly one descriptor set
vkcv::DescriptorSetHandle computeDescriptorSet = core.createDescriptorSet(computeShaderProgram.getReflectedDescriptors()[0]);
vkcv::PipelineHandle computePipeline = core.createComputePipeline(
computeShaderProgram,
{ core.getDescriptorSet(computeDescriptorSet).layout });
struct ComputeTestBuffer {
float test1[10];
float test2[10];
float test3[10];
};
vkcv::Buffer computeTestBuffer = core.createBuffer<ComputeTestBuffer>(vkcv::BufferType::STORAGE, 1);
vkcv::DescriptorWrites computeDescriptorWrites;
computeDescriptorWrites.storageBufferWrites = { vkcv::StorageBufferDescriptorWrite(0, computeTestBuffer.getHandle()) };
core.writeDescriptorSet(computeDescriptorSet, computeDescriptorWrites);
/*
* BufferHandle triangleVertices = core.createBuffer(vertices);
* BufferHandle triangleIndices = core.createBuffer(indices);
*
* // triangle Model creation goes here
*
*
* // attachment creation goes here
* PassHandle trianglePass = core.CreatePass(presentationPass);
*
* // shader creation goes here
* // material creation goes here
*
* PipelineHandle trianglePipeline = core.CreatePipeline(trianglePipeline);
*/
auto start = std::chrono::system_clock::now();
vkcv::ImageHandle swapchainImageHandle = vkcv::ImageHandle::createSwapchainImageHandle();
const vkcv::Mesh renderMesh({}, triangleIndexBuffer.getVulkanHandle(), 3);
vkcv::DrawcallInfo drawcall(renderMesh, {},1);
......@@ -181,7 +93,7 @@ int main(int argc, const char** argv) {
while (window.isWindowOpen())
{
window.pollEvents();
vkcv::Window::pollEvents();
uint32_t swapchainWidth, swapchainHeight; // No resizing = No problem
if (!core.beginFrame(swapchainWidth, swapchainHeight)) {
......@@ -195,37 +107,21 @@ int main(int argc, const char** argv) {
cameraManager.update(0.000001 * static_cast<double>(deltatime.count()));
glm::mat4 mvp = cameraManager.getActiveCamera().getMVP();
vkcv::PushConstantData pushConstantData((void*)&mvp, sizeof(glm::mat4));
vkcv::PushConstants pushConstants (sizeof(glm::mat4));
pushConstants.appendDrawcall(mvp);
auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics);
core.recordDrawcallsToCmdStream(
cmdStream,
trianglePass,
trianglePipeline,
pushConstantData,
pushConstants,
{ drawcall },
{ swapchainInput });
const uint32_t dispatchSize[3] = { 2, 1, 1 };
const float theMeaningOfLife = 42;
core.recordComputeDispatchToCmdStream(
cmdStream,
computePipeline,
dispatchSize,
{ vkcv::DescriptorSetUsage(0, core.getDescriptorSet(computeDescriptorSet).vulkanHandle) },
vkcv::PushConstantData((void*)&theMeaningOfLife, sizeof(theMeaningOfLife)));
core.prepareSwapchainImageForPresent(cmdStream);
core.submitCommandStream(cmdStream);
gui.beginGUI();
ImGui::Begin("Hello world");
ImGui::Text("This is a test!");
ImGui::End();
gui.endGUI();
core.endFrame();
}
......
indirect_dispatch
cmake_minimum_required(VERSION 3.16)
project(indirect_dispatch)
# setting c++ standard for the project
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# this should fix the execution path to load local files from the project
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
# adding source files to the project
add_executable(indirect_dispatch src/main.cpp)
target_sources(indirect_dispatch PRIVATE
src/App.hpp
src/App.cpp
src/AppConfig.hpp
src/MotionBlurConfig.hpp
src/AppSetup.hpp
src/AppSetup.cpp
src/MotionBlur.hpp
src/MotionBlur.cpp
src/MotionBlurSetup.hpp
src/MotionBlurSetup.cpp)
# this should fix the execution path to load local files from the project (for MSVC)
if(MSVC)
set_target_properties(indirect_dispatch PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set_target_properties(indirect_dispatch PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
# in addition to setting the output directory, the working directory has to be set
# by default visual studio sets the working directory to the build directory, when using the debugger
set_target_properties(indirect_dispatch PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif()
# including headers of dependencies and the VkCV framework
target_include_directories(indirect_dispatch SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes} ${vkcv_testing_include} ${vkcv_camera_include} ${vkcv_shader_compiler_include} ${vkcv_gui_include})
# linking with libraries from all dependencies and the VkCV framework
target_link_libraries(indirect_dispatch vkcv ${vkcv_libraries} vkcv_asset_loader ${vkcv_asset_loader_libraries} vkcv_testing vkcv_camera vkcv_shader_compiler vkcv_gui)
\ No newline at end of file
projects/indirect_dispatch/resources/models/grid.png

130 B

File added
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
#version 440
#extension GL_GOOGLE_include_directive : enable
layout(set=0, binding=0) uniform texture2D inTexture;
layout(set=0, binding=1) uniform sampler textureSampler;
layout(set=0, binding=2, rgba8) uniform image2D outImage;
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
void main(){
ivec2 outImageRes = imageSize(outImage);
ivec2 coord = ivec2(gl_GlobalInvocationID.xy);
if(any(greaterThanEqual(coord, outImageRes)))
return;
vec2 uv = vec2(coord) / outImageRes;
vec3 linearColor = texture(sampler2D(inTexture, textureSampler), uv).rgb;
vec3 gammaCorrected = pow(linearColor, vec3(1 / 2.2));
imageStore(outImage, coord, vec4(gammaCorrected, 0.f));
}
\ No newline at end of file
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec3 passNormal;
layout(location = 1) in vec2 passUV;
layout(location = 0) out vec3 outColor;
layout(set=0, binding=0) uniform texture2D albedoTexture;
layout(set=0, binding=1) uniform sampler textureSampler;
void main() {
vec3 albedo = texture(sampler2D(albedoTexture, textureSampler), passUV).rgb;
vec3 N = normalize(passNormal);
float light = max(N.y * 0.5 + 0.5, 0);
outColor = light * albedo;
}
\ No newline at end of file