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

Target

Select target project
  • vulkan2021/vkcv-framework
1 result
Show changes
Commits on Source (3)
Showing
with 7 additions and 387 deletions
......@@ -40,3 +40,6 @@
[submodule "modules/algorithm/lib/FidelityFX-SPD"]
path = modules/algorithm/lib/FidelityFX-SPD
url = https://github.com/GPUOpen-Effects/FidelityFX-SPD.git
[submodule "projects"]
path = projects
url = https://gitlab.uni-koblenz.de/vulkan2021/vkcv-projects.git
......@@ -3,7 +3,7 @@ project(vkcv)
# cmake options
option(BUILD_MODULES "Enables building VkCV as shared libraries" ON)
option(BUILD_PROJECTS "Enables building the VkCV projects" ON)
option(BUILD_PROJECTS "Enables building the VkCV projects" OFF)
option(BUILD_CLANG_FORMAT "Enables formatting the source code" OFF)
option(BUILD_DOXYGEN_DOCS "Enables building the VkCV doxygen documentation" OFF)
option(BUILD_SHARED "Enables building VkCV as shared libraries" OFF)
......@@ -97,7 +97,7 @@ add_compile_definitions(${vkcv_definitions})
# check if the framework is used from a parent scope
get_directory_property(vkcv_parent_scope PARENT_DIRECTORY)
if (BUILD_MODULES)
if ((BUILD_MODULES) AND (EXISTS ${PROJECT_SOURCE_DIR}/modules))
message(STATUS "Modules: ON")
# add modules as targets
......@@ -137,7 +137,7 @@ target_include_directories(vkcv BEFORE PUBLIC ${vkcv_include})
# link the framework using all required libraries
target_link_libraries(vkcv ${vkcv_libraries})
if (BUILD_PROJECTS)
if ((BUILD_PROJECTS) AND (EXISTS ${PROJECT_SOURCE_DIR}/projects))
message(STATUS "Projects: ON")
# add sub-projects/examples as targets
......
Subproject commit 2d2af7ff7c58e3dfca74c56396ee3a87535511b9
include(${vkcv_config_ext}/Project.cmake)
# Add new projects/examples here:
add_subdirectory(bindless_textures)
add_subdirectory(fire_works)
add_subdirectory(first_triangle)
add_subdirectory(first_mesh)
add_subdirectory(first_scene)
add_subdirectory(head_demo)
add_subdirectory(indirect_dispatch)
add_subdirectory(indirect_draw)
add_subdirectory(mesh_shader)
add_subdirectory(particle_simulation)
add_subdirectory(path_tracer)
add_subdirectory(rtx_ambient_occlusion)
add_subdirectory(saf_r)
add_subdirectory(sph)
add_subdirectory(voxelization)
add_subdirectory(wobble_bobble)
\ No newline at end of file
bindless_textures
\ No newline at end of file
cmake_minimum_required(VERSION 3.16)
project(bindless_textures)
# setting c++ standard for the project
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# adding source files to the project
add_project(bindless_textures src/main.cpp)
# including headers of dependencies and the VkCV framework
target_include_directories(bindless_textures SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes} ${vkcv_asset_loader_include} ${vkcv_camera_include} ${vkcv_shader_compiler_include})
# linking with libraries from all dependencies and the VkCV framework
target_link_libraries(bindless_textures vkcv ${vkcv_libraries} vkcv_asset_loader ${vkcv_asset_loader_libraries} vkcv_camera vkcv_shader_compiler)
projects/bindless_textures/resources/cube/Grass001_1K_Color.jpg

132 B

projects/bindless_textures/resources/cube/Grass001_1K_Normal.jpg

132 B

projects/bindless_textures/resources/cube/Grass001_1K_Roughness.jpg

131 B

projects/bindless_textures/resources/cube/boards2_vcyc_jpg.jpg

132 B

