}
}
+std::string getImageComponentTypeName (const tcu::TextureFormat& format)
+{
+ switch (tcu::getTextureChannelClass(format.type))
+ {
+ case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
+ return "%type_uint";
+ case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
+ return "%type_int";
+ default:
+ DE_ASSERT(0);
+ return "";
+ }
+}
+
+std::string getImageComponentVec4TypeName (const tcu::TextureFormat& format)
+{
+ switch (tcu::getTextureChannelClass(format.type))
+ {
+ case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
+ return "%type_uvec4";
+ case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
+ return "%type_ivec4";
+ default:
+ DE_ASSERT(0);
+ return "";
+ }
+}
+
std::string getOpTypeImageSparse (const ImageType imageType,
const tcu::TextureFormat& format,
const std::string& componentType,
SPARSE_SPIRV_FUNCTION_TYPE_LAST
};
-std::string getOpTypeImageComponent (const tcu::TextureFormat& format);
+std::string getOpTypeImageComponent (const tcu::TextureFormat& format);
+std::string getImageComponentTypeName (const tcu::TextureFormat& format);
+std::string getImageComponentVec4TypeName (const tcu::TextureFormat& format);
std::string getOpTypeImageSparse (const ImageType imageType,
const tcu::TextureFormat& format,
// Create fragment shader
std::ostringstream fs;
+ const std::string typeImgComp = getImageComponentTypeName(m_format);
+ const std::string typeImgCompVec4 = getImageComponentVec4TypeName(m_format);
+
fs << "OpCapability Shader\n"
<< "OpCapability SampledCubeArray\n"
<< "OpCapability ImageCubeArray\n"
<< "%type_vec2 = OpTypeVector %type_float 2\n"
<< "%type_vec3 = OpTypeVector %type_float 3\n"
<< "%type_vec4 = OpTypeVector %type_float 4\n"
+ << "%type_ivec4 = OpTypeVector %type_int 4\n"
+ << "%type_uvec4 = OpTypeVector %type_uint 4\n"
<< "%type_uniformblock = OpTypeStruct %type_uint %type_vec2\n"
- << "%type_img_comp = " << getOpTypeImageComponent(m_format) << "\n"
- << "%type_img_comp_vec4 = OpTypeVector %type_img_comp 4\n"
- << "%type_struct_int_img_comp_vec4 = OpTypeStruct %type_int %type_img_comp_vec4\n"
+ << "%type_struct_int_img_comp_vec4 = OpTypeStruct %type_int " << typeImgCompVec4 << "\n"
<< "%type_input_vec3 = OpTypePointer Input %type_vec3\n"
<< "%type_input_float = OpTypePointer Input %type_float\n"
- << "%type_output_img_comp_vec4 = OpTypePointer Output %type_img_comp_vec4\n"
+ << "%type_output_img_comp_vec4 = OpTypePointer Output " << typeImgCompVec4 << "\n"
<< "%type_output_uint = OpTypePointer Output %type_uint\n"
<< "%type_function_int = OpTypePointer Function %type_int\n"
- << "%type_function_img_comp = OpTypePointer Function %type_img_comp\n"
- << "%type_function_img_comp_vec4 = OpTypePointer Function %type_img_comp_vec4\n"
+ << "%type_function_img_comp_vec4 = OpTypePointer Function " << typeImgCompVec4 << "\n"
<< "%type_function_int_img_comp_vec4 = OpTypePointer Function %type_struct_int_img_comp_vec4\n"
<< "%type_pushconstant_uniformblock = OpTypePointer PushConstant %type_uniformblock\n"
<< "%type_pushconstant_uniformblock_member_lod = OpTypePointer PushConstant %type_uint\n"
<< "%type_pushconstant_uniformblock_member_size = OpTypePointer PushConstant %type_vec2\n"
- << "%type_image_sparse = " << getOpTypeImageSparse(m_imageType, m_format, "%type_img_comp", true) << "\n"
+ << "%type_image_sparse = " << getOpTypeImageSparse(m_imageType, m_format, typeImgComp, true) << "\n"
<< "%type_sampled_image_sparse = OpTypeSampledImage %type_image_sparse\n"
<< "%type_uniformconst_image_sparse = OpTypePointer UniformConstant %type_sampled_image_sparse\n"
<< sparseImageOpString("%local_sparse_op_result", "%type_struct_int_img_comp_vec4", "%local_image_sparse", coordString, "%local_uniformblock_member_float_lod") << "\n"
// Load texel value
- << "%local_img_comp_vec4 = OpCompositeExtract %type_img_comp_vec4 %local_sparse_op_result 1\n"
+ << "%local_img_comp_vec4 = OpCompositeExtract " << typeImgCompVec4 << " %local_sparse_op_result 1\n"
<< "OpStore %output_texel %local_img_comp_vec4\n"
std::ostringstream src;
+ const std::string typeImgComp = getImageComponentTypeName(m_format);
+ const std::string typeImgCompVec4 = getImageComponentVec4TypeName(m_format);
+
// Bias the coord value by half a texel, so we sample from center of 2x2 gather rectangle
src << "%local_image_width = OpCompositeExtract %type_float %local_uniformblock_member_size 0\n";
src << "%local_gather_residency_code = OpCompositeExtract %type_int %local_sparse_gather_result_x 0\n";
- src << "%local_gather_texels_x = OpCompositeExtract %type_img_comp_vec4 %local_sparse_gather_result_x 1\n";
- src << "%local_gather_texels_y = OpCompositeExtract %type_img_comp_vec4 %local_sparse_gather_result_y 1\n";
- src << "%local_gather_texels_z = OpCompositeExtract %type_img_comp_vec4 %local_sparse_gather_result_z 1\n";
- src << "%local_gather_texels_w = OpCompositeExtract %type_img_comp_vec4 %local_sparse_gather_result_w 1\n";
+ src << "%local_gather_texels_x = OpCompositeExtract " << typeImgCompVec4 << " %local_sparse_gather_result_x 1\n";
+ src << "%local_gather_texels_y = OpCompositeExtract " << typeImgCompVec4 << " %local_sparse_gather_result_y 1\n";
+ src << "%local_gather_texels_z = OpCompositeExtract " << typeImgCompVec4 << " %local_sparse_gather_result_z 1\n";
+ src << "%local_gather_texels_w = OpCompositeExtract " << typeImgCompVec4 << " %local_sparse_gather_result_w 1\n";
- src << "%local_gather_primary_texel_x = OpCompositeExtract %type_img_comp %local_gather_texels_x 3\n";
- src << "%local_gather_primary_texel_y = OpCompositeExtract %type_img_comp %local_gather_texels_y 3\n";
- src << "%local_gather_primary_texel_z = OpCompositeExtract %type_img_comp %local_gather_texels_z 3\n";
- src << "%local_gather_primary_texel_w = OpCompositeExtract %type_img_comp %local_gather_texels_w 3\n";
+ src << "%local_gather_primary_texel_x = OpCompositeExtract " << typeImgComp << " %local_gather_texels_x 3\n";
+ src << "%local_gather_primary_texel_y = OpCompositeExtract " << typeImgComp << " %local_gather_texels_y 3\n";
+ src << "%local_gather_primary_texel_z = OpCompositeExtract " << typeImgComp << " %local_gather_texels_z 3\n";
+ src << "%local_gather_primary_texel_w = OpCompositeExtract " << typeImgComp << " %local_gather_texels_w 3\n";
- src << "%local_gather_primary_texel = OpCompositeConstruct %type_img_comp_vec4 %local_gather_primary_texel_x %local_gather_primary_texel_y %local_gather_primary_texel_z %local_gather_primary_texel_w\n";
+ src << "%local_gather_primary_texel = OpCompositeConstruct " << typeImgCompVec4 << " %local_gather_primary_texel_x %local_gather_primary_texel_y %local_gather_primary_texel_z %local_gather_primary_texel_w\n";
src << resultVariable << " = OpCompositeConstruct " << resultType << " %local_gather_residency_code %local_gather_primary_texel\n";
return src.str();
// Create compute program
std::ostringstream src;
+ const std::string typeImgComp = getImageComponentTypeName(m_format);
+ const std::string typeImgCompVec4 = getImageComponentVec4TypeName(m_format);
+ const std::string typeImageSparse = getSparseImageTypeName();
+ const std::string typeUniformConstImageSparse = getUniformConstSparseImageTypeName();
+
src << "OpCapability Shader\n"
<< "OpCapability ImageCubeArray\n"
<< "OpCapability SparseResidency\n"
<< "%type_uint = OpTypeInt 32 0\n"
<< "%type_ivec2 = OpTypeVector %type_int 2\n"
<< "%type_ivec3 = OpTypeVector %type_int 3\n"
+ << "%type_ivec4 = OpTypeVector %type_int 4\n"
<< "%type_uvec3 = OpTypeVector %type_uint 3\n"
<< "%type_uvec4 = OpTypeVector %type_uint 4\n"
- << "%type_img_comp = " << getOpTypeImageComponent(m_format) << "\n"
- << "%type_img_comp_vec4 = OpTypeVector %type_img_comp 4\n"
- << "%type_struct_int_img_comp_vec4 = OpTypeStruct %type_int %type_img_comp_vec4\n"
+ << "%type_struct_int_img_comp_vec4 = OpTypeStruct %type_int " << typeImgCompVec4 << "\n"
<< "%type_input_uint = OpTypePointer Input %type_uint\n"
<< "%type_input_uvec3 = OpTypePointer Input %type_uvec3\n"
<< "%type_function_int = OpTypePointer Function %type_int\n"
- << "%type_function_img_comp_vec4 = OpTypePointer Function %type_img_comp_vec4\n"
+ << "%type_function_img_comp_vec4 = OpTypePointer Function " << typeImgCompVec4 << "\n"
<< "%type_void = OpTypeVoid\n"
<< "%type_void_func = OpTypeFunction %type_void\n"
- // Sparse image type declaration
- << sparseImageTypeDecl("%type_image_sparse", "%type_img_comp")
- << "%type_uniformconst_image_sparse = OpTypePointer UniformConstant %type_image_sparse\n"
+ // Sparse image without sampler type declaration
+ << "%type_image_sparse = " << getOpTypeImageSparse(m_imageType, m_format, typeImgComp, false) << "\n"
+ << "%type_uniformconst_image_sparse = OpTypePointer UniformConstant %type_image_sparse\n"
- // Texels image type declaration
- << "%type_image_texels = " << getOpTypeImageSparse(m_imageType, m_format, "%type_img_comp", false) << "\n"
- << "%type_uniformconst_image_texels = OpTypePointer UniformConstant %type_image_texels\n"
+ // Sparse image with sampler type declaration
+ << "%type_image_sparse_with_sampler = " << getOpTypeImageSparse(m_imageType, m_format, typeImgComp, true) << "\n"
+ << "%type_uniformconst_image_sparse_with_sampler = OpTypePointer UniformConstant %type_image_sparse_with_sampler\n"
// Residency image type declaration
<< "%type_image_residency = " << getOpTypeImageResidency(m_imageType) << "\n"
<< "%type_uniformconst_image_residency = OpTypePointer UniformConstant %type_image_residency\n"
// Declare sparse image variable
- << "%uniform_image_sparse = OpVariable %type_uniformconst_image_sparse UniformConstant\n"
+ << "%uniform_image_sparse = OpVariable " << typeUniformConstImageSparse << " UniformConstant\n"
// Declare output image variable for storing texels
- << "%uniform_image_texels = OpVariable %type_uniformconst_image_texels UniformConstant\n"
+ << "%uniform_image_texels = OpVariable %type_uniformconst_image_sparse UniformConstant\n"
// Declare output image variable for storing residency information
<< "%uniform_image_residency = OpVariable %type_uniformconst_image_residency UniformConstant\n"
<< "%label_in_range_z = OpLabel\n"
// Load sparse image
- << "%local_image_sparse = OpLoad %type_image_sparse %uniform_image_sparse\n"
+ << "%local_image_sparse = OpLoad " << typeImageSparse << " %uniform_image_sparse\n"
// Call OpImageSparse*
<< sparseImageOpString("%local_sparse_op_result", "%type_struct_int_img_comp_vec4", "%local_image_sparse", coordString, "%constant_int_0") << "\n"
// Load the texel from the sparse image to local variable for OpImageSparse*
- << "%local_img_comp_vec4 = OpCompositeExtract %type_img_comp_vec4 %local_sparse_op_result 1\n"
+ << "%local_img_comp_vec4 = OpCompositeExtract " << typeImgCompVec4 << " %local_sparse_op_result 1\n"
// Load residency code for OpImageSparse*
<< "%local_residency_code = OpCompositeExtract %type_int %local_sparse_op_result 0\n"
// End Call OpImageSparse*
// Load texels image
- << "%local_image_texels = OpLoad %type_image_texels %uniform_image_texels\n"
+ << "%local_image_texels = OpLoad %type_image_sparse %uniform_image_texels\n"
// Write the texel to output image via OpImageWrite
<< "OpImageWrite %local_image_texels " << coordString << " %local_img_comp_vec4\n"
programCollection.spirvAsmSources.add("compute") << src.str();
}
-std::string SparseCaseOpImageSparseFetch::sparseImageTypeDecl (const std::string& imageType, const std::string& componentType) const
+std::string SparseCaseOpImageSparseFetch::getSparseImageTypeName (void) const
{
- std::ostringstream src;
-
- src << imageType << " = " << getOpTypeImageSparse(m_imageType, m_format, componentType, true) << "\n";
+ return "%type_image_sparse_with_sampler";
+}
- return src.str();
+std::string SparseCaseOpImageSparseFetch::getUniformConstSparseImageTypeName (void) const
+{
+ return "%type_uniformconst_image_sparse_with_sampler";
}
std::string SparseCaseOpImageSparseFetch::sparseImageOpString (const std::string& resultVariable,
return src.str();
}
-std::string SparseCaseOpImageSparseRead::sparseImageTypeDecl (const std::string& imageType, const std::string& componentType) const
+std::string SparseCaseOpImageSparseRead::getSparseImageTypeName (void) const
{
- std::ostringstream src;
-
- src << imageType << " = " << getOpTypeImageSparse(m_imageType, m_format, componentType, false) << "\n";
+ return "%type_image_sparse";
+}
- return src.str();
+std::string SparseCaseOpImageSparseRead::getUniformConstSparseImageTypeName (void) const
+{
+ return "%type_uniformconst_image_sparse";
}
std::string SparseCaseOpImageSparseRead::sparseImageOpString (const std::string& resultVariable,
void initPrograms (vk::SourceCollections& programCollection) const;
- virtual std::string sparseImageTypeDecl(const std::string& imageType,
- const std::string& componentType) const = 0;
+ virtual std::string getSparseImageTypeName (void) const = 0;
+ virtual std::string getUniformConstSparseImageTypeName (void) const = 0;
virtual std::string sparseImageOpString (const std::string& resultVariable,
const std::string& resultType,
TestInstance* createInstance(Context& context) const;
- std::string sparseImageTypeDecl(const std::string& imageType, const std::string& componentType) const;
+ std::string getSparseImageTypeName (void) const;
+ std::string getUniformConstSparseImageTypeName (void) const;
std::string sparseImageOpString(const std::string& resultVariable, const std::string& resultType, const std::string& image, const std::string& coord, const std::string& mipLevel) const;
};
TestInstance* createInstance(Context& context) const;
- std::string sparseImageTypeDecl(const std::string& imageType, const std::string& componentType) const;
+ std::string getSparseImageTypeName (void) const;
+ std::string getUniformConstSparseImageTypeName (void) const;
std::string sparseImageOpString(const std::string& resultVariable, const std::string& resultType, const std::string& image, const std::string& coord, const std::string& mipLevel) const;
};