Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ This framework provides a YAML representation for describing GPU pipelines and b
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
DispatchParameters:
DispatchGroupCount: [2, 1, 1] # Define how many groups to dispatch, if omitted one group is launched.
Buffers:
- Name: Constants
Format: Int32
Expand Down
27 changes: 22 additions & 5 deletions include/Support/Pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,6 @@ struct IOBindings {
Stride += VA.size();
return Stride;
}

uint32_t getVertexCount() const {
return VertexBufferPtr->size() / getVertexStride();
}
};

// Describes a contiguous group of bytes in a push constant block.
Expand Down Expand Up @@ -400,10 +396,14 @@ struct Shader {
std::string Entry;
std::unique_ptr<llvm::MemoryBuffer> Shader;
std::unique_ptr<llvm::MemoryBuffer> Reflection;
int DispatchSize[3];
llvm::SmallVector<SpecializationConstant> SpecializationConstants;
};

struct DispatchParametersSet {
std::array<uint32_t, 3> DispatchGroupCount = {1, 1, 1};
std::optional<uint32_t> VertexCount;
};

struct Pipeline {
ShaderPipelineKind Kind;
llvm::SmallVector<Shader> Shaders;
Expand All @@ -415,6 +415,17 @@ struct Pipeline {
llvm::SmallVector<Sampler> Samplers;
llvm::SmallVector<Result> Results;
llvm::SmallVector<DescriptorSet> Sets;
DispatchParametersSet DispatchParameters;

uint32_t getVertexCount() const {
if (DispatchParameters.VertexCount)
return *DispatchParameters.VertexCount;

assert(Bindings.VertexBufferPtr != nullptr &&
"No VertexCount specified and no Vertex Buffer available to imply "
"VertexCount from.");
return Bindings.VertexBufferPtr->size() / Bindings.getVertexStride();
}

uint32_t getDescriptorCount() const {
uint32_t DescriptorCount = 0;
Expand Down Expand Up @@ -446,6 +457,7 @@ struct Pipeline {
}

llvm::Error validatePipelineKind();
llvm::Error validateDispatchParameters();

bool isCompute() const { return Kind == ShaderPipelineKind::Compute; }
bool isTraditionalRaster() const {
Expand All @@ -465,6 +477,7 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::VertexAttribute)
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::SpecializationConstant)
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::PushConstantBlock)
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::PushConstantValue)
LLVM_YAML_IS_SEQUENCE_VECTOR(offloadtest::DispatchParametersSet)

