Skip to content

layers: Suppress incorrect validation error for buffer_reference#5349

Merged
spencer-lunarg merged 1 commit intoKhronosGroup:mainfrom
piofra01-arm:suppress-buf-ref-error
Mar 5, 2023
Merged

layers: Suppress incorrect validation error for buffer_reference#5349
spencer-lunarg merged 1 commit intoKhronosGroup:mainfrom
piofra01-arm:suppress-buf-ref-error

Conversation

@piofra01-arm
Copy link
Copy Markdown
Contributor

SHADER_MODULE_STATE::GetBaseType returns zero when passed a physical storage buffer to a struct, which later results in a validation error, despite no check whether structs passed between shader stages are compatible. This change suppresses the validation error.

Conceptually, this change addresses a wider spectrum of cases, where in the TypesMatch function we failed to identify both of the compared types, and would return false (types don't match). Currently the only clear path for this to happen is dealing with a physical storage buffer to a struct, in which case a potentially unhelpful validation error is produced:

Validation Error: [ UNASSIGNED-CoreValidation-Shader-InterfaceTypeMismatch ] Object 0: handle = 0x9294aa0000036c76, type = VK_OBJECT_TYPE_SHADER_MODULE; | MessageID = 0xb6cf33fe | Type mismatch on location 0.0, between vertex shader and fragment shader: 'ptr to Output ptr to PhysicalStorageBuffer struct of (sint32, sint32)' vs 'ptr to Input ptr to PhysicalStorageBuffer struct of (sint32, sint32)'

This logic seems to hold for a general case, where both types are unknown - since we failed to identify parameter types, we cannot validate their compatibility.

Returning true in this case leads to some counter-intuitive logic, where true doesn't mean we verified the types match, rather, that we're not certain that they don't match. If this is not acceptable, I can refactor this to also be able to express the case where we were unable to compare the types.

Otherwise, TypesMatch is only used in one place, and is static within the shader_validation.cpp file, so this workaround doesn't introduce issues elsewhere.

Conceptually, failing to identify types in TypesMatch likely warrants its own validation warnings, but handling this is beyond the scope of this pull request.

An ideal solution would be to implement a mechanism to compare this type of parameters being passed between shader stages, at least for cases where they can be resolved, and validate struct compatibility. The above validation error shows the types are known, and BaseTypesMatch already contains the code for comparing structs. This is also beyond the scope of this pull request.

@piofra01-arm piofra01-arm requested a review from a team as a code owner February 27, 2023 19:30
@ci-tester-lunarg
Copy link
Copy Markdown
Collaborator

Author piofra01-arm not on autobuild list. Waiting for curator authorization before starting CI build.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 27, 2023

CLA assistant check
All committers have signed the CLA.

@ci-tester-lunarg
Copy link
Copy Markdown
Collaborator

CI Vulkan-ValidationLayers build queued with queue ID 28684.

@ci-tester-lunarg
Copy link
Copy Markdown
Collaborator

CI Vulkan-ValidationLayers build # 10886 running.

@ci-tester-lunarg
Copy link
Copy Markdown
Collaborator

CI Vulkan-ValidationLayers build # 10886 passed.

@juan-lunarg
Copy link
Copy Markdown
Contributor

juan-lunarg commented Feb 27, 2023

@spencer-lunarg
Copy link
Copy Markdown
Contributor

I really want a test to prevent regression of this. Do you have a SPIR-V example that was hitting this, I am willing to add the test if you don't want to

@ci-tester-lunarg
Copy link
Copy Markdown
Collaborator

Author piofra01-arm not on autobuild list. Waiting for curator authorization before starting CI build.

@piofra01-arm piofra01-arm force-pushed the suppress-buf-ref-error branch from 22827c3 to f065e1c Compare March 2, 2023 10:02
@ci-tester-lunarg
Copy link
Copy Markdown
Collaborator

Author piofra01-arm not on autobuild list. Waiting for curator authorization before starting CI build.

@piofra01-arm piofra01-arm changed the title layers: Suppress buffer_reference incompatibility validation error. layers: Suppress incorrect validation error for buffer_reference Mar 2, 2023
@piofra01-arm
Copy link
Copy Markdown
Contributor Author

Here are the shaders used in the test where the issue was spotted:

5349.vert.txt

5349.frag.txt

The test mostly just draws a quad, the only twist is that it uses data from the shared buffer in the fragment shader. It doesn't do anything special, besides setting up basic scaffolding to create the buffer and pass it to the vertex shader.

Specifically:

  • The shared buffer is created with usage flags: VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT_KHR | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT and alloc flag: VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR.
  • We instantiate some test data and upload it to the buffer.
  • Then the shared buffer is referenced with a VkDeviceAddress, whose value is then stored in yet another buffer that is passed to the vertex shader.

The input description/state looks as follows:

	/* Vertex input descriptions */
	VkVertexInputBindingDescription binding_desc[2] = {};
	binding_desc[0].binding = 0;
	binding_desc[0].stride = sizeof(float) * 4;
	binding_desc[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
	binding_desc[1].binding = 1;
	binding_desc[1].stride = sizeof(VkDeviceAddress);
	binding_desc[1].inputRate = VK_VERTEX_INPUT_RATE_INSTANCE;

	/* Vertex input attribute descriptions */
	VkVertexInputAttributeDescription attributes[2] = {};
	attributes[0].location = 0;
	attributes[0].binding = binding_desc[0].binding;
	attributes[0].format = VK_FORMAT_R32G32B32A32_SFLOAT;
	attributes[0].offset = 0;
	attributes[1].location = 1;
	attributes[1].binding = binding_desc[1].binding;
	attributes[1].format = VK_FORMAT_R32G32_UINT;
	attributes[1].offset = 0;

	/* Vertex input state */
	VkPipelineVertexInputStateCreateInfo pipe_vert_state_create_info = {};
	pipe_vert_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
	pipe_vert_state_create_info.pNext = nullptr;
	pipe_vert_state_create_info.vertexBindingDescriptionCount = 2;
	pipe_vert_state_create_info.pVertexBindingDescriptions = binding_desc;
	pipe_vert_state_create_info.vertexAttributeDescriptionCount = 2;
	pipe_vert_state_create_info.pVertexAttributeDescriptions = attributes;

@spencer-lunarg spencer-lunarg self-assigned this Mar 2, 2023
SHADER_MODULE_STATE::GetBaseType returns zero when passed
a physical storage buffer to a struct, which later results
in a validation error, despite no check whether structs passed
between shader stages are compatible.
This change suppresses the validation error.
@piofra01-arm piofra01-arm force-pushed the suppress-buf-ref-error branch from f065e1c to 13abd6e Compare March 3, 2023 09:49
@ci-tester-lunarg
Copy link
Copy Markdown
Collaborator

Author piofra01-arm not on autobuild list. Waiting for curator authorization before starting CI build.

@spencer-lunarg
Copy link
Copy Markdown
Contributor

@piofra01-arm thanks for the descriptive example. I am going to quick write up a negative test to

  1. Prevent future regressions
  2. Make sure this is the actual correct fix and that there isn't something more subtle that needs to be fixed

Copy link
Copy Markdown
Contributor

@spencer-lunarg spencer-lunarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So looking into this, the real issue is I wasn't aware that you could use a PhysicalStorageBuffer struct as a shader interface type

I wrote up some test to make sure to test this correctly

Because currently we are falsely reporting any PhysicalStorageBuffer interface, I am ok for taking this change now until I finish up my change to correctly check these types of interfaces (Will create an issue once this is merged to track it)

@ci-tester-lunarg
Copy link
Copy Markdown
Collaborator

CI Vulkan-ValidationLayers build queued with queue ID 31975.

@ci-tester-lunarg
Copy link
Copy Markdown
Collaborator

CI Vulkan-ValidationLayers build # 10967 running.

@ci-tester-lunarg
Copy link
Copy Markdown
Collaborator

CI Vulkan-ValidationLayers build # 10967 passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants