Skip to content

Commit 225a130

Browse files
committed
Implement dynamic buffer offsets.
Tests: *dynamic* Bug: b/126330097 Change-Id: I7e4f7e3d921acb72878b7728216415ba66f63ec7 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28249 Reviewed-by: Nicolas Capens <nicolascapens@google.com> Tested-by: Ben Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
1 parent fcbb145 commit 225a130

25 files changed

+287
-108
lines changed

src/Device/Context.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,6 @@ namespace sw
112112

113113
void Context::init()
114114
{
115-
for(int i = 0; i < vk::MAX_BOUND_DESCRIPTOR_SETS; i++)
116-
{
117-
descriptorSets[i] = nullptr;
118-
}
119-
120115
// Set vertex streams to null stream
121116
for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
122117
{

src/Device/Context.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define sw_Context_hpp
1717

1818
#include "Vulkan/VkConfig.h"
19+
#include "Vulkan/VkDescriptorSet.hpp"
1920
#include "Sampler.hpp"
2021
#include "Stream.hpp"
2122
#include "Point.hpp"
@@ -153,7 +154,8 @@ namespace sw
153154
int colorWriteActive(int index);
154155
bool colorUsed();
155156

156-
vk::DescriptorSet *descriptorSets[vk::MAX_BOUND_DESCRIPTOR_SETS];
157+
vk::DescriptorSet::Bindings descriptorSets = {};
158+
vk::DescriptorSet::DynamicOffsets descriptorDynamicOffsets = {};
157159
Stream input[MAX_VERTEX_INPUTS];
158160
void *indexBuffer;
159161

src/Device/QuadRasterizer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace sw
2828
QuadRasterizer(const PixelProcessor::State &state, SpirvShader const *spirvShader);
2929
virtual ~QuadRasterizer();
3030

31-
virtual void generate();
31+
void generate();
3232

3333
protected:
3434
Pointer<Byte> constants;

src/Device/Renderer.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,8 @@ namespace sw
388388
draw->setupPrimitives = setupPrimitives;
389389
draw->setupState = setupState;
390390

391-
for(int i = 0; i < vk::MAX_BOUND_DESCRIPTOR_SETS; i++)
392-
{
393-
data->descriptorSets[i] = context->descriptorSets[i];
394-
}
391+
data->descriptorSets = context->descriptorSets;
392+
data->descriptorDynamicOffsets = context->descriptorDynamicOffsets;
395393

396394
for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
397395
{

src/Device/Renderer.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "System/MutexLock.hpp"
2424
#include "System/Thread.hpp"
2525
#include "Device/Config.hpp"
26+
#include "Vulkan/VkDescriptorSet.hpp"
2627

2728
#include <list>
2829

@@ -114,7 +115,8 @@ namespace sw
114115
{
115116
const Constants *constants;
116117

117-
vk::DescriptorSet *descriptorSets[vk::MAX_BOUND_DESCRIPTOR_SETS];
118+
vk::DescriptorSet::Bindings descriptorSets = {};
119+
vk::DescriptorSet::DynamicOffsets descriptorDynamicOffsets = {};
118120

119121
const void *input[MAX_VERTEX_INPUTS];
120122
unsigned int stride[MAX_VERTEX_INPUTS];

src/Pipeline/ComputeProgram.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,9 @@ namespace sw
4545

4646
void ComputeProgram::emit()
4747
{
48-
Pointer<Pointer<Byte>> descriptorSetsIn = *Pointer<Pointer<Pointer<Byte>>>(data + OFFSET(Data, descriptorSets));
49-
size_t numDescriptorSets = routine.pipelineLayout->getNumDescriptorSets();
50-
for(unsigned int i = 0; i < numDescriptorSets; i++)
51-
{
52-
routine.descriptorSets[i] = descriptorSetsIn[i];
53-
}
54-
55-
routine.pushConstants = Pointer<Byte>(data + OFFSET(Data, pushConstants));
48+
routine.descriptorSets = data + OFFSET(Data, descriptorSets);
49+
routine.descriptorDynamicOffsets = data + OFFSET(Data, descriptorDynamicOffsets);
50+
routine.pushConstants = data + OFFSET(Data, pushConstants);
5651

5752
auto &modes = shader->getModes();
5853

@@ -178,13 +173,17 @@ namespace sw
178173
}
179174

180175
void ComputeProgram::run(
181-
Routine *routine, void** descriptorSets, PushConstantStorage const &pushConstants,
176+
Routine *routine,
177+
vk::DescriptorSet::Bindings const &descriptorSets,
178+
vk::DescriptorSet::DynamicOffsets const &descriptorDynamicOffsets,
179+
PushConstantStorage const &pushConstants,
182180
uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ)
183181
{
184182
auto runWorkgroup = (void(*)(void*))(routine->getEntry());
185183

186184
Data data;
187185
data.descriptorSets = descriptorSets;
186+
data.descriptorDynamicOffsets = descriptorDynamicOffsets;
188187
data.numWorkgroups[X] = groupCountX;
189188
data.numWorkgroups[Y] = groupCountY;
190189
data.numWorkgroups[Z] = groupCountZ;

src/Pipeline/ComputeProgram.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "Reactor/Reactor.hpp"
2121
#include "Device/Context.hpp"
22+
#include "Vulkan/VkDescriptorSet.hpp"
2223

2324
#include <functional>
2425

@@ -48,7 +49,10 @@ namespace sw
4849
// run executes the compute shader routine for all workgroups.
4950
// TODO(bclayton): This probably does not belong here. Consider moving.
5051
static void run(
51-
Routine *routine, void** descriptorSets, PushConstantStorage const &pushConstants,
52+
Routine *routine,
53+
vk::DescriptorSet::Bindings const &descriptorSetBindings,
54+
vk::DescriptorSet::DynamicOffsets const &descriptorDynamicOffsets,
55+
PushConstantStorage const &pushConstants,
5256
uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ);
5357

5458
protected:
@@ -60,7 +64,8 @@ namespace sw
6064

6165
struct Data
6266
{
63-
void** descriptorSets;
67+
vk::DescriptorSet::Bindings descriptorSets;
68+
vk::DescriptorSet::DynamicOffsets descriptorDynamicOffsets;
6469
uint4 numWorkgroups;
6570
uint4 workgroupID;
6671
PushConstantStorage pushConstants;

src/Pipeline/PixelProgram.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ namespace sw
3131
{
3232
enableIndex = 0;
3333

34+
routine.descriptorSets = data + OFFSET(DrawData, descriptorSets);
35+
routine.descriptorDynamicOffsets = data + OFFSET(DrawData, descriptorDynamicOffsets);
3436
routine.pushConstants = data + OFFSET(DrawData, pushConstants);
3537

3638
auto activeLaneMask = SIMD::Int(0xFFFFFFFF); // TODO: Control this.

src/Pipeline/PixelRoutine.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,6 @@ namespace sw
5454
{
5555
}
5656

57-
void PixelRoutine::generate()
58-
{
59-
Pointer<Pointer<Byte>> descriptorSets = Pointer<Pointer<Byte>>(data + OFFSET(DrawData, descriptorSets));
60-
auto numDescriptorSets = routine.pipelineLayout->getNumDescriptorSets();
61-
for(unsigned int i = 0; i < numDescriptorSets; i++)
62-
{
63-
routine.descriptorSets[i] = descriptorSets[i];
64-
}
65-
66-
QuadRasterizer::generate();
67-
}
68-
6957
void PixelRoutine::quad(Pointer<Byte> cBuffer[RENDERTARGETS], Pointer<Byte> &zBuffer, Pointer<Byte> &sBuffer, Int cMask[4], Int &x, Int &y)
7058
{
7159
#if PERF_PROFILE

src/Pipeline/PixelRoutine.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ namespace sw
3131

3232
virtual ~PixelRoutine();
3333

34-
void generate() override;
35-
3634
protected:
3735
Float4 z[4]; // Multisampled z
3836
Float4 w; // Used as is

0 commit comments

Comments
 (0)