Export (0) Print
Expand All

RWTexture2D

A read/write resource.

MethodDescription
GetDimensions Gets the resource dimensions.
Load Reads texture data.
Operator[] Gets a resource variable.

 

You can prefix RWTexture2D objects with the storage class globallycoherent. This storage class causes memory barriers and syncs to flush data across the entire GPU such that other groups can see writes. Without this specifier, a memory barrier or sync will flush only an unordered access view (UAV) within the current group.

A RWTexture2D object requires an element type in a declaration statement for the object. For example, the following declaration is not correct:



// The following declaration is incorrectly coded.
RWTexture2D myTexture;


The following declaration is correct:



// The following declaration is correctly coded.
RWTexture2D<float> tex;


Because a RWTexture2D object is a UAV-type object, its properties differ from a shader resource view (SRV)-type object, such as a Texture2D object. For example, you can read from and write to a RWTexture2D object, but you can only read from a Texture2D object.

A RWTexture2D object cannot use methods from a Texture2D object, such as Sample. However, because you can create multiple view types to the same resource, you can declare multiple texture types as a single texture in multiple shaders. For example, the following code snippets show how you can declare and use a RWTexture2D object as tex in a compute shader and then declare and use a Texture2D object as tex in a pixel shader.

Note  The runtime enforces certain usage patterns when you create multiple view types to the same resource. For example, the runtime does not allow you to have both a UAV mapping for a resource and SRV mapping for the same resource active at the same time.

The following code is for the compute shader:


RWTexture2D<float> tex;
[numthreads(groupDim_x, groupDim_y, 1)]
void main(
    uint3 groupId : SV_GroupID,
    uint3 groupThreadId : SV_GroupThreadID,
    uint3 dispatchThreadId : SV_DispatchThreadID,
    uint groupIndex : SV_GroupIndex)
{
    tex [dispatchThreadId.xy] = <something>;
}


The following code is for the pixel shader:


struct PixelShaderInput
{
    float4 pos : SV_POSITION;
    float2 tex : TEXTURE;
};

Texture2D<float> tex;
float4 main(PixelShaderInput input) : SV_TARGET
{
    return tex.Sample(TextureSampler, input.tex);
}


Minimum Shader Model

This object is supported in the following shader models.

Shader ModelSupported
Shader Model 5 and higher shader modelsyes

 

This object is supported for the following types of shaders:

VertexHullDomainGeometryPixelCompute
xx

 

 

 

Community Additions

ADD
Show:
© 2014 Microsoft