Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion include/API/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ struct TraditionalRasterPipelineCreateDesc {
std::optional<ShaderContainer> DS;
std::optional<ShaderContainer> GS;
ShaderContainer PS;
// View-instancing fan-out (1 == no view instancing). When > 1, backends
// that implement view instancing should route view N to render-target
// array slice N.
uint32_t ViewInstanceCount = 1;

void setShader(Stages Stage, ShaderContainer &&SC) {
switch (Stage) {
Expand Down Expand Up @@ -253,7 +257,8 @@ createRenderTargetFromCPUBuffer(Device &Dev, const CPUBuffer &Buf);

// Creates a depth/stencil texture matching the dimensions of a render target.
llvm::Expected<std::unique_ptr<Texture>>
createDefaultDepthStencilTarget(Device &Dev, uint32_t Width, uint32_t Height);
createDefaultDepthStencilTarget(Device &Dev, uint32_t Width, uint32_t Height,
uint32_t ArraySize = 1);

llvm::Expected<std::unique_ptr<offloadtest::Buffer>>
createBufferWithData(Device &Dev, std::string Name,
Expand Down
1 change: 1 addition & 0 deletions include/API/Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum class ResourceKind {
StructuredBuffer,
ByteAddressBuffer,
Texture2D,
Texture2DArray,
RWBuffer,
RWStructuredBuffer,
RWByteAddressBuffer,
Expand Down
18 changes: 14 additions & 4 deletions include/API/FormatConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "llvm/Support/Error.h"

#include <algorithm>

namespace offloadtest {

// Bridge for code that still describes textures as DataFormat + Channels (e.g.
Expand Down Expand Up @@ -139,20 +141,28 @@ validateTextureDescMatchesCPUBuffer(const TextureCreateDesc &Desc,
"TextureCreateDesc mip levels %u does not match CPUBuffer mip "
"levels %d.",
Desc.MipLevels, Buf.OutputProps.MipLevels);
if (Desc.ArraySize !=
static_cast<uint32_t>(std::max(1, Buf.OutputProps.ArraySize)))
return llvm::createStringError(
std::errc::invalid_argument,
"TextureCreateDesc array size %u does not match CPUBuffer array "
"size %d.",
Desc.ArraySize, Buf.OutputProps.ArraySize);
const uint32_t TexelSize = getFormatSizeInBytes(Desc.Fmt);
if (Buf.Stride > 0 && static_cast<uint32_t>(Buf.Stride) != TexelSize)
return llvm::createStringError(
std::errc::invalid_argument,
"CPUBuffer stride %d does not match texture format element size %u.",
Buf.Stride, TexelSize);
const uint64_t ExpectedSize =
static_cast<uint64_t>(Desc.Width) * Desc.Height * TexelSize;
const uint64_t ExpectedSize = static_cast<uint64_t>(Desc.Width) *
Desc.Height * Desc.ArraySize * TexelSize;
if (static_cast<uint64_t>(Buf.size()) != ExpectedSize)
return llvm::createStringError(
std::errc::invalid_argument,
"CPUBuffer size %u does not match expected size %llu "
"(width %u * height %u * element size %u).",
Buf.size(), ExpectedSize, Desc.Width, Desc.Height, TexelSize);
"(width %u * height %u * array size %u * element size %u).",
Buf.size(), ExpectedSize, Desc.Width, Desc.Height, Desc.ArraySize,
TexelSize);
return llvm::Error::success();
}

Expand Down
4 changes: 4 additions & 0 deletions include/API/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ struct TextureCreateDesc {
uint32_t Width;
uint32_t Height;
uint32_t MipLevels;
// Texture array slice count (1 == plain Texture2D). Render targets used
// with view instancing require this to match the pipeline's
// ViewInstanceCount.
uint32_t ArraySize = 1;
// Clear value for render target or depth/stencil textures.
// How and when this is applied depends on the backend:
// - DX uses it as an optimized clear hint at resource creation time
Expand Down
13 changes: 13 additions & 0 deletions include/Support/Pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static inline DescriptorKind getDescriptorKind(ResourceKind RK) {
case ResourceKind::StructuredBuffer:
case ResourceKind::ByteAddressBuffer:
case ResourceKind::Texture2D:
case ResourceKind::Texture2DArray:
case ResourceKind::AccelerationStructure:
return DescriptorKind::SRV;

Expand Down Expand Up @@ -145,6 +146,7 @@ struct OutputProperties {
int Width;
int Depth;
int MipLevels = 1;
int ArraySize = 1;
};

static inline uint32_t getFormatSize(DataFormat Format) {
Expand Down Expand Up @@ -246,6 +248,7 @@ struct Resource {
case ResourceKind::Buffer:
case ResourceKind::RWBuffer:
case ResourceKind::Texture2D:
case ResourceKind::Texture2DArray:
case ResourceKind::RWTexture2D:
case ResourceKind::Sampler:
case ResourceKind::SampledTexture2D:
Expand Down Expand Up @@ -273,6 +276,7 @@ struct Resource {
case ResourceKind::RWByteAddressBuffer:
case ResourceKind::ConstantBuffer:
case ResourceKind::Texture2D:
case ResourceKind::Texture2DArray:
case ResourceKind::RWTexture2D:
case ResourceKind::SampledTexture2D:
case ResourceKind::AccelerationStructure:
Expand All @@ -294,6 +298,7 @@ struct Resource {
case ResourceKind::AccelerationStructure:
return false;
case ResourceKind::Texture2D:
case ResourceKind::Texture2DArray:
case ResourceKind::RWTexture2D:
case ResourceKind::SampledTexture2D:
return true;
Expand Down Expand Up @@ -356,6 +361,7 @@ struct Resource {
case ResourceKind::StructuredBuffer:
case ResourceKind::ByteAddressBuffer:
case ResourceKind::Texture2D:
case ResourceKind::Texture2DArray:
case ResourceKind::ConstantBuffer:
case ResourceKind::Sampler:
case ResourceKind::SampledTexture2D:
Expand Down Expand Up @@ -541,6 +547,12 @@ struct Pipeline {
DispatchParametersSet DispatchParameters;
AccelerationStructureDescs AccelStructs;

// Number of view instances to render in a single draw (D3D12 view
// instancing). Default 1 = no view instancing. When > 1 the render target
// must be a Texture2DArray whose ArraySize is at least this value, and the
// backend routes view N to array slice N of the render/depth target.
uint32_t ViewInstanceCount = 1;

uint32_t getVertexCount() const {
if (DispatchParameters.VertexCount)
return *DispatchParameters.VertexCount;
Expand Down Expand Up @@ -829,6 +841,7 @@ template <> struct ScalarEnumerationTraits<offloadtest::ResourceKind> {
ENUM_CASE(StructuredBuffer);
ENUM_CASE(ByteAddressBuffer);
ENUM_CASE(Texture2D);
ENUM_CASE(Texture2DArray);
ENUM_CASE(RWBuffer);
ENUM_CASE(RWStructuredBuffer);
ENUM_CASE(RWByteAddressBuffer);
Expand Down
Loading
Loading