Skip to content

Commit

Permalink
Merge branch 'main' into dynamic_blending
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof-Dmitruk-Mobica authored Sep 12, 2023
2 parents e0941df + 5e4e3d2 commit cbb2b9d
Show file tree
Hide file tree
Showing 46 changed files with 2,651 additions and 1,600 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ endif()

# Add vulkan app (runs all samples)
add_subdirectory(app)

add_subdirectory(antora)
53 changes: 53 additions & 0 deletions antora/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2022-2023 The Khronos Group Inc.
# SPDX-License-Identifier: Apache-2.0

# Configure Vulkan Guide Antora tree with transformed markup files.
# Branch selection may come later. For now it is the current branch.

function(gatherAntoraAssets)
set(DIRS_TO_SEARCH
app
assets
components
docs
framework
samples
scripts
shaders
tests
)
set(PAGES_DIR_SEARCH)
set(IMAGES_DIR_SEARCH)
foreach (DIR ${DIRS_TO_SEARCH})
list(APPEND PAGES_DIR_SEARCH ${CMAKE_SOURCE_DIR}/${DIR}/*.adoc)
list(APPEND IMAGES_DIR_SEARCH ${CMAKE_SOURCE_DIR}/${DIR}/*.jpg ${CMAKE_SOURCE_DIR}/${DIR}/*.png ${CMAKE_SOURCE_DIR}/${DIR}/*.gif)
endforeach ()
file(GLOB PAGES ${CMAKE_SOURCE_DIR}/*.adoc)
file(GLOB IMAGES ${CMAKE_SOURCE_DIR}/*.jpg ${CMAKE_SOURCE_DIR}/*.png ${CMAKE_SOURCE_DIR}/*.gif)
file(GLOB_RECURSE PAGES_R ${PAGES_DIR_SEARCH})
file(GLOB_RECURSE IMAGES_R ${IMAGES_DIR_SEARCH})

foreach(page ${PAGES})
file(COPY ${page} DESTINATION ${CMAKE_CURRENT_LIST_DIR}/modules/ROOT/pages)
endforeach ()

foreach(image ${IMAGES})
file(COPY ${image} DESTINATION ${CMAKE_CURRENT_LIST_DIR}/modules/ROOT/images)
endforeach ()

foreach (page ${PAGES_R})
file(RELATIVE_PATH relpage ${CMAKE_SOURCE_DIR} ${page})
get_filename_component(directory ${relpage} DIRECTORY)
file(COPY ${page} DESTINATION ${CMAKE_CURRENT_LIST_DIR}/modules/ROOT/pages/${directory})
endforeach ()

foreach(image ${IMAGES_R})
file(RELATIVE_PATH relpage ${CMAKE_SOURCE_DIR} ${image})
get_filename_component(directory ${relpage} DIRECTORY)
file(COPY ${image} DESTINATION ${CMAKE_CURRENT_LIST_DIR}/modules/ROOT/images/${directory})
endforeach ()
endfunction()

if(VKB_GENERATE_ANTORA_SITE)
gatherAntoraAssets()
endif()
13 changes: 13 additions & 0 deletions antora/antora.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2022-2023 The Khronos Group Inc.
# SPDX-License-Identifier: Apache-2.0

name: samples
title: Vulkan Samples
version: latest
start_page: README.adoc
asciidoc:
attributes:
source-language: asciidoc@
table-caption: false
nav:
- modules/ROOT/nav.adoc
107 changes: 107 additions & 0 deletions antora/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
////
- Copyright (c) 2023, Holochip Inc
-
- SPDX-License-Identifier: Apache-2.0
-
- Licensed under the Apache License, Version 2.0 the "License";
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
////
* xref:README.adoc[Readme]
* xref:vulkan_basics.adoc[Vulkan basics]
* xref:framework/README.adoc[Sample framework]
* xref:api/README.adoc[Api usage samples]
** xref:api/compute_nbody/README.adoc[Compute N-body❕]
*** xref:api/hpp_compute_nbody/README.adoc[hpp compute nbody❕]
** xref:api/dynamic_uniform_buffers/README.adoc[Dynamic uniform buffers❕]
*** xref:api/hpp_dynamic_uniform_buffers/README.adoc[hpp dynamic uniform buffers❕]
** xref:api/hdr/README.adoc[HDR❕]
*** xref:api/hpp_hdr/README.adoc[hpp hdr❕]
** xref:api/hello_triangle/README.adoc[Hello Triangle❕]
*** xref:api/hpp_hello_triangle/README.adoc[hpp hello triangle❕]
** xref:api/hlsl_shaders/README.adoc[HLSL Shaders]
*** xref:api/hpp_hlsl_shaders/README.adoc[hpp hlsl shaders]
** xref:api/instancing/README.adoc[Instancing❕]
*** xref:api/hpp_instancing/README.adoc[hpp instancing❕]
** xref:api/separate_image_sampler/README.adoc[Separate image sampler]
*** xref:api/hpp_separate_image_sampler/README.adoc[hpp separate image sampler]
** xref:api/terrain_tessellation/README.adoc[Terrain tessellation❕]
*** xref:api/hpp_terrain_tessellation/README.adoc[hpp terrain tessellation❕]
** xref:api/texture_loading/README.adoc[Texture loading❕]
*** xref:api/hpp_texture_loading/README.adoc[hpp texture loading❕]
** xref:api/texture_mipmap_generation/README.adoc[Texture mipmap generation]
*** xref:api/hpp_texture_mipmap_generation/README.adoc[hpp texture mipmap generation]
** xref:api/timestamp_queries/README.adoc[Timestamp queries]
*** xref:api/hpp_timestamp_queries/README.adoc[hpp timestamp queries]
* xref:extensions/README.adoc[Extension usage samples]
** xref:extensions/buffer_device_address/README.adoc[Buffer device address]
** xref:extensions/calibrated_timestamps/README.adoc[Calibrated timestamps]
** xref:extensions/conditional_rendering/README.adoc[Conditional rendering]
** xref:extensions/conservative_rasterization/README.adoc[Conservative rasterization❕]
** xref:extensions/debug_utils/README.adoc[Debug utils]
** xref:extensions/descriptor_buffer_basic/README.adoc[Descriptor buffer basic]
** xref:extensions/descriptor_indexing/README.adoc[Descriptor indexing]
** xref:extensions/dynamic_rendering/README.adoc[Dynamic rendering]
** xref:extensions/extended_dynamic_state2/README.adoc[Extended dynamic state2]
** xref:extensions/fragment_shader_barycentric/README.adoc[Fragment shader barycentric]
** xref:extensions/fragment_shading_rate/README.adoc[Fragment shading rate❕]
** xref:extensions/fragment_shading_rate_dynamic/README.adoc[Fragment shading rate dynamic]
** xref:extensions/full_screen_exclusive/README.adoc[Full screen exclusive]
** xref:extensions/graphics_pipeline_library/README.adoc[Graphics pipeline library]
** xref:extensions/logic_op_dynamic_state/README.adoc[Logic op dynamic state]
** xref:extensions/memory_budget/README.adoc[Memory budget]
** xref:extensions/mesh_shader_culling/README.adoc[Mesh shader culling]
** xref:extensions/mesh_shading/README.adoc[Mesh shading❕]
** xref:extensions/open_cl_interop/README.adoc[OpenCL interop (Cross-vendor)]
** xref:extensions/open_cl_interop_arm/README.adoc[OpenCl interop (Arm)]
** xref:extensions/open_gl_interop/README.adoc[OpenGL interop❕]
** xref:extensions/portability/README.adoc[Portability]
** xref:extensions/push_descriptors/README.adoc[Push descriptors❕]
** xref:extensions/raytracing_basic/README.adoc[Raytracing basic❕]
** xref:extensions/raytracing_extended/README.adoc[Raytracing extended]
** xref:extensions/ray_queries/README.adoc[Ray queries❕]
** xref:extensions/ray_tracing_reflection/README.adoc[Ray tracing reflection]
** xref:extensions/synchronization_2/README.adoc[Synchronization 2❕]
** xref:extensions/timeline_semaphore/README.adoc[Timeline semaphore]
** xref:extensions/vertex_dynamic_state/README.adoc[Vertex dynamic state]
* xref:performance/README.adoc[Performance samples]
** xref:performance/16bit_arithmetic/README.adoc[16bit arithmetic]
** xref:performance/16bit_storage_input_output/README.adoc[16bit storage input output]
** xref:performance/afbc/README.adoc[AFBC]
** xref:performance/async_compute/README.adoc[Async compute]
** xref:performance/command_buffer_usage/README.adoc[Command buffer usage]
** xref:performance/constant_data/README.adoc[Constant data]
** xref:performance/descriptor_management/README.adoc[Descriptor management]
** xref:performance/layout_transitions/README.adoc[Layout transitions]
** xref:performance/msaa/README.adoc[MSAA]
** xref:performance/multithreading_render_passes/README.adoc[Multithreading render passes]
** xref:performance/multi_draw_indirect/README.adoc[Multi draw indirect]
** xref:performance/pipeline_barriers/README.adoc[Pipeline barriers]
** xref:performance/pipeline_cache/README.adoc[Pipeline cache]
*** xref:performance/hpp_pipeline_cache/README.adoc[hpp pipeline cache]
** xref:performance/render_passes/README.adoc[Render passes]
** xref:performance/specialization_constants/README.adoc[Specialization constants]
** xref:performance/subpasses/README.adoc[Subpasses]
** xref:performance/surface_rotation/README.adoc[Surface rotation]
** xref:performance/swapchain_images/README.adoc[Swapchain images]
*** xref:performance/hpp_swapchain_images/README.adoc[hpp swapchain images]
** xref:performance/texture_compression_basisu/README.adoc[Texture compression basisu]
** xref:performance/texture_compression_comparison/README.adoc[Texture compression comparison❕]
** xref:performance/wait_idle/README.adoc[Wait idle]
* xref:tooling/README.adoc[Tooling samples]
** xref:tooling/profiles/README.adoc[Profiles]
* xref:docs/README.adoc[General documentation]
** xref:docs/build.adoc[Build guide]
** xref:docs/create_sample.adoc[Creating a new sample]
** xref:docs/debug_graphs.adoc[Debug graphics]
** xref:docs/memory_limits.adoc[Memory limits]
** xref:docs/misc.adoc[Miscellaneous]
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void fatalError(final String log_file) {
intent.setDataAndType(path, context.getContentResolver().getType(path));
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, Notifications.CHANNEL_ID)
.setSmallIcon(R.drawable.icon)
Expand Down
2 changes: 1 addition & 1 deletion framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ set(CORE_FILES
core/hpp_buffer.cpp
core/hpp_command_buffer.cpp
core/hpp_command_pool.cpp
core/hpp_debug.cpp
core/hpp_device.cpp
core/hpp_image.cpp
core/hpp_image_view.cpp
Expand All @@ -313,7 +314,6 @@ set(CORE_FILES
core/hpp_queue.cpp
core/hpp_sampler.cpp
core/hpp_swapchain.cpp
core/hpp_vulkan_resource.cpp
)

set(PLATFORM_FILES
Expand Down
63 changes: 33 additions & 30 deletions framework/buffer_pool.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2019-2022, Arm Limited and Contributors
/* Copyright (c) 2019-2023, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -50,21 +50,29 @@ BufferBlock::BufferBlock(Device &device, VkDeviceSize size, VkBufferUsageFlags u
}
}

BufferAllocation BufferBlock::allocate(const uint32_t allocate_size)
VkDeviceSize BufferBlock::aligned_offset() const
{
assert(allocate_size > 0 && "Allocation size must be greater than zero");
return (offset + alignment - 1) & ~(alignment - 1);
}

auto aligned_offset = (offset + alignment - 1) & ~(alignment - 1);
bool BufferBlock::can_allocate(VkDeviceSize size) const
{
assert(size > 0 && "Allocation size must be greater than zero");
return (aligned_offset() + size <= buffer.get_size());
}

if (aligned_offset + allocate_size > buffer.get_size())
BufferAllocation BufferBlock::allocate(VkDeviceSize size)
{
if (can_allocate(size))
{
// No more space available from the underlying buffer, return empty allocation
return BufferAllocation{};
// Move the current offset and return an allocation
auto aligned = aligned_offset();
offset = aligned + size;
return BufferAllocation{buffer, size, aligned};
}

// Move the current offset and return an allocation
offset = aligned_offset + allocate_size;
return BufferAllocation{buffer, allocate_size, aligned_offset};
// No more space available from the underlying buffer, return empty allocation
return BufferAllocation{};
}

VkDeviceSize BufferBlock::get_size() const
Expand All @@ -87,28 +95,25 @@ BufferPool::BufferPool(Device &device, VkDeviceSize block_size, VkBufferUsageFla

BufferBlock &BufferPool::request_buffer_block(const VkDeviceSize minimum_size, bool minimal)
{
// Find the first block in the range of the inactive blocks
// which can fit the minimum size
auto it = std::upper_bound(buffer_blocks.begin() + active_buffer_block_count, buffer_blocks.end(), minimum_size,
[](const VkDeviceSize &a, const std::unique_ptr<BufferBlock> &b) -> bool { return a <= b->get_size(); });

if (it != buffer_blocks.end())
// Find a block in the range of the blocks which can fit the minimum size
auto it = minimal ? std::find_if(buffer_blocks.begin(),
buffer_blocks.end(),
[&minimum_size](const std::unique_ptr<BufferBlock> &buffer_block) { return (buffer_block->get_size() == minimum_size) && buffer_block->can_allocate(minimum_size); }) :
std::find_if(buffer_blocks.begin(),
buffer_blocks.end(),
[&minimum_size](const std::unique_ptr<BufferBlock> &buffer_block) { return buffer_block->can_allocate(minimum_size); });

if (it == buffer_blocks.end())
{
// Recycle inactive block
active_buffer_block_count++;
return *it->get();
}

LOGD("Building #{} buffer block ({})", buffer_blocks.size(), usage);

VkDeviceSize new_block_size = minimal ? minimum_size : std::max(block_size, minimum_size);
LOGD("Building #{} buffer block ({})", buffer_blocks.size(), usage);

// Create a new block, store and return it
buffer_blocks.emplace_back(std::make_unique<BufferBlock>(device, new_block_size, usage, memory_usage));
VkDeviceSize new_block_size = minimal ? minimum_size : std::max(block_size, minimum_size);

auto &block = buffer_blocks[active_buffer_block_count++];
// Create a new block and get the iterator on it
it = buffer_blocks.emplace(buffer_blocks.end(), std::make_unique<BufferBlock>(device, new_block_size, usage, memory_usage));
}

return *block.get();
return *it->get();
}

void BufferPool::reset()
Expand All @@ -117,8 +122,6 @@ void BufferPool::reset()
{
buffer_block->reset();
}

active_buffer_block_count = 0;
}

BufferAllocation::BufferAllocation(core::Buffer &buffer, VkDeviceSize size, VkDeviceSize offset) :
Expand Down
21 changes: 16 additions & 5 deletions framework/buffer_pool.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2019-2022, Arm Limited and Contributors
/* Copyright (c) 2019-2023, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -75,15 +75,29 @@ class BufferBlock
public:
BufferBlock(Device &device, VkDeviceSize size, VkBufferUsageFlags usage, VmaMemoryUsage memory_usage);

/**
* @brief check if this BufferBlock can allocate a given amount of memory
* @param size the number of bytes to check
* @return \c true if \a size bytes can be allocated from this \c BufferBlock, otherwise \c false.
*/
bool can_allocate(VkDeviceSize size) const;

/**
* @return An usable view on a portion of the underlying buffer
*/
BufferAllocation allocate(uint32_t size);
BufferAllocation allocate(VkDeviceSize size);

VkDeviceSize get_size() const;

void reset();

private:
/**
* @ brief Determine the current aligned offset.
* @return The current aligned offset.
*/
VkDeviceSize aligned_offset() const;

private:
core::Buffer buffer;

Expand Down Expand Up @@ -131,8 +145,5 @@ class BufferPool
VkBufferUsageFlags usage{};

VmaMemoryUsage memory_usage{};

/// Numbers of active blocks from the start of buffer_blocks
uint32_t active_buffer_block_count{0};
};
} // namespace vkb
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
Loading

0 comments on commit cbb2b9d

Please sign in to comment.