Skip to content

Commit

Permalink
Refactored API sample hpp_terrain_tessellation. (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
asuessenbach authored Aug 28, 2023
1 parent a473cde commit ee05d72
Show file tree
Hide file tree
Showing 12 changed files with 461 additions and 460 deletions.
10 changes: 7 additions & 3 deletions framework/common/hpp_vk_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ inline vk::Framebuffer create_framebuffer(vk::Device device, vk::RenderPass rend

inline vk::Pipeline create_graphics_pipeline(vk::Device device,
vk::PipelineCache pipeline_cache,
std::array<vk::PipelineShaderStageCreateInfo, 2> const &shader_stages,
std::vector<vk::PipelineShaderStageCreateInfo> const &shader_stages,
vk::PipelineVertexInputStateCreateInfo const &vertex_input_state,
vk::PrimitiveTopology primitive_topology,
uint32_t patch_control_points,
vk::PolygonMode polygon_mode,
vk::CullModeFlags cull_mode,
vk::FrontFace front_face,
std::vector<vk::PipelineColorBlendAttachmentState> const &blend_attachment_states,
Expand All @@ -188,10 +190,12 @@ inline vk::Pipeline create_graphics_pipeline(vk::Device
{
vk::PipelineInputAssemblyStateCreateInfo input_assembly_state({}, primitive_topology, false);

vk::PipelineTessellationStateCreateInfo tessellation_state({}, patch_control_points);

vk::PipelineViewportStateCreateInfo viewport_state({}, 1, nullptr, 1, nullptr);

vk::PipelineRasterizationStateCreateInfo rasterization_state;
rasterization_state.polygonMode = vk::PolygonMode::eFill;
rasterization_state.polygonMode = polygon_mode;
rasterization_state.cullMode = cull_mode;
rasterization_state.frontFace = front_face;
rasterization_state.lineWidth = 1.0f;
Expand All @@ -208,7 +212,7 @@ inline vk::Pipeline create_graphics_pipeline(vk::Device
shader_stages,
&vertex_input_state,
&input_assembly_state,
{},
&tessellation_state,
&viewport_state,
&rasterization_state,
&multisample_state,
Expand Down
16 changes: 8 additions & 8 deletions framework/hpp_api_vulkan_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ vk::ImageLayout HPPApiVulkanSample::descriptor_type_to_image_layout(vk::Descript
}
}

HPPTexture HPPApiVulkanSample::load_texture(const std::string &file, vkb::sg::Image::ContentType content_type)
HPPTexture HPPApiVulkanSample::load_texture(const std::string &file, vkb::sg::Image::ContentType content_type, vk::SamplerAddressMode address_mode)
{
HPPTexture texture;

Expand Down Expand Up @@ -906,9 +906,9 @@ HPPTexture HPPApiVulkanSample::load_texture(const std::string &file, vkb::sg::Im
sampler_create_info.magFilter = vk::Filter::eLinear;
sampler_create_info.minFilter = vk::Filter::eLinear;
sampler_create_info.mipmapMode = vk::SamplerMipmapMode::eLinear;
sampler_create_info.addressModeU = vk::SamplerAddressMode::eRepeat;
sampler_create_info.addressModeV = vk::SamplerAddressMode::eRepeat;
sampler_create_info.addressModeW = vk::SamplerAddressMode::eRepeat;
sampler_create_info.addressModeU = address_mode;
sampler_create_info.addressModeV = address_mode;
sampler_create_info.addressModeW = address_mode;
sampler_create_info.mipLodBias = 0.0f;
sampler_create_info.compareOp = vk::CompareOp::eNever;
sampler_create_info.minLod = 0.0f;
Expand All @@ -927,7 +927,7 @@ HPPTexture HPPApiVulkanSample::load_texture(const std::string &file, vkb::sg::Im
return texture;
}

HPPTexture HPPApiVulkanSample::load_texture_array(const std::string &file, vkb::sg::Image::ContentType content_type)
HPPTexture HPPApiVulkanSample::load_texture_array(const std::string &file, vkb::sg::Image::ContentType content_type, vk::SamplerAddressMode address_mode)
{
HPPTexture texture{};

Expand Down Expand Up @@ -993,9 +993,9 @@ HPPTexture HPPApiVulkanSample::load_texture_array(const std::string &file, vkb::
sampler_create_info.magFilter = vk::Filter::eLinear;
sampler_create_info.minFilter = vk::Filter::eLinear;
sampler_create_info.mipmapMode = vk::SamplerMipmapMode::eLinear;
sampler_create_info.addressModeU = vk::SamplerAddressMode::eClampToEdge;
sampler_create_info.addressModeV = vk::SamplerAddressMode::eClampToEdge;
sampler_create_info.addressModeW = vk::SamplerAddressMode::eClampToEdge;
sampler_create_info.addressModeU = address_mode;
sampler_create_info.addressModeV = address_mode;
sampler_create_info.addressModeW = address_mode;
sampler_create_info.mipLodBias = 0.0f;
sampler_create_info.compareOp = vk::CompareOp::eNever;
sampler_create_info.minLod = 0.0f;
Expand Down
9 changes: 7 additions & 2 deletions framework/hpp_api_vulkan_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,20 @@ class HPPApiVulkanSample : public vkb::HPPVulkanSample
* @brief Loads in a ktx 2D texture
* @param file The filename of the texture to load
* @param content_type The type of content in the image file
* @param address_mode The address mode to use in u-, v-, and w-direction. Defaults to /c vk::SamplerAddressMode::eRepeat.
*/
HPPTexture load_texture(const std::string &file, vkb::sg::Image::ContentType content_type);
HPPTexture
load_texture(const std::string &file, vkb::sg::Image::ContentType content_type, vk::SamplerAddressMode address_mode = vk::SamplerAddressMode::eRepeat);

/**
* @brief Loads in a ktx 2D texture array
* @param file The filename of the texture to load
* @param content_type The type of content in the image file
* @param address_mode The address mode to use in u-, v-, and w-direction. Defaults to /c vk::SamplerAddressMode::eClampToEdge.
*/
HPPTexture load_texture_array(const std::string &file, vkb::sg::Image::ContentType content_type);
HPPTexture load_texture_array(const std::string &file,
vkb::sg::Image::ContentType content_type,
vk::SamplerAddressMode address_mode = vk::SamplerAddressMode::eClampToEdge);

/**
* @brief Loads in a ktx 2D texture cubemap
Expand Down
6 changes: 4 additions & 2 deletions samples/api/hpp_compute_nbody/hpp_compute_nbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ vk::DescriptorSetLayout HPPComputeNBody::create_graphics_descriptor_set_layout()
vk::Pipeline HPPComputeNBody::create_graphics_pipeline()
{
// Load shaders
std::array<vk::PipelineShaderStageCreateInfo, 2> shader_stages = {{load_shader("compute_nbody/particle.vert", vk::ShaderStageFlagBits::eVertex),
load_shader("compute_nbody/particle.frag", vk::ShaderStageFlagBits::eFragment)}};
std::vector<vk::PipelineShaderStageCreateInfo> shader_stages = {load_shader("compute_nbody/particle.vert", vk::ShaderStageFlagBits::eVertex),
load_shader("compute_nbody/particle.frag", vk::ShaderStageFlagBits::eFragment)};

// Vertex bindings and attributes
vk::VertexInputBindingDescription vertex_input_bindings(0, sizeof(Particle), vk::VertexInputRate::eVertex);
Expand Down Expand Up @@ -338,6 +338,8 @@ vk::Pipeline HPPComputeNBody::create_graphics_pipeline()
shader_stages,
vertex_input_state,
vk::PrimitiveTopology::ePointList,
0,
vk::PolygonMode::eFill,
vk::CullModeFlagBits::eNone,
vk::FrontFace::eCounterClockwise,
{blend_attachment_state},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ bool HPPDynamicUniformBuffers::prepare(const vkb::ApplicationOptions &options)
descriptor_set_layout = create_descriptor_set_layout();
pipeline_layout = get_device()->get_handle().createPipelineLayout({{}, descriptor_set_layout});
pipeline = create_pipeline();
descriptor_pool = create_descriptor_pool();
descriptor_set = vkb::common::allocate_descriptor_set(get_device()->get_handle(), descriptor_pool, descriptor_set_layout);

descriptor_pool = create_descriptor_pool();
descriptor_set = vkb::common::allocate_descriptor_set(get_device()->get_handle(), descriptor_pool, descriptor_set_layout);

update_descriptor_set();
build_command_buffers();
Expand Down Expand Up @@ -186,9 +187,8 @@ vk::DescriptorSetLayout HPPDynamicUniformBuffers::create_descriptor_set_layout()
vk::Pipeline HPPDynamicUniformBuffers::create_pipeline()
{
// Load shaders
std::array<vk::PipelineShaderStageCreateInfo, 2> shader_stages = {{load_shader("dynamic_uniform_buffers/base.vert", vk::ShaderStageFlagBits::eVertex),
load_shader("dynamic_uniform_buffers/base.frag",
vk::ShaderStageFlagBits::eFragment)}};
std::vector<vk::PipelineShaderStageCreateInfo> shader_stages = {load_shader("dynamic_uniform_buffers/base.vert", vk::ShaderStageFlagBits::eVertex),
load_shader("dynamic_uniform_buffers/base.frag", vk::ShaderStageFlagBits::eFragment)};

// Vertex bindings and attributes
vk::VertexInputBindingDescription vertex_input_binding(0, sizeof(Vertex), vk::VertexInputRate::eVertex);
Expand All @@ -213,6 +213,8 @@ vk::Pipeline HPPDynamicUniformBuffers::create_pipeline()
shader_stages,
vertex_input_state,
vk::PrimitiveTopology::eTriangleList,
0,
vk::PolygonMode::eFill,
vk::CullModeFlagBits::eNone,
vk::FrontFace::eCounterClockwise,
{blend_attachment_state},
Expand Down
20 changes: 12 additions & 8 deletions samples/api/hpp_hdr/hpp_hdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,8 @@ vk::DescriptorPool HPPHDR::create_descriptor_pool()

vk::Pipeline HPPHDR::create_bloom_pipeline(uint32_t direction)
{
std::array<vk::PipelineShaderStageCreateInfo, 2> shader_stages{
load_shader("hdr/bloom.vert", vk::ShaderStageFlagBits::eVertex),
load_shader("hdr/bloom.frag", vk::ShaderStageFlagBits::eFragment)};
std::vector<vk::PipelineShaderStageCreateInfo> shader_stages{load_shader("hdr/bloom.vert", vk::ShaderStageFlagBits::eVertex),
load_shader("hdr/bloom.frag", vk::ShaderStageFlagBits::eFragment)};

// Set constant parameters via specialization constants
vk::SpecializationMapEntry specialization_map_entry(0, 0, sizeof(uint32_t));
Expand Down Expand Up @@ -282,6 +281,8 @@ vk::Pipeline HPPHDR::create_bloom_pipeline(uint32_t direction)
shader_stages,
{},
vk::PrimitiveTopology::eTriangleList,
0,
vk::PolygonMode::eFill,
vk::CullModeFlagBits::eFront,
vk::FrontFace::eCounterClockwise,
{blend_attachment_state},
Expand All @@ -292,8 +293,8 @@ vk::Pipeline HPPHDR::create_bloom_pipeline(uint32_t direction)

vk::Pipeline HPPHDR::create_composition_pipeline()
{
std::array<vk::PipelineShaderStageCreateInfo, 2> shader_stages{load_shader("hdr/composition.vert", vk::ShaderStageFlagBits::eVertex),
load_shader("hdr/composition.frag", vk::ShaderStageFlagBits::eFragment)};
std::vector<vk::PipelineShaderStageCreateInfo> shader_stages{load_shader("hdr/composition.vert", vk::ShaderStageFlagBits::eVertex),
load_shader("hdr/composition.frag", vk::ShaderStageFlagBits::eFragment)};

vk::PipelineColorBlendAttachmentState blend_attachment_state;
blend_attachment_state.colorWriteMask =
Expand All @@ -311,6 +312,8 @@ vk::Pipeline HPPHDR::create_composition_pipeline()
shader_stages,
{},
vk::PrimitiveTopology::eTriangleList,
0,
vk::PolygonMode::eFill,
vk::CullModeFlagBits::eFront,
vk::FrontFace::eCounterClockwise,
{blend_attachment_state},
Expand Down Expand Up @@ -364,9 +367,8 @@ vk::ImageView HPPHDR::create_image_view(vk::Format format, vk::ImageUsageFlagBit

vk::Pipeline HPPHDR::create_models_pipeline(uint32_t shaderType, vk::CullModeFlagBits cullMode, bool depthTestAndWrite)
{
std::array<vk::PipelineShaderStageCreateInfo, 2> shader_stages{
load_shader("hdr/gbuffer.vert", vk::ShaderStageFlagBits::eVertex),
load_shader("hdr/gbuffer.frag", vk::ShaderStageFlagBits::eFragment)};
std::vector<vk::PipelineShaderStageCreateInfo> shader_stages{load_shader("hdr/gbuffer.vert", vk::ShaderStageFlagBits::eVertex),
load_shader("hdr/gbuffer.frag", vk::ShaderStageFlagBits::eFragment)};

// Set constant parameters via specialization constants
vk::SpecializationMapEntry specialization_map_entry(0, 0, sizeof(uint32_t));
Expand Down Expand Up @@ -404,6 +406,8 @@ vk::Pipeline HPPHDR::create_models_pipeline(uint32_t shaderType, vk::CullModeFla
shader_stages,
vertex_input_state,
vk::PrimitiveTopology::eTriangleList,
0,
vk::PolygonMode::eFill,
cullMode,
vk::FrontFace::eCounterClockwise,
blend_attachment_states,
Expand Down
4 changes: 3 additions & 1 deletion samples/api/hpp_hello_triangle/hpp_hello_triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ vk::Device HPPHelloTriangle::create_device(const std::vector<const char *> &requ
vk::Pipeline HPPHelloTriangle::create_graphics_pipeline()
{
// Load our SPIR-V shaders.
std::array<vk::PipelineShaderStageCreateInfo, 2> shader_stages{
std::vector<vk::PipelineShaderStageCreateInfo> shader_stages{
vk::PipelineShaderStageCreateInfo({}, vk::ShaderStageFlagBits::eVertex, create_shader_module("triangle.vert"), "main"),
vk::PipelineShaderStageCreateInfo({}, vk::ShaderStageFlagBits::eFragment, create_shader_module("triangle.frag"), "main")};

Expand All @@ -394,6 +394,8 @@ vk::Pipeline HPPHelloTriangle::create_graphics_pipeline()
shader_stages,
vertex_input,
vk::PrimitiveTopology::eTriangleList, // We will use triangle lists to draw geometry.
0,
vk::PolygonMode::eFill,
vk::CullModeFlagBits::eBack,
vk::FrontFace::eClockwise,
{blend_attachment},
Expand Down
8 changes: 5 additions & 3 deletions samples/api/hpp_hlsl_shaders/hpp_hlsl_shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ vk::DescriptorPool HPPHlslShaders::create_descriptor_pool()

vk::Pipeline HPPHlslShaders::create_pipeline()
{
size_t vertex_shader_index = shader_modules.size() - 2;
std::array<vk::PipelineShaderStageCreateInfo, 2> shader_stages{{{{}, vk::ShaderStageFlagBits::eVertex, shader_modules[vertex_shader_index], "main"},
{{}, vk::ShaderStageFlagBits::eFragment, shader_modules[vertex_shader_index + 1], "main"}}};
size_t vertex_shader_index = shader_modules.size() - 2;
std::vector<vk::PipelineShaderStageCreateInfo> shader_stages{{{}, vk::ShaderStageFlagBits::eVertex, shader_modules[vertex_shader_index], "main"},
{{}, vk::ShaderStageFlagBits::eFragment, shader_modules[vertex_shader_index + 1], "main"}};

// Vertex bindings and attributes
vk::VertexInputBindingDescription vertex_input_binding(0, sizeof(VertexStructure), vk::VertexInputRate::eVertex);
Expand All @@ -194,6 +194,8 @@ vk::Pipeline HPPHlslShaders::create_pipeline()
shader_stages,
vertex_input_state,
vk::PrimitiveTopology::eTriangleList,
0,
vk::PolygonMode::eFill,
vk::CullModeFlagBits::eNone,
vk::FrontFace::eCounterClockwise,
{blend_attachment_state},
Expand Down
Loading

0 comments on commit ee05d72

Please sign in to comment.