| /*------------------------------------------------------------------------- |
| * Vulkan Conformance Tests |
| * ------------------------ |
| * |
| * Copyright (c) 2017 Google Inc. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| * |
| *//*! |
| * \file |
| * \brief Graphics pipeline for SPIR-V assembly tests |
| *//*--------------------------------------------------------------------*/ |
| |
| #include "vktSpvAsmGraphicsShaderTestUtil.hpp" |
| |
| #include "tcuFloat.hpp" |
| #include "tcuStringTemplate.hpp" |
| #include "tcuTextureUtil.hpp" |
| |
| #include "vkDefs.hpp" |
| #include "vkMemUtil.hpp" |
| #include "vkPlatform.hpp" |
| #include "vkQueryUtil.hpp" |
| #include "vkRefUtil.hpp" |
| #include "vkTypeUtil.hpp" |
| #include "vkImageUtil.hpp" |
| #include "vkCmdUtil.hpp" |
| |
| #include "deRandom.hpp" |
| |
| namespace vkt |
| { |
| namespace SpirVAssembly |
| { |
| |
| using namespace vk; |
| using std::map; |
| using std::string; |
| using std::vector; |
| using tcu::Float16; |
| using tcu::Float32; |
| using tcu::Float64; |
| using tcu::IVec3; |
| using tcu::IVec4; |
| using tcu::RGBA; |
| using tcu::TestLog; |
| using tcu::TestStatus; |
| using tcu::Vec4; |
| using de::UniquePtr; |
| using tcu::StringTemplate; |
| using tcu::Vec4; |
| |
| deUint32 IFDataType::getElementNumBytes (void) const |
| { |
| if (elementType < NUMBERTYPE_END32) |
| return 4; |
| |
| if (elementType < NUMBERTYPE_END16) |
| return 2; |
| |
| return 8; |
| } |
| |
| VkFormat IFDataType::getVkFormat (void) const |
| { |
| if (numElements == 1) |
| { |
| switch (elementType) |
| { |
| case NUMBERTYPE_FLOAT64: return VK_FORMAT_R64_SFLOAT; |
| case NUMBERTYPE_FLOAT32: return VK_FORMAT_R32_SFLOAT; |
| case NUMBERTYPE_INT32: return VK_FORMAT_R32_SINT; |
| case NUMBERTYPE_UINT32: return VK_FORMAT_R32_UINT; |
| case NUMBERTYPE_FLOAT16: return VK_FORMAT_R16_SFLOAT; |
| case NUMBERTYPE_INT16: return VK_FORMAT_R16_SINT; |
| case NUMBERTYPE_UINT16: return VK_FORMAT_R16_UINT; |
| default: break; |
| } |
| } |
| else if (numElements == 2) |
| { |
| switch (elementType) |
| { |
| case NUMBERTYPE_FLOAT64: return VK_FORMAT_R64G64_SFLOAT; |
| case NUMBERTYPE_FLOAT32: return VK_FORMAT_R32G32_SFLOAT; |
| case NUMBERTYPE_INT32: return VK_FORMAT_R32G32_SINT; |
| case NUMBERTYPE_UINT32: return VK_FORMAT_R32G32_UINT; |
| case NUMBERTYPE_FLOAT16: return VK_FORMAT_R16G16_SFLOAT; |
| case NUMBERTYPE_INT16: return VK_FORMAT_R16G16_SINT; |
| case NUMBERTYPE_UINT16: return VK_FORMAT_R16G16_UINT; |
| default: break; |
| } |
| } |
| else if (numElements == 3) |
| { |
| switch (elementType) |
| { |
| case NUMBERTYPE_FLOAT64: return VK_FORMAT_R64G64B64_SFLOAT; |
| case NUMBERTYPE_FLOAT32: return VK_FORMAT_R32G32B32_SFLOAT; |
| case NUMBERTYPE_INT32: return VK_FORMAT_R32G32B32_SINT; |
| case NUMBERTYPE_UINT32: return VK_FORMAT_R32G32B32_UINT; |
| case NUMBERTYPE_FLOAT16: return VK_FORMAT_R16G16B16_SFLOAT; |
| case NUMBERTYPE_INT16: return VK_FORMAT_R16G16B16_SINT; |
| case NUMBERTYPE_UINT16: return VK_FORMAT_R16G16B16_UINT; |
| default: break; |
| } |
| } |
| else if (numElements == 4) |
| { |
| switch (elementType) |
| { |
| case NUMBERTYPE_FLOAT64: return VK_FORMAT_R64G64B64A64_SFLOAT; |
| case NUMBERTYPE_FLOAT32: return VK_FORMAT_R32G32B32A32_SFLOAT; |
| case NUMBERTYPE_INT32: return VK_FORMAT_R32G32B32A32_SINT; |
| case NUMBERTYPE_UINT32: return VK_FORMAT_R32G32B32A32_UINT; |
| case NUMBERTYPE_FLOAT16: return VK_FORMAT_R16G16B16A16_SFLOAT; |
| case NUMBERTYPE_INT16: return VK_FORMAT_R16G16B16A16_SINT; |
| case NUMBERTYPE_UINT16: return VK_FORMAT_R16G16B16A16_UINT; |
| default: break; |
| } |
| } |
| |
| DE_ASSERT(false); |
| return VK_FORMAT_UNDEFINED; |
| } |
| |
| tcu::TextureFormat IFDataType::getTextureFormat (void) const |
| { |
| tcu::TextureFormat::ChannelType ct = tcu::TextureFormat::CHANNELTYPE_LAST; |
| tcu::TextureFormat::ChannelOrder co = tcu::TextureFormat::CHANNELORDER_LAST; |
| |
| switch (elementType) |
| { |
| case NUMBERTYPE_FLOAT64: ct = tcu::TextureFormat::FLOAT64; break; |
| case NUMBERTYPE_FLOAT32: ct = tcu::TextureFormat::FLOAT; break; |
| case NUMBERTYPE_INT32: ct = tcu::TextureFormat::SIGNED_INT32; break; |
| case NUMBERTYPE_UINT32: ct = tcu::TextureFormat::UNSIGNED_INT32; break; |
| case NUMBERTYPE_FLOAT16: ct = tcu::TextureFormat::HALF_FLOAT; break; |
| case NUMBERTYPE_INT16: ct = tcu::TextureFormat::SIGNED_INT16; break; |
| case NUMBERTYPE_UINT16: ct = tcu::TextureFormat::UNSIGNED_INT16; break; |
| default: DE_ASSERT(false); |
| } |
| |
| switch (numElements) |
| { |
| case 1: co = tcu::TextureFormat::R; break; |
| case 2: co = tcu::TextureFormat::RG; break; |
| case 3: co = tcu::TextureFormat::RGB; break; |
| case 4: co = tcu::TextureFormat::RGBA; break; |
| default: DE_ASSERT(false); |
| } |
| |
| return tcu::TextureFormat(co, ct); |
| } |
| |
| string IFDataType::str (void) const |
| { |
| string ret; |
| |
| switch (elementType) |
| { |
| case NUMBERTYPE_FLOAT64: ret = "f64"; break; |
| case NUMBERTYPE_FLOAT32: ret = "f32"; break; |
| case NUMBERTYPE_INT32: ret = "i32"; break; |
| case NUMBERTYPE_UINT32: ret = "u32"; break; |
| case NUMBERTYPE_FLOAT16: ret = "f16"; break; |
| case NUMBERTYPE_INT16: ret = "i16"; break; |
| case NUMBERTYPE_UINT16: ret = "u16"; break; |
| default: DE_ASSERT(false); |
| } |
| |
| if (numElements == 1) |
| return ret; |
| |
| return string("v") + numberToString(numElements) + ret; |
| } |
| |
| VkBufferUsageFlagBits getMatchingBufferUsageFlagBit (VkDescriptorType dType) |
| { |
| switch (dType) |
| { |
| case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: return VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; |
| case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: return VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; |
| case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: return VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: return VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: return VK_BUFFER_USAGE_TRANSFER_SRC_BIT; |
| default: DE_ASSERT(0 && "not implemented"); |
| } |
| return (VkBufferUsageFlagBits)0; |
| } |
| |
| VkImageUsageFlags getMatchingImageUsageFlags (VkDescriptorType dType) |
| { |
| switch (dType) |
| { |
| case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: return VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: return VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: return VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| default: DE_FATAL("Not implemented"); |
| } |
| return (VkImageUsageFlags)0; |
| } |
| |
| static void requireFormatUsageSupport (const InstanceInterface& vki, VkPhysicalDevice physicalDevice, VkFormat format, VkImageTiling imageTiling, VkImageUsageFlags requiredUsageFlags) |
| { |
| VkFormatProperties properties; |
| VkFormatFeatureFlags tilingFeatures = 0; |
| |
| vki.getPhysicalDeviceFormatProperties(physicalDevice, format, &properties); |
| |
| switch (imageTiling) |
| { |
| case VK_IMAGE_TILING_LINEAR: |
| tilingFeatures = properties.linearTilingFeatures; |
| break; |
| |
| case VK_IMAGE_TILING_OPTIMAL: |
| tilingFeatures = properties.optimalTilingFeatures; |
| break; |
| |
| default: |
| DE_ASSERT(false); |
| break; |
| } |
| |
| if ((requiredUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) != 0) |
| { |
| if ((tilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) == 0) |
| TCU_THROW(NotSupportedError, "Image format cannot be used as color attachment"); |
| requiredUsageFlags ^= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| } |
| |
| |
| if ((requiredUsageFlags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) != 0) |
| { |
| if ((tilingFeatures & VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR) == 0) |
| TCU_THROW(NotSupportedError, "Image format cannot be used as transfer source"); |
| requiredUsageFlags ^= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| } |
| |
| |
| DE_ASSERT(!requiredUsageFlags && "checking other image usage bits not supported yet"); |
| } |
| |
| InstanceContext::InstanceContext (const RGBA (&inputs)[4], |
| const RGBA (&outputs)[4], |
| const map<string, string>& testCodeFragments_, |
| const StageToSpecConstantMap& specConstants_, |
| const PushConstants& pushConsants_, |
| const GraphicsResources& resources_, |
| const GraphicsInterfaces& interfaces_, |
| const vector<string>& extensions_, |
| VulkanFeatures vulkanFeatures_, |
| VkShaderStageFlags customizedStages_) |
| : testCodeFragments (testCodeFragments_) |
| , specConstants (specConstants_) |
| , hasTessellation (false) |
| , requiredStages (static_cast<VkShaderStageFlagBits>(0)) |
| , requiredDeviceExtensions (extensions_) |
| , requestedFeatures (vulkanFeatures_) |
| , pushConstants (pushConsants_) |
| , customizedStages (customizedStages_) |
| , resources (resources_) |
| , interfaces (interfaces_) |
| , failResult (QP_TEST_RESULT_FAIL) |
| , failMessageTemplate ("${reason}") |
| , renderFullSquare (false) |
| , splitRenderArea (false) |
| { |
| inputColors[0] = inputs[0]; |
| inputColors[1] = inputs[1]; |
| inputColors[2] = inputs[2]; |
| inputColors[3] = inputs[3]; |
| |
| outputColors[0] = outputs[0]; |
| outputColors[1] = outputs[1]; |
| outputColors[2] = outputs[2]; |
| outputColors[3] = outputs[3]; |
| } |
| |
| InstanceContext::InstanceContext (const InstanceContext& other) |
| : moduleMap (other.moduleMap) |
| , testCodeFragments (other.testCodeFragments) |
| , specConstants (other.specConstants) |
| , hasTessellation (other.hasTessellation) |
| , requiredStages (other.requiredStages) |
| , requiredDeviceExtensions (other.requiredDeviceExtensions) |
| , requestedFeatures (other.requestedFeatures) |
| , pushConstants (other.pushConstants) |
| , customizedStages (other.customizedStages) |
| , resources (other.resources) |
| , interfaces (other.interfaces) |
| , failResult (other.failResult) |
| , failMessageTemplate (other.failMessageTemplate) |
| , renderFullSquare (other.renderFullSquare) |
| , splitRenderArea (other.splitRenderArea) |
| { |
| inputColors[0] = other.inputColors[0]; |
| inputColors[1] = other.inputColors[1]; |
| inputColors[2] = other.inputColors[2]; |
| inputColors[3] = other.inputColors[3]; |
| |
| outputColors[0] = other.outputColors[0]; |
| outputColors[1] = other.outputColors[1]; |
| outputColors[2] = other.outputColors[2]; |
| outputColors[3] = other.outputColors[3]; |
| } |
| |
| string InstanceContext::getSpecializedFailMessage (const string& failureReason) |
| { |
| map<string, string> parameters; |
| parameters["reason"] = failureReason; |
| return StringTemplate(failMessageTemplate).specialize(parameters); |
| } |
| |
| InstanceContext createInstanceContext (const std::vector<ShaderElement>& elements, |
| const tcu::RGBA (&inputColors)[4], |
| const tcu::RGBA (&outputColors)[4], |
| const std::map<std::string, std::string>& testCodeFragments, |
| const StageToSpecConstantMap& specConstants, |
| const PushConstants& pushConstants, |
| const GraphicsResources& resources, |
| const GraphicsInterfaces& interfaces, |
| const std::vector<std::string>& extensions, |
| VulkanFeatures vulkanFeatures, |
| VkShaderStageFlags customizedStages, |
| const qpTestResult failResult, |
| const std::string& failMessageTemplate) |
| { |
| InstanceContext ctx (inputColors, outputColors, testCodeFragments, specConstants, pushConstants, resources, interfaces, extensions, vulkanFeatures, customizedStages); |
| for (size_t i = 0; i < elements.size(); ++i) |
| { |
| ctx.moduleMap[elements[i].moduleName].push_back(std::make_pair(elements[i].entryName, elements[i].stage)); |
| ctx.requiredStages = static_cast<VkShaderStageFlagBits>(ctx.requiredStages | elements[i].stage); |
| } |
| ctx.failResult = failResult; |
| if (!failMessageTemplate.empty()) |
| ctx.failMessageTemplate = failMessageTemplate; |
| return ctx; |
| } |
| |
| InstanceContext createInstanceContext (const std::vector<ShaderElement>& elements, |
| tcu::RGBA (&inputColors)[4], |
| const tcu::RGBA (&outputColors)[4], |
| const std::map<std::string, std::string>& testCodeFragments) |
| { |
| return createInstanceContext(elements, inputColors, outputColors, testCodeFragments, |
| StageToSpecConstantMap(), PushConstants(), GraphicsResources(), |
| GraphicsInterfaces(), std::vector<std::string>(), |
| VulkanFeatures(), vk::VK_SHADER_STAGE_ALL); |
| } |
| |
| InstanceContext createInstanceContext (const std::vector<ShaderElement>& elements, |
| const std::map<std::string, std::string>& testCodeFragments) |
| { |
| tcu::RGBA defaultColors[4]; |
| getDefaultColors(defaultColors); |
| return createInstanceContext(elements, defaultColors, defaultColors, testCodeFragments); |
| } |
| |
| UnusedVariableContext createUnusedVariableContext(const ShaderTaskArray& shaderTasks, const VariableLocation& location) |
| { |
| for (size_t i = 0; i < DE_LENGTH_OF_ARRAY(shaderTasks); ++i) |
| { |
| DE_ASSERT(shaderTasks[i] >= 0 && shaderTasks[i] < SHADER_TASK_LAST); |
| } |
| |
| std::vector<ShaderElement> elements; |
| |
| DE_ASSERT(shaderTasks[SHADER_TASK_INDEX_VERTEX] != SHADER_TASK_NONE); |
| DE_ASSERT(shaderTasks[SHADER_TASK_INDEX_FRAGMENT] != SHADER_TASK_NONE); |
| elements.push_back(ShaderElement("vert", "main", vk::VK_SHADER_STAGE_VERTEX_BIT)); |
| elements.push_back(ShaderElement("frag", "main", vk::VK_SHADER_STAGE_FRAGMENT_BIT)); |
| |
| if (shaderTasks[SHADER_TASK_INDEX_GEOMETRY] != SHADER_TASK_NONE) |
| elements.push_back(ShaderElement("geom", "main", vk::VK_SHADER_STAGE_GEOMETRY_BIT)); |
| |
| if (shaderTasks[SHADER_TASK_INDEX_TESS_CONTROL] != SHADER_TASK_NONE) |
| elements.push_back(ShaderElement("tessc", "main", vk::VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT)); |
| |
| if (shaderTasks[SHADER_TASK_INDEX_TESS_EVAL] != SHADER_TASK_NONE) |
| elements.push_back(ShaderElement("tesse", "main", vk::VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)); |
| |
| return UnusedVariableContext( |
| createInstanceContext(elements, map<string, string>()), |
| shaderTasks, |
| location); |
| } |
| |
| ShaderElement::ShaderElement (const string& moduleName_, |
| const string& entryPoint_, |
| VkShaderStageFlagBits shaderStage_) |
| : moduleName(moduleName_) |
| , entryName(entryPoint_) |
| , stage(shaderStage_) |
| { |
| } |
| |
| void getDefaultColors (RGBA (&colors)[4]) |
| { |
| colors[0] = RGBA::white(); |
| colors[1] = RGBA::red(); |
| colors[2] = RGBA::green(); |
| colors[3] = RGBA::blue(); |
| } |
| |
| void getHalfColorsFullAlpha (RGBA (&colors)[4]) |
| { |
| colors[0] = RGBA(127, 127, 127, 255); |
| colors[1] = RGBA(127, 0, 0, 255); |
| colors[2] = RGBA(0, 127, 0, 255); |
| colors[3] = RGBA(0, 0, 127, 255); |
| } |
| |
| void getInvertedDefaultColors (RGBA (&colors)[4]) |
| { |
| colors[0] = RGBA(0, 0, 0, 255); |
| colors[1] = RGBA(0, 255, 255, 255); |
| colors[2] = RGBA(255, 0, 255, 255); |
| colors[3] = RGBA(255, 255, 0, 255); |
| } |
| |
| // For the current InstanceContext, constructs the required modules and shader stage create infos. |
| void createPipelineShaderStages (const DeviceInterface& vk, |
| const VkDevice vkDevice, |
| InstanceContext& instance, |
| Context& context, |
| vector<ModuleHandleSp>& modules, |
| vector<VkPipelineShaderStageCreateInfo>& createInfos) |
| { |
| for (ModuleMap::const_iterator moduleNdx = instance.moduleMap.begin(); moduleNdx != instance.moduleMap.end(); ++moduleNdx) |
| { |
| const ModuleHandleSp mod(new Unique<VkShaderModule>(createShaderModule(vk, vkDevice, context.getBinaryCollection().get(moduleNdx->first), 0))); |
| modules.push_back(ModuleHandleSp(mod)); |
| for (vector<EntryToStage>::const_iterator shaderNdx = moduleNdx->second.begin(); shaderNdx != moduleNdx->second.end(); ++shaderNdx) |
| { |
| const EntryToStage& stage = *shaderNdx; |
| const VkPipelineShaderStageCreateInfo shaderParam = |
| { |
| VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType; |
| DE_NULL, // const void* pNext; |
| (VkPipelineShaderStageCreateFlags)0, |
| stage.second, // VkShaderStageFlagBits stage; |
| **modules.back(), // VkShaderModule module; |
| stage.first.c_str(), // const char* pName; |
| (const VkSpecializationInfo*)DE_NULL, |
| }; |
| createInfos.push_back(shaderParam); |
| } |
| } |
| } |
| |
| // Creates vertex-shader assembly by specializing a boilerplate StringTemplate |
| // on fragments, which must (at least) map "testfun" to an OpFunction definition |
| // for %test_code that takes and returns a %v4f32. Boilerplate IDs are prefixed |
| // with "BP_" to avoid collisions with fragments. |
| // |
| // It corresponds roughly to this GLSL: |
| //; |
| // layout(location = 0) in vec4 position; |
| // layout(location = 1) in vec4 color; |
| // layout(location = 1) out highp vec4 vtxColor; |
| // void main (void) { gl_Position = position; vtxColor = test_func(color); } |
| string makeVertexShaderAssembly (const map<string, string>& fragments) |
| { |
| static const char vertexShaderBoilerplate[] = |
| "OpCapability Shader\n" |
| "${capability:opt}\n" |
| "${extension:opt}\n" |
| "OpMemoryModel Logical GLSL450\n" |
| "OpEntryPoint Vertex %BP_main \"main\" %BP_stream %BP_position %BP_vtx_color %BP_color %BP_gl_VertexIndex %BP_gl_InstanceIndex ${IF_entrypoint:opt} \n" |
| "${execution_mode:opt}\n" |
| "${debug:opt}\n" |
| "${moduleprocessed:opt}\n" |
| "OpMemberDecorate %BP_gl_PerVertex 0 BuiltIn Position\n" |
| "OpMemberDecorate %BP_gl_PerVertex 1 BuiltIn PointSize\n" |
| "OpMemberDecorate %BP_gl_PerVertex 2 BuiltIn ClipDistance\n" |
| "OpMemberDecorate %BP_gl_PerVertex 3 BuiltIn CullDistance\n" |
| "OpDecorate %BP_gl_PerVertex Block\n" |
| "OpDecorate %BP_position Location 0\n" |
| "OpDecorate %BP_vtx_color Location 1\n" |
| "OpDecorate %BP_color Location 1\n" |
| "OpDecorate %BP_gl_VertexIndex BuiltIn VertexIndex\n" |
| "OpDecorate %BP_gl_InstanceIndex BuiltIn InstanceIndex\n" |
| "${IF_decoration:opt}\n" |
| "${decoration:opt}\n" |
| SPIRV_ASSEMBLY_TYPES |
| SPIRV_ASSEMBLY_CONSTANTS |
| SPIRV_ASSEMBLY_ARRAYS |
| "%BP_gl_PerVertex = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" |
| "%BP_op_gl_PerVertex = OpTypePointer Output %BP_gl_PerVertex\n" |
| "%BP_stream = OpVariable %BP_op_gl_PerVertex Output\n" |
| "%BP_position = OpVariable %ip_v4f32 Input\n" |
| "%BP_vtx_color = OpVariable %op_v4f32 Output\n" |
| "%BP_color = OpVariable %ip_v4f32 Input\n" |
| "%BP_gl_VertexIndex = OpVariable %ip_i32 Input\n" |
| "%BP_gl_InstanceIndex = OpVariable %ip_i32 Input\n" |
| "${pre_main:opt}\n" |
| "${IF_variable:opt}\n" |
| "%BP_main = OpFunction %void None %voidf\n" |
| "%BP_label = OpLabel\n" |
| "${IF_carryforward:opt}\n" |
| "${post_interface_op_vert:opt}\n" |
| "%BP_pos = OpLoad %v4f32 %BP_position\n" |
| "%BP_gl_pos = OpAccessChain %op_v4f32 %BP_stream %c_i32_0\n" |
| "OpStore %BP_gl_pos %BP_pos\n" |
| "%BP_col = OpLoad %v4f32 %BP_color\n" |
| "%BP_col_transformed = OpFunctionCall %v4f32 %test_code %BP_col\n" |
| "OpStore %BP_vtx_color %BP_col_transformed\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n" |
| "${interface_op_func:opt}\n" |
| |
| "%isUniqueIdZero = OpFunction %bool None %bool_function\n" |
| "%getId_label = OpLabel\n" |
| "%vert_id = OpLoad %i32 %BP_gl_VertexIndex\n" |
| "%is_id_0 = OpIEqual %bool %vert_id %c_i32_0\n" |
| "OpReturnValue %is_id_0\n" |
| "OpFunctionEnd\n" |
| |
| "${testfun}\n"; |
| return tcu::StringTemplate(vertexShaderBoilerplate).specialize(fragments); |
| } |
| |
| // Creates tess-control-shader assembly by specializing a boilerplate |
| // StringTemplate on fragments, which must (at least) map "testfun" to an |
| // OpFunction definition for %test_code that takes and returns a %v4f32. |
| // Boilerplate IDs are prefixed with "BP_" to avoid collisions with fragments. |
| // |
| // It roughly corresponds to the following GLSL. |
| // |
| // #version 450 |
| // layout(vertices = 3) out; |
| // layout(location = 1) in vec4 in_color[]; |
| // layout(location = 1) out vec4 out_color[]; |
| // |
| // void main() { |
| // out_color[gl_InvocationID] = testfun(in_color[gl_InvocationID]); |
| // gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; |
| // if (gl_InvocationID == 0) { |
| // gl_TessLevelOuter[0] = 1.0; |
| // gl_TessLevelOuter[1] = 1.0; |
| // gl_TessLevelOuter[2] = 1.0; |
| // gl_TessLevelInner[0] = 1.0; |
| // } |
| // } |
| string makeTessControlShaderAssembly (const map<string, string>& fragments) |
| { |
| static const char tessControlShaderBoilerplate[] = |
| "OpCapability Tessellation\n" |
| "${capability:opt}\n" |
| "${extension:opt}\n" |
| "OpMemoryModel Logical GLSL450\n" |
| "OpEntryPoint TessellationControl %BP_main \"main\" %BP_out_color %BP_gl_InvocationID %BP_gl_PrimitiveID %BP_in_color %BP_gl_out %BP_gl_in %BP_gl_TessLevelOuter %BP_gl_TessLevelInner ${IF_entrypoint:opt} \n" |
| "OpExecutionMode %BP_main OutputVertices 3\n" |
| "${execution_mode:opt}\n" |
| "${debug:opt}\n" |
| "${moduleprocessed:opt}\n" |
| "OpDecorate %BP_out_color Location 1\n" |
| "OpDecorate %BP_gl_InvocationID BuiltIn InvocationId\n" |
| "OpDecorate %BP_gl_PrimitiveID BuiltIn PrimitiveId\n" |
| "OpDecorate %BP_in_color Location 1\n" |
| "OpMemberDecorate %BP_gl_PerVertex 0 BuiltIn Position\n" |
| "OpMemberDecorate %BP_gl_PerVertex 1 BuiltIn PointSize\n" |
| "OpMemberDecorate %BP_gl_PerVertex 2 BuiltIn ClipDistance\n" |
| "OpMemberDecorate %BP_gl_PerVertex 3 BuiltIn CullDistance\n" |
| "OpDecorate %BP_gl_PerVertex Block\n" |
| "OpMemberDecorate %BP_gl_PVOut 0 BuiltIn Position\n" |
| "OpMemberDecorate %BP_gl_PVOut 1 BuiltIn PointSize\n" |
| "OpMemberDecorate %BP_gl_PVOut 2 BuiltIn ClipDistance\n" |
| "OpMemberDecorate %BP_gl_PVOut 3 BuiltIn CullDistance\n" |
| "OpDecorate %BP_gl_PVOut Block\n" |
| "OpDecorate %BP_gl_TessLevelOuter Patch\n" |
| "OpDecorate %BP_gl_TessLevelOuter BuiltIn TessLevelOuter\n" |
| "OpDecorate %BP_gl_TessLevelInner Patch\n" |
| "OpDecorate %BP_gl_TessLevelInner BuiltIn TessLevelInner\n" |
| "${IF_decoration:opt}\n" |
| "${decoration:opt}\n" |
| "${decoration_tessc:opt}\n" |
| SPIRV_ASSEMBLY_TYPES |
| SPIRV_ASSEMBLY_CONSTANTS |
| SPIRV_ASSEMBLY_ARRAYS |
| "%BP_out_color = OpVariable %op_a3v4f32 Output\n" |
| "%BP_gl_InvocationID = OpVariable %ip_i32 Input\n" |
| "%BP_gl_PrimitiveID = OpVariable %ip_i32 Input\n" |
| "%BP_in_color = OpVariable %ip_a32v4f32 Input\n" |
| "%BP_gl_PerVertex = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" |
| "%BP_a3_gl_PerVertex = OpTypeArray %BP_gl_PerVertex %c_u32_3\n" |
| "%BP_op_a3_gl_PerVertex = OpTypePointer Output %BP_a3_gl_PerVertex\n" |
| "%BP_gl_out = OpVariable %BP_op_a3_gl_PerVertex Output\n" |
| "%BP_gl_PVOut = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" |
| "%BP_a32_gl_PVOut = OpTypeArray %BP_gl_PVOut %c_u32_32\n" |
| "%BP_ip_a32_gl_PVOut = OpTypePointer Input %BP_a32_gl_PVOut\n" |
| "%BP_gl_in = OpVariable %BP_ip_a32_gl_PVOut Input\n" |
| "%BP_gl_TessLevelOuter = OpVariable %op_a4f32 Output\n" |
| "%BP_gl_TessLevelInner = OpVariable %op_a2f32 Output\n" |
| "${pre_main:opt}\n" |
| "${IF_variable:opt}\n" |
| |
| "%BP_main = OpFunction %void None %voidf\n" |
| "%BP_label = OpLabel\n" |
| "%BP_gl_Invoc = OpLoad %i32 %BP_gl_InvocationID\n" |
| "${IF_carryforward:opt}\n" |
| "${post_interface_op_tessc:opt}\n" |
| "%BP_in_col_loc = OpAccessChain %ip_v4f32 %BP_in_color %BP_gl_Invoc\n" |
| "%BP_out_col_loc = OpAccessChain %op_v4f32 %BP_out_color %BP_gl_Invoc\n" |
| "%BP_in_col_val = OpLoad %v4f32 %BP_in_col_loc\n" |
| "%BP_clr_transformed = OpFunctionCall %v4f32 %test_code %BP_in_col_val\n" |
| "OpStore %BP_out_col_loc %BP_clr_transformed\n" |
| |
| "%BP_in_pos_loc = OpAccessChain %ip_v4f32 %BP_gl_in %BP_gl_Invoc %c_i32_0\n" |
| "%BP_out_pos_loc = OpAccessChain %op_v4f32 %BP_gl_out %BP_gl_Invoc %c_i32_0\n" |
| "%BP_in_pos_val = OpLoad %v4f32 %BP_in_pos_loc\n" |
| "OpStore %BP_out_pos_loc %BP_in_pos_val\n" |
| |
| "%BP_cmp = OpIEqual %bool %BP_gl_Invoc %c_i32_0\n" |
| "OpSelectionMerge %BP_merge_label None\n" |
| "OpBranchConditional %BP_cmp %BP_if_label %BP_merge_label\n" |
| "%BP_if_label = OpLabel\n" |
| "%BP_gl_TessLevelOuterPos_0 = OpAccessChain %op_f32 %BP_gl_TessLevelOuter %c_i32_0\n" |
| "%BP_gl_TessLevelOuterPos_1 = OpAccessChain %op_f32 %BP_gl_TessLevelOuter %c_i32_1\n" |
| "%BP_gl_TessLevelOuterPos_2 = OpAccessChain %op_f32 %BP_gl_TessLevelOuter %c_i32_2\n" |
| "%BP_gl_TessLevelInnerPos_0 = OpAccessChain %op_f32 %BP_gl_TessLevelInner %c_i32_0\n" |
| "OpStore %BP_gl_TessLevelOuterPos_0 %c_f32_1\n" |
| "OpStore %BP_gl_TessLevelOuterPos_1 %c_f32_1\n" |
| "OpStore %BP_gl_TessLevelOuterPos_2 %c_f32_1\n" |
| "OpStore %BP_gl_TessLevelInnerPos_0 %c_f32_1\n" |
| "OpBranch %BP_merge_label\n" |
| "%BP_merge_label = OpLabel\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n" |
| "${interface_op_func:opt}\n" |
| |
| "%isUniqueIdZero = OpFunction %bool None %bool_function\n" |
| "%getId_label = OpLabel\n" |
| "%invocation_id = OpLoad %i32 %BP_gl_InvocationID\n" |
| "%primitive_id = OpLoad %i32 %BP_gl_PrimitiveID\n" |
| "%is_invocation_0 = OpIEqual %bool %invocation_id %c_i32_0\n" |
| "%is_primitive_0 = OpIEqual %bool %primitive_id %c_i32_0\n" |
| "%is_id_0 = OpLogicalAnd %bool %is_invocation_0 %is_primitive_0\n" |
| "OpReturnValue %is_id_0\n" |
| "OpFunctionEnd\n" |
| |
| "${testfun}\n"; |
| return tcu::StringTemplate(tessControlShaderBoilerplate).specialize(fragments); |
| } |
| |
| // Creates tess-evaluation-shader assembly by specializing a boilerplate |
| // StringTemplate on fragments, which must (at least) map "testfun" to an |
| // OpFunction definition for %test_code that takes and returns a %v4f32. |
| // Boilerplate IDs are prefixed with "BP_" to avoid collisions with fragments. |
| // |
| // It roughly corresponds to the following glsl. |
| // |
| // #version 450 |
| // |
| // layout(triangles, equal_spacing, ccw) in; |
| // layout(location = 1) in vec4 in_color[]; |
| // layout(location = 1) out vec4 out_color; |
| // |
| // #define interpolate(val) |
| // vec4(gl_TessCoord.x) * val[0] + vec4(gl_TessCoord.y) * val[1] + |
| // vec4(gl_TessCoord.z) * val[2] |
| // |
| // void main() { |
| // gl_Position = vec4(gl_TessCoord.x) * gl_in[0].gl_Position + |
| // vec4(gl_TessCoord.y) * gl_in[1].gl_Position + |
| // vec4(gl_TessCoord.z) * gl_in[2].gl_Position; |
| // out_color = testfun(interpolate(in_color)); |
| // } |
| string makeTessEvalShaderAssembly (const map<string, string>& fragments) |
| { |
| static const char tessEvalBoilerplate[] = |
| "OpCapability Tessellation\n" |
| "${capability:opt}\n" |
| "${extension:opt}\n" |
| "OpMemoryModel Logical GLSL450\n" |
| "OpEntryPoint TessellationEvaluation %BP_main \"main\" %BP_stream %BP_gl_TessCoord %BP_gl_PrimitiveID %BP_gl_in %BP_out_color %BP_in_color ${IF_entrypoint:opt} \n" |
| "OpExecutionMode %BP_main Triangles\n" |
| "OpExecutionMode %BP_main SpacingEqual\n" |
| "OpExecutionMode %BP_main VertexOrderCcw\n" |
| "${execution_mode:opt}\n" |
| "${debug:opt}\n" |
| "${moduleprocessed:opt}\n" |
| "OpMemberDecorate %BP_gl_PerVertexOut 0 BuiltIn Position\n" |
| "OpMemberDecorate %BP_gl_PerVertexOut 1 BuiltIn PointSize\n" |
| "OpMemberDecorate %BP_gl_PerVertexOut 2 BuiltIn ClipDistance\n" |
| "OpMemberDecorate %BP_gl_PerVertexOut 3 BuiltIn CullDistance\n" |
| "OpDecorate %BP_gl_PerVertexOut Block\n" |
| "OpDecorate %BP_gl_PrimitiveID BuiltIn PrimitiveId\n" |
| "OpDecorate %BP_gl_TessCoord BuiltIn TessCoord\n" |
| "OpMemberDecorate %BP_gl_PerVertexIn 0 BuiltIn Position\n" |
| "OpMemberDecorate %BP_gl_PerVertexIn 1 BuiltIn PointSize\n" |
| "OpMemberDecorate %BP_gl_PerVertexIn 2 BuiltIn ClipDistance\n" |
| "OpMemberDecorate %BP_gl_PerVertexIn 3 BuiltIn CullDistance\n" |
| "OpDecorate %BP_gl_PerVertexIn Block\n" |
| "OpDecorate %BP_out_color Location 1\n" |
| "OpDecorate %BP_in_color Location 1\n" |
| "${IF_decoration:opt}\n" |
| "${decoration:opt}\n" |
| SPIRV_ASSEMBLY_TYPES |
| SPIRV_ASSEMBLY_CONSTANTS |
| SPIRV_ASSEMBLY_ARRAYS |
| "%BP_gl_PerVertexOut = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" |
| "%BP_op_gl_PerVertexOut = OpTypePointer Output %BP_gl_PerVertexOut\n" |
| "%BP_stream = OpVariable %BP_op_gl_PerVertexOut Output\n" |
| "%BP_gl_TessCoord = OpVariable %ip_v3f32 Input\n" |
| "%BP_gl_PrimitiveID = OpVariable %ip_i32 Input\n" |
| "%BP_gl_PerVertexIn = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" |
| "%BP_a32_gl_PerVertexIn = OpTypeArray %BP_gl_PerVertexIn %c_u32_32\n" |
| "%BP_ip_a32_gl_PerVertexIn = OpTypePointer Input %BP_a32_gl_PerVertexIn\n" |
| "%BP_gl_in = OpVariable %BP_ip_a32_gl_PerVertexIn Input\n" |
| "%BP_out_color = OpVariable %op_v4f32 Output\n" |
| "%BP_in_color = OpVariable %ip_a32v4f32 Input\n" |
| "${pre_main:opt}\n" |
| "${IF_variable:opt}\n" |
| "%BP_main = OpFunction %void None %voidf\n" |
| "%BP_label = OpLabel\n" |
| "${IF_carryforward:opt}\n" |
| "${post_interface_op_tesse:opt}\n" |
| "%BP_gl_TC_0 = OpAccessChain %ip_f32 %BP_gl_TessCoord %c_u32_0\n" |
| "%BP_gl_TC_1 = OpAccessChain %ip_f32 %BP_gl_TessCoord %c_u32_1\n" |
| "%BP_gl_TC_2 = OpAccessChain %ip_f32 %BP_gl_TessCoord %c_u32_2\n" |
| "%BP_gl_in_gl_Pos_0 = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_0 %c_i32_0\n" |
| "%BP_gl_in_gl_Pos_1 = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_1 %c_i32_0\n" |
| "%BP_gl_in_gl_Pos_2 = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_2 %c_i32_0\n" |
| |
| "%BP_gl_OPos = OpAccessChain %op_v4f32 %BP_stream %c_i32_0\n" |
| "%BP_in_color_0 = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_0\n" |
| "%BP_in_color_1 = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_1\n" |
| "%BP_in_color_2 = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_2\n" |
| |
| "%BP_TC_W_0 = OpLoad %f32 %BP_gl_TC_0\n" |
| "%BP_TC_W_1 = OpLoad %f32 %BP_gl_TC_1\n" |
| "%BP_TC_W_2 = OpLoad %f32 %BP_gl_TC_2\n" |
| "%BP_v4f32_TC_0 = OpCompositeConstruct %v4f32 %BP_TC_W_0 %BP_TC_W_0 %BP_TC_W_0 %BP_TC_W_0\n" |
| "%BP_v4f32_TC_1 = OpCompositeConstruct %v4f32 %BP_TC_W_1 %BP_TC_W_1 %BP_TC_W_1 %BP_TC_W_1\n" |
| "%BP_v4f32_TC_2 = OpCompositeConstruct %v4f32 %BP_TC_W_2 %BP_TC_W_2 %BP_TC_W_2 %BP_TC_W_2\n" |
| |
| "%BP_gl_IP_0 = OpLoad %v4f32 %BP_gl_in_gl_Pos_0\n" |
| "%BP_gl_IP_1 = OpLoad %v4f32 %BP_gl_in_gl_Pos_1\n" |
| "%BP_gl_IP_2 = OpLoad %v4f32 %BP_gl_in_gl_Pos_2\n" |
| |
| "%BP_IP_W_0 = OpFMul %v4f32 %BP_v4f32_TC_0 %BP_gl_IP_0\n" |
| "%BP_IP_W_1 = OpFMul %v4f32 %BP_v4f32_TC_1 %BP_gl_IP_1\n" |
| "%BP_IP_W_2 = OpFMul %v4f32 %BP_v4f32_TC_2 %BP_gl_IP_2\n" |
| |
| "%BP_pos_sum_0 = OpFAdd %v4f32 %BP_IP_W_0 %BP_IP_W_1\n" |
| "%BP_pos_sum_1 = OpFAdd %v4f32 %BP_pos_sum_0 %BP_IP_W_2\n" |
| |
| "OpStore %BP_gl_OPos %BP_pos_sum_1\n" |
| |
| "%BP_IC_0 = OpLoad %v4f32 %BP_in_color_0\n" |
| "%BP_IC_1 = OpLoad %v4f32 %BP_in_color_1\n" |
| "%BP_IC_2 = OpLoad %v4f32 %BP_in_color_2\n" |
| |
| "%BP_IC_W_0 = OpFMul %v4f32 %BP_v4f32_TC_0 %BP_IC_0\n" |
| "%BP_IC_W_1 = OpFMul %v4f32 %BP_v4f32_TC_1 %BP_IC_1\n" |
| "%BP_IC_W_2 = OpFMul %v4f32 %BP_v4f32_TC_2 %BP_IC_2\n" |
| |
| "%BP_col_sum_0 = OpFAdd %v4f32 %BP_IC_W_0 %BP_IC_W_1\n" |
| "%BP_col_sum_1 = OpFAdd %v4f32 %BP_col_sum_0 %BP_IC_W_2\n" |
| |
| "%BP_clr_transformed = OpFunctionCall %v4f32 %test_code %BP_col_sum_1\n" |
| |
| "OpStore %BP_out_color %BP_clr_transformed\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n" |
| "${interface_op_func:opt}\n" |
| |
| "%isUniqueIdZero = OpFunction %bool None %bool_function\n" |
| "%getId_label = OpLabel\n" |
| "%primitive_id = OpLoad %i32 %BP_gl_PrimitiveID\n" |
| "%is_primitive_0 = OpIEqual %bool %primitive_id %c_i32_0\n" |
| "%TC_0_loc = OpAccessChain %ip_f32 %BP_gl_TessCoord %c_u32_0\n" |
| "%TC_1_loc = OpAccessChain %ip_f32 %BP_gl_TessCoord %c_u32_1\n" |
| "%TC_2_loc = OpAccessChain %ip_f32 %BP_gl_TessCoord %c_u32_2\n" |
| "%TC_W_0 = OpLoad %f32 %TC_0_loc\n" |
| "%TC_W_1 = OpLoad %f32 %TC_1_loc\n" |
| "%TC_W_2 = OpLoad %f32 %TC_2_loc\n" |
| "%is_W_0_1 = OpFOrdEqual %bool %TC_W_0 %c_f32_1\n" |
| "%is_W_1_0 = OpFOrdEqual %bool %TC_W_1 %c_f32_0\n" |
| "%is_W_2_0 = OpFOrdEqual %bool %TC_W_2 %c_f32_0\n" |
| "%is_tessCoord_1_0 = OpLogicalAnd %bool %is_W_0_1 %is_W_1_0\n" |
| "%is_tessCoord_1_0_0 = OpLogicalAnd %bool %is_tessCoord_1_0 %is_W_2_0\n" |
| "%is_unique_id_0 = OpLogicalAnd %bool %is_tessCoord_1_0_0 %is_primitive_0\n" |
| "OpReturnValue %is_unique_id_0\n" |
| "OpFunctionEnd\n" |
| |
| "${testfun}\n"; |
| return tcu::StringTemplate(tessEvalBoilerplate).specialize(fragments); |
| } |
| |
| // Creates geometry-shader assembly by specializing a boilerplate StringTemplate |
| // on fragments, which must (at least) map "testfun" to an OpFunction definition |
| // for %test_code that takes and returns a %v4f32. Boilerplate IDs are prefixed |
| // with "BP_" to avoid collisions with fragments. |
| // |
| // Derived from this GLSL: |
| // |
| // #version 450 |
| // layout(triangles) in; |
| // layout(triangle_strip, max_vertices = 3) out; |
| // |
| // layout(location = 1) in vec4 in_color[]; |
| // layout(location = 1) out vec4 out_color; |
| // |
| // void main() { |
| // gl_Position = gl_in[0].gl_Position; |
| // out_color = test_fun(in_color[0]); |
| // EmitVertex(); |
| // gl_Position = gl_in[1].gl_Position; |
| // out_color = test_fun(in_color[1]); |
| // EmitVertex(); |
| // gl_Position = gl_in[2].gl_Position; |
| // out_color = test_fun(in_color[2]); |
| // EmitVertex(); |
| // EndPrimitive(); |
| // } |
| string makeGeometryShaderAssembly (const map<string, string>& fragments) |
| { |
| static const char geometryShaderBoilerplate[] = |
| "OpCapability Geometry\n" |
| "${capability:opt}\n" |
| "${extension:opt}\n" |
| "OpMemoryModel Logical GLSL450\n" |
| "OpEntryPoint Geometry %BP_main \"main\" %BP_out_gl_position %BP_gl_PrimitiveID %BP_gl_in %BP_out_color %BP_in_color ${IF_entrypoint:opt} ${GL_entrypoint:opt} \n" |
| "OpExecutionMode %BP_main Triangles\n" |
| "OpExecutionMode %BP_main Invocations 1\n" |
| "OpExecutionMode %BP_main OutputTriangleStrip\n" |
| "OpExecutionMode %BP_main OutputVertices 3\n" |
| "${execution_mode:opt}\n" |
| "${debug:opt}\n" |
| "${moduleprocessed:opt}\n" |
| "OpDecorate %BP_gl_PrimitiveID BuiltIn PrimitiveId\n" |
| "OpDecorate %BP_out_gl_position BuiltIn Position\n" |
| "OpMemberDecorate %BP_per_vertex_in 0 BuiltIn Position\n" |
| "OpMemberDecorate %BP_per_vertex_in 1 BuiltIn PointSize\n" |
| "OpMemberDecorate %BP_per_vertex_in 2 BuiltIn ClipDistance\n" |
| "OpMemberDecorate %BP_per_vertex_in 3 BuiltIn CullDistance\n" |
| "OpDecorate %BP_per_vertex_in Block\n" |
| "OpDecorate %BP_out_color Location 1\n" |
| "OpDecorate %BP_in_color Location 1\n" |
| "${IF_decoration:opt}\n" |
| "${decoration:opt}\n" |
| SPIRV_ASSEMBLY_TYPES |
| SPIRV_ASSEMBLY_CONSTANTS |
| SPIRV_ASSEMBLY_ARRAYS |
| "%BP_per_vertex_in = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" |
| "%BP_a3_per_vertex_in = OpTypeArray %BP_per_vertex_in %c_u32_3\n" |
| "%BP_ip_a3_per_vertex_in = OpTypePointer Input %BP_a3_per_vertex_in\n" |
| "%BP_pp_i32 = OpTypePointer Private %i32\n" |
| "%BP_pp_v4i32 = OpTypePointer Private %v4i32\n" |
| |
| "%BP_gl_in = OpVariable %BP_ip_a3_per_vertex_in Input\n" |
| "%BP_out_color = OpVariable %op_v4f32 Output\n" |
| "%BP_in_color = OpVariable %ip_a3v4f32 Input\n" |
| "%BP_gl_PrimitiveID = OpVariable %ip_i32 Input\n" |
| "%BP_out_gl_position = OpVariable %op_v4f32 Output\n" |
| "%BP_vertexIdInCurrentPatch = OpVariable %BP_pp_v4i32 Private\n" |
| "${pre_main:opt}\n" |
| "${IF_variable:opt}\n" |
| |
| "%BP_main = OpFunction %void None %voidf\n" |
| "%BP_label = OpLabel\n" |
| |
| "${IF_carryforward:opt}\n" |
| "${post_interface_op_geom:opt}\n" |
| |
| "%BP_primitiveId = OpLoad %i32 %BP_gl_PrimitiveID\n" |
| "%BP_addr_vertexIdInCurrentPatch = OpAccessChain %BP_pp_i32 %BP_vertexIdInCurrentPatch %BP_primitiveId\n" |
| |
| "%BP_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_0 %c_i32_0\n" |
| "%BP_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_1 %c_i32_0\n" |
| "%BP_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %BP_gl_in %c_i32_2 %c_i32_0\n" |
| |
| "%BP_in_position_0 = OpLoad %v4f32 %BP_gl_in_0_gl_position\n" |
| "%BP_in_position_1 = OpLoad %v4f32 %BP_gl_in_1_gl_position\n" |
| "%BP_in_position_2 = OpLoad %v4f32 %BP_gl_in_2_gl_position \n" |
| |
| "%BP_in_color_0_ptr = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_0\n" |
| "%BP_in_color_1_ptr = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_1\n" |
| "%BP_in_color_2_ptr = OpAccessChain %ip_v4f32 %BP_in_color %c_i32_2\n" |
| |
| "%BP_in_color_0 = OpLoad %v4f32 %BP_in_color_0_ptr\n" |
| "%BP_in_color_1 = OpLoad %v4f32 %BP_in_color_1_ptr\n" |
| "%BP_in_color_2 = OpLoad %v4f32 %BP_in_color_2_ptr\n" |
| |
| "OpStore %BP_addr_vertexIdInCurrentPatch %c_i32_0\n" |
| "%BP_transformed_in_color_0 = OpFunctionCall %v4f32 %test_code %BP_in_color_0\n" |
| "OpStore %BP_addr_vertexIdInCurrentPatch %c_i32_1\n" |
| "%BP_transformed_in_color_1 = OpFunctionCall %v4f32 %test_code %BP_in_color_1\n" |
| "OpStore %BP_addr_vertexIdInCurrentPatch %c_i32_2\n" |
| "%BP_transformed_in_color_2 = OpFunctionCall %v4f32 %test_code %BP_in_color_2\n" |
| |
| |
| "OpStore %BP_out_gl_position %BP_in_position_0\n" |
| "OpStore %BP_out_color %BP_transformed_in_color_0\n" |
| "OpEmitVertex\n" |
| |
| "OpStore %BP_out_gl_position %BP_in_position_1\n" |
| "OpStore %BP_out_color %BP_transformed_in_color_1\n" |
| "OpEmitVertex\n" |
| |
| "OpStore %BP_out_gl_position %BP_in_position_2\n" |
| "OpStore %BP_out_color %BP_transformed_in_color_2\n" |
| "OpEmitVertex\n" |
| |
| "OpEndPrimitive\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n" |
| "${interface_op_func:opt}\n" |
| |
| "%isUniqueIdZero = OpFunction %bool None %bool_function\n" |
| "%getId_label = OpLabel\n" |
| "%primitive_id = OpLoad %i32 %BP_gl_PrimitiveID\n" |
| "%addr_vertexIdInCurrentPatch = OpAccessChain %BP_pp_i32 %BP_vertexIdInCurrentPatch %primitive_id\n" |
| "%vertexIdInCurrentPatch = OpLoad %i32 %addr_vertexIdInCurrentPatch\n" |
| "%is_primitive_0 = OpIEqual %bool %primitive_id %c_i32_0\n" |
| "%is_vertex_0 = OpIEqual %bool %vertexIdInCurrentPatch %c_i32_0\n" |
| "%is_unique_id_0 = OpLogicalAnd %bool %is_primitive_0 %is_vertex_0\n" |
| "OpReturnValue %is_unique_id_0\n" |
| "OpFunctionEnd\n" |
| |
| "${testfun}\n"; |
| return tcu::StringTemplate(geometryShaderBoilerplate).specialize(fragments); |
| } |
| |
| // Creates fragment-shader assembly by specializing a boilerplate StringTemplate |
| // on fragments, which must (at least) map "testfun" to an OpFunction definition |
| // for %test_code that takes and returns a %v4f32. Boilerplate IDs are prefixed |
| // with "BP_" to avoid collisions with fragments. |
| // |
| // Derived from this GLSL: |
| // |
| // layout(location = 1) in highp vec4 vtxColor; |
| // layout(location = 0) out highp vec4 fragColor; |
| // highp vec4 testfun(highp vec4 x) { return x; } |
| // void main(void) { fragColor = testfun(vtxColor); } |
| // |
| // with modifications including passing vtxColor by value and ripping out |
| // testfun() definition. |
| string makeFragmentShaderAssembly (const map<string, string>& fragments) |
| { |
| static const char fragmentShaderBoilerplate[] = |
| "OpCapability Shader\n" |
| "${capability:opt}\n" |
| "${extension:opt}\n" |
| "OpMemoryModel Logical GLSL450\n" |
| "OpEntryPoint Fragment %BP_main \"main\" %BP_vtxColor %BP_fragColor %BP_gl_FragCoord ${IF_entrypoint:opt} \n" |
| "OpExecutionMode %BP_main OriginUpperLeft\n" |
| "${execution_mode:opt}\n" |
| "${debug:opt}\n" |
| "${moduleprocessed:opt}\n" |
| "OpDecorate %BP_fragColor Location 0\n" |
| "OpDecorate %BP_vtxColor Location 1\n" |
| "OpDecorate %BP_gl_FragCoord BuiltIn FragCoord\n" |
| "${IF_decoration:opt}\n" |
| "${decoration:opt}\n" |
| SPIRV_ASSEMBLY_TYPES |
| SPIRV_ASSEMBLY_CONSTANTS |
| SPIRV_ASSEMBLY_ARRAYS |
| "%BP_gl_FragCoord = OpVariable %ip_v4f32 Input\n" |
| "%BP_fragColor = OpVariable %op_v4f32 Output\n" |
| "%BP_vtxColor = OpVariable %ip_v4f32 Input\n" |
| "${pre_main:opt}\n" |
| "${IF_variable:opt}\n" |
| "%BP_main = OpFunction %void None %voidf\n" |
| "%BP_label_main = OpLabel\n" |
| "${IF_carryforward:opt}\n" |
| "${post_interface_op_frag:opt}\n" |
| "%BP_tmp1 = OpLoad %v4f32 %BP_vtxColor\n" |
| "%BP_tmp2 = OpFunctionCall %v4f32 %test_code %BP_tmp1\n" |
| "OpStore %BP_fragColor %BP_tmp2\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n" |
| "${interface_op_func:opt}\n" |
| |
| "%isUniqueIdZero = OpFunction %bool None %bool_function\n" |
| "%getId_label = OpLabel\n" |
| "%loc_x_coord = OpAccessChain %ip_f32 %BP_gl_FragCoord %c_i32_0\n" |
| "%loc_y_coord = OpAccessChain %ip_f32 %BP_gl_FragCoord %c_i32_1\n" |
| "%x_coord = OpLoad %f32 %loc_x_coord\n" |
| "%y_coord = OpLoad %f32 %loc_y_coord\n" |
| "%is_x_idx0 = OpFOrdEqual %bool %x_coord %c_f32_0_5\n" |
| "%is_y_idx0 = OpFOrdEqual %bool %y_coord %c_f32_0_5\n" |
| "%is_frag_0 = OpLogicalAnd %bool %is_x_idx0 %is_y_idx0\n" |
| "OpReturnValue %is_frag_0\n" |
| "OpFunctionEnd\n" |
| |
| "${testfun}\n"; |
| return tcu::StringTemplate(fragmentShaderBoilerplate).specialize(fragments); |
| } |
| |
| // Creates mappings from placeholders to pass-through shader code which copies |
| // the input to the output faithfully. |
| map<string, string> passthruInterface (const IFDataType& data_type) |
| { |
| const string var_type = data_type.str(); |
| map<string, string> fragments = passthruFragments(); |
| const string functype = string("%") + var_type + "_" + var_type + "_function"; |
| |
| fragments["interface_op_call"] = "OpCopyObject %" + var_type; |
| fragments["interface_op_func"] = ""; |
| fragments["input_type"] = var_type; |
| fragments["output_type"] = var_type; |
| fragments["pre_main"] = ""; |
| |
| if (!data_type.elementIs32bit()) |
| { |
| if (data_type.elementType == NUMBERTYPE_FLOAT64) |
| { |
| fragments["capability"] = "OpCapability Float64\n\n"; |
| fragments["pre_main"] += "%f64 = OpTypeFloat 64\n"; |
| } |
| else if (data_type.elementType == NUMBERTYPE_FLOAT16) |
| { |
| fragments["capability"] = "OpCapability StorageInputOutput16\n"; |
| fragments["extension"] = "OpExtension \"SPV_KHR_16bit_storage\"\n"; |
| fragments["pre_main"] += "%f16 = OpTypeFloat 16\n"; |
| } |
| else if (data_type.elementType == NUMBERTYPE_INT16) |
| { |
| fragments["capability"] = "OpCapability StorageInputOutput16\n"; |
| fragments["extension"] = "OpExtension \"SPV_KHR_16bit_storage\"\n"; |
| fragments["pre_main"] += "%i16 = OpTypeInt 16 1\n"; |
| } |
| else if (data_type.elementType == NUMBERTYPE_UINT16) |
| { |
| fragments["capability"] = "OpCapability StorageInputOutput16\n"; |
| fragments["extension"] = "OpExtension \"SPV_KHR_16bit_storage\"\n"; |
| fragments["pre_main"] += "%u16 = OpTypeInt 16 0\n"; |
| } |
| else |
| { |
| DE_ASSERT(0 && "unhandled type"); |
| } |
| |
| if (data_type.isVector()) |
| { |
| fragments["pre_main"] += "%" + var_type + " = OpTypeVector %" + IFDataType(1, data_type.elementType).str() + " " + numberToString(data_type.numElements) + "\n"; |
| } |
| |
| fragments["pre_main"] += |
| "%ip_" + var_type + " = OpTypePointer Input %" + var_type + "\n" |
| "%op_" + var_type + " = OpTypePointer Output %" + var_type + "\n"; |
| } |
| |
| if (strcmp(var_type.c_str(), "v4f32") != 0) |
| fragments["pre_main"] += |
| functype + " = OpTypeFunction %" + var_type + " %" + var_type + "\n" |
| "%a3" + var_type + " = OpTypeArray %" + var_type + " %c_i32_3\n" |
| "%ip_a3" + var_type + " = OpTypePointer Input %a3" + var_type + "\n" |
| "%op_a3" + var_type + " = OpTypePointer Output %a3" + var_type + "\n"; |
| |
| return fragments; |
| } |
| |
| // Returns mappings from interface placeholders to their concrete values. |
| // |
| // The concrete values should be specialized again to provide ${input_type} |
| // and ${output_type}. |
| // |
| // %ip_${input_type} and %op_${output_type} should also be defined in the final code. |
| map<string, string> fillInterfacePlaceholderVert (void) |
| { |
| map<string, string> fragments; |
| |
| fragments["IF_entrypoint"] = "%IF_input %IF_output"; |
| fragments["IF_variable"] = |
| " %IF_input = OpVariable %ip_${input_type} Input\n" |
| "%IF_output = OpVariable %op_${output_type} Output\n"; |
| fragments["IF_decoration"] = |
| "OpDecorate %IF_input Location 2\n" |
| "OpDecorate %IF_output Location 2\n"; |
| fragments["IF_carryforward"] = |
| "%IF_input_val = OpLoad %${input_type} %IF_input\n" |
| " %IF_result = ${interface_op_call} %IF_input_val\n" |
| " OpStore %IF_output %IF_result\n"; |
| |
| // Make sure the rest still need to be instantialized. |
| fragments["capability"] = "${capability:opt}"; |
| fragments["extension"] = "${extension:opt}"; |
| fragments["execution_mode"] = "${execution_mode:opt}"; |
| fragments["debug"] = "${debug:opt}"; |
| fragments["decoration"] = "${decoration:opt}"; |
| fragments["pre_main"] = "${pre_main:opt}"; |
| fragments["testfun"] = "${testfun}"; |
| fragments["interface_op_call"] = "${interface_op_call}"; |
| fragments["interface_op_func"] = "${interface_op_func}"; |
| fragments["post_interface_op_vert"] = "${post_interface_op_vert:opt}"; |
| |
| return fragments; |
| } |
| |
| // Returns mappings from interface placeholders to their concrete values. |
| // |
| // The concrete values should be specialized again to provide ${input_type} |
| // and ${output_type}. |
| // |
| // %ip_${input_type} and %op_${output_type} should also be defined in the final code. |
| map<string, string> fillInterfacePlaceholderFrag (void) |
| { |
| map<string, string> fragments; |
| |
| fragments["IF_entrypoint"] = "%IF_input %IF_output"; |
| fragments["IF_variable"] = |
| " %IF_input = OpVariable %ip_${input_type} Input\n" |
| "%IF_output = OpVariable %op_${output_type} Output\n"; |
| fragments["IF_decoration"] = |
| "OpDecorate %IF_input Flat\n" |
| "OpDecorate %IF_input Location 2\n" |
| "OpDecorate %IF_output Location 1\n"; // Fragment shader should write to location #1. |
| fragments["IF_carryforward"] = |
| "%IF_input_val = OpLoad %${input_type} %IF_input\n" |
| " %IF_result = ${interface_op_call} %IF_input_val\n" |
| " OpStore %IF_output %IF_result\n"; |
| |
| // Make sure the rest still need to be instantialized. |
| fragments["capability"] = "${capability:opt}"; |
| fragments["extension"] = "${extension:opt}"; |
| fragments["execution_mode"] = "${execution_mode:opt}"; |
| fragments["debug"] = "${debug:opt}"; |
| fragments["decoration"] = "${decoration:opt}"; |
| fragments["pre_main"] = "${pre_main:opt}"; |
| fragments["testfun"] = "${testfun}"; |
| fragments["interface_op_call"] = "${interface_op_call}"; |
| fragments["interface_op_func"] = "${interface_op_func}"; |
| fragments["post_interface_op_frag"] = "${post_interface_op_frag:opt}"; |
| |
| return fragments; |
| } |
| |
| // Returns mappings from interface placeholders to their concrete values. |
| // |
| // The concrete values should be specialized again to provide ${input_type} |
| // and ${output_type}. |
| // |
| // %ip_${input_type}, %op_${output_type}, %ip_a3${input_type}, and $op_a3${output_type} |
| // should also be defined in the final code. |
| map<string, string> fillInterfacePlaceholderTessCtrl (void) |
| { |
| map<string, string> fragments; |
| |
| fragments["IF_entrypoint"] = "%IF_input %IF_output"; |
| fragments["IF_variable"] = |
| " %IF_input = OpVariable %ip_a3${input_type} Input\n" |
| "%IF_output = OpVariable %op_a3${output_type} Output\n"; |
| fragments["IF_decoration"] = |
| "OpDecorate %IF_input Location 2\n" |
| "OpDecorate %IF_output Location 2\n"; |
| fragments["IF_carryforward"] = |
| " %IF_input_ptr0 = OpAccessChain %ip_${input_type} %IF_input %c_i32_0\n" |
| " %IF_input_ptr1 = OpAccessChain %ip_${input_type} %IF_input %c_i32_1\n" |
| " %IF_input_ptr2 = OpAccessChain %ip_${input_type} %IF_input %c_i32_2\n" |
| "%IF_output_ptr0 = OpAccessChain %op_${output_type} %IF_output %c_i32_0\n" |
| "%IF_output_ptr1 = OpAccessChain %op_${output_type} %IF_output %c_i32_1\n" |
| "%IF_output_ptr2 = OpAccessChain %op_${output_type} %IF_output %c_i32_2\n" |
| "%IF_input_val0 = OpLoad %${input_type} %IF_input_ptr0\n" |
| "%IF_input_val1 = OpLoad %${input_type} %IF_input_ptr1\n" |
| "%IF_input_val2 = OpLoad %${input_type} %IF_input_ptr2\n" |
| "%IF_input_res0 = ${interface_op_call} %IF_input_val0\n" |
| "%IF_input_res1 = ${interface_op_call} %IF_input_val1\n" |
| "%IF_input_res2 = ${interface_op_call} %IF_input_val2\n" |
| "OpStore %IF_output_ptr0 %IF_input_res0\n" |
| "OpStore %IF_output_ptr1 %IF_input_res1\n" |
| "OpStore %IF_output_ptr2 %IF_input_res2\n"; |
| |
| // Make sure the rest still need to be instantialized. |
| fragments["capability"] = "${capability:opt}"; |
| fragments["extension"] = "${extension:opt}"; |
| fragments["execution_mode"] = "${execution_mode:opt}"; |
| fragments["debug"] = "${debug:opt}"; |
| fragments["decoration"] = "${decoration:opt}"; |
| fragments["decoration_tessc"] = "${decoration_tessc:opt}"; |
| fragments["pre_main"] = "${pre_main:opt}"; |
| fragments["testfun"] = "${testfun}"; |
| fragments["interface_op_call"] = "${interface_op_call}"; |
| fragments["interface_op_func"] = "${interface_op_func}"; |
| fragments["post_interface_op_tessc"] = "${post_interface_op_tessc:opt}"; |
| |
| return fragments; |
| } |
| |
| // Returns mappings from interface placeholders to their concrete values. |
| // |
| // The concrete values should be specialized again to provide ${input_type} |
| // and ${output_type}. |
| // |
| // %ip_${input_type}, %op_${output_type}, %ip_a3${input_type}, and $op_a3${output_type} |
| // should also be defined in the final code. |
| map<string, string> fillInterfacePlaceholderTessEvalGeom (void) |
| { |
| map<string, string> fragments; |
| |
| fragments["IF_entrypoint"] = "%IF_input %IF_output"; |
| fragments["IF_variable"] = |
| " %IF_input = OpVariable %ip_a3${input_type} Input\n" |
| "%IF_output = OpVariable %op_${output_type} Output\n"; |
| fragments["IF_decoration"] = |
| "OpDecorate %IF_input Location 2\n" |
| "OpDecorate %IF_output Location 2\n"; |
| fragments["IF_carryforward"] = |
| // Only get the first value since all three values are the same anyway. |
| " %IF_input_ptr0 = OpAccessChain %ip_${input_type} %IF_input %c_i32_0\n" |
| " %IF_input_val0 = OpLoad %${input_type} %IF_input_ptr0\n" |
| " %IF_input_res0 = ${interface_op_call} %IF_input_val0\n" |
| "OpStore %IF_output %IF_input_res0\n"; |
| |
| // Make sure the rest still need to be instantialized. |
| fragments["capability"] = "${capability:opt}"; |
| fragments["extension"] = "${extension:opt}"; |
| fragments["execution_mode"] = "${execution_mode:opt}"; |
| fragments["debug"] = "${debug:opt}"; |
| fragments["decoration"] = "${decoration:opt}"; |
| fragments["pre_main"] = "${pre_main:opt}"; |
| fragments["testfun"] = "${testfun}"; |
| fragments["interface_op_call"] = "${interface_op_call}"; |
| fragments["interface_op_func"] = "${interface_op_func}"; |
| fragments["post_interface_op_tesse"] = "${post_interface_op_tesse:opt}"; |
| fragments["post_interface_op_geom"] = "${post_interface_op_geom:opt}"; |
| |
| return fragments; |
| } |
| |
| map<string, string> passthruFragments (void) |
| { |
| map<string, string> fragments; |
| fragments["testfun"] = |
| // A %test_code function that returns its argument unchanged. |
| "%test_code = OpFunction %v4f32 None %v4f32_v4f32_function\n" |
| "%param1 = OpFunctionParameter %v4f32\n" |
| "%label_testfun = OpLabel\n" |
| "OpReturnValue %param1\n" |
| "OpFunctionEnd\n"; |
| return fragments; |
| } |
| |
| // Adds shader assembly text to dst.spirvAsmSources for all shader kinds. |
| // Vertex shader gets custom code from context, the rest are pass-through. |
| void addShaderCodeCustomVertex (vk::SourceCollections& dst, InstanceContext& context, const SpirVAsmBuildOptions* spirVAsmBuildOptions) |
| { |
| const deUint32 vulkanVersion = dst.usedVulkanVersion; |
| SpirvVersion targetSpirvVersion; |
| |
| if (spirVAsmBuildOptions == DE_NULL) |
| targetSpirvVersion = context.resources.spirvVersion; |
| else |
| targetSpirvVersion = spirVAsmBuildOptions->targetVersion; |
| |
| if (!context.interfaces.empty()) |
| { |
| // Inject boilerplate code to wire up additional input/output variables between stages. |
| // Just copy the contents in input variable to output variable in all stages except |
| // the customized stage. |
| dst.spirvAsmSources.add("vert", spirVAsmBuildOptions) << StringTemplate(makeVertexShaderAssembly(fillInterfacePlaceholderVert())).specialize(context.testCodeFragments) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("frag", spirVAsmBuildOptions) << StringTemplate(makeFragmentShaderAssembly(fillInterfacePlaceholderFrag())).specialize(passthruInterface(context.interfaces.getOutputType())) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| } else { |
| map<string, string> passthru = passthruFragments(); |
| |
| dst.spirvAsmSources.add("vert", spirVAsmBuildOptions) << makeVertexShaderAssembly(context.testCodeFragments) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("frag", spirVAsmBuildOptions) << makeFragmentShaderAssembly(passthru) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| } |
| } |
| |
| void addShaderCodeCustomVertex (vk::SourceCollections& dst, InstanceContext context) |
| { |
| addShaderCodeCustomVertex(dst, context, DE_NULL); |
| } |
| |
| // Adds shader assembly text to dst.spirvAsmSources for all shader kinds. |
| // Tessellation control shader gets custom code from context, the rest are |
| // pass-through. |
| void addShaderCodeCustomTessControl (vk::SourceCollections& dst, InstanceContext& context, const SpirVAsmBuildOptions* spirVAsmBuildOptions) |
| { |
| const deUint32 vulkanVersion = dst.usedVulkanVersion; |
| SpirvVersion targetSpirvVersion; |
| |
| if (spirVAsmBuildOptions == DE_NULL) |
| targetSpirvVersion = context.resources.spirvVersion; |
| else |
| targetSpirvVersion = spirVAsmBuildOptions->targetVersion; |
| |
| if (!context.interfaces.empty()) |
| { |
| // Inject boilerplate code to wire up additional input/output variables between stages. |
| // Just copy the contents in input variable to output variable in all stages except |
| // the customized stage. |
| dst.spirvAsmSources.add("vert", spirVAsmBuildOptions) << StringTemplate(makeVertexShaderAssembly(fillInterfacePlaceholderVert())).specialize(passthruInterface(context.interfaces.getInputType())) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("tessc", spirVAsmBuildOptions) << StringTemplate(makeTessControlShaderAssembly(fillInterfacePlaceholderTessCtrl())).specialize(context.testCodeFragments) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("tesse", spirVAsmBuildOptions) << StringTemplate(makeTessEvalShaderAssembly(fillInterfacePlaceholderTessEvalGeom())).specialize(passthruInterface(context.interfaces.getOutputType())) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("frag", spirVAsmBuildOptions) << StringTemplate(makeFragmentShaderAssembly(fillInterfacePlaceholderFrag())).specialize(passthruInterface(context.interfaces.getOutputType())) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| } |
| else |
| { |
| map<string, string> passthru = passthruFragments(); |
| |
| dst.spirvAsmSources.add("vert", spirVAsmBuildOptions) << makeVertexShaderAssembly(passthru) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("tessc", spirVAsmBuildOptions) << makeTessControlShaderAssembly(context.testCodeFragments) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("tesse", spirVAsmBuildOptions) << makeTessEvalShaderAssembly(passthru) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("frag", spirVAsmBuildOptions) << makeFragmentShaderAssembly(passthru) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| } |
| } |
| |
| void addShaderCodeCustomTessControl (vk::SourceCollections& dst, InstanceContext context) |
| { |
| addShaderCodeCustomTessControl(dst, context, DE_NULL); |
| } |
| |
| // Adds shader assembly text to dst.spirvAsmSources for all shader kinds. |
| // Tessellation evaluation shader gets custom code from context, the rest are |
| // pass-through. |
| void addShaderCodeCustomTessEval (vk::SourceCollections& dst, InstanceContext& context, const SpirVAsmBuildOptions* spirVAsmBuildOptions) |
| { |
| const deUint32 vulkanVersion = dst.usedVulkanVersion; |
| SpirvVersion targetSpirvVersion; |
| |
| if (spirVAsmBuildOptions == DE_NULL) |
| targetSpirvVersion = context.resources.spirvVersion; |
| else |
| targetSpirvVersion = spirVAsmBuildOptions->targetVersion; |
| |
| if (!context.interfaces.empty()) |
| { |
| // Inject boilerplate code to wire up additional input/output variables between stages. |
| // Just copy the contents in input variable to output variable in all stages except |
| // the customized stage. |
| dst.spirvAsmSources.add("vert", spirVAsmBuildOptions) << StringTemplate(makeVertexShaderAssembly(fillInterfacePlaceholderVert())).specialize(passthruInterface(context.interfaces.getInputType())) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("tessc", spirVAsmBuildOptions) << StringTemplate(makeTessControlShaderAssembly(fillInterfacePlaceholderTessCtrl())).specialize(passthruInterface(context.interfaces.getInputType())) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("tesse", spirVAsmBuildOptions) << StringTemplate(makeTessEvalShaderAssembly(fillInterfacePlaceholderTessEvalGeom())).specialize(context.testCodeFragments) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("frag", spirVAsmBuildOptions) << StringTemplate(makeFragmentShaderAssembly(fillInterfacePlaceholderFrag())).specialize(passthruInterface(context.interfaces.getOutputType())) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| } |
| else |
| { |
| map<string, string> passthru = passthruFragments(); |
| dst.spirvAsmSources.add("vert", spirVAsmBuildOptions) << makeVertexShaderAssembly(passthru) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("tessc", spirVAsmBuildOptions) << makeTessControlShaderAssembly(passthru) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("tesse", spirVAsmBuildOptions) << makeTessEvalShaderAssembly(context.testCodeFragments) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("frag", spirVAsmBuildOptions) << makeFragmentShaderAssembly(passthru) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| } |
| } |
| |
| void addShaderCodeCustomTessEval (vk::SourceCollections& dst, InstanceContext context) |
| { |
| addShaderCodeCustomTessEval(dst, context, DE_NULL); |
| } |
| |
| // Adds shader assembly text to dst.spirvAsmSources for all shader kinds. |
| // Geometry shader gets custom code from context, the rest are pass-through. |
| void addShaderCodeCustomGeometry (vk::SourceCollections& dst, InstanceContext& context, const SpirVAsmBuildOptions* spirVAsmBuildOptions) |
| { |
| const deUint32 vulkanVersion = dst.usedVulkanVersion; |
| SpirvVersion targetSpirvVersion; |
| |
| if (spirVAsmBuildOptions == DE_NULL) |
| targetSpirvVersion = context.resources.spirvVersion; |
| else |
| targetSpirvVersion = spirVAsmBuildOptions->targetVersion; |
| |
| if (!context.interfaces.empty()) |
| { |
| // Inject boilerplate code to wire up additional input/output variables between stages. |
| // Just copy the contents in input variable to output variable in all stages except |
| // the customized stage. |
| dst.spirvAsmSources.add("vert", spirVAsmBuildOptions) << StringTemplate(makeVertexShaderAssembly(fillInterfacePlaceholderVert())).specialize(passthruInterface(context.interfaces.getInputType())) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("geom", spirVAsmBuildOptions) << StringTemplate(makeGeometryShaderAssembly(fillInterfacePlaceholderTessEvalGeom())).specialize(context.testCodeFragments) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("frag", spirVAsmBuildOptions) << StringTemplate(makeFragmentShaderAssembly(fillInterfacePlaceholderFrag())).specialize(passthruInterface(context.interfaces.getOutputType())) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| } |
| else |
| { |
| map<string, string> passthru = passthruFragments(); |
| dst.spirvAsmSources.add("vert", spirVAsmBuildOptions) << makeVertexShaderAssembly(passthru) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("geom", spirVAsmBuildOptions) << makeGeometryShaderAssembly(context.testCodeFragments) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("frag", spirVAsmBuildOptions) << makeFragmentShaderAssembly(passthru) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| } |
| } |
| |
| void addShaderCodeCustomGeometry (vk::SourceCollections& dst, InstanceContext context) |
| { |
| addShaderCodeCustomGeometry(dst, context, DE_NULL); |
| } |
| |
| // Adds shader assembly text to dst.spirvAsmSources for all shader kinds. |
| // Fragment shader gets custom code from context, the rest are pass-through. |
| void addShaderCodeCustomFragment (vk::SourceCollections& dst, InstanceContext& context, const SpirVAsmBuildOptions* spirVAsmBuildOptions) |
| { |
| const deUint32 vulkanVersion = dst.usedVulkanVersion; |
| SpirvVersion targetSpirvVersion; |
| |
| if (spirVAsmBuildOptions == DE_NULL) |
| targetSpirvVersion = context.resources.spirvVersion; |
| else |
| targetSpirvVersion = spirVAsmBuildOptions->targetVersion; |
| |
| if (!context.interfaces.empty()) |
| { |
| // Inject boilerplate code to wire up additional input/output variables between stages. |
| // Just copy the contents in input variable to output variable in all stages except |
| // the customized stage. |
| dst.spirvAsmSources.add("vert", spirVAsmBuildOptions) << StringTemplate(makeVertexShaderAssembly(fillInterfacePlaceholderVert())).specialize(passthruInterface(context.interfaces.getInputType())) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("frag", spirVAsmBuildOptions) << StringTemplate(makeFragmentShaderAssembly(fillInterfacePlaceholderFrag())).specialize(context.testCodeFragments) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| } |
| else |
| { |
| map<string, string> passthru = passthruFragments(); |
| dst.spirvAsmSources.add("vert", spirVAsmBuildOptions) << makeVertexShaderAssembly(passthru) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| dst.spirvAsmSources.add("frag", spirVAsmBuildOptions) << makeFragmentShaderAssembly(context.testCodeFragments) << SpirVAsmBuildOptions(vulkanVersion, targetSpirvVersion); |
| } |
| } |
| |
| void addShaderCodeCustomFragment (vk::SourceCollections& dst, InstanceContext context) |
| { |
| addShaderCodeCustomFragment(dst, context, DE_NULL); |
| } |
| |
| void createCombinedModule (vk::SourceCollections& dst, InstanceContext ctx) |
| { |
| const bool useTessellation (ctx.requiredStages & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT)); |
| const bool useGeometry (ctx.requiredStages & VK_SHADER_STAGE_GEOMETRY_BIT); |
| std::stringstream combinedModule; |
| std::stringstream opCapabilities; |
| std::stringstream opEntryPoints; |
| |
| // opCapabilities |
| { |
| opCapabilities << "OpCapability Shader\n"; |
| |
| if (useGeometry) |
| opCapabilities << "OpCapability Geometry\n"; |
| |
| if (useTessellation) |
| opCapabilities << "OpCapability Tessellation\n"; |
| } |
| |
| // opEntryPoints |
| { |
| if (useTessellation) |
| opEntryPoints << "OpEntryPoint Vertex %vert_main \"main\" %vert_Position %vert_vtxColor %vert_color %vert_vtxPosition %vert_vertex_id %vert_instance_id\n"; |
| else |
| opEntryPoints << "OpEntryPoint Vertex %vert_main \"main\" %vert_Position %vert_vtxColor %vert_color %vert_glPerVertex %vert_vertex_id %vert_instance_id\n"; |
| |
| if (useGeometry) |
| opEntryPoints << "OpEntryPoint Geometry %geom_main \"main\" %geom_out_gl_position %geom_gl_in %geom_out_color %geom_in_color\n"; |
| |
| if (useTessellation) |
| { |
| opEntryPoints << "OpEntryPoint TessellationControl %tessc_main \"main\" %tessc_out_color %tessc_gl_InvocationID %tessc_in_color %tessc_out_position %tessc_in_position %tessc_gl_TessLevelOuter %tessc_gl_TessLevelInner\n" |
| "OpEntryPoint TessellationEvaluation %tesse_main \"main\" %tesse_stream %tesse_gl_tessCoord %tesse_in_position %tesse_out_color %tesse_in_color \n"; |
| } |
| |
| opEntryPoints << "OpEntryPoint Fragment %frag_main \"main\" %frag_vtxColor %frag_fragColor\n"; |
| } |
| |
| combinedModule << opCapabilities.str() |
| << "OpMemoryModel Logical GLSL450\n" |
| << opEntryPoints.str(); |
| |
| if (useGeometry) |
| { |
| combinedModule << "OpExecutionMode %geom_main Triangles\n" |
| "OpExecutionMode %geom_main Invocations 1\n" |
| "OpExecutionMode %geom_main OutputTriangleStrip\n" |
| "OpExecutionMode %geom_main OutputVertices 3\n"; |
| } |
| |
| if (useTessellation) |
| { |
| combinedModule << "OpExecutionMode %tessc_main OutputVertices 3\n" |
| "OpExecutionMode %tesse_main Triangles\n" |
| "OpExecutionMode %tesse_main SpacingEqual\n" |
| "OpExecutionMode %tesse_main VertexOrderCcw\n"; |
| } |
| |
| combinedModule << "OpExecutionMode %frag_main OriginUpperLeft\n" |
| |
| "; Vertex decorations\n" |
| "OpDecorate %vert_Position Location 0\n" |
| "OpDecorate %vert_vtxColor Location 1\n" |
| "OpDecorate %vert_color Location 1\n" |
| "OpDecorate %vert_vertex_id BuiltIn VertexIndex\n" |
| "OpDecorate %vert_instance_id BuiltIn InstanceIndex\n"; |
| |
| // If tessellation is used, vertex position is written by tessellation stage. |
| // Otherwise it will be written by vertex stage. |
| if (useTessellation) |
| combinedModule << "OpDecorate %vert_vtxPosition Location 2\n"; |
| else |
| { |
| combinedModule << "OpMemberDecorate %vert_per_vertex_out 0 BuiltIn Position\n" |
| "OpMemberDecorate %vert_per_vertex_out 1 BuiltIn PointSize\n" |
| "OpMemberDecorate %vert_per_vertex_out 2 BuiltIn ClipDistance\n" |
| "OpMemberDecorate %vert_per_vertex_out 3 BuiltIn CullDistance\n" |
| "OpDecorate %vert_per_vertex_out Block\n"; |
| } |
| |
| if (useGeometry) |
| { |
| combinedModule << "; Geometry decorations\n" |
| "OpDecorate %geom_out_gl_position BuiltIn Position\n" |
| "OpMemberDecorate %geom_per_vertex_in 0 BuiltIn Position\n" |
| "OpMemberDecorate %geom_per_vertex_in 1 BuiltIn PointSize\n" |
| "OpMemberDecorate %geom_per_vertex_in 2 BuiltIn ClipDistance\n" |
| "OpMemberDecorate %geom_per_vertex_in 3 BuiltIn CullDistance\n" |
| "OpDecorate %geom_per_vertex_in Block\n" |
| "OpDecorate %geom_out_color Location 1\n" |
| "OpDecorate %geom_in_color Location 1\n"; |
| } |
| |
| if (useTessellation) |
| { |
| combinedModule << "; Tessellation Control decorations\n" |
| "OpDecorate %tessc_out_color Location 1\n" |
| "OpDecorate %tessc_gl_InvocationID BuiltIn InvocationId\n" |
| "OpDecorate %tessc_in_color Location 1\n" |
| "OpDecorate %tessc_out_position Location 2\n" |
| "OpDecorate %tessc_in_position Location 2\n" |
| "OpDecorate %tessc_gl_TessLevelOuter Patch\n" |
| "OpDecorate %tessc_gl_TessLevelOuter BuiltIn TessLevelOuter\n" |
| "OpDecorate %tessc_gl_TessLevelInner Patch\n" |
| "OpDecorate %tessc_gl_TessLevelInner BuiltIn TessLevelInner\n" |
| |
| "; Tessellation Evaluation decorations\n" |
| "OpMemberDecorate %tesse_per_vertex_out 0 BuiltIn Position\n" |
| "OpMemberDecorate %tesse_per_vertex_out 1 BuiltIn PointSize\n" |
| "OpMemberDecorate %tesse_per_vertex_out 2 BuiltIn ClipDistance\n" |
| "OpMemberDecorate %tesse_per_vertex_out 3 BuiltIn CullDistance\n" |
| "OpDecorate %tesse_per_vertex_out Block\n" |
| "OpDecorate %tesse_gl_tessCoord BuiltIn TessCoord\n" |
| "OpDecorate %tesse_in_position Location 2\n" |
| "OpDecorate %tesse_out_color Location 1\n" |
| "OpDecorate %tesse_in_color Location 1\n"; |
| } |
| |
| combinedModule << "; Fragment decorations\n" |
| "OpDecorate %frag_fragColor Location 0\n" |
| "OpDecorate %frag_vtxColor Location 1\n" |
| |
| SPIRV_ASSEMBLY_TYPES |
| SPIRV_ASSEMBLY_CONSTANTS |
| SPIRV_ASSEMBLY_ARRAYS |
| |
| "; Vertex Variables\n" |
| "%vert_Position = OpVariable %ip_v4f32 Input\n" |
| "%vert_vtxColor = OpVariable %op_v4f32 Output\n" |
| "%vert_color = OpVariable %ip_v4f32 Input\n" |
| "%vert_vertex_id = OpVariable %ip_i32 Input\n" |
| "%vert_instance_id = OpVariable %ip_i32 Input\n"; |
| |
| if (useTessellation) |
| combinedModule << "%vert_vtxPosition = OpVariable %op_v4f32 Output\n"; |
| else |
| { |
| combinedModule << "%vert_per_vertex_out = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" |
| "%vert_op_per_vertex_out = OpTypePointer Output %vert_per_vertex_out\n" |
| "%vert_glPerVertex = OpVariable %vert_op_per_vertex_out Output\n"; |
| } |
| |
| if (useGeometry) |
| { |
| combinedModule << "; Geometry Variables\n" |
| "%geom_per_vertex_in = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" |
| "%geom_a3_per_vertex_in = OpTypeArray %geom_per_vertex_in %c_u32_3\n" |
| "%geom_ip_a3_per_vertex_in = OpTypePointer Input %geom_a3_per_vertex_in\n" |
| "%geom_gl_in = OpVariable %geom_ip_a3_per_vertex_in Input\n" |
| "%geom_out_color = OpVariable %op_v4f32 Output\n" |
| "%geom_in_color = OpVariable %ip_a3v4f32 Input\n" |
| "%geom_out_gl_position = OpVariable %op_v4f32 Output\n"; |
| } |
| |
| if (useTessellation) |
| { |
| combinedModule << "; Tessellation Control Variables\n" |
| "%tessc_out_color = OpVariable %op_a3v4f32 Output\n" |
| "%tessc_gl_InvocationID = OpVariable %ip_i32 Input\n" |
| "%tessc_in_color = OpVariable %ip_a32v4f32 Input\n" |
| "%tessc_out_position = OpVariable %op_a3v4f32 Output\n" |
| "%tessc_in_position = OpVariable %ip_a32v4f32 Input\n" |
| "%tessc_gl_TessLevelOuter = OpVariable %op_a4f32 Output\n" |
| "%tessc_gl_TessLevelInner = OpVariable %op_a2f32 Output\n" |
| |
| "; Tessellation Evaluation Decorations\n" |
| "%tesse_per_vertex_out = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" |
| "%tesse_op_per_vertex_out = OpTypePointer Output %tesse_per_vertex_out\n" |
| "%tesse_stream = OpVariable %tesse_op_per_vertex_out Output\n" |
| "%tesse_gl_tessCoord = OpVariable %ip_v3f32 Input\n" |
| "%tesse_in_position = OpVariable %ip_a32v4f32 Input\n" |
| "%tesse_out_color = OpVariable %op_v4f32 Output\n" |
| "%tesse_in_color = OpVariable %ip_a32v4f32 Input\n"; |
| } |
| |
| combinedModule << "; Fragment Variables\n" |
| "%frag_fragColor = OpVariable %op_v4f32 Output\n" |
| "%frag_vtxColor = OpVariable %ip_v4f32 Input\n" |
| |
| "; Vertex Entry\n" |
| "%vert_main = OpFunction %void None %voidf\n" |
| "%vert_label = OpLabel\n" |
| "%vert_tmp_position = OpLoad %v4f32 %vert_Position\n"; |
| |
| if (useTessellation) |
| combinedModule << "OpStore %vert_vtxPosition %vert_tmp_position\n"; |
| else |
| { |
| combinedModule << "%vert_out_pos_ptr = OpAccessChain %op_v4f32 %vert_glPerVertex %c_i32_0\n" |
| "OpStore %vert_out_pos_ptr %vert_tmp_position\n"; |
| } |
| |
| combinedModule << "%vert_tmp_color = OpLoad %v4f32 %vert_color\n" |
| "OpStore %vert_vtxColor %vert_tmp_color\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n"; |
| |
| if (useGeometry) |
| { |
| combinedModule << "; Geometry Entry\n" |
| "%geom_main = OpFunction %void None %voidf\n" |
| "%geom_label = OpLabel\n" |
| "%geom_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %geom_gl_in %c_i32_0 %c_i32_0\n" |
| "%geom_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %geom_gl_in %c_i32_1 %c_i32_0\n" |
| "%geom_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %geom_gl_in %c_i32_2 %c_i32_0\n" |
| "%geom_in_position_0 = OpLoad %v4f32 %geom_gl_in_0_gl_position\n" |
| "%geom_in_position_1 = OpLoad %v4f32 %geom_gl_in_1_gl_position\n" |
| "%geom_in_position_2 = OpLoad %v4f32 %geom_gl_in_2_gl_position \n" |
| "%geom_in_color_0_ptr = OpAccessChain %ip_v4f32 %geom_in_color %c_i32_0\n" |
| "%geom_in_color_1_ptr = OpAccessChain %ip_v4f32 %geom_in_color %c_i32_1\n" |
| "%geom_in_color_2_ptr = OpAccessChain %ip_v4f32 %geom_in_color %c_i32_2\n" |
| "%geom_in_color_0 = OpLoad %v4f32 %geom_in_color_0_ptr\n" |
| "%geom_in_color_1 = OpLoad %v4f32 %geom_in_color_1_ptr\n" |
| "%geom_in_color_2 = OpLoad %v4f32 %geom_in_color_2_ptr\n" |
| "OpStore %geom_out_gl_position %geom_in_position_0\n" |
| "OpStore %geom_out_color %geom_in_color_0\n" |
| "OpEmitVertex\n" |
| "OpStore %geom_out_gl_position %geom_in_position_1\n" |
| "OpStore %geom_out_color %geom_in_color_1\n" |
| "OpEmitVertex\n" |
| "OpStore %geom_out_gl_position %geom_in_position_2\n" |
| "OpStore %geom_out_color %geom_in_color_2\n" |
| "OpEmitVertex\n" |
| "OpEndPrimitive\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n"; |
| } |
| |
| if (useTessellation) |
| { |
| combinedModule << "; Tessellation Control Entry\n" |
| "%tessc_main = OpFunction %void None %voidf\n" |
| "%tessc_label = OpLabel\n" |
| "%tessc_invocation_id = OpLoad %i32 %tessc_gl_InvocationID\n" |
| "%tessc_in_color_ptr = OpAccessChain %ip_v4f32 %tessc_in_color %tessc_invocation_id\n" |
| "%tessc_in_position_ptr = OpAccessChain %ip_v4f32 %tessc_in_position %tessc_invocation_id\n" |
| "%tessc_in_color_val = OpLoad %v4f32 %tessc_in_color_ptr\n" |
| "%tessc_in_position_val = OpLoad %v4f32 %tessc_in_position_ptr\n" |
| "%tessc_out_color_ptr = OpAccessChain %op_v4f32 %tessc_out_color %tessc_invocation_id\n" |
| "%tessc_out_position_ptr = OpAccessChain %op_v4f32 %tessc_out_position %tessc_invocation_id\n" |
| "OpStore %tessc_out_color_ptr %tessc_in_color_val\n" |
| "OpStore %tessc_out_position_ptr %tessc_in_position_val\n" |
| "%tessc_is_first_invocation = OpIEqual %bool %tessc_invocation_id %c_i32_0\n" |
| "OpSelectionMerge %tessc_merge_label None\n" |
| "OpBranchConditional %tessc_is_first_invocation %tessc_first_invocation %tessc_merge_label\n" |
| "%tessc_first_invocation = OpLabel\n" |
| "%tessc_tess_outer_0 = OpAccessChain %op_f32 %tessc_gl_TessLevelOuter %c_i32_0\n" |
| "%tessc_tess_outer_1 = OpAccessChain %op_f32 %tessc_gl_TessLevelOuter %c_i32_1\n" |
| "%tessc_tess_outer_2 = OpAccessChain %op_f32 %tessc_gl_TessLevelOuter %c_i32_2\n" |
| "%tessc_tess_inner = OpAccessChain %op_f32 %tessc_gl_TessLevelInner %c_i32_0\n" |
| "OpStore %tessc_tess_outer_0 %c_f32_1\n" |
| "OpStore %tessc_tess_outer_1 %c_f32_1\n" |
| "OpStore %tessc_tess_outer_2 %c_f32_1\n" |
| "OpStore %tessc_tess_inner %c_f32_1\n" |
| "OpBranch %tessc_merge_label\n" |
| "%tessc_merge_label = OpLabel\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n" |
| |
| "; Tessellation Evaluation Entry\n" |
| "%tesse_main = OpFunction %void None %voidf\n" |
| "%tesse_label = OpLabel\n" |
| "%tesse_tc_0_ptr = OpAccessChain %ip_f32 %tesse_gl_tessCoord %c_u32_0\n" |
| "%tesse_tc_1_ptr = OpAccessChain %ip_f32 %tesse_gl_tessCoord %c_u32_1\n" |
| "%tesse_tc_2_ptr = OpAccessChain %ip_f32 %tesse_gl_tessCoord %c_u32_2\n" |
| "%tesse_tc_0 = OpLoad %f32 %tesse_tc_0_ptr\n" |
| "%tesse_tc_1 = OpLoad %f32 %tesse_tc_1_ptr\n" |
| "%tesse_tc_2 = OpLoad %f32 %tesse_tc_2_ptr\n" |
| "%tesse_in_pos_0_ptr = OpAccessChain %ip_v4f32 %tesse_in_position %c_i32_0\n" |
| "%tesse_in_pos_1_ptr = OpAccessChain %ip_v4f32 %tesse_in_position %c_i32_1\n" |
| "%tesse_in_pos_2_ptr = OpAccessChain %ip_v4f32 %tesse_in_position %c_i32_2\n" |
| "%tesse_in_pos_0 = OpLoad %v4f32 %tesse_in_pos_0_ptr\n" |
| "%tesse_in_pos_1 = OpLoad %v4f32 %tesse_in_pos_1_ptr\n" |
| "%tesse_in_pos_2 = OpLoad %v4f32 %tesse_in_pos_2_ptr\n" |
| "%tesse_in_pos_0_weighted = OpVectorTimesScalar %v4f32 %tesse_in_pos_0 %tesse_tc_0\n" |
| "%tesse_in_pos_1_weighted = OpVectorTimesScalar %v4f32 %tesse_in_pos_1 %tesse_tc_1\n" |
| "%tesse_in_pos_2_weighted = OpVectorTimesScalar %v4f32 %tesse_in_pos_2 %tesse_tc_2\n" |
| "%tesse_out_pos_ptr = OpAccessChain %op_v4f32 %tesse_stream %c_i32_0\n" |
| "%tesse_in_pos_0_plus_pos_1 = OpFAdd %v4f32 %tesse_in_pos_0_weighted %tesse_in_pos_1_weighted\n" |
| "%tesse_computed_out = OpFAdd %v4f32 %tesse_in_pos_0_plus_pos_1 %tesse_in_pos_2_weighted\n" |
| "OpStore %tesse_out_pos_ptr %tesse_computed_out\n" |
| "%tesse_in_clr_0_ptr = OpAccessChain %ip_v4f32 %tesse_in_color %c_i32_0\n" |
| "%tesse_in_clr_1_ptr = OpAccessChain %ip_v4f32 %tesse_in_color %c_i32_1\n" |
| "%tesse_in_clr_2_ptr = OpAccessChain %ip_v4f32 %tesse_in_color %c_i32_2\n" |
| "%tesse_in_clr_0 = OpLoad %v4f32 %tesse_in_clr_0_ptr\n" |
| "%tesse_in_clr_1 = OpLoad %v4f32 %tesse_in_clr_1_ptr\n" |
| "%tesse_in_clr_2 = OpLoad %v4f32 %tesse_in_clr_2_ptr\n" |
| "%tesse_in_clr_0_weighted = OpVectorTimesScalar %v4f32 %tesse_in_clr_0 %tesse_tc_0\n" |
| "%tesse_in_clr_1_weighted = OpVectorTimesScalar %v4f32 %tesse_in_clr_1 %tesse_tc_1\n" |
| "%tesse_in_clr_2_weighted = OpVectorTimesScalar %v4f32 %tesse_in_clr_2 %tesse_tc_2\n" |
| "%tesse_in_clr_0_plus_col_1 = OpFAdd %v4f32 %tesse_in_clr_0_weighted %tesse_in_clr_1_weighted\n" |
| "%tesse_computed_clr = OpFAdd %v4f32 %tesse_in_clr_0_plus_col_1 %tesse_in_clr_2_weighted\n" |
| "OpStore %tesse_out_color %tesse_computed_clr\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n"; |
| } |
| |
| combinedModule << "; Fragment Entry\n" |
| "%frag_main = OpFunction %void None %voidf\n" |
| "%frag_label_main = OpLabel\n" |
| "%frag_tmp1 = OpLoad %v4f32 %frag_vtxColor\n" |
| "OpStore %frag_fragColor %frag_tmp1\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n"; |
| |
| dst.spirvAsmSources.add("module") << combinedModule.str(); |
| } |
| |
| void createUnusedVariableModules (vk::SourceCollections& dst, UnusedVariableContext ctx) |
| { |
| if (ctx.shaderTasks[SHADER_TASK_INDEX_VERTEX] != SHADER_TASK_NONE) |
| { |
| std::ostringstream shader; |
| bool tessellation = (ctx.shaderTasks[SHADER_TASK_INDEX_TESS_CONTROL] != SHADER_TASK_NONE |
| || ctx.shaderTasks[SHADER_TASK_INDEX_TESS_EVAL] != SHADER_TASK_NONE); |
| const ShaderTask& task = ctx.shaderTasks[SHADER_TASK_INDEX_VERTEX]; |
| |
| shader << "OpCapability Shader\n" |
| << "OpMemoryModel Logical GLSL450\n"; |
| |
| // Entry point depends on if tessellation is enabled or not to provide the vertex position. |
| shader << "OpEntryPoint Vertex %main \"main\" %Position %vtxColor %color " |
| << (tessellation ? "%vtxPosition" : "%vtx_glPerVertex") |
| << " %vertex_id %instance_id\n"; |
| if (task == SHADER_TASK_UNUSED_FUNC) |
| { |
| shader << getUnusedEntryPoint(); |
| } |
| |
| // Decorations. |
| shader << "OpDecorate %Position Location 0\n" |
| << "OpDecorate %vtxColor Location 1\n" |
| << "OpDecorate %color Location 1\n" |
| << "OpDecorate %vertex_id BuiltIn VertexIndex\n" |
| << "OpDecorate %instance_id BuiltIn InstanceIndex\n"; |
| if (tessellation) |
| { |
| shader << "OpDecorate %vtxPosition Location 2\n"; |
| } |
| else |
| { |
| shader << "OpMemberDecorate %vert_per_vertex_out 0 BuiltIn Position\n" |
| << "OpMemberDecorate %vert_per_vertex_out 1 BuiltIn PointSize\n" |
| << "OpMemberDecorate %vert_per_vertex_out 2 BuiltIn ClipDistance\n" |
| << "OpMemberDecorate %vert_per_vertex_out 3 BuiltIn CullDistance\n" |
| << "OpDecorate %vert_per_vertex_out Block\n"; |
| } |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getUnusedDecorations(ctx.variableLocation); |
| } |
| |
| // Standard types, constants and arrays. |
| shader << "; Start of standard types, constants and arrays\n" |
| << SPIRV_ASSEMBLY_TYPES |
| << SPIRV_ASSEMBLY_CONSTANTS |
| << SPIRV_ASSEMBLY_ARRAYS |
| << "; End of standard types, constants and arrays\n"; |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getUnusedTypesAndConstants(); |
| } |
| |
| // Variables. |
| if (tessellation) |
| { |
| shader << "%vtxPosition = OpVariable %op_v4f32 Output\n"; |
| } |
| else |
| { |
| shader << "%vert_per_vertex_out = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" |
| << "%vert_op_per_vertex_out = OpTypePointer Output %vert_per_vertex_out\n" |
| << "%vtx_glPerVertex = OpVariable %vert_op_per_vertex_out Output\n"; |
| } |
| shader << "%Position = OpVariable %ip_v4f32 Input\n" |
| << "%vtxColor = OpVariable %op_v4f32 Output\n" |
| << "%color = OpVariable %ip_v4f32 Input\n" |
| << "%vertex_id = OpVariable %ip_i32 Input\n" |
| << "%instance_id = OpVariable %ip_i32 Input\n"; |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getUnusedBuffer(); |
| } |
| |
| // Vertex main function. |
| shader << "%main = OpFunction %void None %voidf\n" |
| << "%label = OpLabel\n" |
| << "%tmp_position = OpLoad %v4f32 %Position\n"; |
| if (tessellation) |
| { |
| shader << "OpStore %vtxPosition %tmp_position\n"; |
| } |
| else |
| { |
| shader << "%vert_out_pos_ptr = OpAccessChain %op_v4f32 %vtx_glPerVertex %c_i32_0\n" |
| << "OpStore %vert_out_pos_ptr %tmp_position\n"; |
| } |
| shader << "%tmp_color = OpLoad %v4f32 %color\n" |
| << "OpStore %vtxColor %tmp_color\n" |
| << "OpReturn\n" |
| << "OpFunctionEnd\n"; |
| if (task == SHADER_TASK_UNUSED_FUNC) |
| { |
| shader << getUnusedFunctionBody(); |
| } |
| |
| dst.spirvAsmSources.add("vert") << shader.str(); |
| } |
| |
| if (ctx.shaderTasks[SHADER_TASK_INDEX_GEOMETRY] != SHADER_TASK_NONE) |
| { |
| const ShaderTask& task = ctx.shaderTasks[SHADER_TASK_INDEX_GEOMETRY]; |
| std::ostringstream shader; |
| |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getOpCapabilityShader(); |
| } |
| shader << "OpCapability Geometry\n" |
| << "OpMemoryModel Logical GLSL450\n"; |
| |
| // Entry points. |
| shader << "OpEntryPoint Geometry %geom1_main \"main\" %out_gl_position %gl_in %out_color %in_color\n"; |
| if (task == SHADER_TASK_UNUSED_FUNC) |
| { |
| shader << getUnusedEntryPoint(); |
| } |
| shader << "OpExecutionMode %geom1_main Triangles\n" |
| << "OpExecutionMode %geom1_main OutputTriangleStrip\n" |
| << "OpExecutionMode %geom1_main OutputVertices 3\n"; |
| |
| // Decorations. |
| shader << "OpDecorate %out_gl_position BuiltIn Position\n" |
| << "OpMemberDecorate %per_vertex_in 0 BuiltIn Position\n" |
| << "OpMemberDecorate %per_vertex_in 1 BuiltIn PointSize\n" |
| << "OpMemberDecorate %per_vertex_in 2 BuiltIn ClipDistance\n" |
| << "OpMemberDecorate %per_vertex_in 3 BuiltIn CullDistance\n" |
| << "OpDecorate %per_vertex_in Block\n" |
| << "OpDecorate %out_color Location 1\n" |
| << "OpDecorate %in_color Location 1\n"; |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getUnusedDecorations(ctx.variableLocation); |
| } |
| |
| // Standard types, constants and arrays. |
| shader << "; Start of standard types, constants and arrays\n" |
| << SPIRV_ASSEMBLY_TYPES |
| << SPIRV_ASSEMBLY_CONSTANTS |
| << SPIRV_ASSEMBLY_ARRAYS |
| << "; End of standard types, constants and arrays\n"; |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getUnusedTypesAndConstants(); |
| } |
| |
| // Variables. |
| shader << "%per_vertex_in = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" |
| << "%a3_per_vertex_in = OpTypeArray %per_vertex_in %c_u32_3\n" |
| << "%ip_a3_per_vertex_in = OpTypePointer Input %a3_per_vertex_in\n" |
| << "%gl_in = OpVariable %ip_a3_per_vertex_in Input\n" |
| << "%out_color = OpVariable %op_v4f32 Output\n" |
| << "%in_color = OpVariable %ip_a3v4f32 Input\n" |
| << "%out_gl_position = OpVariable %op_v4f32 Output\n"; |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getUnusedBuffer(); |
| } |
| |
| // Main function. |
| shader << "%geom1_main = OpFunction %void None %voidf\n" |
| << "%geom1_label = OpLabel\n" |
| << "%geom1_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_0 %c_i32_0\n" |
| << "%geom1_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_1 %c_i32_0\n" |
| << "%geom1_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_2 %c_i32_0\n" |
| << "%geom1_in_position_0 = OpLoad %v4f32 %geom1_gl_in_0_gl_position\n" |
| << "%geom1_in_position_1 = OpLoad %v4f32 %geom1_gl_in_1_gl_position\n" |
| << "%geom1_in_position_2 = OpLoad %v4f32 %geom1_gl_in_2_gl_position \n" |
| << "%geom1_in_color_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n" |
| << "%geom1_in_color_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n" |
| << "%geom1_in_color_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n" |
| << "%geom1_in_color_0 = OpLoad %v4f32 %geom1_in_color_0_ptr\n" |
| << "%geom1_in_color_1 = OpLoad %v4f32 %geom1_in_color_1_ptr\n" |
| << "%geom1_in_color_2 = OpLoad %v4f32 %geom1_in_color_2_ptr\n" |
| << "OpStore %out_gl_position %geom1_in_position_0\n" |
| << "OpStore %out_color %geom1_in_color_0\n" |
| << "OpEmitVertex\n" |
| << "OpStore %out_gl_position %geom1_in_position_1\n" |
| << "OpStore %out_color %geom1_in_color_1\n" |
| << "OpEmitVertex\n" |
| << "OpStore %out_gl_position %geom1_in_position_2\n" |
| << "OpStore %out_color %geom1_in_color_2\n" |
| << "OpEmitVertex\n" |
| << "OpEndPrimitive\n" |
| << "OpReturn\n" |
| << "OpFunctionEnd\n"; |
| if (task == SHADER_TASK_UNUSED_FUNC) |
| { |
| shader << getUnusedFunctionBody(); |
| } |
| |
| dst.spirvAsmSources.add("geom") << shader.str(); |
| } |
| |
| if (ctx.shaderTasks[SHADER_TASK_INDEX_TESS_CONTROL] != SHADER_TASK_NONE) |
| { |
| const ShaderTask& task = ctx.shaderTasks[SHADER_TASK_INDEX_TESS_CONTROL]; |
| std::ostringstream shader; |
| |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getOpCapabilityShader(); |
| } |
| shader << "OpCapability Tessellation\n" |
| << "OpMemoryModel Logical GLSL450\n"; |
| |
| // Entry point. |
| shader << "OpEntryPoint TessellationControl %tessc1_main \"main\" %out_color %gl_InvocationID %in_color %out_position %in_position %gl_TessLevelOuter %gl_TessLevelInner\n"; |
| if (task == SHADER_TASK_UNUSED_FUNC) |
| { |
| shader << getUnusedEntryPoint(); |
| } |
| shader << "OpExecutionMode %tessc1_main OutputVertices 3\n"; |
| |
| // Decorations. |
| shader << "OpDecorate %out_color Location 1\n" |
| << "OpDecorate %gl_InvocationID BuiltIn InvocationId\n" |
| << "OpDecorate %in_color Location 1\n" |
| << "OpDecorate %out_position Location 2\n" |
| << "OpDecorate %in_position Location 2\n" |
| << "OpDecorate %gl_TessLevelOuter Patch\n" |
| << "OpDecorate %gl_TessLevelOuter BuiltIn TessLevelOuter\n" |
| << "OpDecorate %gl_TessLevelInner Patch\n" |
| << "OpDecorate %gl_TessLevelInner BuiltIn TessLevelInner\n"; |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getUnusedDecorations(ctx.variableLocation); |
| } |
| |
| // Standard types, constants and arrays. |
| shader << "; Start of standard types, constants and arrays\n" |
| << SPIRV_ASSEMBLY_TYPES |
| << SPIRV_ASSEMBLY_CONSTANTS |
| << SPIRV_ASSEMBLY_ARRAYS |
| << "; End of standard types, constants and arrays\n"; |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getUnusedTypesAndConstants(); |
| } |
| |
| // Variables. |
| shader << "%out_color = OpVariable %op_a3v4f32 Output\n" |
| << "%gl_InvocationID = OpVariable %ip_i32 Input\n" |
| << "%in_color = OpVariable %ip_a32v4f32 Input\n" |
| << "%out_position = OpVariable %op_a3v4f32 Output\n" |
| << "%in_position = OpVariable %ip_a32v4f32 Input\n" |
| << "%gl_TessLevelOuter = OpVariable %op_a4f32 Output\n" |
| << "%gl_TessLevelInner = OpVariable %op_a2f32 Output\n"; |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getUnusedBuffer(); |
| } |
| |
| // Main entry point. |
| shader << "%tessc1_main = OpFunction %void None %voidf\n" |
| << "%tessc1_label = OpLabel\n" |
| << "%tessc1_invocation_id = OpLoad %i32 %gl_InvocationID\n" |
| << "%tessc1_in_color_ptr = OpAccessChain %ip_v4f32 %in_color %tessc1_invocation_id\n" |
| << "%tessc1_in_position_ptr = OpAccessChain %ip_v4f32 %in_position %tessc1_invocation_id\n" |
| << "%tessc1_in_color_val = OpLoad %v4f32 %tessc1_in_color_ptr\n" |
| << "%tessc1_in_position_val = OpLoad %v4f32 %tessc1_in_position_ptr\n" |
| << "%tessc1_out_color_ptr = OpAccessChain %op_v4f32 %out_color %tessc1_invocation_id\n" |
| << "%tessc1_out_position_ptr = OpAccessChain %op_v4f32 %out_position %tessc1_invocation_id\n" |
| << "OpStore %tessc1_out_color_ptr %tessc1_in_color_val\n" |
| << "OpStore %tessc1_out_position_ptr %tessc1_in_position_val\n" |
| << "%tessc1_is_first_invocation = OpIEqual %bool %tessc1_invocation_id %c_i32_0\n" |
| << "OpSelectionMerge %tessc1_merge_label None\n" |
| << "OpBranchConditional %tessc1_is_first_invocation %tessc1_first_invocation %tessc1_merge_label\n" |
| << "%tessc1_first_invocation = OpLabel\n" |
| << "%tessc1_tess_outer_0 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_0\n" |
| << "%tessc1_tess_outer_1 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_1\n" |
| << "%tessc1_tess_outer_2 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_2\n" |
| << "%tessc1_tess_inner = OpAccessChain %op_f32 %gl_TessLevelInner %c_i32_0\n" |
| << "OpStore %tessc1_tess_outer_0 %c_f32_1\n" |
| << "OpStore %tessc1_tess_outer_1 %c_f32_1\n" |
| << "OpStore %tessc1_tess_outer_2 %c_f32_1\n" |
| << "OpStore %tessc1_tess_inner %c_f32_1\n" |
| << "OpBranch %tessc1_merge_label\n" |
| << "%tessc1_merge_label = OpLabel\n" |
| << "OpReturn\n" |
| << "OpFunctionEnd\n"; |
| if (task == SHADER_TASK_UNUSED_FUNC) |
| { |
| shader << getUnusedFunctionBody(); |
| } |
| |
| dst.spirvAsmSources.add("tessc") << shader.str(); |
| } |
| |
| if (ctx.shaderTasks[SHADER_TASK_INDEX_TESS_EVAL] != SHADER_TASK_NONE) |
| { |
| const ShaderTask& task = ctx.shaderTasks[SHADER_TASK_INDEX_TESS_EVAL]; |
| std::ostringstream shader; |
| |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getOpCapabilityShader(); |
| } |
| shader << "OpCapability Tessellation\n" |
| << "OpMemoryModel Logical GLSL450\n"; |
| |
| // Entry point. |
| shader << "OpEntryPoint TessellationEvaluation %tesse1_main \"main\" %stream %gl_tessCoord %in_position %out_color %in_color \n"; |
| if (task == SHADER_TASK_UNUSED_FUNC) |
| { |
| shader << getUnusedEntryPoint(); |
| } |
| shader << "OpExecutionMode %tesse1_main Triangles\n" |
| << "OpExecutionMode %tesse1_main SpacingEqual\n" |
| << "OpExecutionMode %tesse1_main VertexOrderCcw\n"; |
| |
| // Decorations. |
| shader << "OpMemberDecorate %per_vertex_out 0 BuiltIn Position\n" |
| << "OpMemberDecorate %per_vertex_out 1 BuiltIn PointSize\n" |
| << "OpMemberDecorate %per_vertex_out 2 BuiltIn ClipDistance\n" |
| << "OpMemberDecorate %per_vertex_out 3 BuiltIn CullDistance\n" |
| << "OpDecorate %per_vertex_out Block\n" |
| << "OpDecorate %gl_tessCoord BuiltIn TessCoord\n" |
| << "OpDecorate %in_position Location 2\n" |
| << "OpDecorate %out_color Location 1\n" |
| << "OpDecorate %in_color Location 1\n"; |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getUnusedDecorations(ctx.variableLocation); |
| } |
| |
| // Standard types, constants and arrays. |
| shader << "; Start of standard types, constants and arrays\n" |
| << SPIRV_ASSEMBLY_TYPES |
| << SPIRV_ASSEMBLY_CONSTANTS |
| << SPIRV_ASSEMBLY_ARRAYS |
| << "; End of standard types, constants and arrays\n"; |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getUnusedTypesAndConstants(); |
| } |
| |
| // Variables. |
| shader << "%per_vertex_out = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" |
| << "%op_per_vertex_out = OpTypePointer Output %per_vertex_out\n" |
| << "%stream = OpVariable %op_per_vertex_out Output\n" |
| << "%gl_tessCoord = OpVariable %ip_v3f32 Input\n" |
| << "%in_position = OpVariable %ip_a32v4f32 Input\n" |
| << "%out_color = OpVariable %op_v4f32 Output\n" |
| << "%in_color = OpVariable %ip_a32v4f32 Input\n"; |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getUnusedBuffer(); |
| } |
| |
| // Main entry point. |
| shader << "%tesse1_main = OpFunction %void None %voidf\n" |
| << "%tesse1_label = OpLabel\n" |
| << "%tesse1_tc_0_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_0\n" |
| << "%tesse1_tc_1_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_1\n" |
| << "%tesse1_tc_2_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_2\n" |
| << "%tesse1_tc_0 = OpLoad %f32 %tesse1_tc_0_ptr\n" |
| << "%tesse1_tc_1 = OpLoad %f32 %tesse1_tc_1_ptr\n" |
| << "%tesse1_tc_2 = OpLoad %f32 %tesse1_tc_2_ptr\n" |
| << "%tesse1_in_pos_0_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_0\n" |
| << "%tesse1_in_pos_1_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_1\n" |
| << "%tesse1_in_pos_2_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_2\n" |
| << "%tesse1_in_pos_0 = OpLoad %v4f32 %tesse1_in_pos_0_ptr\n" |
| << "%tesse1_in_pos_1 = OpLoad %v4f32 %tesse1_in_pos_1_ptr\n" |
| << "%tesse1_in_pos_2 = OpLoad %v4f32 %tesse1_in_pos_2_ptr\n" |
| << "%tesse1_in_pos_0_weighted = OpVectorTimesScalar %v4f32 %tesse1_in_pos_0 %tesse1_tc_0\n" |
| << "%tesse1_in_pos_1_weighted = OpVectorTimesScalar %v4f32 %tesse1_in_pos_1 %tesse1_tc_1\n" |
| << "%tesse1_in_pos_2_weighted = OpVectorTimesScalar %v4f32 %tesse1_in_pos_2 %tesse1_tc_2\n" |
| << "%tesse1_out_pos_ptr = OpAccessChain %op_v4f32 %stream %c_i32_0\n" |
| << "%tesse1_in_pos_0_plus_pos_1 = OpFAdd %v4f32 %tesse1_in_pos_0_weighted %tesse1_in_pos_1_weighted\n" |
| << "%tesse1_computed_out = OpFAdd %v4f32 %tesse1_in_pos_0_plus_pos_1 %tesse1_in_pos_2_weighted\n" |
| << "OpStore %tesse1_out_pos_ptr %tesse1_computed_out\n" |
| << "%tesse1_in_clr_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n" |
| << "%tesse1_in_clr_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n" |
| << "%tesse1_in_clr_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n" |
| << "%tesse1_in_clr_0 = OpLoad %v4f32 %tesse1_in_clr_0_ptr\n" |
| << "%tesse1_in_clr_1 = OpLoad %v4f32 %tesse1_in_clr_1_ptr\n" |
| << "%tesse1_in_clr_2 = OpLoad %v4f32 %tesse1_in_clr_2_ptr\n" |
| << "%tesse1_in_clr_0_weighted = OpVectorTimesScalar %v4f32 %tesse1_in_clr_0 %tesse1_tc_0\n" |
| << "%tesse1_in_clr_1_weighted = OpVectorTimesScalar %v4f32 %tesse1_in_clr_1 %tesse1_tc_1\n" |
| << "%tesse1_in_clr_2_weighted = OpVectorTimesScalar %v4f32 %tesse1_in_clr_2 %tesse1_tc_2\n" |
| << "%tesse1_in_clr_0_plus_col_1 = OpFAdd %v4f32 %tesse1_in_clr_0_weighted %tesse1_in_clr_1_weighted\n" |
| << "%tesse1_computed_clr = OpFAdd %v4f32 %tesse1_in_clr_0_plus_col_1 %tesse1_in_clr_2_weighted\n" |
| << "OpStore %out_color %tesse1_computed_clr\n" |
| << "OpReturn\n" |
| << "OpFunctionEnd\n"; |
| if (task == SHADER_TASK_UNUSED_FUNC) |
| { |
| shader << getUnusedFunctionBody(); |
| } |
| |
| dst.spirvAsmSources.add("tesse") << shader.str(); |
| } |
| |
| if (ctx.shaderTasks[SHADER_TASK_INDEX_FRAGMENT] != SHADER_TASK_NONE) |
| { |
| const ShaderTask& task = ctx.shaderTasks[SHADER_TASK_INDEX_FRAGMENT]; |
| std::ostringstream shader; |
| |
| shader << "OpCapability Shader\n" |
| << "OpMemoryModel Logical GLSL450\n"; |
| |
| // Entry point. |
| shader << "OpEntryPoint Fragment %main \"main\" %vtxColor %fragColor\n"; |
| if (task == SHADER_TASK_UNUSED_FUNC) |
| { |
| shader << getUnusedEntryPoint(); |
| } |
| shader << "OpExecutionMode %main OriginUpperLeft\n"; |
| |
| // Decorations. |
| shader << "OpDecorate %fragColor Location 0\n" |
| << "OpDecorate %vtxColor Location 1\n"; |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getUnusedDecorations(ctx.variableLocation); |
| } |
| |
| // Standard types, constants and arrays. |
| shader << "; Start of standard types, constants and arrays\n" |
| << SPIRV_ASSEMBLY_TYPES |
| << SPIRV_ASSEMBLY_CONSTANTS |
| << SPIRV_ASSEMBLY_ARRAYS |
| << "; End of standard types, constants and arrays\n"; |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getUnusedTypesAndConstants(); |
| } |
| |
| // Variables. |
| shader << "%fragColor = OpVariable %op_v4f32 Output\n" |
| << "%vtxColor = OpVariable %ip_v4f32 Input\n"; |
| if (task != SHADER_TASK_NORMAL) |
| { |
| shader << getUnusedBuffer(); |
| } |
| |
| // Main entry point. |
| shader << "%main = OpFunction %void None %voidf\n" |
| << "%label_main = OpLabel\n" |
| << "%tmp1 = OpLoad %v4f32 %vtxColor\n" |
| << "OpStore %fragColor %tmp1\n" |
| << "OpReturn\n" |
| << "OpFunctionEnd\n"; |
| if (task == SHADER_TASK_UNUSED_FUNC) |
| { |
| shader << getUnusedFunctionBody(); |
| } |
| |
| dst.spirvAsmSources.add("frag") << shader.str(); |
| } |
| } |
| |
| void createMultipleEntries (vk::SourceCollections& dst, InstanceContext) |
| { |
| dst.spirvAsmSources.add("vert") << |
| // This module contains 2 vertex shaders. One that is a passthrough |
| // and a second that inverts the color of the output (1.0 - color). |
| "OpCapability Shader\n" |
| "OpMemoryModel Logical GLSL450\n" |
| "OpEntryPoint Vertex %main \"vert1\" %Position %vtxColor %color %vtxPosition %vertex_id %instance_id\n" |
| "OpEntryPoint Vertex %main2 \"vert2\" %Position %vtxColor %color %vtxPosition %vertex_id %instance_id\n" |
| |
| "OpDecorate %vtxPosition Location 2\n" |
| "OpDecorate %Position Location 0\n" |
| "OpDecorate %vtxColor Location 1\n" |
| "OpDecorate %color Location 1\n" |
| "OpDecorate %vertex_id BuiltIn VertexIndex\n" |
| "OpDecorate %instance_id BuiltIn InstanceIndex\n" |
| SPIRV_ASSEMBLY_TYPES |
| SPIRV_ASSEMBLY_CONSTANTS |
| SPIRV_ASSEMBLY_ARRAYS |
| "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n" |
| "%vtxPosition = OpVariable %op_v4f32 Output\n" |
| "%Position = OpVariable %ip_v4f32 Input\n" |
| "%vtxColor = OpVariable %op_v4f32 Output\n" |
| "%color = OpVariable %ip_v4f32 Input\n" |
| "%vertex_id = OpVariable %ip_i32 Input\n" |
| "%instance_id = OpVariable %ip_i32 Input\n" |
| |
| "%main = OpFunction %void None %voidf\n" |
| "%label = OpLabel\n" |
| "%tmp_position = OpLoad %v4f32 %Position\n" |
| "OpStore %vtxPosition %tmp_position\n" |
| "%tmp_color = OpLoad %v4f32 %color\n" |
| "OpStore %vtxColor %tmp_color\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n" |
| |
| "%main2 = OpFunction %void None %voidf\n" |
| "%label2 = OpLabel\n" |
| "%tmp_position2 = OpLoad %v4f32 %Position\n" |
| "OpStore %vtxPosition %tmp_position2\n" |
| "%tmp_color2 = OpLoad %v4f32 %color\n" |
| "%tmp_color3 = OpFSub %v4f32 %cval %tmp_color2\n" |
| "%tmp_color4 = OpVectorInsertDynamic %v4f32 %tmp_color3 %c_f32_1 %c_i32_3\n" |
| "OpStore %vtxColor %tmp_color4\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n"; |
| |
| dst.spirvAsmSources.add("frag") << |
| // This is a single module that contains 2 fragment shaders. |
| // One that passes color through and the other that inverts the output |
| // color (1.0 - color). |
| "OpCapability Shader\n" |
| "OpMemoryModel Logical GLSL450\n" |
| "OpEntryPoint Fragment %main \"frag1\" %vtxColor %fragColor\n" |
| "OpEntryPoint Fragment %main2 \"frag2\" %vtxColor %fragColor\n" |
| "OpExecutionMode %main OriginUpperLeft\n" |
| "OpExecutionMode %main2 OriginUpperLeft\n" |
| |
| "OpDecorate %fragColor Location 0\n" |
| "OpDecorate %vtxColor Location 1\n" |
| SPIRV_ASSEMBLY_TYPES |
| SPIRV_ASSEMBLY_CONSTANTS |
| SPIRV_ASSEMBLY_ARRAYS |
| "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n" |
| "%fragColor = OpVariable %op_v4f32 Output\n" |
| "%vtxColor = OpVariable %ip_v4f32 Input\n" |
| |
| "%main = OpFunction %void None %voidf\n" |
| "%label_main = OpLabel\n" |
| "%tmp1 = OpLoad %v4f32 %vtxColor\n" |
| "OpStore %fragColor %tmp1\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n" |
| |
| "%main2 = OpFunction %void None %voidf\n" |
| "%label_main2 = OpLabel\n" |
| "%tmp2 = OpLoad %v4f32 %vtxColor\n" |
| "%tmp3 = OpFSub %v4f32 %cval %tmp2\n" |
| "%tmp4 = OpVectorInsertDynamic %v4f32 %tmp3 %c_f32_1 %c_i32_3\n" |
| "OpStore %fragColor %tmp4\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n"; |
| |
| dst.spirvAsmSources.add("geom") << |
| "OpCapability Geometry\n" |
| "OpMemoryModel Logical GLSL450\n" |
| "OpEntryPoint Geometry %geom1_main \"geom1\" %out_gl_position %gl_in %out_color %in_color\n" |
| "OpEntryPoint Geometry %geom2_main \"geom2\" %out_gl_position %gl_in %out_color %in_color\n" |
| "OpExecutionMode %geom1_main Triangles\n" |
| "OpExecutionMode %geom2_main Triangles\n" |
| "OpExecutionMode %geom1_main OutputTriangleStrip\n" |
| "OpExecutionMode %geom2_main OutputTriangleStrip\n" |
| "OpExecutionMode %geom1_main OutputVertices 3\n" |
| "OpExecutionMode %geom2_main OutputVertices 3\n" |
| "OpDecorate %out_gl_position BuiltIn Position\n" |
| "OpMemberDecorate %per_vertex_in 0 BuiltIn Position\n" |
| "OpMemberDecorate %per_vertex_in 1 BuiltIn PointSize\n" |
| "OpMemberDecorate %per_vertex_in 2 BuiltIn ClipDistance\n" |
| "OpMemberDecorate %per_vertex_in 3 BuiltIn CullDistance\n" |
| "OpDecorate %per_vertex_in Block\n" |
| "OpDecorate %out_color Location 1\n" |
| "OpDecorate %in_color Location 1\n" |
| SPIRV_ASSEMBLY_TYPES |
| SPIRV_ASSEMBLY_CONSTANTS |
| SPIRV_ASSEMBLY_ARRAYS |
| "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n" |
| "%per_vertex_in = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" |
| "%a3_per_vertex_in = OpTypeArray %per_vertex_in %c_u32_3\n" |
| "%ip_a3_per_vertex_in = OpTypePointer Input %a3_per_vertex_in\n" |
| "%gl_in = OpVariable %ip_a3_per_vertex_in Input\n" |
| "%out_color = OpVariable %op_v4f32 Output\n" |
| "%in_color = OpVariable %ip_a3v4f32 Input\n" |
| "%out_gl_position = OpVariable %op_v4f32 Output\n" |
| |
| "%geom1_main = OpFunction %void None %voidf\n" |
| "%geom1_label = OpLabel\n" |
| "%geom1_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_0 %c_i32_0\n" |
| "%geom1_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_1 %c_i32_0\n" |
| "%geom1_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_2 %c_i32_0\n" |
| "%geom1_in_position_0 = OpLoad %v4f32 %geom1_gl_in_0_gl_position\n" |
| "%geom1_in_position_1 = OpLoad %v4f32 %geom1_gl_in_1_gl_position\n" |
| "%geom1_in_position_2 = OpLoad %v4f32 %geom1_gl_in_2_gl_position \n" |
| "%geom1_in_color_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n" |
| "%geom1_in_color_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n" |
| "%geom1_in_color_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n" |
| "%geom1_in_color_0 = OpLoad %v4f32 %geom1_in_color_0_ptr\n" |
| "%geom1_in_color_1 = OpLoad %v4f32 %geom1_in_color_1_ptr\n" |
| "%geom1_in_color_2 = OpLoad %v4f32 %geom1_in_color_2_ptr\n" |
| "OpStore %out_gl_position %geom1_in_position_0\n" |
| "OpStore %out_color %geom1_in_color_0\n" |
| "OpEmitVertex\n" |
| "OpStore %out_gl_position %geom1_in_position_1\n" |
| "OpStore %out_color %geom1_in_color_1\n" |
| "OpEmitVertex\n" |
| "OpStore %out_gl_position %geom1_in_position_2\n" |
| "OpStore %out_color %geom1_in_color_2\n" |
| "OpEmitVertex\n" |
| "OpEndPrimitive\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n" |
| |
| "%geom2_main = OpFunction %void None %voidf\n" |
| "%geom2_label = OpLabel\n" |
| "%geom2_gl_in_0_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_0 %c_i32_0\n" |
| "%geom2_gl_in_1_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_1 %c_i32_0\n" |
| "%geom2_gl_in_2_gl_position = OpAccessChain %ip_v4f32 %gl_in %c_i32_2 %c_i32_0\n" |
| "%geom2_in_position_0 = OpLoad %v4f32 %geom2_gl_in_0_gl_position\n" |
| "%geom2_in_position_1 = OpLoad %v4f32 %geom2_gl_in_1_gl_position\n" |
| "%geom2_in_position_2 = OpLoad %v4f32 %geom2_gl_in_2_gl_position \n" |
| "%geom2_in_color_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n" |
| "%geom2_in_color_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n" |
| "%geom2_in_color_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n" |
| "%geom2_in_color_0 = OpLoad %v4f32 %geom2_in_color_0_ptr\n" |
| "%geom2_in_color_1 = OpLoad %v4f32 %geom2_in_color_1_ptr\n" |
| "%geom2_in_color_2 = OpLoad %v4f32 %geom2_in_color_2_ptr\n" |
| "%geom2_transformed_in_color_0 = OpFSub %v4f32 %cval %geom2_in_color_0\n" |
| "%geom2_transformed_in_color_1 = OpFSub %v4f32 %cval %geom2_in_color_1\n" |
| "%geom2_transformed_in_color_2 = OpFSub %v4f32 %cval %geom2_in_color_2\n" |
| "%geom2_transformed_in_color_0_a = OpVectorInsertDynamic %v4f32 %geom2_transformed_in_color_0 %c_f32_1 %c_i32_3\n" |
| "%geom2_transformed_in_color_1_a = OpVectorInsertDynamic %v4f32 %geom2_transformed_in_color_1 %c_f32_1 %c_i32_3\n" |
| "%geom2_transformed_in_color_2_a = OpVectorInsertDynamic %v4f32 %geom2_transformed_in_color_2 %c_f32_1 %c_i32_3\n" |
| "OpStore %out_gl_position %geom2_in_position_0\n" |
| "OpStore %out_color %geom2_transformed_in_color_0_a\n" |
| "OpEmitVertex\n" |
| "OpStore %out_gl_position %geom2_in_position_1\n" |
| "OpStore %out_color %geom2_transformed_in_color_1_a\n" |
| "OpEmitVertex\n" |
| "OpStore %out_gl_position %geom2_in_position_2\n" |
| "OpStore %out_color %geom2_transformed_in_color_2_a\n" |
| "OpEmitVertex\n" |
| "OpEndPrimitive\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n"; |
| |
| dst.spirvAsmSources.add("tessc") << |
| "OpCapability Tessellation\n" |
| "OpMemoryModel Logical GLSL450\n" |
| "OpEntryPoint TessellationControl %tessc1_main \"tessc1\" %out_color %gl_InvocationID %in_color %out_position %in_position %gl_TessLevelOuter %gl_TessLevelInner\n" |
| "OpEntryPoint TessellationControl %tessc2_main \"tessc2\" %out_color %gl_InvocationID %in_color %out_position %in_position %gl_TessLevelOuter %gl_TessLevelInner\n" |
| "OpExecutionMode %tessc1_main OutputVertices 3\n" |
| "OpExecutionMode %tessc2_main OutputVertices 3\n" |
| "OpDecorate %out_color Location 1\n" |
| "OpDecorate %gl_InvocationID BuiltIn InvocationId\n" |
| "OpDecorate %in_color Location 1\n" |
| "OpDecorate %out_position Location 2\n" |
| "OpDecorate %in_position Location 2\n" |
| "OpDecorate %gl_TessLevelOuter Patch\n" |
| "OpDecorate %gl_TessLevelOuter BuiltIn TessLevelOuter\n" |
| "OpDecorate %gl_TessLevelInner Patch\n" |
| "OpDecorate %gl_TessLevelInner BuiltIn TessLevelInner\n" |
| SPIRV_ASSEMBLY_TYPES |
| SPIRV_ASSEMBLY_CONSTANTS |
| SPIRV_ASSEMBLY_ARRAYS |
| "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n" |
| "%out_color = OpVariable %op_a3v4f32 Output\n" |
| "%gl_InvocationID = OpVariable %ip_i32 Input\n" |
| "%in_color = OpVariable %ip_a32v4f32 Input\n" |
| "%out_position = OpVariable %op_a3v4f32 Output\n" |
| "%in_position = OpVariable %ip_a32v4f32 Input\n" |
| "%gl_TessLevelOuter = OpVariable %op_a4f32 Output\n" |
| "%gl_TessLevelInner = OpVariable %op_a2f32 Output\n" |
| |
| "%tessc1_main = OpFunction %void None %voidf\n" |
| "%tessc1_label = OpLabel\n" |
| "%tessc1_invocation_id = OpLoad %i32 %gl_InvocationID\n" |
| "%tessc1_in_color_ptr = OpAccessChain %ip_v4f32 %in_color %tessc1_invocation_id\n" |
| "%tessc1_in_position_ptr = OpAccessChain %ip_v4f32 %in_position %tessc1_invocation_id\n" |
| "%tessc1_in_color_val = OpLoad %v4f32 %tessc1_in_color_ptr\n" |
| "%tessc1_in_position_val = OpLoad %v4f32 %tessc1_in_position_ptr\n" |
| "%tessc1_out_color_ptr = OpAccessChain %op_v4f32 %out_color %tessc1_invocation_id\n" |
| "%tessc1_out_position_ptr = OpAccessChain %op_v4f32 %out_position %tessc1_invocation_id\n" |
| "OpStore %tessc1_out_color_ptr %tessc1_in_color_val\n" |
| "OpStore %tessc1_out_position_ptr %tessc1_in_position_val\n" |
| "%tessc1_is_first_invocation = OpIEqual %bool %tessc1_invocation_id %c_i32_0\n" |
| "OpSelectionMerge %tessc1_merge_label None\n" |
| "OpBranchConditional %tessc1_is_first_invocation %tessc1_first_invocation %tessc1_merge_label\n" |
| "%tessc1_first_invocation = OpLabel\n" |
| "%tessc1_tess_outer_0 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_0\n" |
| "%tessc1_tess_outer_1 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_1\n" |
| "%tessc1_tess_outer_2 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_2\n" |
| "%tessc1_tess_inner = OpAccessChain %op_f32 %gl_TessLevelInner %c_i32_0\n" |
| "OpStore %tessc1_tess_outer_0 %c_f32_1\n" |
| "OpStore %tessc1_tess_outer_1 %c_f32_1\n" |
| "OpStore %tessc1_tess_outer_2 %c_f32_1\n" |
| "OpStore %tessc1_tess_inner %c_f32_1\n" |
| "OpBranch %tessc1_merge_label\n" |
| "%tessc1_merge_label = OpLabel\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n" |
| |
| "%tessc2_main = OpFunction %void None %voidf\n" |
| "%tessc2_label = OpLabel\n" |
| "%tessc2_invocation_id = OpLoad %i32 %gl_InvocationID\n" |
| "%tessc2_in_color_ptr = OpAccessChain %ip_v4f32 %in_color %tessc2_invocation_id\n" |
| "%tessc2_in_position_ptr = OpAccessChain %ip_v4f32 %in_position %tessc2_invocation_id\n" |
| "%tessc2_in_color_val = OpLoad %v4f32 %tessc2_in_color_ptr\n" |
| "%tessc2_in_position_val = OpLoad %v4f32 %tessc2_in_position_ptr\n" |
| "%tessc2_out_color_ptr = OpAccessChain %op_v4f32 %out_color %tessc2_invocation_id\n" |
| "%tessc2_out_position_ptr = OpAccessChain %op_v4f32 %out_position %tessc2_invocation_id\n" |
| "%tessc2_transformed_color = OpFSub %v4f32 %cval %tessc2_in_color_val\n" |
| "%tessc2_transformed_color_a = OpVectorInsertDynamic %v4f32 %tessc2_transformed_color %c_f32_1 %c_i32_3\n" |
| "OpStore %tessc2_out_color_ptr %tessc2_transformed_color_a\n" |
| "OpStore %tessc2_out_position_ptr %tessc2_in_position_val\n" |
| "%tessc2_is_first_invocation = OpIEqual %bool %tessc2_invocation_id %c_i32_0\n" |
| "OpSelectionMerge %tessc2_merge_label None\n" |
| "OpBranchConditional %tessc2_is_first_invocation %tessc2_first_invocation %tessc2_merge_label\n" |
| "%tessc2_first_invocation = OpLabel\n" |
| "%tessc2_tess_outer_0 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_0\n" |
| "%tessc2_tess_outer_1 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_1\n" |
| "%tessc2_tess_outer_2 = OpAccessChain %op_f32 %gl_TessLevelOuter %c_i32_2\n" |
| "%tessc2_tess_inner = OpAccessChain %op_f32 %gl_TessLevelInner %c_i32_0\n" |
| "OpStore %tessc2_tess_outer_0 %c_f32_1\n" |
| "OpStore %tessc2_tess_outer_1 %c_f32_1\n" |
| "OpStore %tessc2_tess_outer_2 %c_f32_1\n" |
| "OpStore %tessc2_tess_inner %c_f32_1\n" |
| "OpBranch %tessc2_merge_label\n" |
| "%tessc2_merge_label = OpLabel\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n"; |
| |
| dst.spirvAsmSources.add("tesse") << |
| "OpCapability Tessellation\n" |
| "OpMemoryModel Logical GLSL450\n" |
| "OpEntryPoint TessellationEvaluation %tesse1_main \"tesse1\" %stream %gl_tessCoord %in_position %out_color %in_color \n" |
| "OpEntryPoint TessellationEvaluation %tesse2_main \"tesse2\" %stream %gl_tessCoord %in_position %out_color %in_color \n" |
| "OpExecutionMode %tesse1_main Triangles\n" |
| "OpExecutionMode %tesse1_main SpacingEqual\n" |
| "OpExecutionMode %tesse1_main VertexOrderCcw\n" |
| "OpExecutionMode %tesse2_main Triangles\n" |
| "OpExecutionMode %tesse2_main SpacingEqual\n" |
| "OpExecutionMode %tesse2_main VertexOrderCcw\n" |
| "OpMemberDecorate %per_vertex_out 0 BuiltIn Position\n" |
| "OpMemberDecorate %per_vertex_out 1 BuiltIn PointSize\n" |
| "OpMemberDecorate %per_vertex_out 2 BuiltIn ClipDistance\n" |
| "OpMemberDecorate %per_vertex_out 3 BuiltIn CullDistance\n" |
| "OpDecorate %per_vertex_out Block\n" |
| "OpDecorate %gl_tessCoord BuiltIn TessCoord\n" |
| "OpDecorate %in_position Location 2\n" |
| "OpDecorate %out_color Location 1\n" |
| "OpDecorate %in_color Location 1\n" |
| SPIRV_ASSEMBLY_TYPES |
| SPIRV_ASSEMBLY_CONSTANTS |
| SPIRV_ASSEMBLY_ARRAYS |
| "%cval = OpConstantComposite %v4f32 %c_f32_1 %c_f32_1 %c_f32_1 %c_f32_0\n" |
| "%per_vertex_out = OpTypeStruct %v4f32 %f32 %a1f32 %a1f32\n" |
| "%op_per_vertex_out = OpTypePointer Output %per_vertex_out\n" |
| "%stream = OpVariable %op_per_vertex_out Output\n" |
| "%gl_tessCoord = OpVariable %ip_v3f32 Input\n" |
| "%in_position = OpVariable %ip_a32v4f32 Input\n" |
| "%out_color = OpVariable %op_v4f32 Output\n" |
| "%in_color = OpVariable %ip_a32v4f32 Input\n" |
| |
| "%tesse1_main = OpFunction %void None %voidf\n" |
| "%tesse1_label = OpLabel\n" |
| "%tesse1_tc_0_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_0\n" |
| "%tesse1_tc_1_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_1\n" |
| "%tesse1_tc_2_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_2\n" |
| "%tesse1_tc_0 = OpLoad %f32 %tesse1_tc_0_ptr\n" |
| "%tesse1_tc_1 = OpLoad %f32 %tesse1_tc_1_ptr\n" |
| "%tesse1_tc_2 = OpLoad %f32 %tesse1_tc_2_ptr\n" |
| "%tesse1_in_pos_0_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_0\n" |
| "%tesse1_in_pos_1_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_1\n" |
| "%tesse1_in_pos_2_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_2\n" |
| "%tesse1_in_pos_0 = OpLoad %v4f32 %tesse1_in_pos_0_ptr\n" |
| "%tesse1_in_pos_1 = OpLoad %v4f32 %tesse1_in_pos_1_ptr\n" |
| "%tesse1_in_pos_2 = OpLoad %v4f32 %tesse1_in_pos_2_ptr\n" |
| "%tesse1_in_pos_0_weighted = OpVectorTimesScalar %v4f32 %tesse1_in_pos_0 %tesse1_tc_0\n" |
| "%tesse1_in_pos_1_weighted = OpVectorTimesScalar %v4f32 %tesse1_in_pos_1 %tesse1_tc_1\n" |
| "%tesse1_in_pos_2_weighted = OpVectorTimesScalar %v4f32 %tesse1_in_pos_2 %tesse1_tc_2\n" |
| "%tesse1_out_pos_ptr = OpAccessChain %op_v4f32 %stream %c_i32_0\n" |
| "%tesse1_in_pos_0_plus_pos_1 = OpFAdd %v4f32 %tesse1_in_pos_0_weighted %tesse1_in_pos_1_weighted\n" |
| "%tesse1_computed_out = OpFAdd %v4f32 %tesse1_in_pos_0_plus_pos_1 %tesse1_in_pos_2_weighted\n" |
| "OpStore %tesse1_out_pos_ptr %tesse1_computed_out\n" |
| "%tesse1_in_clr_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n" |
| "%tesse1_in_clr_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n" |
| "%tesse1_in_clr_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n" |
| "%tesse1_in_clr_0 = OpLoad %v4f32 %tesse1_in_clr_0_ptr\n" |
| "%tesse1_in_clr_1 = OpLoad %v4f32 %tesse1_in_clr_1_ptr\n" |
| "%tesse1_in_clr_2 = OpLoad %v4f32 %tesse1_in_clr_2_ptr\n" |
| "%tesse1_in_clr_0_weighted = OpVectorTimesScalar %v4f32 %tesse1_in_clr_0 %tesse1_tc_0\n" |
| "%tesse1_in_clr_1_weighted = OpVectorTimesScalar %v4f32 %tesse1_in_clr_1 %tesse1_tc_1\n" |
| "%tesse1_in_clr_2_weighted = OpVectorTimesScalar %v4f32 %tesse1_in_clr_2 %tesse1_tc_2\n" |
| "%tesse1_in_clr_0_plus_col_1 = OpFAdd %v4f32 %tesse1_in_clr_0_weighted %tesse1_in_clr_1_weighted\n" |
| "%tesse1_computed_clr = OpFAdd %v4f32 %tesse1_in_clr_0_plus_col_1 %tesse1_in_clr_2_weighted\n" |
| "OpStore %out_color %tesse1_computed_clr\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n" |
| |
| "%tesse2_main = OpFunction %void None %voidf\n" |
| "%tesse2_label = OpLabel\n" |
| "%tesse2_tc_0_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_0\n" |
| "%tesse2_tc_1_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_1\n" |
| "%tesse2_tc_2_ptr = OpAccessChain %ip_f32 %gl_tessCoord %c_u32_2\n" |
| "%tesse2_tc_0 = OpLoad %f32 %tesse2_tc_0_ptr\n" |
| "%tesse2_tc_1 = OpLoad %f32 %tesse2_tc_1_ptr\n" |
| "%tesse2_tc_2 = OpLoad %f32 %tesse2_tc_2_ptr\n" |
| "%tesse2_in_pos_0_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_0\n" |
| "%tesse2_in_pos_1_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_1\n" |
| "%tesse2_in_pos_2_ptr = OpAccessChain %ip_v4f32 %in_position %c_i32_2\n" |
| "%tesse2_in_pos_0 = OpLoad %v4f32 %tesse2_in_pos_0_ptr\n" |
| "%tesse2_in_pos_1 = OpLoad %v4f32 %tesse2_in_pos_1_ptr\n" |
| "%tesse2_in_pos_2 = OpLoad %v4f32 %tesse2_in_pos_2_ptr\n" |
| "%tesse2_in_pos_0_weighted = OpVectorTimesScalar %v4f32 %tesse2_in_pos_0 %tesse2_tc_0\n" |
| "%tesse2_in_pos_1_weighted = OpVectorTimesScalar %v4f32 %tesse2_in_pos_1 %tesse2_tc_1\n" |
| "%tesse2_in_pos_2_weighted = OpVectorTimesScalar %v4f32 %tesse2_in_pos_2 %tesse2_tc_2\n" |
| "%tesse2_out_pos_ptr = OpAccessChain %op_v4f32 %stream %c_i32_0\n" |
| "%tesse2_in_pos_0_plus_pos_1 = OpFAdd %v4f32 %tesse2_in_pos_0_weighted %tesse2_in_pos_1_weighted\n" |
| "%tesse2_computed_out = OpFAdd %v4f32 %tesse2_in_pos_0_plus_pos_1 %tesse2_in_pos_2_weighted\n" |
| "OpStore %tesse2_out_pos_ptr %tesse2_computed_out\n" |
| "%tesse2_in_clr_0_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_0\n" |
| "%tesse2_in_clr_1_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_1\n" |
| "%tesse2_in_clr_2_ptr = OpAccessChain %ip_v4f32 %in_color %c_i32_2\n" |
| "%tesse2_in_clr_0 = OpLoad %v4f32 %tesse2_in_clr_0_ptr\n" |
| "%tesse2_in_clr_1 = OpLoad %v4f32 %tesse2_in_clr_1_ptr\n" |
| "%tesse2_in_clr_2 = OpLoad %v4f32 %tesse2_in_clr_2_ptr\n" |
| "%tesse2_in_clr_0_weighted = OpVectorTimesScalar %v4f32 %tesse2_in_clr_0 %tesse2_tc_0\n" |
| "%tesse2_in_clr_1_weighted = OpVectorTimesScalar %v4f32 %tesse2_in_clr_1 %tesse2_tc_1\n" |
| "%tesse2_in_clr_2_weighted = OpVectorTimesScalar %v4f32 %tesse2_in_clr_2 %tesse2_tc_2\n" |
| "%tesse2_in_clr_0_plus_col_1 = OpFAdd %v4f32 %tesse2_in_clr_0_weighted %tesse2_in_clr_1_weighted\n" |
| "%tesse2_computed_clr = OpFAdd %v4f32 %tesse2_in_clr_0_plus_col_1 %tesse2_in_clr_2_weighted\n" |
| "%tesse2_clr_transformed = OpFSub %v4f32 %cval %tesse2_computed_clr\n" |
| "%tesse2_clr_transformed_a = OpVectorInsertDynamic %v4f32 %tesse2_clr_transformed %c_f32_1 %c_i32_3\n" |
| "OpStore %out_color %tesse2_clr_transformed_a\n" |
| "OpReturn\n" |
| "OpFunctionEnd\n"; |
| } |
| |
| bool compare16BitFloat (float original, deUint16 returned, RoundingModeFlags flags, tcu::TestLog& log) |
| { |
| // We only support RTE, RTZ, or both. |
| DE_ASSERT(static_cast<int>(flags) > 0 && static_cast<int>(flags) < 4); |
| |
| const Float32 originalFloat (original); |
| const Float16 returnedFloat (returned); |
| |
| // Zero are turned into zero under both RTE and RTZ. |
| if (originalFloat.isZero()) |
| { |
| if (returnedFloat.isZero()) |
| return true; |
| |
| log << TestLog::Message << "Error: expected zero but returned " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| // Any denormalized value input into a shader may be flushed to 0. |
| if (originalFloat.isDenorm() && returnedFloat.isZero()) |
| return true; |
| |
| // Inf are always turned into Inf with the same sign, too. |
| if (originalFloat.isInf()) |
| { |
| if (returnedFloat.isInf() && originalFloat.signBit() == returnedFloat.signBit()) |
| return true; |
| |
| log << TestLog::Message << "Error: expected Inf but returned " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| // NaN are always turned into NaN, too. |
| if (originalFloat.isNaN()) |
| { |
| if (returnedFloat.isNaN()) |
| return true; |
| |
| log << TestLog::Message << "Error: expected NaN but returned " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| // Check all rounding modes |
| for (int bitNdx = 0; bitNdx < 2; ++bitNdx) |
| { |
| if ((flags & (1u << bitNdx)) == 0) |
| continue; // This rounding mode is not selected. |
| |
| const Float16 expectedFloat (deFloat32To16Round(original, deRoundingMode(bitNdx))); |
| |
| // Any denormalized value potentially generated by any instruction in a shader may be flushed to 0. |
| if (expectedFloat.isDenorm() && returnedFloat.isZero()) |
| return true; |
| |
| // If not matched in the above cases, they should have the same bit pattern. |
| if (expectedFloat.bits() == returnedFloat.bits()) |
| return true; |
| } |
| |
| log << TestLog::Message << "Error: found unmatched 32-bit and 16-bit floats: " << originalFloat.bits() << " vs " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| bool compare16BitFloat (deUint16 original, deUint16 returned, tcu::TestLog& log) |
| { |
| const Float16 originalFloat (original); |
| const Float16 returnedFloat (returned); |
| |
| if (originalFloat.isZero()) |
| { |
| if (returnedFloat.isZero()) |
| return true; |
| |
| log << TestLog::Message << "Error: expected zero but returned " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| // Any denormalized value input into a shader or potentially generated by any instruction in a shader |
| // may be flushed to 0. |
| if (originalFloat.isDenorm() && returnedFloat.isZero()) |
| return true; |
| |
| // Inf are always turned into Inf with the same sign, too. |
| if (originalFloat.isInf()) |
| { |
| if (returnedFloat.isInf() && originalFloat.signBit() == returnedFloat.signBit()) |
| return true; |
| |
| log << TestLog::Message << "Error: expected Inf but returned " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| // NaN are always turned into NaN, too. |
| if (originalFloat.isNaN()) |
| { |
| if (returnedFloat.isNaN()) |
| return true; |
| |
| log << TestLog::Message << "Error: expected NaN but returned " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| // If not matched in the above cases, they should have the same bit pattern. |
| if (originalFloat.bits() == returnedFloat.bits()) |
| return true; |
| |
| log << TestLog::Message << "Error: found unmatched 16-bit and 16-bit floats: " << original << " vs " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| bool compare16BitFloat(deUint16 original, float returned, tcu::TestLog & log) |
| { |
| const Float16 originalFloat (original); |
| const Float32 returnedFloat (returned); |
| |
| // Zero are turned into zero under both RTE and RTZ. |
| if (originalFloat.isZero()) |
| { |
| if (returnedFloat.isZero()) |
| return true; |
| |
| log << TestLog::Message << "Error: expected zero but returned " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| // Any denormalized value input into a shader may be flushed to 0. |
| if (originalFloat.isDenorm() && returnedFloat.isZero()) |
| return true; |
| |
| // Inf are always turned into Inf with the same sign, too. |
| if (originalFloat.isInf()) |
| { |
| if (returnedFloat.isInf() && originalFloat.signBit() == returnedFloat.signBit()) |
| return true; |
| |
| log << TestLog::Message << "Error: expected Inf but returned " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| // NaN are always turned into NaN, too. |
| if (originalFloat.isNaN()) |
| { |
| if (returnedFloat.isNaN()) |
| return true; |
| |
| log << TestLog::Message << "Error: expected NaN but returned " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| // In all other cases, conversion should be exact. |
| const Float32 expectedFloat (deFloat16To32(original)); |
| if (expectedFloat.bits() == returnedFloat.bits()) |
| return true; |
| |
| log << TestLog::Message << "Error: found unmatched 16-bit and 32-bit floats: " << original << " vs " << returnedFloat.bits() << TestLog::EndMessage; |
| return false; |
| } |
| |
| bool compare16BitFloat (deFloat16 original, deFloat16 returned, std::string& error) |
| { |
| std::ostringstream log; |
| const Float16 originalFloat (original); |
| const Float16 returnedFloat (returned); |
| |
| if (originalFloat.isZero()) |
| { |
| if (returnedFloat.isZero()) |
| return true; |
| |
| log << "Error: expected zero but returned " << std::hex << "0x" << returned << " (" << returnedFloat.asFloat() << ")"; |
| error = log.str(); |
| return false; |
| } |
| |
| // Any denormalized value input into a shader may be flushed to 0. |
| if (originalFloat.isDenorm() && returnedFloat.isZero()) |
| return true; |
| |
| // Inf are always turned into Inf with the same sign, too. |
| if (originalFloat.isInf()) |
| { |
| if (returnedFloat.isInf() && originalFloat.signBit() == returnedFloat.signBit()) |
| return true; |
| |
| log << "Error: expected Inf but returned " << std::hex << "0x" << returned << " (" << returnedFloat.asFloat() << ")"; |
| error = log.str(); |
| return false; |
| } |
| |
| // NaN are always turned into NaN, too. |
| if (originalFloat.isNaN()) |
| { |
| if (returnedFloat.isNaN()) |
| return true; |
| |
| log << "Error: expected NaN but returned " << std::hex << "0x" << returned << " (" << returnedFloat.asFloat() << ")"; |
| error = log.str(); |
| return false; |
| } |
| |
| // Any denormalized value potentially generated by any instruction in a shader may be flushed to 0. |
| if (originalFloat.isDenorm() && returnedFloat.isZero()) |
| return true; |
| |
| // If not matched in the above cases, they should have the same bit pattern. |
| if (originalFloat.bits() == returnedFloat.bits()) |
| return true; |
| |
| log << "Error: found unmatched 16-bit and 16-bit floats: 0x" |
| << std::hex << original << " <=> 0x" << returned |
| << " (" << originalFloat.asFloat() << " <=> " << returnedFloat.asFloat() << ")"; |
| error = log.str(); |
| return false; |
| } |
| |
| bool compare16BitFloat64 (double original, deUint16 returned, RoundingModeFlags flags, tcu::TestLog& log) |
| { |
| // We only support RTE, RTZ, or both. |
| DE_ASSERT(static_cast<int>(flags) > 0 && static_cast<int>(flags) < 4); |
| |
| const Float64 originalFloat (original); |
| const Float16 returnedFloat (returned); |
| |
| // Zero are turned into zero under both RTE and RTZ. |
| if (originalFloat.isZero()) |
| { |
| if (returnedFloat.isZero()) |
| return true; |
| |
| log << TestLog::Message << "Error: expected zero but returned " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| // Any denormalized value input into a shader may be flushed to 0. |
| if (originalFloat.isDenorm() && returnedFloat.isZero()) |
| return true; |
| |
| // Inf are always turned into Inf with the same sign, too. |
| if (originalFloat.isInf()) |
| { |
| if (returnedFloat.isInf() && originalFloat.signBit() == returnedFloat.signBit()) |
| return true; |
| |
| log << TestLog::Message << "Error: expected Inf but returned " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| // NaN are always turned into NaN, too. |
| if (originalFloat.isNaN()) |
| { |
| if (returnedFloat.isNaN()) |
| return true; |
| |
| log << TestLog::Message << "Error: expected NaN but returned " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| // Check all rounding modes |
| for (int bitNdx = 0; bitNdx < 2; ++bitNdx) |
| { |
| if ((flags & (1u << bitNdx)) == 0) |
| continue; // This rounding mode is not selected. |
| |
| const Float16 expectedFloat (deFloat64To16Round(original, deRoundingMode(bitNdx))); |
| |
| // Any denormalized value potentially generated by any instruction in a shader may be flushed to 0. |
| if (expectedFloat.isDenorm() && returnedFloat.isZero()) |
| return true; |
| |
| // If not matched in the above cases, they should have the same bit pattern. |
| if (expectedFloat.bits() == returnedFloat.bits()) |
| return true; |
| } |
| |
| log << TestLog::Message << "Error: found unmatched 64-bit and 16-bit floats: " << originalFloat.bits() << " vs " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| bool compare32BitFloat (float expected, float returned, tcu::TestLog& log) |
| { |
| const Float32 expectedFloat (expected); |
| const Float32 returnedFloat (returned); |
| |
| // Any denormalized value potentially generated by any instruction in a shader may be flushed to 0. |
| if (expectedFloat.isDenorm() && returnedFloat.isZero()) |
| return true; |
| |
| { |
| const Float16 originalFloat (deFloat32To16(expected)); |
| |
| // Any denormalized value input into a shader may be flushed to 0. |
| if (originalFloat.isDenorm() && returnedFloat.isZero()) |
| return true; |
| } |
| |
| if (expectedFloat.isNaN()) |
| { |
| if (returnedFloat.isNaN()) |
| return true; |
| |
| log << TestLog::Message << "Error: expected NaN but returned " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| if (returned == expected) |
| return true; |
| |
| log << TestLog::Message << "Error: found unmatched 32-bit float: expected " << expectedFloat.bits() << " vs. returned " << returnedFloat.bits() << TestLog::EndMessage; |
| return false; |
| } |
| |
| bool compare64BitFloat (double expected, double returned, tcu::TestLog& log) |
| { |
| const Float64 expectedDouble (expected); |
| const Float64 returnedDouble (returned); |
| |
| // Any denormalized value potentially generated by any instruction in a shader may be flushed to 0. |
| if (expectedDouble.isDenorm() && returnedDouble.isZero()) |
| return true; |
| |
| { |
| const Float16 originalDouble (deFloat64To16(expected)); |
| |
| // Any denormalized value input into a shader may be flushed to 0. |
| if (originalDouble.isDenorm() && returnedDouble.isZero()) |
| return true; |
| } |
| |
| if (expectedDouble.isNaN()) |
| { |
| if (returnedDouble.isNaN()) |
| return true; |
| |
| log << TestLog::Message << "Error: expected NaN but returned " << returned << TestLog::EndMessage; |
| return false; |
| } |
| |
| if (returned == expected) |
| return true; |
| |
| log << TestLog::Message << "Error: found unmatched 64-bit float: expected " << expectedDouble.bits() << " vs. returned " << returnedDouble.bits() << TestLog::EndMessage; |
| return false; |
| } |
| |
| Move<VkBuffer> createBufferForResource (const DeviceInterface& vk, const VkDevice vkDevice, const Resource& resource, deUint32 queueFamilyIndex) |
| { |
| const vk::VkDescriptorType resourceType = resource.getDescriptorType(); |
| |
| vector<deUint8> resourceBytes; |
| resource.getBytes(resourceBytes); |
| |
| const VkBufferCreateInfo resourceBufferParams = |
| { |
| VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // sType |
| DE_NULL, // pNext |
| (VkBufferCreateFlags)0, // flags |
| (VkDeviceSize)resourceBytes.size(), // size |
| (VkBufferUsageFlags)getMatchingBufferUsageFlagBit(resourceType), // usage |
| VK_SHARING_MODE_EXCLUSIVE, // sharingMode |
| 1u, // queueFamilyCount |
| &queueFamilyIndex, // pQueueFamilyIndices |
| }; |
| |
| return createBuffer(vk, vkDevice, &resourceBufferParams); |
| } |
| |
| Move<VkImage> createImageForResource (const DeviceInterface& vk, const VkDevice vkDevice, const Resource& resource, VkFormat inputFormat, deUint32 queueFamilyIndex) |
| { |
| const VkImageCreateInfo resourceImageParams = |
| { |
| VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType; |
| DE_NULL, // const void* pNext; |
| 0u, // VkImageCreateFlags flags; |
| VK_IMAGE_TYPE_2D, // VkImageType imageType; |
| inputFormat, // VkFormat format; |
| { 8, 8, 1 }, // VkExtent3D extent; |
| 1u, // deUint32 mipLevels; |
| 1u, // deUint32 arraySize; |
| VK_SAMPLE_COUNT_1_BIT, // deUint32 samples; |
| VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling; |
| getMatchingImageUsageFlags(resource.getDescriptorType()), // VkImageUsageFlags usage; |
| VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode; |
| 1u, // deUint32 queueFamilyCount; |
| &queueFamilyIndex, // const deUint32* pQueueFamilyIndices; |
| VK_IMAGE_LAYOUT_UNDEFINED // VkImageLayout initialLayout; |
| }; |
| |
| return createImage(vk, vkDevice, &resourceImageParams); |
| } |
| |
| void copyBufferToImage (const DeviceInterface& vk, const VkDevice& device, const VkQueue& queue, VkCommandBuffer cmdBuffer, VkBuffer buffer, VkImage image, VkImageAspectFlags aspect) |
| { |
| const VkBufferImageCopy copyRegion = |
| { |
| 0u, // VkDeviceSize bufferOffset; |
| 0u, // deUint32 bufferRowLength; |
| 0u, // deUint32 bufferImageHeight; |
| { |
| aspect, // VkImageAspectFlags aspect; |
| 0u, // deUint32 mipLevel; |
| 0u, // deUint32 baseArrayLayer; |
| 1u, // deUint32 layerCount; |
| }, // VkImageSubresourceLayers imageSubresource; |
| { 0, 0, 0 }, // VkOffset3D imageOffset; |
| { 8, 8, 1 } // VkExtent3D imageExtent; |
| }; |
| |
| // Copy buffer to image |
| beginCommandBuffer(vk, cmdBuffer); |
| |
| copyBufferToImage(vk, cmdBuffer, buffer, VK_WHOLE_SIZE, vector<VkBufferImageCopy>(1, copyRegion), aspect, 1u, 1u, image, VK_IMAGE_LAYOUT_GENERAL, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT); |
| |
| endCommandBuffer(vk, cmdBuffer); |
| |
| submitCommandsAndWait(vk, device, queue, cmdBuffer); |
| } |
| |
| VkImageAspectFlags getImageAspectFlags (VkFormat format) |
| { |
| const tcu::TextureFormat::ChannelOrder channelOrder = vk::mapVkFormat(format).order; |
| VkImageAspectFlags aspectFlags = (VkImageAspectFlags)0u; |
| |
| if (tcu::hasDepthComponent(channelOrder)) |
| aspectFlags |= VK_IMAGE_ASPECT_DEPTH_BIT; |
| |
| if (tcu::hasStencilComponent(channelOrder)) |
| aspectFlags |= VK_IMAGE_ASPECT_STENCIL_BIT; |
| |
| if (!aspectFlags) |
| aspectFlags |= VK_IMAGE_ASPECT_COLOR_BIT; |
| |
| return aspectFlags; |
| } |
| |
| TestStatus runAndVerifyUnusedVariablePipeline (Context &context, UnusedVariableContext unusedVariableContext) |
| { |
| return runAndVerifyDefaultPipeline(context, unusedVariableContext.instanceContext); |
| } |
| |
| TestStatus runAndVerifyDefaultPipeline (Context& context, InstanceContext instance) |
| { |
| if (getMinRequiredVulkanVersion(instance.resources.spirvVersion) > context.getUsedApiVersion()) |
| { |
| TCU_THROW(NotSupportedError, string("Vulkan higher than or equal to " + getVulkanName(getMinRequiredVulkanVersion(instance.resources.spirvVersion)) + " is required for this test to run").c_str()); |
| } |
| |
| const DeviceInterface& vk = context.getDeviceInterface(); |
| const InstanceInterface& vkInstance = context.getInstanceInterface(); |
| const VkPhysicalDevice vkPhysicalDevice = context.getPhysicalDevice(); |
| const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); |
| const VkQueue queue = context.getUniversalQueue(); |
| const VkDevice& device = context.getDevice(); |
| Allocator& allocator = context.getDefaultAllocator(); |
| vector<ModuleHandleSp> modules; |
| map<VkShaderStageFlagBits, VkShaderModule> moduleByStage; |
| const deUint32 fullRenderSize = 256; |
| const deUint32 quarterRenderSize = 64; |
| const tcu::UVec2 renderSize (fullRenderSize, fullRenderSize); |
| const int testSpecificSeed = 31354125; |
| const int seed = context.getTestContext().getCommandLine().getBaseSeed() ^ testSpecificSeed; |
| bool supportsGeometry = false; |
| bool supportsTessellation = false; |
| bool hasGeometry = false; |
| bool hasTessellation = false; |
| const bool hasPushConstants = !instance.pushConstants.empty(); |
| const deUint32 numInResources = static_cast<deUint32>(instance.resources.inputs.size()); |
| const deUint32 numOutResources = static_cast<deUint32>(instance.resources.outputs.size()); |
| const deUint32 numResources = numInResources + numOutResources; |
| const bool needInterface = !instance.interfaces.empty(); |
| const VkPhysicalDeviceFeatures& features = context.getDeviceFeatures(); |
| const Vec4 defaulClearColor (0.125f, 0.25f, 0.75f, 1.0f); |
| bool splitRenderArea = instance.splitRenderArea; |
| |
| const deUint32 renderDimension = splitRenderArea ? quarterRenderSize : fullRenderSize; |
| const int numRenderSegments = splitRenderArea ? 4 : 1; |
| |
| supportsGeometry = features.geometryShader == VK_TRUE; |
| supportsTessellation = features.tessellationShader == VK_TRUE; |
| hasGeometry = (instance.requiredStages & VK_SHADER_STAGE_GEOMETRY_BIT); |
| hasTessellation = (instance.requiredStages & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) || |
| (instance.requiredStages & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT); |
| |
| if (hasGeometry && !supportsGeometry) |
| { |
| TCU_THROW(NotSupportedError, "Geometry not supported"); |
| } |
| |
| if (hasTessellation && !supportsTessellation) |
| { |
| TCU_THROW(NotSupportedError, "Tessellation not supported"); |
| } |
| |
| // Check all required extensions are supported |
| for (std::vector<std::string>::const_iterator i = instance.requiredDeviceExtensions.begin(); i != instance.requiredDeviceExtensions.end(); ++i) |
| { |
| |