Skip to content
Draft
13 changes: 13 additions & 0 deletions include/API/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "API/Capabilities.h"
#include "API/CommandBuffer.h"
#include "API/RenderPass.h"
#include "API/Sampler.h"
#include "API/ShaderBindingTable.h"
#include "API/Texture.h"

Expand Down Expand Up @@ -346,6 +347,9 @@ class Device {
virtual llvm::Expected<std::unique_ptr<Texture>>
createTexture(std::string Name, const TextureCreateDesc &Desc) = 0;

virtual llvm::Expected<std::unique_ptr<Sampler>>
createSampler(std::string Name, const SamplerCreateDesc &Desc) = 0;

virtual llvm::Expected<std::unique_ptr<MemoryHeap>>
createMemoryHeap(std::string Name, size_t SizeInBytes) = 0;

Expand All @@ -354,6 +358,12 @@ class Device {
virtual uint32_t
getTextureUploadRowStrideInBytes(const TextureCreateDesc &Desc) const = 0;

// The layout an upload buffer must have to feed createTextureWithData /
// copyBufferToTexture for the given texture description. Encodes per-mip
// offsets, row pitch, and total size in the backend's required alignment.
virtual TextureUploadLayout
getTextureUploadLayout(const TextureCreateDesc &Desc) const = 0;

virtual llvm::Expected<std::unique_ptr<RenderPass>>
createRenderPass(const RenderPassDesc &Desc) = 0;

Expand Down Expand Up @@ -421,6 +431,9 @@ createBufferWithData(Device &Dev, std::string Name,
size_t SizeInBytes, ComputeEncoder *Encoder,
std::unique_ptr<offloadtest::Buffer> *OutUploadBuffer);

// Create a texture and upload `Data` (tightly-packed across mip levels) into
// it via a staging buffer recorded on `Encoder`. The staging buffer is handed
// back through `OutUploadBuffer` and must outlive command-buffer submission.
llvm::Expected<std::unique_ptr<offloadtest::Texture>>
createTextureWithData(Device &Dev, std::string Name,
const TextureCreateDesc &Desc, const void *Data,
Expand Down
67 changes: 67 additions & 0 deletions include/API/Sampler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//===- Sampler.h - Offload API Texture ------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
//
//===----------------------------------------------------------------------===//

#ifndef OFFLOADTEST_API_SAMPLER_H
#define OFFLOADTEST_API_SAMPLER_H

#include "API/API.h"
#include "API/Resources.h"

namespace offloadtest {

enum class FilterMode { Nearest, Linear };

enum class AddressMode { Clamp, Repeat, Mirror, Border, MirrorOnce };

enum class CompareFunction {
Never,
Less,
Equal,
LessEqual,
Greater,
NotEqual,
GreaterEqual,
Always
};

enum class SamplerKind { Sampler, SamplerComparison };

struct SamplerCreateDesc {
FilterMode MinFilter = FilterMode::Linear;
FilterMode MagFilter = FilterMode::Linear;
AddressMode Address = AddressMode::Clamp;
float MinLOD = 0.0f;
float MaxLOD = std::numeric_limits<float>::max();
float MipLODBias = 0.0f;
CompareFunction ComparisonOp = CompareFunction::Never;
SamplerKind Kind = SamplerKind::Sampler;
};

class Sampler {
GPUAPI API;

public:
virtual ~Sampler();
Sampler(const Sampler &) = delete;
// Sampler(Sampler &&) = delete;
Sampler &operator=(const Sampler &) = delete;
// Sampler &operator=(Sampler &&) = delete;

GPUAPI getAPI() const { return API; }
virtual const SamplerCreateDesc &getDesc() const = 0;

protected:
explicit Sampler(GPUAPI API) : API(API) {}
};

} // namespace offloadtest

#endif // OFFLOADTEST_API_SAMPLER_H
25 changes: 19 additions & 6 deletions include/API/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "API/Resources.h"

#include "llvm/ADT/BitmaskEnum.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Error.h"
Expand Down Expand Up @@ -105,12 +106,6 @@ inline llvm::Error validateTextureCreateDesc(const TextureCreateDesc &Desc) {
std::errc::not_supported,
"DepthStencil combined with Storage is not yet supported.");

// Depth formats require DepthStencil usage; non-depth formats forbid it.
if (IsDepth && !IsDS)
return llvm::createStringError(
std::errc::invalid_argument,
"Depth format '%s' requires DepthStencil usage.",
getFormatName(Desc.Fmt).data());
if (!IsDepth && IsDS)
return llvm::createStringError(
std::errc::invalid_argument,
Expand Down Expand Up @@ -154,6 +149,24 @@ struct TileShape {
uint32_t Depth = 1;
};

struct SubresourceFootprint {
uint64_t Offset = 0; // Byte offset of this subresource in the buffer.
uint32_t RowPitchInBytes = 0; // Destination row stride (may include padding).
uint32_t RowSizeInBytes = 0; // Tightly-packed bytes per row to copy.
uint32_t NumRows = 0; // Number of rows in this subresource.
};

struct TextureUploadLayout {
llvm::SmallVector<SubresourceFootprint> Subresources; // One entry per mip.
uint64_t TotalSizeInBytes = 0;
};

// Compute a tightly-packed upload layout (no row or subresource padding) for
// the given texture description. Suitable for backends whose buffer-to-texture
// copy consumes a tightly-packed staging buffer (e.g. Vulkan, Metal).
TextureUploadLayout
computeTightTextureUploadLayout(const TextureCreateDesc &Desc);

class Texture {
GPUAPI API;

Expand Down
32 changes: 8 additions & 24 deletions include/Support/Pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "API/AccelerationStructure.h"
#include "API/Enums.h"
#include "API/Resources.h"
#include "API/Sampler.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
Expand Down Expand Up @@ -140,24 +141,7 @@ static inline DescriptorKind getDescriptorKind(ResourceKind RK) {
llvm_unreachable("All cases handled");
}

enum class FilterMode { Nearest, Linear };

enum class AddressMode { Clamp, Repeat, Mirror, Border, MirrorOnce };

enum class CompareFunction {
Never,
Less,
Equal,
LessEqual,
Greater,
NotEqual,
GreaterEqual,
Always
};

enum class SamplerKind { Sampler, SamplerComparison };

struct Sampler {
struct YAMLSampler {
std::string Name;
FilterMode MinFilter = FilterMode::Linear;
FilterMode MagFilter = FilterMode::Linear;
Expand Down Expand Up @@ -270,7 +254,7 @@ struct Resource {
DirectXBinding DXBinding;
std::optional<VulkanBinding> VKBinding;
CPUBuffer *BufferPtr = nullptr;
Sampler *SamplerPtr = nullptr;
YAMLSampler *SamplerPtr = nullptr;
bool HasCounter = false;
std::optional<uint32_t> TilesMapped;
bool IsReserved = false;
Expand Down Expand Up @@ -630,7 +614,7 @@ struct Pipeline {
IOBindings Bindings;
llvm::SmallVector<PushConstantBlock> PushConstants;
llvm::SmallVector<CPUBuffer> Buffers;
llvm::SmallVector<Sampler> Samplers;
llvm::SmallVector<YAMLSampler> Samplers;
llvm::SmallVector<Result> Results;
llvm::SmallVector<DescriptorSet> Sets;
DispatchParametersSet DispatchParameters;
Expand Down Expand Up @@ -671,7 +655,7 @@ struct Pipeline {
return nullptr;
}

Sampler *getSampler(llvm::StringRef Name) {
YAMLSampler *getSampler(llvm::StringRef Name) {
for (auto &S : Samplers)
if (Name == S.Name)
return &S;
Expand Down Expand Up @@ -712,7 +696,7 @@ struct Pipeline {
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::DescriptorSet)
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::Resource)
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::CPUBuffer)
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::Sampler)
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::YAMLSampler)
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::Shader)
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::dx::RootParameter)
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::Result)
Expand Down Expand Up @@ -744,8 +728,8 @@ template <> struct MappingTraits<offloadtest::CPUBuffer> {
static void mapping(IO &I, offloadtest::CPUBuffer &R);
};

template <> struct MappingTraits<offloadtest::Sampler> {
static void mapping(IO &I, offloadtest::Sampler &S);
template <> struct MappingTraits<offloadtest::YAMLSampler> {
static void mapping(IO &I, offloadtest::YAMLSampler &S);
};

template <> struct MappingTraits<offloadtest::Result> {
Expand Down
Loading
Loading