PTX ISA v9.4

5.3. Texture Sampler and Surface Types

PTX includes built-in opaque types for defining texture, sampler, and surface descriptor variables. These types have named fields similar to structures, but all information about layout, field ordering, base address, and overall size is hidden to a PTX program, hence the term opaque. The use of these opaque types is limited to:

  • Variable definition within global (module) scope and in kernel entry parameter lists.
  • Static initialization of module-scope variables using comma-delimited static assignment expressions for the named members of the type.
  • Referencing textures, samplers, or surfaces via texture and surface load/store instructions (tex, suld, sust, sured).
  • Retrieving the value of a named member via query instructions (txq, suq).
  • Creating pointers to opaque variables using mov, e.g., mov.u64 reg, opaque_var;. The resulting pointer may be stored to and loaded from memory, passed as a parameter to functions, and de-referenced by texture and surface load, store, and query instructions, but the pointer cannot otherwise be treated as an address, i.e., accessing the pointer with ld and st instructions, or performing pointer arithmetic will result in undefined results.
  • Opaque variables may not appear in initializers, e.g., to initialize a pointer to an opaque variable.

Note: Indirect access to textures and surfaces using pointers to opaque variables is supported beginning with PTX ISA version 3.1 and requires target sm_20 or later.

>

Indirect access to textures is supported only in unified texture mode (see below).

The three built-in types are .texref, .samplerref, and .surfref. For working with textures and samplers, PTX has two modes of operation. In the unified mode, texture and sampler information is accessed through a single .texref handle. In the independent mode, texture and sampler information each have their own handle, allowing them to be defined separately and combined at the site of usage in the program. In independent mode, the fields of the .texref type that describe sampler properties are ignored, since these properties are defined by .samplerref variables.

Table 10 and Table 11 list the named members of each type for unified and independent texture modes. These members and their values have precise mappings to methods and values defined in the texture HW class as well as exposed values via the API.

Table 10 Opaque Type Fields in Unified Texture Mode

Member .texref values .surfref values
width in elements in elements
height in elements in elements
depth in elements in elements
channel_data_type enum type corresponding to source language API enum type corresponding to source language API
channel_order enum type corresponding to source language API enum type corresponding to source language API
normalized_coords 0, 1 N/A
filter_mode nearest, linear N/A
addr_mode_0, addr_mode_1, addr_mode_2 wrap, mirror, clamp_ogl, clamp_to_edge, clamp_to_border N/A
array_size as number of textures in a texture array as number of surfaces in a surface array
num_mipmap_levels as number of levels in a mipmapped texture N/A
num_samples as number of samples in a multi-sample texture N/A
memory_layout N/A 1 for linear memory layout; 0 otherwise

5.3.1. Texture and Surface Properties

Fields width, height, and depth specify the size of the texture or surface in number of elements in each dimension.

The channel_data_type and channel_order fields specify these properties of the texture or surface using enumeration types corresponding to the source language API. For example, see Channel Data Type and Channel Order Fields for the OpenCL enumeration types currently supported in PTX.

5.3.2. Sampler Properties

The normalized_coords field indicates whether the texture or surface uses normalized coordinates in the range [0.0, 1.0) instead of unnormalized coordinates in the range [0, N). If no value is specified, the default is set by the runtime system based on the source language.

The filter_mode field specifies how the values returned by texture reads are computed based on the input texture coordinates.

The addr_mode_{0,1,2} fields define the addressing mode in each dimension, which determine how out-of-range coordinates are handled.

See the CUDA C++ Programming Guide for more details of these properties.

Table 11 Opaque Type Fields in Independent Texture Mode

Member .samplerref values .texref values .surfref values
width N/A in elements in elements
height N/A in elements in elements
depth N/A in elements in elements
channel_data_type N/A enum type corresponding to source language API enum type corresponding to source language API
channel_order N/A enum type corresponding to source language API enum type corresponding to source language API
normalized_coords N/A 0, 1 N/A
force_unnormalized_coords 0, 1 N/A N/A
filter_mode nearest, linear ignored N/A
addr_mode_0, addr_mode_1, addr_mode_2 wrap, mirror, clamp_ogl, clamp_to_edge, clamp_to_border N/A N/A
array_size N/A as number of textures in a texture array as number of surfaces in a surface array
num_mipmap_levels N/A as number of levels in a mipmapped texture N/A
num_samples N/A as number of samples in a multi-sample texture N/A
memory_layout N/A N/A 1 for linear memory layout; 0 otherwise

In independent texture mode, the sampler properties are carried in an independent .samplerref variable, and these fields are disabled in the .texref variables. One additional sampler property, force_unnormalized_coords, is available in independent texture mode.

The force_unnormalized_coords field is a property of .samplerref variables that allows the sampler to override the texture header normalized_coords property. This field is defined only in independent texture mode. When True, the texture header setting is overridden and unnormalized coordinates are used; when False, the texture header setting is used.

The force_unnormalized_coords property is used in compiling OpenCL; in OpenCL, the property of normalized coordinates is carried in sampler headers. To compile OpenCL to PTX, texture headers are always initialized with normalized_coords set to True, and the OpenCL sampler-based normalized_coords flag maps (negated) to the PTX-level force_unnormalized_coords flag.

Variables using these types may be declared at module scope or within kernel entry parameter lists. At module scope, these variables must be in the .global state space. As kernel parameters, these variables are declared in the .param state space.

Example

ptx
.global .texref     my_texture_name;
.global .samplerref my_sampler_name;
.global .surfref    my_surface_name;

When declared at module scope, the types may be initialized using a list of static expressions assigning values to the named members.

Example

ptx
.global .texref tex1;
.global .samplerref tsamp1 = { addr_mode_0 = clamp_to_border,
                               filter_mode = nearest
                             };

5.3.3. Channel Data Type and Channel Order Fields

The channel_data_type and channel_order fields have enumeration types corresponding to the source language API. Currently, OpenCL is the only source language that defines these fields. Table 13 and Table 12 show the enumeration values defined in OpenCL version 1.0 for channel data type and channel order.

Table 12 OpenCL 1.0 Channel Data Type Definition

Name Value
CL_SNORM_INT8 0x10D0
CL_SNORM_INT16 0x10D1
CL_UNORM_INT8 0x10D2
CL_UNORM_INT16 0x10D3
CL_UNORM_SHORT_565 0x10D4
CL_UNORM_SHORT_555 0x10D5
CL_UNORM_INT_101010 0x10D6
CL_SIGNED_INT8 0x10D7
CL_SIGNED_INT16 0x10D8
CL_SIGNED_INT32 0x10D9
CL_UNSIGNED_INT8 0x10DA
CL_UNSIGNED_INT16 0x10DB
CL_UNSIGNED_INT32 0x10DC
CL_HALF_FLOAT 0x10DD
CL_FLOAT 0x10DE

Table 13 OpenCL 1.0 Channel Order Definition

Name Value
CL_R 0x10B0
CL_A 0x10B1
CL_RG 0x10B2
CL_RA 0x10B3
CL_RGB 0x10B4
CL_RGBA 0x10B5
CL_BGRA 0x10B6
CL_ARGB 0x10B7
CL_INTENSITY 0x10B8
CL_LUMINANCE 0x10B9
esc
Type to search across all documentation