Skip to content

Commit

Permalink
tests: Test gpuav with shader objects and pipelines together
Browse files Browse the repository at this point in the history
  • Loading branch information
ziga-lunarg authored and spencer-lunarg committed Dec 28, 2024
1 parent 0401c38 commit 6151f60
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/unit/gpu_av_shader_object_positive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "../framework/descriptor_helper.h"
#include "../framework/shader_object_helper.h"
#include "../framework/shader_templates.h"
#include "../framework/pipeline_helper.h"

class PositiveGpuAVShaderObject : public GpuAVTest {
public:
Expand Down Expand Up @@ -453,3 +454,59 @@ TEST_F(PositiveGpuAVShaderObject, RestoreUserPushConstants2) {
}
graphics_storage_buffer.Memory().Unmap();
}

TEST_F(PositiveGpuAVShaderObject, DispatchShaderObjectAndPipeline) {
TEST_DESCRIPTION("GPU validation: Validate selection of which shaders get instrumented for GPU-AV");
InitBasicShaderObject();

AddRequiredFeature(vkt::Feature::robustBufferAccess);
const VkBool32 value = true;
const VkLayerSettingEXT setting = {OBJECT_LAYER_NAME, "gpuav_select_instrumented_shaders", VK_LAYER_SETTING_TYPE_BOOL32_EXT, 1,
&value};
VkLayerSettingsCreateInfoEXT layer_settings_create_info = {VK_STRUCTURE_TYPE_LAYER_SETTINGS_CREATE_INFO_EXT, nullptr, 1,
&setting};
RETURN_IF_SKIP(InitGpuAvFramework(&layer_settings_create_info));
InitState();

static const char comp_src[] = R"glsl(
#version 450
layout(local_size_x=16, local_size_x=1, local_size_x=1) in;
void main() {
}
)glsl";

const auto comp_spv = GLSLToSPV(VK_SHADER_STAGE_COMPUTE_BIT, comp_src);
VkShaderCreateInfoEXT comp_create_info = ShaderCreateInfo(comp_spv, VK_SHADER_STAGE_COMPUTE_BIT);

VkValidationFeatureEnableEXT enabled[] = {VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_EXT};
VkValidationFeaturesEXT features = vku::InitStructHelper();
features.enabledValidationFeatureCount = 1;
features.pEnabledValidationFeatures = enabled;
comp_create_info.pNext = &features;

const vkt::Shader compShader(*m_device, comp_create_info);

CreateComputePipelineHelper compute_pipe(*this);
compute_pipe.cs_ = std::make_unique<VkShaderObj>(this, comp_src, VK_SHADER_STAGE_COMPUTE_BIT);
compute_pipe.CreateComputePipeline();

vkt::Buffer indirect_dispatch_parameters_buffer(*m_device, sizeof(VkDispatchIndirectCommand),
VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT, kHostVisibleMemProps);
auto &indirect_dispatch_parameters =
*static_cast<VkDispatchIndirectCommand *>(indirect_dispatch_parameters_buffer.Memory().Map());
indirect_dispatch_parameters.x = 1u;
indirect_dispatch_parameters.y = 1u;
indirect_dispatch_parameters.z = 1u;
indirect_dispatch_parameters_buffer.Memory().Unmap();

m_command_buffer.Begin();
SetDefaultDynamicStatesExclude();
m_command_buffer.BindCompShader(compShader);
vk::CmdDispatchIndirect(m_command_buffer.handle(), indirect_dispatch_parameters_buffer.handle(), 0u);

vk::CmdBindPipeline(m_command_buffer.handle(), VK_PIPELINE_BIND_POINT_COMPUTE, compute_pipe.Handle());
vk::CmdDispatchIndirect(m_command_buffer.handle(), indirect_dispatch_parameters_buffer.handle(), 0u);

m_command_buffer.End();
}

0 comments on commit 6151f60

Please sign in to comment.