Skip to content

Commit

Permalink
tests: Add tests for VK_EXT_shader_object
Browse files Browse the repository at this point in the history
  • Loading branch information
ziga-lunarg committed Aug 19, 2023
1 parent ccdbc33 commit 9eaf317
Show file tree
Hide file tree
Showing 7 changed files with 7,901 additions and 206 deletions.
50 changes: 50 additions & 0 deletions tests/framework/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,56 @@ VkResult Shader::init_try(const Device &dev, const VkShaderCreateInfoEXT &info)
return err;
}

Shader::Shader(const Device &dev, const VkShaderStageFlagBits stage, const std::vector<uint32_t> &spv,
const VkDescriptorSetLayout *descriptorSetLayout, const VkPushConstantRange* pushConstRange) {
VkShaderCreateInfoEXT createInfo = LvlInitStruct<VkShaderCreateInfoEXT>();
createInfo.stage = stage;
createInfo.codeType = VK_SHADER_CODE_TYPE_SPIRV_EXT;
createInfo.codeSize = spv.size() * sizeof(spv[0]);
createInfo.pCode = spv.data();
createInfo.pName = "main";
if (descriptorSetLayout) {
createInfo.setLayoutCount = 1u;
createInfo.pSetLayouts = descriptorSetLayout;
}
if (pushConstRange) {
createInfo.pushConstantRangeCount = 1u;
createInfo.pPushConstantRanges = pushConstRange;
}
init(dev, createInfo);
}

Shader::Shader(const Device &dev, const VkShaderStageFlagBits stage, const std::vector<uint8_t> &binary,
const VkDescriptorSetLayout *descriptorSetLayout, const VkPushConstantRange *pushConstRange) {
VkShaderCreateInfoEXT createInfo = LvlInitStruct<VkShaderCreateInfoEXT>();
createInfo.stage = stage;
createInfo.codeType = VK_SHADER_CODE_TYPE_BINARY_EXT;
createInfo.codeSize = binary.size();
createInfo.pCode = binary.data();
createInfo.pName = "main";
if (descriptorSetLayout) {
createInfo.setLayoutCount = 1u;
createInfo.pSetLayouts = descriptorSetLayout;
}
if (pushConstRange) {
createInfo.pushConstantRangeCount = 1u;
createInfo.pPushConstantRanges = pushConstRange;
}
init(dev, createInfo);
}

Shader::Shader(const Device &dev, const VkShaderStageFlagBits stage, const std::vector<uint32_t> &spv,
VkShaderCreateFlagsEXT flags) {
VkShaderCreateInfoEXT createInfo = LvlInitStruct<VkShaderCreateInfoEXT>();
createInfo.flags = flags;
createInfo.stage = stage;
createInfo.codeType = VK_SHADER_CODE_TYPE_SPIRV_EXT;
createInfo.codeSize = spv.size() * sizeof(spv[0]);
createInfo.pCode = spv.data();
createInfo.pName = "main";
init(dev, createInfo);
}

NON_DISPATCHABLE_HANDLE_DTOR(Pipeline, vk::DestroyPipeline)

