MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / ValidateImageWrite

Function ValidateImageWrite

source/val/validate_image.cpp:2005–2076  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2003}
2004
2005spv_result_t ValidateImageWrite(ValidationState_t& _, const Instruction* inst) {
2006 const uint32_t image_type = _.GetOperandTypeId(inst, 0);
2007 if (_.GetIdOpcode(image_type) != spv::Op::OpTypeImage) {
2008 return _.diag(SPV_ERROR_INVALID_DATA, inst)
2009 << "Expected Image to be of type OpTypeImage";
2010 }
2011
2012 ImageTypeInfo info;
2013 if (!GetImageTypeInfo(_, image_type, &info)) {
2014 return _.diag(SPV_ERROR_INVALID_DATA, inst)
2015 << "Corrupt image type definition";
2016 }
2017
2018 if (info.dim == spv::Dim::SubpassData) {
2019 return _.diag(SPV_ERROR_INVALID_DATA, inst)
2020 << "Image 'Dim' cannot be SubpassData";
2021 }
2022
2023 if (info.dim == spv::Dim::TileImageDataEXT) {
2024 return _.diag(SPV_ERROR_INVALID_DATA, inst)
2025 << "Image 'Dim' cannot be TileImageDataEXT";
2026 }
2027
2028 if (spv_result_t result = ValidateImageReadWrite(_, inst, info))
2029 return result;
2030
2031 if (spv_result_t result =
2032 ValidateImageCoordinate(_, inst, info, /* word_index = */ 1))
2033 return result;
2034
2035 // because it needs to match with 'Sampled Type' the Texel can't be a boolean
2036 const uint32_t texel_type = _.GetOperandTypeId(inst, 2);
2037 if (!_.IsIntScalarOrVectorType(texel_type) &&
2038 !_.IsFloatScalarOrVectorType(texel_type)) {
2039 return _.diag(SPV_ERROR_INVALID_DATA, inst)
2040 << "Expected Texel to be int or float vector or scalar";
2041 }
2042
2043 if (_.GetIdOpcode(info.sampled_type) != spv::Op::OpTypeVoid) {
2044 const uint32_t texel_component_type = _.GetComponentType(texel_type);
2045 if (texel_component_type != info.sampled_type) {
2046 return _.diag(SPV_ERROR_INVALID_DATA, inst)
2047 << "Expected Image 'Sampled Type' to be the same as Texel "
2048 << "components";
2049 }
2050 }
2051
2052 if (spvIsVulkanEnv(_.context()->target_env)) {
2053 if (info.format == spv::ImageFormat::Unknown &&
2054 info.dim != spv::Dim::SubpassData &&
2055 !_.HasCapability(spv::Capability::StorageImageWriteWithoutFormat)) {
2056 return _.diag(SPV_ERROR_INVALID_DATA, inst)
2057 << "Capability StorageImageWriteWithoutFormat is required to "
2058 "write "
2059 << "to storage image";
2060 }
2061 }
2062

Callers 1

ImagePassFunction · 0.85

Calls 15

GetImageTypeInfoFunction · 0.85
ValidateImageReadWriteFunction · 0.85
ValidateImageCoordinateFunction · 0.85
spvIsVulkanEnvFunction · 0.85
spvIsOpenCLEnvFunction · 0.85
ValidateImageOperandsFunction · 0.85
GetOperandTypeIdMethod · 0.80
GetIdOpcodeMethod · 0.80
diagMethod · 0.80
GetComponentTypeMethod · 0.45

Tested by

no test coverage detected