File deleted
File deleted
File deleted
File deleted
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_EXT_nonuniform_qualifier : enable
layout(location = 0) in vec3 passNormal;
layout(location = 1) in vec2 passUV;
layout(location = 2) in flat int passTextureIndex;
layout(location = 0) out vec3 outColor;
layout(set=0, binding=0) uniform sampler textureSampler;
layout(set=0, binding=1) uniform texture2D materialTextures[];
void main() {
outColor = texture(sampler2D(materialTextures[nonuniformEXT(passTextureIndex)], textureSampler), passUV).rgb;
}
\ No newline at end of file
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNormal;
layout(location = 2) in vec2 inUV;
layout(location = 0) out vec3 passNormal;
layout(location = 1) out vec2 passUV;
layout(location = 2) out flat int passTextureIndex;
layout( push_constant ) uniform constants{
mat4 mvp;
};
void main()
{
gl_Position = mvp * vec4(inPosition, 1.0);
passNormal = inNormal;
passUV = inUV;
passTextureIndex = (gl_VertexIndex / 4);
/*
if(inNormal.x > 0.9)
passTextureIndex = 0;
if(inNormal.x < -0.9)
passTextureIndex = 1;
if(inNormal.y > 0.9)
passTextureIndex = 2;
if(inNormal.y < -0.9)
passTextureIndex = 3;
if(inNormal.z > 0.9)
passTextureIndex = 4;
if(inNormal.z < -0.9)
passTextureIndex = 5;
*/
}
\ No newline at end of file
#include <iostream>
#include <vkcv/Buffer.hpp>
#include <vkcv/Core.hpp>
#include <vkcv/Image.hpp>
#include <vkcv/Pass.hpp>
#include <vkcv/Sampler.hpp>
#include <GLFW/glfw3.h>
#include <vkcv/camera/CameraManager.hpp>
#include <chrono>
#include <vkcv/asset/asset_loader.hpp>
#include <vkcv/shader/GLSLCompiler.hpp>
int main(int argc, const char** argv) {
const std::string applicationName = "Bindless Textures";
vkcv::Features features;
features.requireExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
features.requireExtensionFeature<vk::PhysicalDeviceDescriptorIndexingFeatures>(
VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME, [](vk::PhysicalDeviceDescriptorIndexingFeatures &features) {
features.setShaderInputAttachmentArrayDynamicIndexing(true);
features.setShaderUniformTexelBufferArrayDynamicIndexing(true);
features.setShaderStorageTexelBufferArrayDynamicIndexing(true);
features.setShaderUniformBufferArrayNonUniformIndexing(true);
features.setShaderSampledImageArrayNonUniformIndexing(true);
features.setShaderStorageBufferArrayNonUniformIndexing(true);
features.setShaderStorageImageArrayNonUniformIndexing(true);
features.setShaderInputAttachmentArrayNonUniformIndexing(true);
features.setShaderUniformTexelBufferArrayNonUniformIndexing(true);
features.setShaderStorageTexelBufferArrayNonUniformIndexing(true);
features.setDescriptorBindingUniformBufferUpdateAfterBind(true);
features.setDescriptorBindingSampledImageUpdateAfterBind(true);
features.setDescriptorBindingStorageImageUpdateAfterBind(true);
features.setDescriptorBindingStorageBufferUpdateAfterBind(true);
features.setDescriptorBindingUniformTexelBufferUpdateAfterBind(true);
features.setDescriptorBindingStorageTexelBufferUpdateAfterBind(true);
features.setDescriptorBindingUpdateUnusedWhilePending(true);
features.setDescriptorBindingPartiallyBound(true);
features.setDescriptorBindingVariableDescriptorCount(true);
features.setRuntimeDescriptorArray(true);
}
);
vkcv::Core core = vkcv::Core::create(
applicationName,
VK_MAKE_VERSION(0, 0, 1),
{ vk::QueueFlagBits::eGraphics ,vk::QueueFlagBits::eCompute , vk::QueueFlagBits::eTransfer },
features
);
vkcv::WindowHandle windowHandle = core.createWindow(applicationName, 800, 600, true);
vkcv::Window& window = core.getWindow(windowHandle);
vkcv::asset::Scene mesh;
// TEST DATA
std::vector<vkcv::Image> texturesArray;
const std::string grassPaths[5] = { "resources/cube/Grass001_1K_AmbientOcclusion.jpg",
"resources/cube/Grass001_1K_Color.jpg",
"resources/cube/Grass001_1K_Displacement.jpg",
"resources/cube/Grass001_1K_Normal.jpg",
"resources/cube/Grass001_1K_Roughness.jpg" };
for (const auto &path : grassPaths) {
std::filesystem::path grassPath(path);
vkcv::asset::Texture grassTexture = vkcv::asset::loadTexture(grassPath);
vkcv::Image texture = vkcv::image(
core,
vk::Format::eR8G8B8A8Srgb,
grassTexture.width,
grassTexture.height
);
texture.fill(grassTexture.data.data());
texturesArray.push_back(texture);
}
const char* path = argc > 1 ? argv[1] : "resources/cube/cube.gltf";
int result = vkcv::asset::loadScene(path, mesh);
if (result == 1) {
std::cout << "Mesh loading successful!" << std::endl;
} else {
std::cerr << "Mesh loading failed: " << result << std::endl;
return 1;
}
assert(!mesh.vertexGroups.empty());
auto vertexBuffer = vkcv::buffer<uint8_t>(
core,
vkcv::BufferType::VERTEX,
mesh.vertexGroups[0].vertexBuffer.data.size(),
vkcv::BufferMemoryType::DEVICE_LOCAL
);
vertexBuffer.fill(mesh.vertexGroups[0].vertexBuffer.data);
auto indexBuffer = vkcv::buffer<uint8_t>(
core,
vkcv::BufferType::INDEX,
mesh.vertexGroups[0].indexBuffer.data.size(),
vkcv::BufferMemoryType::DEVICE_LOCAL
);
indexBuffer.fill(mesh.vertexGroups[0].indexBuffer.data);
vkcv::PassHandle firstMeshPass = vkcv::passSwapchain(
core,
window.getSwapchain(),
{ vk::Format::eUndefined, vk::Format::eD32Sfloat }
);
if (!firstMeshPass) {
std::cerr << "Error. Could not create renderpass. Exiting." << std::endl;
return EXIT_FAILURE;
}
vkcv::ShaderProgram firstMeshProgram;
vkcv::shader::GLSLCompiler compiler;
compiler.compileProgram(firstMeshProgram, {
{ vkcv::ShaderStage::VERTEX, "resources/shaders/shader.vert" },
{ vkcv::ShaderStage::FRAGMENT, "resources/shaders/shader.frag" }
}, nullptr);
const auto vertexBufferBindings = vkcv::asset::loadVertexBufferBindings(
mesh.vertexGroups[0].vertexBuffer.attributes,
vertexBuffer.getHandle(),
{
vkcv::asset::PrimitiveType::POSITION,
vkcv::asset::PrimitiveType::NORMAL,
vkcv::asset::PrimitiveType::TEXCOORD_0
}
);
std::vector<vkcv::VertexBinding> bindings = vkcv::createVertexBindings(
firstMeshProgram.getVertexAttachments()
);
const vkcv::VertexLayout firstMeshLayout { bindings };
const std::unordered_map<uint32_t, vkcv::DescriptorBinding> &descriptorBindings = firstMeshProgram.getReflectedDescriptors().at(0);
std::unordered_map<uint32_t, vkcv::DescriptorBinding> adjustedBindings = descriptorBindings;
adjustedBindings[1].descriptorCount = 6;
vkcv::DescriptorSetLayoutHandle descriptorSetLayout = core.createDescriptorSetLayout(adjustedBindings);
vkcv::DescriptorSetHandle descriptorSet = core.createDescriptorSet(descriptorSetLayout);
vkcv::GraphicsPipelineHandle firstMeshPipeline = core.createGraphicsPipeline(
vkcv::GraphicsPipelineConfig(
firstMeshProgram,
firstMeshPass,
{ firstMeshLayout },
{ descriptorSetLayout }
)
);
if (!firstMeshPipeline) {
std::cerr << "Error. Could not create graphics pipeline. Exiting." << std::endl;
return EXIT_FAILURE;
}
if (mesh.textures.empty()) {
std::cerr << "Error. No textures found. Exiting." << std::endl;
return EXIT_FAILURE;
}
{
vkcv::asset::Texture &tex = mesh.textures[0];
vkcv::Image texture = vkcv::image(core, vk::Format::eR8G8B8A8Srgb, tex.w, tex.h);
texture.fill(tex.data.data());
texturesArray.push_back(texture);
}
auto downsampleStream = core.createCommandStream(vkcv::QueueType::Graphics);
for (auto& texture : texturesArray) {
texture.recordMipChainGeneration(downsampleStream, core.getDownsampler());
}
core.submitCommandStream(downsampleStream, false);
vkcv::SamplerHandle sampler = vkcv::samplerLinear(core);
vkcv::DescriptorWrites setWrites;
for(uint32_t i = 0; i < 6; i++)
{
setWrites.writeSampledImage(
1,
texturesArray[i].getHandle(),
0,
false,
i
);
}
setWrites.writeSampler(0, sampler);
core.writeDescriptorSet(descriptorSet, setWrites);
vkcv::ImageHandle depthBuffer;
const vkcv::ImageHandle swapchainInput = vkcv::ImageHandle::createSwapchainImageHandle();
vkcv::VertexData vertexData (vertexBufferBindings);
vertexData.setIndexBuffer(indexBuffer.getHandle());
vertexData.setCount(mesh.vertexGroups[0].numIndices);
vkcv::InstanceDrawcall drawcall (vertexData);
drawcall.useDescriptorSet(0, descriptorSet);
vkcv::camera::CameraManager cameraManager(window);
auto camHandle0 = cameraManager.addCamera(vkcv::camera::ControllerType::PILOT);
cameraManager.addCamera(vkcv::camera::ControllerType::TRACKBALL);
cameraManager.getCamera(camHandle0).setPosition(glm::vec3(0, 0, -3));
core.run([&](const vkcv::WindowHandle &windowHandle, double t, double dt,
uint32_t swapchainWidth, uint32_t swapchainHeight) {
if ((!depthBuffer) ||
(swapchainWidth != core.getImageWidth(depthBuffer)) ||
(swapchainHeight != core.getImageHeight(depthBuffer))) {
depthBuffer = core.createImage(
vk::Format::eD32Sfloat,
swapchainWidth,
swapchainHeight
);
}
cameraManager.update(dt);
glm::mat4 mvp = cameraManager.getActiveCamera().getMVP();
vkcv::PushConstants pushConstants = vkcv::pushConstants<glm::mat4>();
pushConstants.appendDrawcall(mvp);
const std::vector<vkcv::ImageHandle> renderTargets = { swapchainInput, depthBuffer };
auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics);
core.recordDrawcallsToCmdStream(
cmdStream,
firstMeshPipeline,
pushConstants,
{ drawcall },
renderTargets,
windowHandle
);
core.prepareSwapchainImageForPresent(cmdStream);
core.submitCommandStream(cmdStream);
});
return 0;
}