Repository navigation
gpuav: Clamp SetMeshOutputsEXT counts in safe mode - #13246
Conversation
|
Author apollo-2006 not on autobuild list. Waiting for curator authorization before starting CI build. |
spencer-lunarg
left a comment
There was a problem hiding this comment.
Seem good, just 2 things
| m_errorMonitor->VerifyFound(); | ||
| } | ||
|
|
||
| TEST_F(NegativeGpuAVMesh, PrimitiveCountPoints) { |
There was a problem hiding this comment.
can you write a simple test (similar to MultipleSetMeshOutput) that does a
if (condition) {
SetMeshOutputsEXT(v0, p0); // valid
} else {
SetMeshOutputsEXT(v1, p1); // invalid
}
does two draws, and only gets one invalid error message (in safe mode)
There was a problem hiding this comment.
Added NegativeGpuAVMesh.MultipleSetMeshOutput for this: draw 0 takes the valid branch and draw 1 the invalid one, and safe mode reports exactly one 07332. I also checked that it fails when both draws go invalid, so it really does catch a second error.
| const uint32_t uint32_type_id = type_manager_.GetTypeInt(32, false).Id(); | ||
| const uint32_t bool_type_id = type_manager_.GetTypeBool().Id(); | ||
|
|
||
| auto clamp = [&](uint32_t word_index, uint32_t max_id) { |
There was a problem hiding this comment.
its only two times, rather no lambda please, easier to debug
// Clamp vertices
{
const uint32_t count_id = set_mesh_outputs_inst.Word(1);
const uint32_t in_range_id = module_.TakeNextId();
const uint32_t clamped_id = module_.TakeNextId();
block.CreateInstruction(spv::OpULessThanEqual, {bool_type_id, in_range_id, count_id, output_vertices_id_}, inst_it);
block.CreateInstruction(spv::OpSelect, {uint32_type_id, clamped_id, in_range_id, count_id, output_vertices_id_}, inst_it);
set_mesh_outputs_inst.UpdateWord(1, clamped_id);
}
// Clamp primitives
{
const uint32_t count_id = set_mesh_outputs_inst.Word(2);
const uint32_t in_range_id = module_.TakeNextId();
const uint32_t clamped_id = module_.TakeNextId();
block.CreateInstruction(spv::OpULessThanEqual, {bool_type_id, in_range_id, count_id, output_primitives_id_}, inst_it);
block.CreateInstruction(spv::OpSelect, {uint32_type_id, clamped_id, in_range_id, count_id, output_primitives_id_}, inst_it);
set_mesh_outputs_inst.UpdateWord(2, clamped_id);
}
There was a problem hiding this comment.
Good call, that does read a lot more clearly without it. Switched it over to the two explicit blocks.
Safe mode put OpSetMeshOutputsEXT behind the validation result and called it with a hardcoded (3, 1) otherwise, with a TODO to use the OutputVertices/OutputPrimitivesEXT values. (3, 1) is out of range for shaders that declare fewer than 3 vertices. Clamp the counts to OutputVertices/OutputPrimitivesEXT with OpSelect instead, so the call is made exactly once with valid counts and without a branch.
4d2e6bb to
a32e502
Compare
|
Author apollo-2006 not on autobuild list. Waiting for curator authorization before starting CI build. |
|
CI Vulkan-ValidationLayers build queued with queue ID 135580. |
|
CI Vulkan-ValidationLayers build # 24696 running. |
|
CI Vulkan-ValidationLayers build # 24696 failed. |
While working through the GPU-AV mesh shading pass, I came across the TODO in
InjectFunctionPreabout using theOutputVertices/OutputPrimitivesEXTvalues forOpSetMeshOutputsEXTin safe mode, and thought I'd have a go at it.Right now, safe mode moves
OpSetMeshOutputsEXTinto the "valid" branch and putsSetMeshOutputsEXT(3, 1)in the "invalid" one. That works nicely for the common triangle case, but for a shader that declares something likemax_vertices = 1, the 3 ends up being out of range itself.This keeps the error reporting exactly as it is, and instead of branching, it rewrites the call's operands to
min(count, max)using the pass's existingoutput_vertices_id_/output_primitives_id_constants, so the call still happens exactly once with counts the driver can handle:With that in place, the
OpSetMeshOutputsEXTspecial case inInjectFunctionPreisn't needed anymore, so I removed it.A nice side effect of not having a branch: lavapipe runs both sides of an if/else under a mask and applies whichever
SetMeshOutputsEXTcomes last, so on mainNegativeGpuAVMesh.PrimitiveCount(which runs in safe mode) segfaults it. That one is a lavapipe bug on the Mesa side, but this change avoids tripping over it here.Tests:
NegativeGpuAVMesh.PrimitiveCountPoints: a points shader withmax_vertices = 1and a count of 60 from a buffer. It reports 07332, and the instrumented shader clamps the count to 1.NegativeGpuAVMesh.MultipleSetMeshOutput: an if/else with a valid and an invalidSetMeshOutputsEXT, two draws taking one branch each, and exactly one 07332 in safe mode.NegativeGpuAVMesh.PrimitiveCountandPrimitiveCountPointspass on RADV (RX 9070 XT) both on main and with this change; on lavapipe both segfault on main and pass with it.spirv-valfor both.PrimitiveCountno longer crashing lavapipe, and nothing new fails or crashes.If you'd rather keep the branch and just use the execution-mode values in the else side instead, I'm very happy to switch it over to that.