namespace llvm {
namespace yaml {
Expand Down Expand Up @@ -513,6 +526,10 @@ template <> struct MappingTraits<offloadtest::PushConstantBlock> {
static void mapping(IO &I, offloadtest::PushConstantBlock &B);
};

template <> struct MappingTraits<offloadtest::DispatchParametersSet> {
static void mapping(IO &I, offloadtest::DispatchParametersSet &B);
};

template <> struct MappingTraits<offloadtest::VertexAttribute> {
static void mapping(IO &I, offloadtest::VertexAttribute &A);
};
Expand Down
10 changes: 5 additions & 5 deletions lib/API/DX/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1787,10 +1787,10 @@ class DXDevice : public offloadtest::Device {
if (!EncoderOrErr)
return EncoderOrErr.takeError();
auto &Encoder = *EncoderOrErr.get();
const llvm::ArrayRef<int> DispatchSize =
llvm::ArrayRef<int>(P.Shaders[0].DispatchSize);
if (auto Err = Encoder.dispatch(DispatchSize[0], DispatchSize[1],
DispatchSize[2]))
if (auto Err =
Encoder.dispatch(P.DispatchParameters.DispatchGroupCount[0],
P.DispatchParameters.DispatchGroupCount[1],
P.DispatchParameters.DispatchGroupCount[2]))
return Err;
Encoder.endEncoding();
}
Expand Down Expand Up @@ -2027,7 +2027,7 @@ class DXDevice : public offloadtest::Device {
static_cast<LONG>(VP.Height)};
IS.CB->CmdList->RSSetScissorRects(1, &Scissor);

IS.CB->CmdList->DrawInstanced(P.Bindings.getVertexCount(), 1, 0, 0);
IS.CB->CmdList->DrawInstanced(P.getVertexCount(), 1, 0, 0);

// Transition the render target to copy source and copy to the readback
// buffer.
Expand Down
9 changes: 4 additions & 5 deletions lib/API/MTL/MTLDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,9 @@ class MTLDevice : public offloadtest::Device {
}
Encoder.setThreadGroupSize(TGS[0], TGS[1], TGS[2]);

const llvm::ArrayRef<int> DispatchSize =
llvm::ArrayRef<int>(P.Shaders[0].DispatchSize);
if (auto Err =
Encoder.dispatch(DispatchSize[0], DispatchSize[1], DispatchSize[2]))
if (auto Err = Encoder.dispatch(P.DispatchParameters.DispatchGroupCount[0],
P.DispatchParameters.DispatchGroupCount[1],
P.DispatchParameters.DispatchGroupCount[2]))
return Err;
Encoder.endEncoding();
return llvm::Error::success();
Expand Down Expand Up @@ -718,7 +717,7 @@ class MTLDevice : public offloadtest::Device {
CmdEncoder->setVertexBuffer(llvm::cast<MTLBuffer>(*IS.VB).Buf, 0, 0);

CmdEncoder->drawPrimitives(MTL::PrimitiveTypeTriangle, NS::UInteger(0),
P.Bindings.getVertexCount());
P.getVertexCount());

CmdEncoder->endEncoding();

Expand Down
18 changes: 10 additions & 8 deletions lib/API/VK/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2724,22 +2724,24 @@ class VulkanDevice : public offloadtest::Device {
if (!EncoderOrErr)
return EncoderOrErr.takeError();
auto &Encoder = *EncoderOrErr.get();
const llvm::ArrayRef<int> DispatchSize =
llvm::ArrayRef<int>(P.Shaders[0].DispatchSize);
if (auto Err = Encoder.dispatch(DispatchSize[0], DispatchSize[1],
DispatchSize[2]))
if (auto Err =
Encoder.dispatch(P.DispatchParameters.DispatchGroupCount[0],
P.DispatchParameters.DispatchGroupCount[1],
P.DispatchParameters.DispatchGroupCount[2]))
return Err;
Encoder.endEncoding();
llvm::outs() << "Dispatched compute shader: { " << DispatchSize[0] << ", "
<< DispatchSize[1] << ", " << DispatchSize[2] << " }\n";
llvm::outs() << "Dispatched compute shader: { "
<< P.DispatchParameters.DispatchGroupCount[0] << ", "
<< P.DispatchParameters.DispatchGroupCount[1] << ", "
<< P.DispatchParameters.DispatchGroupCount[2] << " }\n";
} else {
VkDeviceSize Offsets[1]{0};
assert(IS.VB);
VkBuffer VBHandle = llvm::cast<VulkanBuffer>(*IS.VB).Buffer;
vkCmdBindVertexBuffers(IS.CB->CmdBuffer, 0, 1, &VBHandle, Offsets);
// instanceCount must be >=1 to draw; previously was 0 which draws nothing
vkCmdDraw(IS.CB->CmdBuffer, P.Bindings.getVertexCount(), 1, 0, 0);
llvm::outs() << "Drew " << P.Bindings.getVertexCount() << " vertices.\n";
vkCmdDraw(IS.CB->CmdBuffer, P.getVertexCount(), 1, 0, 0);
llvm::outs() << "Drew " << P.getVertexCount() << " vertices.\n";
vkCmdEndRenderPass(IS.CB->CmdBuffer);
copyTextureToReadback(IS.CB->CmdBuffer,
llvm::cast<VulkanTexture>(*IS.RenderTarget),
Expand Down
37 changes: 30 additions & 7 deletions lib/Support/Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ void MappingTraits<offloadtest::Pipeline>::mapping(IO &I,
I.mapOptional("Bindings", P.Bindings);
I.mapOptional("PushConstants", P.PushConstants);

I.mapOptional("DispatchParameters", P.DispatchParameters);
if (auto Err = P.validateDispatchParameters())
I.setError(llvm::toString(std::move(Err)));

if (!I.outputting()) {
for (auto &D : P.Sets) {
for (auto &R : D.Resources) {
Expand Down Expand Up @@ -464,6 +468,12 @@ void MappingTraits<offloadtest::PushConstantValue>::mapping(
}
}

void MappingTraits<offloadtest::DispatchParametersSet>::mapping(
IO &I, offloadtest::DispatchParametersSet &Set) {
I.mapOptional("DispatchGroupCount", Set.DispatchGroupCount);
I.mapOptional("VertexCount", Set.VertexCount);
}

void MappingTraits<offloadtest::OutputProperties>::mapping(
IO &I, offloadtest::OutputProperties &P) {
I.mapRequired("Height", P.Height);
Expand Down Expand Up @@ -516,13 +526,6 @@ void MappingTraits<offloadtest::Shader>::mapping(IO &I,
I.mapRequired("Stage", S.Stage);
I.mapRequired("Entry", S.Entry);
I.mapOptional("SpecializationConstants", S.SpecializationConstants);

if (S.Stage == Stages::Compute) {
// Stage-specific data, not sure if this should be optional
// or moved into the Shaders structure.
MutableArrayRef<int> MutableDispatchSize(S.DispatchSize);
I.mapRequired("DispatchSize", MutableDispatchSize);
}
}

void MappingTraits<offloadtest::Result>::mapping(IO &I,
Expand Down Expand Up @@ -589,3 +592,23 @@ llvm::Error offloadtest::Pipeline::validatePipelineKind() {
return llvm::createStringError(
"The pipeline misses a Compute or Vertex Shader.");
}

llvm::Error offloadtest::Pipeline::validateDispatchParameters() {
switch (Kind) {
case ShaderPipelineKind::Compute:
if (DispatchParameters.VertexCount)
return llvm::createStringError(
"DispatchParameters.VertexCount set on a Compute pipeline. Only "
"allowed on a TraditionalRaster pipeline.");
break;
case ShaderPipelineKind::TraditionalRaster:
if (DispatchParameters.DispatchGroupCount !=
std::array<uint32_t, 3>{1, 1, 1})
return llvm::createStringError(
"DispatchParameters.DispatchGroupCount set on a TraditionalRaster "
"pipeline. Only allowed on a Compute pipeline.");
break;
Comment on lines +604 to +610
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we validate that VertexCount is not set if a vertex buffer was provided, or are there sensible reasons to override the "default" number of vertices in a buffer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are valid reasons to specify this manually even though you have defined a vertex buffer. Especially when we start passing arguments like FirstVertex.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only validation would be if FirstVertex + VertexCount <= NumVerticesInBuffer perhaps?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically that would still be a valid case though, but you would be reading zeroes.

}

return llvm::Error::success();
}
1 change: 0 additions & 1 deletion test/Basic/DescriptorSets.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ void main(uint GI : SV_GroupIndex) {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Float32
Expand Down
3 changes: 2 additions & 1 deletion test/Basic/Mandelbrot.test
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ const static int Dimension = 4096;
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [16384, 1, 1]
DispatchParameters:
DispatchGroupCount: [16384, 1, 1]
Buffers:
- Name: Tex
Format: Float32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_const_single_subscript.i2x3.test
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ void main() {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Int32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_const_single_subscript.test
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ void main() {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Int32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_construct_by_sub_mat.test
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ void main(uint GI : SV_GroupIndex) {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Int32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_elementwise_cast.test
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ void main(uint GI : SV_GroupIndex) {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Float32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_elementwise_vector_cast.test
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ void main(uint GI : SV_GroupIndex) {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Float32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ void main(uint GI : SV_GroupIndex) {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Int32
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ void main(uint GI : SV_GroupIndex) {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Int32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_m-based_getter.test
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ void main() {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Float32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_m-based_setter.test
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ void main() {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Float32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_m-based_swizzle_getter.test
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ void main() {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Float32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_one-based_getter.test
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ void main() {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Float32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_one-based_setter.test
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ void main() {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Float32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_one-based_swizzle_getter.test
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ void main() {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Float32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_scalar_arithmetic.test
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ void main(uint GI : SV_GroupIndex) {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Int32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_scalar_constructor.test
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ void main(uint GI : SV_GroupIndex) {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Int32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_single_subscript_basic.i2x3.test
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ void main() {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Int32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_single_subscript_basic.i3x2.test
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ void main() {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Int32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_single_subscript_basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ void main() {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Int32
Expand Down
1 change: 0 additions & 1 deletion test/Basic/Matrix/matrix_single_subscript_load.test
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ void main() {
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In
Format: Int32
Expand Down
Loading
Loading