#include "vkQueryUtil.hpp"
#include "vkDeviceUtil.hpp"
-
#include <vector>
#include <string>
// ShaderRenderCaseInstance.
-ShaderRenderCaseInstance::ShaderRenderCaseInstance (Context& context, const string& name, bool isVertexCase, ShaderEvaluator& evaluator)
+ShaderRenderCaseInstance::ShaderRenderCaseInstance (Context& context, const string& name, bool isVertexCase, ShaderEvaluator& evaluator, UniformSetupFunc uniformFunc)
: vkt::TestInstance(context)
, m_clearColor(DEFAULT_CLEAR_COLOR)
+ , memAlloc(m_context.getDeviceInterface(), m_context.getDevice(), getPhysicalDeviceMemoryProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice()))
, m_name(name)
, m_isVertexCase(isVertexCase)
, m_evaluator(evaluator)
+ , m_uniformFunc(uniformFunc)
, m_renderSize(100, 100)
, m_colorFormat(VK_FORMAT_R8G8B8A8_UNORM)
{
return tcu::TestStatus::fail("Image mismatch");
}
+void ShaderRenderCaseInstance::setupUniformData (deUint32 size, void* dataPtr)
+{
+ const VkDevice vkDevice = m_context.getDevice();
+ const DeviceInterface& vk = m_context.getDeviceInterface();
+ const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
+
+ const VkBufferCreateInfo uniformBufferParams =
+ {
+ VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
+ DE_NULL, // const void* pNext;
+ size, // VkDeviceSize size;
+ VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, // VkBufferUsageFlags usage;
+ 0u, // VkBufferCreateFlags flags;
+ VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
+ 1u, // deUint32 queueFamilyCount;
+ &queueFamilyIndex // const deUint32* pQueueFamilyIndices;
+ };
+
+ Move<VkBuffer> buffer = createBuffer(vk, vkDevice, &uniformBufferParams);
+ de::MovePtr<Allocation> alloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *buffer), MemoryRequirement::HostVisible);
+ VK_CHECK(vk.bindBufferMemory(vkDevice, *buffer, alloc->getMemory(), 0));
+
+ void* bufferPtr;
+ VK_CHECK(vk.mapMemory(vkDevice, alloc->getMemory(), 0, size, 0, &bufferPtr));
+ deMemcpy(bufferPtr, dataPtr, size);
+ VK_CHECK(vk.unmapMemory(vkDevice, alloc->getMemory()));
+
+ const VkBufferViewCreateInfo viewInfo =
+ {
+ VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO, // VkStructureType sType;
+ DE_NULL, // void* pNext;
+ *buffer, // VkBuffer buffer;
+ VK_BUFFER_VIEW_TYPE_FORMATTED, // VkBufferViewType viewType;
+ VK_FORMAT_R32_SFLOAT, // VkFormat format;
+ 0u, // VkDeviceSize offset;
+ size // VkDeviceSize range;
+ };
+
+ m_uniformBufferViews.push_back(createBufferView(vk, vkDevice, &viewInfo).disown());
+
+ m_uniformBuffers.push_back(buffer.disown());
+ m_uniformBufferAllocs.push_back(alloc.release());
+}
+
+
+void ShaderRenderCaseInstance::addUniform (deUint32 bindingLocation, VkDescriptorType descriptorType, float data)
+{
+ m_descriptorSetLayoutBuilder.addSingleBinding(descriptorType, VK_SHADER_STAGE_VERTEX_BIT);
+ m_descriptorPoolBuilder.addType(descriptorType);
+
+ setupUniformData(sizeof(data), &data);
+
+ const VkDescriptorInfo view =
+ {
+ m_uniformBufferViews[m_uniformBufferViews.size() - 1], // VkBufferView bufferView;
+ 0, // VkSampler sampler;
+ 0, // VkImageView imageView;
+ 0, // VkAttachmentView attachmentView;
+ (VkImageLayout)0, // VkImageLayout imageLayout;
+ };
+
+ m_uniformDescriptorInfos.push_back(view);
+
+ m_uniformLocations.push_back(bindingLocation);
+}
+
+void ShaderRenderCaseInstance::addUniform (deUint32 bindingLocation, VkDescriptorType descriptorType, tcu::Vec4 data)
+{
+ m_descriptorSetLayoutBuilder.addSingleBinding(descriptorType, VK_SHADER_STAGE_VERTEX_BIT);
+ m_descriptorPoolBuilder.addType(descriptorType);
+
+ setupUniformData(sizeof(data), &data[0]);
+
+ const VkDescriptorInfo view =
+ {
+ m_uniformBufferViews[m_uniformBufferViews.size() - 1], // VkBufferView bufferView;
+ 0, // VkSampler sampler;
+ 0, // VkImageView imageView;
+ 0, // VkAttachmentView attachmentView;
+ (VkImageLayout)0, // VkImageLayout imageLayout;
+ };
+
+ m_uniformDescriptorInfos.push_back(view);
+
+ m_uniformLocations.push_back(bindingLocation);
+}
+
+
void ShaderRenderCaseInstance::setupShaderData (void)
{
// TODO!!!
{
// TODO!!
DE_UNREF(constCoords);
+ m_uniformFunc(*this);
}
tcu::IVec2 ShaderRenderCaseInstance::getViewportSize (void) const
const DeviceInterface& vk = m_context.getDeviceInterface();
const VkQueue queue = m_context.getUniversalQueue();
const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
- SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice()));
+ //SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice()));
// Create color image
{
// Create descriptors
{
- const VkDescriptorSetLayoutBinding layoutBindings[1] =
- {
- {
- VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, // VkDescriptorType descriptorType;
- 1u, // deUint32 arraySize;
- VK_SHADER_STAGE_VERTEX_BIT, // VkShaderStageFlags stageFlags;
- DE_NULL // const VkSampler* pImmutableSamplers;
- },
- };
-
- const VkDescriptorSetLayoutCreateInfo descriptorLayoutParams =
- {
- VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, // VkStructureType sType;
- DE_NULL, // cost void* pNexŧ;
- DE_LENGTH_OF_ARRAY(layoutBindings), // deUint32 count;
- layoutBindings // const VkDescriptorSetLayoutBinding pBinding;
- };
-
- m_descriptorSetLayout = createDescriptorSetLayout(vk, vkDevice, &descriptorLayoutParams);
-
-
- const float uniformData[] = { 1.0f };
- const VkDeviceSize uniformSize = DE_LENGTH_OF_ARRAY(uniformData) * sizeof(float);
- const VkBufferCreateInfo uniformBufferParams =
- {
- VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
- DE_NULL, // const void* pNext;
- uniformSize, // VkDeviceSize size;
- VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, // VkBufferUsageFlags usage;
- 0u, // VkBufferCreateFlags flags;
- VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
- 1u, // deUint32 queueFamilyCount;
- &queueFamilyIndex // const deUint32* pQueueFamilyIndices;
- };
-
- m_uniformBuffer = createBuffer(vk, vkDevice, &uniformBufferParams);
- m_uniformBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_uniformBuffer), MemoryRequirement::HostVisible);
-
- VK_CHECK(vk.bindBufferMemory(vkDevice, *m_uniformBuffer, m_uniformBufferAlloc->getMemory(), 0));
-
- void* bufferPtr;
- VK_CHECK(vk.mapMemory(vkDevice, m_uniformBufferAlloc->getMemory(), 0, uniformSize, 0, &bufferPtr));
- deMemcpy(bufferPtr, uniformData, uniformSize);
- VK_CHECK(vk.unmapMemory(vkDevice, m_uniformBufferAlloc->getMemory()));
-
- const VkBufferViewCreateInfo viewInfo =
- {
- VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO, // VkStructureType sType;
- DE_NULL, // void* pNext;
- *m_uniformBuffer, // VkBuffer buffer;
- VK_BUFFER_VIEW_TYPE_FORMATTED, // VkBufferViewType viewType;
- VK_FORMAT_R32_SFLOAT, // VkFormat format;
- 0u, // VkDeviceSize offset;
- uniformSize // VkDeviceSize range;
- };
-
- m_uniformBufferView = createBufferView(vk, vkDevice, &viewInfo);
-
- const VkDescriptorTypeCount descriptorTypes[] =
- {
- {
- VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, // VkDescriptorType type;
- 1 // deUint32 count;
- }
- };
-
- const VkDescriptorPoolCreateInfo descriptorPoolParams =
- {
- VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, // VkStructureType sType;
- DE_NULL, // void* pNext;
- DE_LENGTH_OF_ARRAY(descriptorTypes), // deUint32 count;
- descriptorTypes // const VkDescriptorTypeCount* pTypeCount
- };
-
- m_descriptorPool = createDescriptorPool(vk, vkDevice, VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, &descriptorPoolParams);
+ setupUniforms(quadGrid.getConstCoords());
+ m_descriptorSetLayout = m_descriptorSetLayoutBuilder.build(vk, vkDevice);
+ m_descriptorPool = m_descriptorPoolBuilder.build(vk, vkDevice, VK_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1u);
m_descriptorSet = allocDescriptorSet(vk, vkDevice, *m_descriptorPool, VK_DESCRIPTOR_SET_USAGE_STATIC, *m_descriptorSetLayout);
- const VkDescriptorInfo descriptorInfos[] =
- {
- {
- *m_uniformBufferView, // VkBufferView bufferView;
- 0, // VkSampler sampler;
- 0, // VkImageView imageView;
- 0, // VkAttachmentView attachmentView;
- (VkImageLayout)0, // VkImageLayout imageLayout;
-
- }
- };
-
- const VkWriteDescriptorSet writeDescritporSets[] =
+ for(deUint32 i = 0; i < m_uniformDescriptorInfos.size(); i++)
{
- {
- VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, // VkStructureType sType;
- DE_NULL, // const void* pNext;
- *m_descriptorSet, // VkDescriptorSet destSet;
- 0, // deUint32 destBinding;
- 0, // deUint32 destArrayElement;
- 1, // deUint32 count;
- VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, // VkDescriptorType descriptorType;
- descriptorInfos, // const VkDescriptorInfo* pDescriptors;
- }
- };
+ m_descriptorSetUpdateBuilder.writeSingle(*m_descriptorSet, DescriptorSetUpdateBuilder::Location::binding(m_uniformLocations[i]), VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &m_uniformDescriptorInfos[i]);
+ }
- VK_CHECK(vk.updateDescriptorSets(vkDevice, 1, writeDescritporSets, 0u, DE_NULL));
+ m_descriptorSetUpdateBuilder.update(vk, vkDevice);
}
// Create pipeline layout
#include "vkPrograms.hpp"
#include "vkRef.hpp"
#include "vkMemUtil.hpp"
+#include "vkBuilderUtil.hpp"
namespace vkt
{
ShaderEvalFunc m_evalFunc;
};
+class ShaderRenderCaseInstance;
+
+typedef void (*UniformSetupFunc) (ShaderRenderCaseInstance& instance);
template<typename Instance>
class ShaderRenderCase : public vkt::TestCase
const std::string& name,
const std::string& description,
bool isVertexCase,
- ShaderEvalFunc evalFunc)
+ ShaderEvalFunc evalFunc,
+ UniformSetupFunc uniformFunc)
: vkt::TestCase(testCtx, name, description)
, m_isVertexCase(isVertexCase)
, m_evaluator(new ShaderEvaluator(evalFunc))
+ , m_uniformFunc(uniformFunc)
{}
ShaderRenderCase (tcu::TestContext& testCtx,
const std::string& name,
const std::string& description,
bool isVertexCase,
- ShaderEvaluator* evaluator)
+ ShaderEvaluator* evaluator,
+ UniformSetupFunc uniformFunc)
: vkt::TestCase(testCtx, name, description)
, m_isVertexCase(isVertexCase)
, m_evaluator(evaluator)
+ , m_uniformFunc(uniformFunc)
{}
programCollection.add(m_name + "_frag") << glu::FragmentSource(m_fragShaderSource);
}
- virtual TestInstance* createInstance (Context& context) const { return new Instance(context, m_name, m_isVertexCase, *m_evaluator); }
+ virtual TestInstance* createInstance (Context& context) const { return new Instance(context, m_name, m_isVertexCase, *m_evaluator, m_uniformFunc); }
protected:
std::string m_vertShaderSource;
private:
bool m_isVertexCase;
ShaderEvaluator* m_evaluator;
-
+ UniformSetupFunc m_uniformFunc;
};
+
+
// ShaderRenderCaseInstance.
class ShaderRenderCaseInstance : public vkt::TestInstance
{
public:
- ShaderRenderCaseInstance (Context& context, const std::string& name, bool isVertexCase, ShaderEvaluator& evaluator);
+ ShaderRenderCaseInstance (Context& context, const std::string& name, bool isVertexCase, ShaderEvaluator& evaluator, UniformSetupFunc uniformFunc);
virtual ~ShaderRenderCaseInstance (void);
virtual tcu::TestStatus iterate (void);
+ void addUniform (deUint32 bindingLocation, vk::VkDescriptorType descriptorType, float data);
+ void addUniform (deUint32 bindingLocation, vk::VkDescriptorType descriptorType, tcu::Vec4 data);
+
protected:
virtual void setupShaderData (void);
virtual void setup (void);
std::vector<tcu::Mat4> m_userAttribTransforms;
tcu::Vec4 m_clearColor;
+ vk::SimpleAllocator memAlloc;
+
private:
+ void setupUniformData (deUint32 size, void* dataPtr);
void setupDefaultInputs (void);
void render (tcu::Surface& result, const QuadGrid& quadGrid);
std::string m_name;
bool m_isVertexCase;
ShaderEvaluator& m_evaluator;
+ UniformSetupFunc m_uniformFunc;
const tcu::IVec2 m_renderSize;
const vk::VkFormat m_colorFormat;
de::MovePtr<vk::Allocation> m_indiceBufferAlloc;
vk::Move<vk::VkDescriptorSetLayout> m_descriptorSetLayout;
- vk::Move<vk::VkBuffer> m_uniformBuffer;
- de::MovePtr<vk::Allocation> m_uniformBufferAlloc;
- vk::Move<vk::VkBufferView> m_uniformBufferView;
vk::Move<vk::VkDescriptorPool> m_descriptorPool;
vk::Move<vk::VkDescriptorSet> m_descriptorSet;
vk::Move<vk::VkCmdBuffer> m_cmdBuffer;
vk::Move<vk::VkFence> m_fence;
+
+ vk::DescriptorSetLayoutBuilder m_descriptorSetLayoutBuilder;
+ vk::DescriptorPoolBuilder m_descriptorPoolBuilder;
+ vk::DescriptorSetUpdateBuilder m_descriptorSetUpdateBuilder;
+
+ std::vector<deUint32> m_uniformLocations;
+ std::vector<vk::VkBuffer> m_uniformBuffers;
+ std::vector<vk::Allocation*> m_uniformBufferAllocs;
+ std::vector<vk::VkBufferView> m_uniformBufferViews;
+ std::vector<vk::VkDescriptorInfo> m_uniformDescriptorInfos;
};
inline void eval_DEBUG (ShaderEvalContext& c) { c.color = tcu::Vec4(1, 0, 1, 1); }
+void empty_uniform (ShaderRenderCaseInstance& instance) {}
+
+
+void dummy_uniforms (ShaderRenderCaseInstance& instance)
+{
+ instance.addUniform(0u, vk::VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1.0f);
+ instance.addUniform(1u, vk::VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0.5f);
+ instance.addUniform(2u, vk::VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, tcu::Vec4(1, 0.5f, 1.0f, 0.5f));
+}
+
+class DummyShaderRenderCaseInstance;
+
class DummyTestRenderCase : public ShaderRenderCase<ShaderRenderCaseInstance>
{
public:
ShaderEvalFunc evalFunc,
std::string vertexShader,
std::string fragmentShader)
- : ShaderRenderCase(testCtx, name, description, isVertexCase, evalFunc)
+ : ShaderRenderCase(testCtx, name, description, isVertexCase, evalFunc, dummy_uniforms)
{
m_vertShaderSource = vertexShader;
m_fragShaderSource = fragmentShader;
" float item;\n"
"};\n"
+ "layout (set=0, binding=1) uniform buf2 {\n"
+ " float item2;\n"
+ "};\n"
+
+ "layout (set=0, binding=2) uniform buf3 {\n"
+ " vec4 item3;\n"
+ "};\n"
+
"out mediump vec4 v_color;\n"
- "void main (void) { gl_Position = a_position; v_color = vec4(a_coords.xyz, item); }\n";
+ "void main (void) { gl_Position = a_position; v_color = vec4(a_coords.xyz, item3.x); }\n";
std::string base_fragment = "#version 300 es\n"
"layout(location = 0) out lowp vec4 o_color;\n"
"in mediump vec4 v_color;\n"
"void main (void) { o_color = v_color; }\n";
- std::string debug_fragment = "#version 300 es\n"
+ std::string debug_fragment = "#version 140 \n"
+ "#extension GL_ARB_separate_shader_objects : enable\n"
+ "#extension GL_ARB_shading_language_420pack : enable\n"
+
"layout(location = 0) out lowp vec4 o_color;\n"
+
+ "layout (set=0, binding=2) uniform buf {\n"
+ " float item[4];\n"
+ "};\n"
+
"in mediump vec4 v_color;\n"
- "void main (void) { o_color = vec4(1,0,1,1); }\n";
+ "void main (void) { o_color = vec4(1,0,item[0],1); }\n";
shaderRenderCaseTests->addChild(new DummyTestRenderCase(testCtx, "testVertex", "testVertex", true, evalCoordsPassthrough, base_vertex, base_fragment));