Skip to content

Commit

Permalink
[OpenCL] Add mipmap builtin functions
Browse files Browse the repository at this point in the history
Add the mipmap builtin functions from the OpenCL extension
specification.

Patch by Pierre Gondois and Sven van Haastregt.
  • Loading branch information
svenvh committed Dec 30, 2019
1 parent dbc136e commit 4a188fd
Showing 1 changed file with 177 additions and 0 deletions.
177 changes: 177 additions & 0 deletions clang/lib/Sema/OpenCLBuiltins.td
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def FuncExtKhrLocalInt32BaseAtomics : FunctionExtension<"cl_khr_local_int32
def FuncExtKhrLocalInt32ExtendedAtomics : FunctionExtension<"cl_khr_local_int32_extended_atomics">;
def FuncExtKhrInt64BaseAtomics : FunctionExtension<"cl_khr_int64_base_atomics">;
def FuncExtKhrInt64ExtendedAtomics : FunctionExtension<"cl_khr_int64_extended_atomics">;
def FuncExtKhrMipmapImage : FunctionExtension<"cl_khr_mipmap_image">;

// Multiple extensions
def FuncExtKhrMipmapAndWrite3d : FunctionExtension<"cl_khr_mipmap_image cl_khr_3d_image_writes">;

// Qualified Type. These map to ASTContext::QualType.
class QualType<string _Name, bit _IsAbstract=0> {
Expand Down Expand Up @@ -1179,3 +1183,176 @@ let MinVersion = CL20 in {
def get_num_sub_groups : Builtin<"get_num_sub_groups", [UInt]>;
}
}

//--------------------------------------------------------------------
// End of the builtin functions defined in the OpenCL C specification.
// Builtin functions defined in the OpenCL C Extension are below.
//--------------------------------------------------------------------


// OpenCL Extension v2.0 s9.18 - Mipmaps
let Extension = FuncExtKhrMipmapImage in {
// Added to section 6.13.14.2.
foreach aQual = ["RO"] in {
foreach imgTy = [Image2d] in {
foreach name = ["read_imagef"] in {
def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
}
foreach name = ["read_imagei"] in {
def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
}
foreach name = ["read_imageui"] in {
def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
}
}
foreach imgTy = [Image2dDepth] in {
foreach name = ["read_imagef"] in {
def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
}
}
foreach imgTy = [Image1d] in {
foreach name = ["read_imagef"] in {
def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
}
foreach name = ["read_imagei"] in {
def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
}
foreach name = ["read_imageui"] in {
def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
}
}
foreach imgTy = [Image3d] in {
foreach name = ["read_imagef"] in {
def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
}
foreach name = ["read_imagei"] in {
def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
}
foreach name = ["read_imageui"] in {
def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
}
}
foreach imgTy = [Image1dArray] in {
foreach name = ["read_imagef"] in {
def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
}
foreach name = ["read_imagei"] in {
def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
}
foreach name = ["read_imageui"] in {
def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
}
}
foreach imgTy = [Image2dArray] in {
foreach name = ["read_imagef"] in {
def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
}
foreach name = ["read_imagei"] in {
def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
}
foreach name = ["read_imageui"] in {
def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
}
}
foreach imgTy = [Image2dArrayDepth] in {
foreach name = ["read_imagef"] in {
def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
}
}
}
// Added to section 6.13.14.4.
foreach aQual = ["WO"] in {
foreach imgTy = [Image2d] in {
foreach name = ["write_imagef"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
}
foreach name = ["write_imagei"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
}
foreach name = ["write_imageui"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
}
}
foreach imgTy = [Image2dDepth] in {
foreach name = ["write_imagef"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, Float]>;
}
}
foreach imgTy = [Image1d] in {
foreach name = ["write_imagef"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Float, 4>]>;
}
foreach name = ["write_imagei"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Int, 4>]>;
}
foreach name = ["write_imageui"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<UInt, 4>]>;
}
}
foreach imgTy = [Image1dArray] in {
foreach name = ["write_imagef"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
}
foreach name = ["write_imagei"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
}
foreach name = ["write_imageui"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
}
}
foreach imgTy = [Image2dArray] in {
foreach name = ["write_imagef"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
}
foreach name = ["write_imagei"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
}
foreach name = ["write_imageui"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
}
}
foreach imgTy = [Image2dArrayDepth] in {
foreach name = ["write_imagef"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, Float]>;
}
}
let Extension = FuncExtKhrMipmapAndWrite3d in {
foreach imgTy = [Image3d] in {
foreach name = ["write_imagef"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
}
foreach name = ["write_imagei"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
}
foreach name = ["write_imageui"] in {
def : Builtin<name, [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
}
}
}
}
// Added to section 6.13.14.5
foreach aQual = ["RO", "WO", "RW"] in {
foreach name = ["get_image_num_mip_levels"] in {
foreach imgTy = [Image1d, Image2d, Image3d, Image1dArray, Image2dArray, Image2dDepth, Image2dArrayDepth] in {
def : Builtin<name, [Int, ImageType<imgTy, aQual>]>;
}
}
}
}

0 comments on commit 4a188fd

Please sign in to comment.