void Pipeline::init(const Device &dev, const VkGraphicsPipelineCreateInfo &info) {
Expand Down
6 changes: 6 additions & 0 deletions tests/framework/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,12 @@ class ShaderModule : public internal::NonDispHandle<VkShaderModule> {
class Shader : public internal::NonDispHandle<VkShaderEXT> {
public:
Shader(const Device &dev, const VkShaderCreateInfoEXT &info) { init(dev, info); }
Shader(const Device &dev, const VkShaderStageFlagBits stage, const std::vector<uint32_t> &spv,
const VkDescriptorSetLayout *descriptorSetLayout = nullptr, const VkPushConstantRange* pushConstRange = nullptr);
Shader(const Device &dev, const VkShaderStageFlagBits stage, const std::vector<uint8_t> &binary,
const VkDescriptorSetLayout *descriptorSetLayout = nullptr, const VkPushConstantRange *pushConstRange = nullptr);
Shader(const Device &dev, const VkShaderStageFlagBits stage, const std::vector<uint32_t> &spv,
VkShaderCreateFlagsEXT flags);
~Shader() noexcept;
void destroy() noexcept;

Expand Down
7 changes: 6 additions & 1 deletion tests/framework/layer_validation_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,13 @@ class NegativeShaderCompute : public ShaderComputeTest {};
class PositiveShaderCompute : public ShaderComputeTest {};

class ShaderObjectTest : public VkLayerTest {
vk_testing::Buffer vertexBuffer;

public:
void InitBasicShaderObject(void *pNextFeatures = nullptr, APIVersion targetApiVersion = VK_API_VERSION_1_1);
void InitBasicShaderObject(void *pNextFeatures = nullptr, APIVersion targetApiVersion = VK_API_VERSION_1_1, bool coreFeatures = true);
void BindVertFragShader(const vk_testing::Shader &vertShader, const vk_testing::Shader &fragShader);
void BindCompShader(const vk_testing::Shader &compShader);
void SetDefaultDynamicStates(const std::vector<VkDynamicState>& exclude = {}, bool tessellation = false, VkCommandBuffer commandBuffer = VK_NULL_HANDLE);
};
class NegativeShaderObject : public ShaderObjectTest {};
class PositiveShaderObject : public ShaderObjectTest {};
Expand Down
45 changes: 45 additions & 0 deletions tests/framework/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,38 @@ void VkRenderFramework::InitRenderTarget(uint32_t targets, VkImageView *dsBindin
m_renderPassBeginInfo.pClearValues = m_renderPassClearValues.data();
}

void VkRenderFramework::InitDynamicRenderTarget(VkFormat format) {
if (format != VK_FORMAT_UNDEFINED) {
m_render_target_fmt = format;
}

m_renderPassClearValues.clear();
VkClearValue clear = {};
clear.color = m_clear_color;

std::unique_ptr<VkImageObj> img(new VkImageObj(m_device));

VkFormatProperties props;

vk::GetPhysicalDeviceFormatProperties(m_device->phy().handle(), m_render_target_fmt, &props);

if (props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
img->Init(m_width, m_height, 1, m_render_target_fmt,
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
VK_IMAGE_TILING_OPTIMAL);
} else {
FAIL() << "Optimal tiling not allowed for render target";
}

m_framebuffer_attachments.push_back(img->targetView(m_render_target_fmt));
m_renderTargets.push_back(std::move(img));
}

VkImageView VkRenderFramework::GetDynamicRenderTarget() const {
assert(m_framebuffer_attachments.size() == 1);
return m_framebuffer_attachments[0];
}

void VkRenderFramework::DestroyRenderTarget() {
vk::DestroyRenderPass(device(), m_renderPass, nullptr);
m_renderPass = VK_NULL_HANDLE;
Expand Down Expand Up @@ -2249,6 +2281,19 @@ void VkCommandBufferObj::BeginRendering(const VkRenderingInfoKHR &renderingInfo)
}
}

void VkCommandBufferObj::BeginRenderingColor(const VkImageView imageView) {
VkRenderingAttachmentInfoKHR color_attachment = LvlInitStruct<VkRenderingAttachmentInfoKHR>();
color_attachment.imageView = imageView;
color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;

VkRenderingInfoKHR renderingInfo = LvlInitStruct<VkRenderingInfoKHR>();
renderingInfo.colorAttachmentCount = 1;
renderingInfo.pColorAttachments = &color_attachment;
renderingInfo.layerCount = 1;

BeginRendering(renderingInfo);
}

void VkCommandBufferObj::EndRendering() {
if (vk::CmdEndRenderingKHR) {
vk::CmdEndRenderingKHR(handle());
Expand Down
3 changes: 3 additions & 0 deletions tests/framework/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ class VkRenderFramework : public VkTestFramework {
void InitRenderTarget(uint32_t targets);
void InitRenderTarget(VkImageView *dsBinding);
void InitRenderTarget(uint32_t targets, VkImageView *dsBinding);
void InitDynamicRenderTarget(VkFormat format = VK_FORMAT_UNDEFINED);
VkImageView GetDynamicRenderTarget() const;
void DestroyRenderTarget();

static bool IgnoreDisableChecks();
Expand Down Expand Up @@ -333,6 +335,7 @@ class VkCommandBufferObj : public vk_testing::CommandBuffer {
void NextSubpass(VkSubpassContents contents = VK_SUBPASS_CONTENTS_INLINE);
void EndRenderPass();
void BeginRendering(const VkRenderingInfoKHR &renderingInfo);
void BeginRenderingColor(const VkImageView imageView);
void EndRendering();
void BeginVideoCoding(const VkVideoBeginCodingInfoKHR &beginInfo);
void ControlVideoCoding(const VkVideoCodingControlInfoKHR &controlInfo);
Expand Down
Loading

0 comments on commit 9eaf317

Please sign in to comment.