Home | History | Annotate | Download | only in shaders
      1 Buffer<float4>    Buffer4F  : register(t0);
      2 Buffer<int4>      Buffer4I  : register(t0);
      3 Buffer<uint4>     Buffer4UI : register(t0);
      4 
      5 struct VS_OUTPUT
      6 {
      7     float4 position : SV_Position;
      8     uint index      : TEXCOORD0;
      9     uint slice      : LAYER;
     10 };
     11 
     12 struct GS_OUTPUT
     13 {
     14     float4 position : SV_Position;
     15     uint index      : TEXCOORD0;
     16     uint slice      : SV_RenderTargetArrayIndex;
     17 };
     18 
     19 cbuffer BufferCopyParams : register(b0)
     20 {
     21     uint FirstPixelOffset;
     22     uint PixelsPerRow;
     23     uint RowStride;
     24     uint RowsPerSlice;
     25     float2 PositionOffset;
     26     float2 PositionScale;
     27     int2 TexLocationOffset;
     28     int2 TexLocationScale;
     29 }
     30 
     31 void ComputePositionAndIndex(uint vertexID, out VS_OUTPUT outVertex)
     32 {
     33     uint PixelsPerSlice = PixelsPerRow * RowsPerSlice;
     34     uint SliceStride    = RowStride * RowsPerSlice;
     35 
     36     uint slice          = vertexID / PixelsPerSlice;
     37     uint sliceOffset    = slice * PixelsPerSlice;
     38     uint row            = (vertexID - sliceOffset) / PixelsPerRow;
     39     uint col            = vertexID - sliceOffset - (row * PixelsPerRow);
     40 
     41     float2 coords       = float2(float(col), float(row));
     42 
     43     outVertex.position  = float4(PositionOffset + PositionScale * coords, 0.0f, 1.0f);
     44     outVertex.index     = FirstPixelOffset + slice * SliceStride + row * RowStride + col;
     45     outVertex.slice     = slice;
     46 }
     47 
     48 void VS_BufferToTexture(in uint vertexID : SV_VertexID, out VS_OUTPUT outVertex)
     49 {
     50     ComputePositionAndIndex(vertexID, outVertex);
     51 }
     52 
     53 [maxvertexcount(1)]
     54 void GS_BufferToTexture(point VS_OUTPUT inVertex[1], inout PointStream<GS_OUTPUT> outStream)
     55 {
     56     GS_OUTPUT outVertex;
     57     outVertex.position  = inVertex[0].position;
     58     outVertex.index     = inVertex[0].index;
     59     outVertex.slice     = inVertex[0].slice;
     60     outStream.Append(outVertex);
     61 }
     62 
     63 float4 PS_BufferToTexture_4F(in float4 inPosition : SV_Position, in uint inIndex : TEXCOORD0) : SV_Target
     64 {
     65     return Buffer4F.Load(inIndex);
     66 }
     67 
     68 int4 PS_BufferToTexture_4I(in float4 inPosition : SV_Position, in uint inIndex : TEXCOORD0) : SV_Target
     69 {
     70     return Buffer4I.Load(inIndex);
     71 }
     72 
     73 uint4 PS_BufferToTexture_4UI(in float4 inPosition : SV_Position, in uint inIndex : TEXCOORD0) : SV_Target
     74 {
     75     return Buffer4UI.Load(inIndex);
     76 }
     77