Skip to content

Commit 6c4084e

Browse files
Merge pull request #98 from GPUOpen-LibrariesAndSDKs/update_wk34
Bug-fixes
2 parents 012eb15 + 913eed3 commit 6c4084e

9 files changed

Lines changed: 138 additions & 26 deletions

include/misc/buffer_create_info.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ namespace Anvil
212212
return m_usage_flags;
213213
}
214214

215+
/** Use to specify contents which should be uploaded to a buffer at memory block assignment time.
216+
*
217+
* Note that this setting will be ignored for partially-resident buffers.
218+
*
219+
* The specified pointer must remain valid until Buffer::set_nonsparse_memory() call time.
220+
*
221+
* @param in_client_data_ptr Pointer to data storage holding contents the created buffer should be filled with.
222+
* Must remain valid until memory block assignment time.
223+
*/
215224
void set_client_data(const void* const in_client_data_ptr)
216225
{
217226
m_client_data_ptr = in_client_data_ptr;

include/misc/render_pass_create_info.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,16 @@ namespace Anvil
377377
return m_device_ptr;
378378
}
379379

380+
/* Returns the largest location assigned to color attachments for the specified subpass.
381+
*
382+
* If no color attachments have been defined for the queried subpass, UINT32_MAX is returned.
383+
*
384+
* @param in_subpass_id ID of the subpass to use for the query.
385+
*
386+
* @return As per description.
387+
**/
388+
uint32_t get_max_color_location_used_by_subpass(const SubPassID& in_subpass_id) const;
389+
380390
/** Returns the number of added attachments */
381391
uint32_t get_n_attachments() const
382392
{

include/misc/types_struct.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,8 @@ namespace Anvil
731731
return &image_barrier_vk;
732732
}
733733

734+
bool operator==(const ImageBarrier& in_barrier) const;
735+
734736
private:
735737
ImageBarrier& operator=(const ImageBarrier&);
736738
} ImageBarrier;

include/wrappers/command_buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ namespace Anvil
481481
* Calling this function for a command buffer which has not been put into a recording mode
482482
* (by issuing a start_recording() call earlier) will result in an assertion failure.
483483
*
484-
* It is also illegal to call this function when not recording renderpass commands. Doing so
484+
* It is also illegal to call this function when recording renderpass commands. Doing so
485485
* will also result in an assertion failure.
486486
*
487487
* Any Vulkan object wrapper instances passed to this function are going to be retained,

src/misc/render_pass_create_info.cpp

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#include <algorithm>
2626
#include <cmath>
2727

28+
#if defined(max)
29+
#undef max
30+
#endif
2831

2932
Anvil::RenderPassCreateInfo::RenderPassCreateInfo(const Anvil::BaseDevice* in_device_ptr)
3033
:m_device_ptr (in_device_ptr),
@@ -715,6 +718,31 @@ bool Anvil::RenderPassCreateInfo::get_depth_stencil_attachment_properties(Render
715718
return result;
716719
}
717720

721+
/* Please see header for specification */
722+
uint32_t Anvil::RenderPassCreateInfo::get_max_color_location_used_by_subpass(const SubPassID& in_subpass_id) const
723+
{
724+
uint32_t result = UINT32_MAX;
725+
auto subpass_iterator = (m_subpasses.size() > in_subpass_id) ? m_subpasses.begin() + in_subpass_id : m_subpasses.end();
726+
727+
if (subpass_iterator == m_subpasses.end() )
728+
{
729+
anvil_assert(subpass_iterator != m_subpasses.end() );
730+
731+
goto end;
732+
}
733+
734+
result = 0;
735+
736+
for (const auto& current_color_attachment_data : (*subpass_iterator)->color_attachments_map)
737+
{
738+
result = std::max(result,
739+
current_color_attachment_data.first);
740+
}
741+
742+
end:
743+
return result;
744+
}
745+
718746
/* Please see header for specification */
719747
bool Anvil::RenderPassCreateInfo::get_subpass_n_attachments(SubPassID in_subpass_id,
720748
AttachmentType in_attachment_type,
@@ -809,12 +837,22 @@ bool Anvil::RenderPassCreateInfo::get_subpass_attachment_properties(SubPassID
809837
: (in_attachment_type == ATTACHMENT_TYPE_INPUT) ? &subpass_ptr->input_attachments_map
810838
: &subpass_ptr->resolved_attachments_map;
811839

812-
auto iterator = subpass_attachments_ptr->find(in_n_subpass_attachment);
840+
auto iterator = subpass_attachments_ptr->begin();
813841

814-
if (iterator == subpass_attachments_ptr->end() )
842+
for (uint32_t n_key = 0;
843+
n_key < in_n_subpass_attachment;
844+
++n_key)
815845
{
816-
anvil_assert_fail();
846+
if (iterator == subpass_attachments_ptr->end() )
847+
{
848+
goto end;
849+
}
850+
851+
iterator ++;
852+
}
817853

854+
if (iterator == subpass_attachments_ptr->end() )
855+
{
818856
goto end;
819857
}
820858

src/misc/types_struct.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ Anvil::ImageFormatProperties::ImageFormatProperties(const VkImageFormatPropertie
745745
/** Please see header for specification */
746746
Anvil::ImageBarrier::ImageBarrier(const ImageBarrier& in)
747747
{
748+
by_region = in.by_region;
748749
dst_access_mask = in.dst_access_mask;
749750
dst_queue_family_index = in.dst_queue_family_index;
750751
image = in.image;
@@ -805,6 +806,30 @@ Anvil::ImageBarrier::~ImageBarrier()
805806
/* Stub */
806807
}
807808

809+
bool Anvil::ImageBarrier::operator==(const ImageBarrier& in_barrier) const
810+
{
811+
bool result = true;
812+
813+
result &= (dst_access_mask == in_barrier.dst_access_mask);
814+
result &= (src_access_mask == in_barrier.src_access_mask);
815+
816+
result &= (by_region == in_barrier.by_region);
817+
result &= (dst_queue_family_index == in_barrier.dst_queue_family_index);
818+
result &= (image == in_barrier.image);
819+
result &= (image_ptr == in_barrier.image_ptr);
820+
result &= (new_layout == in_barrier.new_layout);
821+
result &= (old_layout == in_barrier.old_layout);
822+
result &= (src_queue_family_index == in_barrier.src_queue_family_index);
823+
824+
result &= (subresource_range.aspectMask == in_barrier.subresource_range.aspectMask);
825+
result &= (subresource_range.baseArrayLayer == in_barrier.subresource_range.baseArrayLayer);
826+
result &= (subresource_range.baseMipLevel == in_barrier.subresource_range.baseMipLevel);
827+
result &= (subresource_range.layerCount == in_barrier.subresource_range.layerCount);
828+
result &= (subresource_range.levelCount == in_barrier.subresource_range.levelCount);
829+
830+
return result;
831+
}
832+
808833
Anvil::KHR16BitStorageFeatures::KHR16BitStorageFeatures()
809834
{
810835
is_input_output_storage_supported = false;

src/wrappers/graphics_pipeline_manager.cpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,18 @@ bool Anvil::GraphicsPipelineManager::bake()
240240
VkPipelineColorBlendStateCreateInfo color_blend_state_create_info;
241241
VkLogicOp logic_op;
242242
bool logic_op_enabled = false;
243+
uint32_t max_location_index = UINT32_MAX;
243244
const uint32_t start_offset = static_cast<uint32_t>(color_blend_attachment_states_vk_cache.size() );
244245

246+
max_location_index = current_pipeline_renderpass_ptr->get_render_pass_create_info()->get_max_color_location_used_by_subpass(current_pipeline_subpass_id);
247+
245248
current_pipeline_create_info_ptr->get_blending_properties(&blend_constant_ptr,
246249
nullptr); /* out_opt_n_blend_attachments_ptr */
247250

248251
current_pipeline_create_info_ptr->get_logic_op_state(&logic_op_enabled,
249252
&logic_op);
250253

251-
color_blend_state_create_info.attachmentCount = subpass_n_color_attachments;
254+
color_blend_state_create_info.attachmentCount = max_location_index + 1;
252255
color_blend_state_create_info.flags = 0;
253256
color_blend_state_create_info.logicOp = logic_op;
254257
color_blend_state_create_info.logicOpEnable = (logic_op_enabled) ? VK_TRUE : VK_FALSE;
@@ -260,24 +263,33 @@ bool Anvil::GraphicsPipelineManager::bake()
260263
blend_constant_ptr,
261264
sizeof(color_blend_state_create_info.blendConstants) );
262265

266+
anvil_assert(subpass_n_color_attachments <= current_pipeline_renderpass_ptr->get_render_pass_create_info()->get_n_attachments() );
267+
263268
for (uint32_t n_subpass_color_attachment = 0;
264-
n_subpass_color_attachment < subpass_n_color_attachments;
269+
n_subpass_color_attachment <= max_location_index;
265270
++n_subpass_color_attachment)
266271
{
267272
color_blend_attachment_states_vk_cache.push_back(VkPipelineColorBlendAttachmentState() );
268273

269274
VkPipelineColorBlendAttachmentState* blend_attachment_state_ptr = &color_blend_attachment_states_vk_cache.back();
275+
VkImageLayout dummy = VK_IMAGE_LAYOUT_MAX_ENUM;
270276
bool is_blending_enabled_for_attachment = false;
271-
272-
if (!current_pipeline_create_info_ptr->get_color_blend_attachment_properties(n_subpass_color_attachment,
273-
&is_blending_enabled_for_attachment,
274-
&blend_attachment_state_ptr->colorBlendOp,
275-
&blend_attachment_state_ptr->alphaBlendOp,
276-
&blend_attachment_state_ptr->srcColorBlendFactor,
277-
&blend_attachment_state_ptr->dstColorBlendFactor,
278-
&blend_attachment_state_ptr->srcAlphaBlendFactor,
279-
&blend_attachment_state_ptr->dstAlphaBlendFactor,
280-
&blend_attachment_state_ptr->colorWriteMask) )
277+
Anvil::RenderPassAttachmentID rp_attachment_id = UINT32_MAX;
278+
279+
if (!current_pipeline_renderpass_ptr->get_render_pass_create_info()->get_subpass_attachment_properties(current_pipeline_subpass_id,
280+
Anvil::ATTACHMENT_TYPE_COLOR,
281+
n_subpass_color_attachment,
282+
&rp_attachment_id,
283+
&dummy) || /* out_layout_ptr */
284+
!current_pipeline_create_info_ptr->get_color_blend_attachment_properties (rp_attachment_id,
285+
&is_blending_enabled_for_attachment,
286+
&blend_attachment_state_ptr->colorBlendOp,
287+
&blend_attachment_state_ptr->alphaBlendOp,
288+
&blend_attachment_state_ptr->srcColorBlendFactor,
289+
&blend_attachment_state_ptr->dstColorBlendFactor,
290+
&blend_attachment_state_ptr->srcAlphaBlendFactor,
291+
&blend_attachment_state_ptr->dstAlphaBlendFactor,
292+
&blend_attachment_state_ptr->colorWriteMask) )
281293
{
282294
/* The user has not defined blending properties for current color attachment. Use default state values .. */
283295
blend_attachment_state_ptr->blendEnable = VK_FALSE;
@@ -294,9 +306,7 @@ bool Anvil::GraphicsPipelineManager::bake()
294306
}
295307
else
296308
{
297-
anvil_assert(is_blending_enabled_for_attachment);
298-
299-
blend_attachment_state_ptr->blendEnable = VK_TRUE;
309+
blend_attachment_state_ptr->blendEnable = (is_blending_enabled_for_attachment) ? VK_TRUE : VK_FALSE;
300310
}
301311
}
302312

src/wrappers/memory_block.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -656,17 +656,26 @@ bool Anvil::MemoryBlock::read(VkDeviceSize in_start_offset,
656656
if ((m_create_info_ptr->get_memory_features() & Anvil::MEMORY_FEATURE_FLAG_HOST_COHERENT) == 0)
657657
{
658658
VkMappedMemoryRange mapped_memory_range;
659-
VkResult result_vk (VK_ERROR_INITIALIZATION_FAILED);
659+
const auto mem_block_size = m_create_info_ptr->get_size();
660+
const auto non_coherent_atom_size = m_create_info_ptr->get_device()->get_physical_device_properties().core_vk1_0_properties_ptr->limits.non_coherent_atom_size;
661+
VkResult result_vk = VK_ERROR_INITIALIZATION_FAILED;
660662

661663
anvil_assert (m_start_offset == 0);
662664
ANVIL_REDUNDANT_VARIABLE(result_vk);
663665

664666
mapped_memory_range.memory = m_memory;
665-
mapped_memory_range.offset = in_start_offset;
667+
mapped_memory_range.offset = Anvil::Utils::round_down(in_start_offset,
668+
non_coherent_atom_size);
666669
mapped_memory_range.pNext = nullptr;
667-
mapped_memory_range.size = in_size;
670+
mapped_memory_range.size = Anvil::Utils::round_up(in_size,
671+
non_coherent_atom_size);
668672
mapped_memory_range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
669673

674+
if (mapped_memory_range.size + mapped_memory_range.offset > mem_block_size)
675+
{
676+
mapped_memory_range.size = mem_block_size - mapped_memory_range.offset;
677+
}
678+
670679
result_vk = vkInvalidateMappedMemoryRanges(m_create_info_ptr->get_device()->get_device_vk(),
671680
1, /* memRangeCount */
672681
&mapped_memory_range);
@@ -746,16 +755,25 @@ bool Anvil::MemoryBlock::write(VkDeviceSize in_start_offset,
746755
if ((m_create_info_ptr->get_memory_features() & Anvil::MEMORY_FEATURE_FLAG_HOST_COHERENT) == 0)
747756
{
748757
VkMappedMemoryRange mapped_memory_range;
749-
VkResult result_vk (VK_ERROR_INITIALIZATION_FAILED);
758+
const auto mem_block_size = m_create_info_ptr->get_size();
759+
const auto non_coherent_atom_size = m_create_info_ptr->get_device()->get_physical_device_properties().core_vk1_0_properties_ptr->limits.non_coherent_atom_size;
760+
auto result_vk = VkResult(VK_ERROR_INITIALIZATION_FAILED);
750761

751762
ANVIL_REDUNDANT_VARIABLE(result_vk);
752763

753764
mapped_memory_range.memory = m_memory;
754-
mapped_memory_range.offset = in_start_offset;
765+
mapped_memory_range.offset = Anvil::Utils::round_down(in_start_offset,
766+
non_coherent_atom_size);
755767
mapped_memory_range.pNext = nullptr;
756-
mapped_memory_range.size = in_size;
768+
mapped_memory_range.size = Anvil::Utils::round_up(in_size,
769+
non_coherent_atom_size);
757770
mapped_memory_range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
758771

772+
if (mapped_memory_range.size + mapped_memory_range.offset > mem_block_size)
773+
{
774+
mapped_memory_range.size = mem_block_size - mapped_memory_range.offset;
775+
}
776+
759777
result_vk = vkFlushMappedMemoryRanges(m_create_info_ptr->get_device()->get_device_vk(),
760778
1, /* memRangeCount */
761779
&mapped_memory_range);

src/wrappers/pipeline_layout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ bool Anvil::PipelineLayout::bake(const std::vector<DescriptorSetCreateInfoUnique
7474
/* Convert descriptor set layouts to Vulkan equivalents */
7575
const VkDescriptorSetLayout dummy_ds_layout = m_device_ptr->get_dummy_descriptor_set_layout()->get_layout();
7676

77-
ds_layouts_vk.resize(in_ds_create_info_items_ptr->size() + 1,
77+
ds_layouts_vk.resize(in_ds_create_info_items_ptr->size(),
7878
dummy_ds_layout);
7979

8080
if (in_ds_create_info_items_ptr != nullptr &&

0 commit comments

Comments
 (0)