Graphics Reference
In-Depth Information
UnorderedAccessViewDescription uavDesc = new
UnorderedAccessViewDescription
{
Dimension = UnorderedAccessViewDimension.Buffer,
Buffer = new UnorderedAccessViewDescription
.BufferResource { FirstElement = 0 }
};
// If a raw buffer
if ((buffer.Description.OptionFlags &
ResourceOptionFlags.BufferAllowRawViews) ==
ResourceOptionFlags.BufferAllowRawViews)
{
// A raw buffer requires R32_Typeless
uavDesc.Format = Format.R32_Typeless;
uavDesc.Buffer.Flags =
UnorderedAccessViewBufferFlags.Raw;
uavDesc.Buffer.ElementCount =
buffer.Description.SizeInBytes / 4;
}
// else if a structured buffer
else if ((buffer.Description.OptionFlags &
ResourceOptionFlags.BufferStructured) ==
ResourceOptionFlags.BufferStructured)
{
uavDesc.Format = Format.Unknown;
uavDesc.Buffer.ElementCount =
buffer.Description.SizeInBytes /
buffer.Description.StructureByteStride;
} else {
throw new ArgumentException("Buffer must be raw or
structured", "buffer");
}
// Create the UAV for this buffer
return new UnorderedAccessView(device, buffer,
uavDesc);
}
5.
With the output resources in place, we can continue to load the image, and run with
the previous HistogramCS shader code.
// Firstly clear the target UAV otherwise the value will
// accumulate between calls.
context.ClearUnorderedAccessView(histogramUAV, Int4.Zero);
// Load the image to process (this could be any compatible
// SRV).
 
Search WWH ::




Custom Search