Skip to content

Commit 909509e

Browse files
Add support for Samplers on DX12.
1 parent 59dede8 commit 909509e

16 files changed

Lines changed: 557 additions & 103 deletions

include/API/Device.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "API/Capabilities.h"
2121
#include "API/CommandBuffer.h"
2222
#include "API/RenderPass.h"
23+
#include "API/Sampler.h"
2324
#include "API/ShaderBindingTable.h"
2425
#include "API/Texture.h"
2526

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

350+
virtual llvm::Expected<std::unique_ptr<Sampler>>
351+
createSampler(std::string Name, const SamplerCreateDesc &Desc) = 0;
352+
349353
virtual llvm::Expected<std::unique_ptr<MemoryHeap>>
350354
createMemoryHeap(std::string Name, size_t SizeInBytes) = 0;
351355

include/API/Sampler.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//===- Sampler.h - Offload API Texture ------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
//
10+
//===----------------------------------------------------------------------===//
11+
12+
#ifndef OFFLOADTEST_API_SAMPLER_H
13+
#define OFFLOADTEST_API_SAMPLER_H
14+
15+
#include "API/API.h"
16+
#include "API/Resources.h"
17+
18+
namespace offloadtest {
19+
20+
enum class FilterMode { Nearest, Linear };
21+
22+
enum class AddressMode { Clamp, Repeat, Mirror, Border, MirrorOnce };
23+
24+
enum class CompareFunction {
25+
Never,
26+
Less,
27+
Equal,
28+
LessEqual,
29+
Greater,
30+
NotEqual,
31+
GreaterEqual,
32+
Always
33+
};
34+
35+
enum class SamplerKind { Sampler, SamplerComparison };
36+
37+
struct SamplerCreateDesc {
38+
FilterMode MinFilter = FilterMode::Linear;
39+
FilterMode MagFilter = FilterMode::Linear;
40+
AddressMode Address = AddressMode::Clamp;
41+
float MinLOD = 0.0f;
42+
float MaxLOD = std::numeric_limits<float>::max();
43+
float MipLODBias = 0.0f;
44+
CompareFunction ComparisonOp = CompareFunction::Never;
45+
SamplerKind Kind = SamplerKind::Sampler;
46+
};
47+
48+
class Sampler {
49+
GPUAPI API;
50+
51+
public:
52+
virtual ~Sampler();
53+
Sampler(const Sampler &) = delete;
54+
// Sampler(Sampler &&) = delete;
55+
Sampler &operator=(const Sampler &) = delete;
56+
// Sampler &operator=(Sampler &&) = delete;
57+
58+
GPUAPI getAPI() const { return API; }
59+
virtual const SamplerCreateDesc &getDesc() const = 0;
60+
61+
protected:
62+
explicit Sampler(GPUAPI API) : API(API) {}
63+
};
64+
65+
} // namespace offloadtest
66+
67+
#endif // OFFLOADTEST_API_SAMPLER_H

include/API/Texture.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,6 @@ inline llvm::Error validateTextureCreateDesc(const TextureCreateDesc &Desc) {
105105
std::errc::not_supported,
106106
"DepthStencil combined with Storage is not yet supported.");
107107

108-
// Depth formats require DepthStencil usage; non-depth formats forbid it.
109-
if (IsDepth && !IsDS)
110-
return llvm::createStringError(
111-
std::errc::invalid_argument,
112-
"Depth format '%s' requires DepthStencil usage.",
113-
getFormatName(Desc.Fmt).data());
114108
if (!IsDepth && IsDS)
115109
return llvm::createStringError(
116110
std::errc::invalid_argument,

include/Support/Pipeline.h

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "API/AccelerationStructure.h"
1717
#include "API/Enums.h"
1818
#include "API/Resources.h"
19+
#include "API/Sampler.h"
1920
#include "llvm/ADT/SmallVector.h"
2021
#include "llvm/ADT/StringRef.h"
2122
#include "llvm/Support/Error.h"
@@ -140,24 +141,7 @@ static inline DescriptorKind getDescriptorKind(ResourceKind RK) {
140141
llvm_unreachable("All cases handled");
141142
}
142143

143-
enum class FilterMode { Nearest, Linear };
144-
145-
enum class AddressMode { Clamp, Repeat, Mirror, Border, MirrorOnce };
146-
147-
enum class CompareFunction {
148-
Never,
149-
Less,
150-
Equal,
151-
LessEqual,
152-
Greater,
153-
NotEqual,
154-
GreaterEqual,
155-
Always
156-
};
157-
158-
enum class SamplerKind { Sampler, SamplerComparison };
159-
160-
struct Sampler {
144+
struct YAMLSampler {
161145
std::string Name;
162146
FilterMode MinFilter = FilterMode::Linear;
163147
FilterMode MagFilter = FilterMode::Linear;
@@ -270,7 +254,7 @@ struct Resource {
270254
DirectXBinding DXBinding;
271255
std::optional<VulkanBinding> VKBinding;
272256
CPUBuffer *BufferPtr = nullptr;
273-
Sampler *SamplerPtr = nullptr;
257+
YAMLSampler *SamplerPtr = nullptr;
274258
bool HasCounter = false;
275259
std::optional<uint32_t> TilesMapped;
276260
bool IsReserved = false;
@@ -630,7 +614,7 @@ struct Pipeline {
630614
IOBindings Bindings;
631615
llvm::SmallVector<PushConstantBlock> PushConstants;
632616
llvm::SmallVector<CPUBuffer> Buffers;
633-
llvm::SmallVector<Sampler> Samplers;
617+
llvm::SmallVector<YAMLSampler> Samplers;
634618
llvm::SmallVector<Result> Results;
635619
llvm::SmallVector<DescriptorSet> Sets;
636620
DispatchParametersSet DispatchParameters;
@@ -671,7 +655,7 @@ struct Pipeline {
671655
return nullptr;
672656
}
673657

674-
Sampler *getSampler(llvm::StringRef Name) {
658+
YAMLSampler *getSampler(llvm::StringRef Name) {
675659
for (auto &S : Samplers)
676660
if (Name == S.Name)
677661
return &S;
@@ -712,7 +696,7 @@ struct Pipeline {
712696
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::DescriptorSet)
713697
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::Resource)
714698
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::CPUBuffer)
715-
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::Sampler)
699+
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::YAMLSampler)
716700
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::Shader)
717701
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::dx::RootParameter)
718702
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::Result)
@@ -744,8 +728,8 @@ template <> struct MappingTraits<offloadtest::CPUBuffer> {
744728
static void mapping(IO &I, offloadtest::CPUBuffer &R);
745729
};
746730

747-
template <> struct MappingTraits<offloadtest::Sampler> {
748-
static void mapping(IO &I, offloadtest::Sampler &S);
731+
template <> struct MappingTraits<offloadtest::YAMLSampler> {
732+
static void mapping(IO &I, offloadtest::YAMLSampler &S);
749733
};
750734

751735
template <> struct MappingTraits<offloadtest::Result> {

0 commit comments

Comments
 (0)