Skip to content

Commit 00ba176

Browse files
committed
Factor out vertex attribute binding from Draw*::play
I'm about to build some more on top of this; don't want to write it multiple times. Change-Id: I9ca84536f47b886e9f03edcaa6dc5dfe6e34091d Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/26688 Tested-by: Chris Forbes <[email protected]> Presubmit-Ready: Chris Forbes <[email protected]> Reviewed-by: Alexis Hétu <[email protected]> Reviewed-by: Nicolas Capens <[email protected]> Kokoro-Presubmit: kokoro <[email protected]>
1 parent 5851ef4 commit 00ba176

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

src/Vulkan/VkCommandBuffer.cpp

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,21 @@ struct IndexBufferBind : public CommandBuffer::Command
185185
const VkIndexType indexType;
186186
};
187187

188+
void CommandBuffer::ExecutionState::bindVertexInputs(sw::Context& context, int firstVertex)
189+
{
190+
for(uint32_t i = 0; i < MAX_VERTEX_INPUT_BINDINGS; i++)
191+
{
192+
auto &attrib = context.input[i];
193+
if (attrib.count)
194+
{
195+
const auto &vertexInput = vertexInputBindings[attrib.binding];
196+
Buffer *buffer = Cast(vertexInput.buffer);
197+
attrib.buffer = buffer ? buffer->getOffsetPointer(
198+
attrib.offset + vertexInput.offset + attrib.stride * firstVertex) : nullptr;
199+
}
200+
}
201+
}
202+
188203
void CommandBuffer::ExecutionState::bindAttachments()
189204
{
190205
// Binds all the attachments for the current subpass
@@ -230,17 +245,7 @@ struct Draw : public CommandBuffer::Command
230245
executionState.pipelines[VK_PIPELINE_BIND_POINT_GRAPHICS]);
231246

232247
sw::Context context = pipeline->getContext();
233-
for(uint32_t i = 0; i < MAX_VERTEX_INPUT_BINDINGS; i++)
234-
{
235-
auto &attrib = context.input[i];
236-
if (attrib.count)
237-
{
238-
const auto &vertexInput = executionState.vertexInputBindings[attrib.binding];
239-
Buffer *buffer = Cast(vertexInput.buffer);
240-
attrib.buffer = buffer ? buffer->getOffsetPointer(
241-
attrib.offset + vertexInput.offset + attrib.stride * firstVertex) : nullptr;
242-
}
243-
}
248+
executionState.bindVertexInputs(context, firstVertex);
244249

245250
context.pushConstants = executionState.pushConstants;
246251

@@ -279,17 +284,7 @@ struct DrawIndexed : public CommandBuffer::Command
279284
executionState.pipelines[VK_PIPELINE_BIND_POINT_GRAPHICS]);
280285

281286
sw::Context context = pipeline->getContext();
282-
for(uint32_t i = 0; i < MAX_VERTEX_INPUT_BINDINGS; i++)
283-
{
284-
auto &attrib = context.input[i];
285-
if (attrib.count)
286-
{
287-
const auto &vertexInput = executionState.vertexInputBindings[attrib.binding];
288-
Buffer *buffer = Cast(vertexInput.buffer);
289-
attrib.buffer = buffer ? buffer->getOffsetPointer(
290-
attrib.offset + vertexInput.offset + attrib.stride * vertexOffset) : nullptr;
291-
}
292-
}
287+
executionState.bindVertexInputs(context, vertexOffset);
293288

294289
context.pushConstants = executionState.pushConstants;
295290

src/Vulkan/VkCommandBuffer.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
namespace sw
2525
{
26+
class Context;
2627
class Renderer;
2728
}
2829

@@ -139,6 +140,7 @@ class CommandBuffer
139140
VkIndexType indexType;
140141

141142
void bindAttachments();
143+
void bindVertexInputs(sw::Context& context, int firstVertex);
142144
};
143145

144146
void submit(CommandBuffer::ExecutionState& executionState);

0 commit comments

Comments
 (0)