mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-25 04:50:04 +00:00
Add AliasedPointer decoration (#5635)
Fix #5607 When inlining, decorate return variable with AliasedPointer if the storage class of the pointee type is PhysicalStorageBuffer.
This commit is contained in:
parent
24f2cdad8e
commit
ade1f7cfd7
@ -213,6 +213,19 @@ uint32_t InlinePass::CreateReturnVar(
|
||||
{(uint32_t)spv::StorageClass::Function}}}));
|
||||
new_vars->push_back(std::move(var_inst));
|
||||
get_decoration_mgr()->CloneDecorations(calleeFn->result_id(), returnVarId);
|
||||
|
||||
// Decorate the return var with AliasedPointer if the storage class of the
|
||||
// pointee type is PhysicalStorageBuffer.
|
||||
auto const pointee_type =
|
||||
type_mgr->GetType(returnVarTypeId)->AsPointer()->pointee_type();
|
||||
if (pointee_type->AsPointer() != nullptr) {
|
||||
if (pointee_type->AsPointer()->storage_class() ==
|
||||
spv::StorageClass::PhysicalStorageBuffer) {
|
||||
get_decoration_mgr()->AddDecoration(
|
||||
returnVarId, uint32_t(spv::Decoration::AliasedPointer));
|
||||
}
|
||||
}
|
||||
|
||||
return returnVarId;
|
||||
}
|
||||
|
||||
|
@ -4422,6 +4422,55 @@ OpFunctionEnd
|
||||
SinglePassRunAndMatch<InlineExhaustivePass>(text, true);
|
||||
}
|
||||
|
||||
TEST_F(InlineTest, DecorateReturnVariableWithAliasedPointer) {
|
||||
const std::string text = R"(OpCapability Int64
|
||||
OpCapability VariablePointers
|
||||
OpCapability PhysicalStorageBufferAddresses
|
||||
OpCapability Shader
|
||||
OpExtension "SPV_KHR_storage_buffer_storage_class"
|
||||
OpExtension "SPV_KHR_variable_pointers"
|
||||
OpExtension "SPV_KHR_physical_storage_buffer"
|
||||
OpMemoryModel PhysicalStorageBuffer64 GLSL450
|
||||
OpEntryPoint GLCompute %1 "main"
|
||||
OpExecutionMode %1 LocalSize 8 8 1
|
||||
OpDecorate %_ptr_PhysicalStorageBuffer__struct_5 ArrayStride 8
|
||||
OpMemberDecorate %_struct_3 0 Offset 0
|
||||
OpMemberDecorate %_struct_3 1 Offset 8
|
||||
OpDecorate %_ptr_PhysicalStorageBuffer_int ArrayStride 4
|
||||
OpMemberDecorate %_struct_5 0 Offset 0
|
||||
OpMemberDecorate %_struct_5 1 Offset 4
|
||||
OpDecorate %6 Aliased
|
||||
; CHECK: OpDecorate %22 AliasedPointer
|
||||
%void = OpTypeVoid
|
||||
%8 = OpTypeFunction %void
|
||||
%int = OpTypeInt 32 1
|
||||
%int_0 = OpConstant %int 0
|
||||
OpTypeForwardPointer %_ptr_PhysicalStorageBuffer__struct_5 PhysicalStorageBuffer
|
||||
%_struct_3 = OpTypeStruct %int %_ptr_PhysicalStorageBuffer__struct_5
|
||||
%_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int
|
||||
%_struct_5 = OpTypeStruct %int %int
|
||||
%11 = OpTypeFunction %_ptr_PhysicalStorageBuffer_int %_ptr_PhysicalStorageBuffer__struct_5
|
||||
%_ptr_PhysicalStorageBuffer__struct_5 = OpTypePointer PhysicalStorageBuffer %_struct_5
|
||||
%_ptr_Function__struct_3 = OpTypePointer Function %_struct_3
|
||||
%1 = OpFunction %void None %8
|
||||
%13 = OpLabel
|
||||
%14 = OpVariable %_ptr_Function__struct_3 Function
|
||||
%15 = OpLoad %_struct_3 %14
|
||||
%16 = OpCompositeExtract %_ptr_PhysicalStorageBuffer__struct_5 %15 1
|
||||
%17 = OpFunctionCall %_ptr_PhysicalStorageBuffer_int %18 %16
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
%18 = OpFunction %_ptr_PhysicalStorageBuffer_int None %11
|
||||
%6 = OpFunctionParameter %_ptr_PhysicalStorageBuffer__struct_5
|
||||
%19 = OpLabel
|
||||
%20 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %6 %int_0
|
||||
OpReturnValue %20
|
||||
OpFunctionEnd)";
|
||||
|
||||
SetTargetEnv(SPV_ENV_VULKAN_1_2);
|
||||
SinglePassRunAndMatch<InlineExhaustivePass>(text, true);
|
||||
}
|
||||
|
||||
// TODO(greg-lunarg): Add tests to verify handling of these cases:
|
||||
//
|
||||
// Empty modules
|
||||
|
Loading…
Reference in New Issue
Block a user