Commit fe3d4978 by Chris Forbes

Fix various issues in vertex fetch setup

There are still some minor sins in here -- we should really unfuse attributes from buffers completely -- but this is enough to have vertex fetch work for all per-vertex attribute scenarios. Bug: b/124177079 Change-Id: I2a7a1a6f049aa80c1a527e9fa9643bb33701d165 Reviewed-on: https://swiftshader-review.googlesource.com/c/25448Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarChris Forbes <chrisforbes@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 024f271a
...@@ -87,6 +87,8 @@ namespace sw ...@@ -87,6 +87,8 @@ namespace sw
type = STREAMTYPE_FLOAT; type = STREAMTYPE_FLOAT;
count = 0; count = 0;
normalized = false; normalized = false;
offset = 0;
binding = 0;
return *this; return *this;
} }
...@@ -99,6 +101,8 @@ namespace sw ...@@ -99,6 +101,8 @@ namespace sw
StreamType type; StreamType type;
unsigned char count; unsigned char count;
bool normalized; bool normalized;
unsigned int offset;
unsigned int binding;
}; };
} }
......
...@@ -88,10 +88,10 @@ namespace sw ...@@ -88,10 +88,10 @@ namespace sw
spirvShader->inputs[i + 3].Type != SpirvShader::ATTRIBTYPE_UNUSED) spirvShader->inputs[i + 3].Type != SpirvShader::ATTRIBTYPE_UNUSED)
{ {
Pointer<Byte> input = *Pointer<Pointer<Byte>>(data + OFFSET(DrawData, input) + sizeof(void *) * i); Pointer<Byte> input = *Pointer<Pointer<Byte>>(data + OFFSET(DrawData, input) + sizeof(void *) * (i/4));
UInt stride = *Pointer<UInt>(data + OFFSET(DrawData, stride) + sizeof(unsigned int) * i); UInt stride = *Pointer<UInt>(data + OFFSET(DrawData, stride) + sizeof(unsigned int) * (i/4));
auto value = readStream(input, stride, state.input[i], index); auto value = readStream(input, stride, state.input[i/4], index);
routine.inputs[i] = value.x; routine.inputs[i] = value.x;
routine.inputs[i+1] = value.y; routine.inputs[i+1] = value.y;
routine.inputs[i+2] = value.z; routine.inputs[i+2] = value.z;
......
...@@ -155,9 +155,14 @@ struct Draw : public CommandBuffer::Command ...@@ -155,9 +155,14 @@ struct Draw : public CommandBuffer::Command
sw::Context context = pipeline->getContext(); sw::Context context = pipeline->getContext();
for(uint32_t i = 0; i < MAX_VERTEX_INPUT_BINDINGS; i++) for(uint32_t i = 0; i < MAX_VERTEX_INPUT_BINDINGS; i++)
{ {
const auto& vertexInput = executionState.vertexInputBindings[i]; auto &attrib = context.input[i];
Buffer* buffer = Cast(vertexInput.buffer); if (attrib.count)
context.input[i].buffer = buffer ? buffer->getOffsetPointer(vertexInput.offset + context.input[i].stride * firstVertex) : nullptr; {
const auto &vertexInput = executionState.vertexInputBindings[attrib.binding];
Buffer *buffer = Cast(vertexInput.buffer);
attrib.buffer = buffer ? buffer->getOffsetPointer(
attrib.offset + vertexInput.offset + attrib.stride * firstVertex) : nullptr;
}
} }
executionState.renderer->setContext(context); executionState.renderer->setContext(context);
...@@ -567,9 +572,9 @@ void CommandBuffer::bindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeli ...@@ -567,9 +572,9 @@ void CommandBuffer::bindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeli
void CommandBuffer::bindVertexBuffers(uint32_t firstBinding, uint32_t bindingCount, void CommandBuffer::bindVertexBuffers(uint32_t firstBinding, uint32_t bindingCount,
const VkBuffer* pBuffers, const VkDeviceSize* pOffsets) const VkBuffer* pBuffers, const VkDeviceSize* pOffsets)
{ {
for(uint32_t i = firstBinding; i < (firstBinding + bindingCount); ++i) for(uint32_t i = 0; i < bindingCount; ++i)
{ {
addCommand<VertexBufferBind>(i, pBuffers[i], pOffsets[i]); addCommand<VertexBufferBind>(i + firstBinding, pBuffers[i], pOffsets[i]);
} }
} }
......
...@@ -229,11 +229,14 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn ...@@ -229,11 +229,14 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
// Temporary in-binding-order representation of buffer strides, to be consumed below
// when considering attributes. TODO: unfuse buffers from attributes in backend, is old GL model.
uint32_t bufferStrides[MAX_VERTEX_INPUT_BINDINGS];
for(uint32_t i = 0; i < vertexInputState->vertexBindingDescriptionCount; i++) for(uint32_t i = 0; i < vertexInputState->vertexBindingDescriptionCount; i++)
{ {
const VkVertexInputBindingDescription* vertexBindingDescription = vertexInputState->pVertexBindingDescriptions; auto const & desc = vertexInputState->pVertexBindingDescriptions[i];
context.input[vertexBindingDescription->binding].stride = vertexBindingDescription->stride; bufferStrides[desc.binding] = desc.stride;
if(vertexBindingDescription->inputRate != VK_VERTEX_INPUT_RATE_VERTEX) if(desc.inputRate != VK_VERTEX_INPUT_RATE_VERTEX)
{ {
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
...@@ -241,20 +244,14 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn ...@@ -241,20 +244,14 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn
for(uint32_t i = 0; i < vertexInputState->vertexAttributeDescriptionCount; i++) for(uint32_t i = 0; i < vertexInputState->vertexAttributeDescriptionCount; i++)
{ {
const VkVertexInputAttributeDescription* vertexAttributeDescriptions = vertexInputState->pVertexAttributeDescriptions; auto const & desc = vertexInputState->pVertexAttributeDescriptions[i];
sw::Stream& input = context.input[vertexAttributeDescriptions->binding]; sw::Stream& input = context.input[desc.location];
input.count = getNumberOfChannels(vertexAttributeDescriptions->format); input.count = getNumberOfChannels(desc.format);
input.type = getStreamType(vertexAttributeDescriptions->format); input.type = getStreamType(desc.format);
input.normalized = !sw::Surface::isNonNormalizedInteger(vertexAttributeDescriptions->format); input.normalized = !sw::Surface::isNonNormalizedInteger(desc.format);
input.offset = desc.offset;
if(vertexAttributeDescriptions->location != vertexAttributeDescriptions->binding) input.binding = desc.binding;
{ input.stride = bufferStrides[desc.binding];
UNIMPLEMENTED();
}
if(vertexAttributeDescriptions->offset != 0)
{
UNIMPLEMENTED();
}
} }
const VkPipelineInputAssemblyStateCreateInfo* assemblyState = pCreateInfo->pInputAssemblyState; const VkPipelineInputAssemblyStateCreateInfo* assemblyState = pCreateInfo->pInputAssemblyState;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment