Commit b766e5e7 by Alexis Hetu Committed by Alexis Hétu

Support more 10_10_10_2 formats as vertex attributes

Vertex input buffers only support VK_FORMAT_A2B10G10R10_UNORM_PACK32. This cl adds all the signed and integer variants of that format. This cl also removes StreamType and replaces it with VkFormat. Tests: dEQP-VK.*r10* Bug: b/142661203 Change-Id: I996705395cbb493c599e1a460a6368a7e00d5a55 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/40348Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 11cb891a
...@@ -1175,12 +1175,13 @@ void Renderer::removeQuery(vk::Query *query) ...@@ -1175,12 +1175,13 @@ void Renderer::removeQuery(vk::Query *query)
occlusionQuery = nullptr; occlusionQuery = nullptr;
} }
// TODO(b/137740918): Optimize instancing to use a single draw call.
void Renderer::advanceInstanceAttributes(Stream *inputs) void Renderer::advanceInstanceAttributes(Stream *inputs)
{ {
for(uint32_t i = 0; i < vk::MAX_VERTEX_INPUT_BINDINGS; i++) for(uint32_t i = 0; i < vk::MAX_VERTEX_INPUT_BINDINGS; i++)
{ {
auto &attrib = inputs[i]; auto &attrib = inputs[i];
if(attrib.count && attrib.instanceStride && (attrib.instanceStride < attrib.robustnessSize)) if((attrib.format != VK_FORMAT_UNDEFINED) && attrib.instanceStride && (attrib.instanceStride < attrib.robustnessSize))
{ {
// Under the casts: attrib.buffer += attrib.instanceStride // Under the casts: attrib.buffer += attrib.instanceStride
attrib.buffer = (void const *)((uintptr_t)attrib.buffer + attrib.instanceStride); attrib.buffer = (void const *)((uintptr_t)attrib.buffer + attrib.instanceStride);
......
...@@ -15,36 +15,17 @@ ...@@ -15,36 +15,17 @@
#ifndef sw_Stream_hpp #ifndef sw_Stream_hpp
#define sw_Stream_hpp #define sw_Stream_hpp
#include "System/Types.hpp" #include <Vulkan/VulkanPlatform.h>
namespace sw { namespace sw {
enum StreamType ENUM_UNDERLYING_TYPE_UNSIGNED_INT
{
STREAMTYPE_COLOR, // 4 normalized unsigned bytes, ZYXW order
STREAMTYPE_FLOAT, // Normalization ignored
STREAMTYPE_BYTE,
STREAMTYPE_SBYTE,
STREAMTYPE_SHORT,
STREAMTYPE_USHORT,
STREAMTYPE_INT,
STREAMTYPE_UINT,
STREAMTYPE_HALF, // Normalization ignored
STREAMTYPE_2_10_10_10_INT,
STREAMTYPE_2_10_10_10_UINT,
STREAMTYPE_LAST = STREAMTYPE_2_10_10_10_UINT
};
struct Stream struct Stream
{ {
const void *buffer = nullptr; const void *buffer = nullptr;
unsigned int robustnessSize = 0; unsigned int robustnessSize = 0;
unsigned int vertexStride = 0; unsigned int vertexStride = 0;
unsigned int instanceStride = 0; unsigned int instanceStride = 0;
StreamType type = STREAMTYPE_FLOAT; VkFormat format = VK_FORMAT_UNDEFINED;
unsigned char count = 0;
bool normalized = false;
unsigned int offset = 0; unsigned int offset = 0;
unsigned int binding = 0; unsigned int binding = 0;
}; };
......
...@@ -44,32 +44,6 @@ uint32_t VertexProcessor::States::computeHash() ...@@ -44,32 +44,6 @@ uint32_t VertexProcessor::States::computeHash()
return hash; return hash;
} }
unsigned int VertexProcessor::States::Input::bytesPerAttrib() const
{
switch(type)
{
case STREAMTYPE_FLOAT:
case STREAMTYPE_INT:
case STREAMTYPE_UINT:
return count * sizeof(uint32_t);
case STREAMTYPE_HALF:
case STREAMTYPE_SHORT:
case STREAMTYPE_USHORT:
return count * sizeof(uint16_t);
case STREAMTYPE_BYTE:
case STREAMTYPE_SBYTE:
return count * sizeof(uint8_t);
case STREAMTYPE_COLOR:
case STREAMTYPE_2_10_10_10_INT:
case STREAMTYPE_2_10_10_10_UINT:
return sizeof(int);
default:
UNSUPPORTED("stream.type %d", int(type));
}
return 0;
}
bool VertexProcessor::State::operator==(const State &state) const bool VertexProcessor::State::operator==(const State &state) const
{ {
if(hash != state.hash) if(hash != state.hash)
...@@ -109,9 +83,7 @@ const VertexProcessor::State VertexProcessor::update(const sw::Context *context) ...@@ -109,9 +83,7 @@ const VertexProcessor::State VertexProcessor::update(const sw::Context *context)
for(int i = 0; i < MAX_INTERFACE_COMPONENTS / 4; i++) for(int i = 0; i < MAX_INTERFACE_COMPONENTS / 4; i++)
{ {
state.input[i].type = context->input[i].type; state.input[i].format = context->input[i].format;
state.input[i].count = context->input[i].count;
state.input[i].normalized = context->input[i].normalized;
// TODO: get rid of attribType -- just keep the VK format all the way through, this fully determines // TODO: get rid of attribType -- just keep the VK format all the way through, this fully determines
// how to handle the attribute. // how to handle the attribute.
state.input[i].attribType = context->vertexShader->inputs[i * 4].Type; state.input[i].attribType = context->vertexShader->inputs[i * 4].Type;
......
...@@ -68,14 +68,10 @@ public: ...@@ -68,14 +68,10 @@ public:
{ {
operator bool() const // Returns true if stream contains data operator bool() const // Returns true if stream contains data
{ {
return count != 0; return format != VK_FORMAT_UNDEFINED;
} }
unsigned int bytesPerAttrib() const; VkFormat format; // TODO(b/148016460): Could be restricted to VK_FORMAT_END_RANGE
StreamType type : BITS(STREAMTYPE_LAST);
unsigned int count : 3;
bool normalized : 1;
unsigned int attribType : BITS(SpirvShader::ATTRIBTYPE_LAST); unsigned int attribType : BITS(SpirvShader::ATTRIBTYPE_LAST);
}; };
......
...@@ -1811,7 +1811,7 @@ void CommandBuffer::ExecutionState::bindVertexInputs(sw::Context &context, int f ...@@ -1811,7 +1811,7 @@ void CommandBuffer::ExecutionState::bindVertexInputs(sw::Context &context, int f
for(uint32_t i = 0; i < MAX_VERTEX_INPUT_BINDINGS; i++) for(uint32_t i = 0; i < MAX_VERTEX_INPUT_BINDINGS; i++)
{ {
auto &attrib = context.input[i]; auto &attrib = context.input[i];
if(attrib.count) if(attrib.format != VK_FORMAT_UNDEFINED)
{ {
const auto &vertexInput = vertexInputBindings[attrib.binding]; const auto &vertexInput = vertexInputBindings[attrib.binding];
VkDeviceSize offset = attrib.offset + vertexInput.offset + VkDeviceSize offset = attrib.offset + vertexInput.offset +
......
...@@ -689,7 +689,14 @@ void PhysicalDevice::getFormatProperties(Format format, VkFormatProperties *pFor ...@@ -689,7 +689,14 @@ void PhysicalDevice::getFormatProperties(Format format, VkFormatProperties *pFor
case VK_FORMAT_A8B8G8R8_SNORM_PACK32: case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
case VK_FORMAT_A8B8G8R8_UINT_PACK32: case VK_FORMAT_A8B8G8R8_UINT_PACK32:
case VK_FORMAT_A8B8G8R8_SINT_PACK32: case VK_FORMAT_A8B8G8R8_SINT_PACK32:
case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
case VK_FORMAT_A2R10G10B10_UINT_PACK32:
case VK_FORMAT_A2R10G10B10_SINT_PACK32:
case VK_FORMAT_A2B10G10R10_UNORM_PACK32: case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
case VK_FORMAT_A2B10G10R10_UINT_PACK32:
case VK_FORMAT_A2B10G10R10_SINT_PACK32:
case VK_FORMAT_R16_UNORM: case VK_FORMAT_R16_UNORM:
case VK_FORMAT_R16_SNORM: case VK_FORMAT_R16_SNORM:
case VK_FORMAT_R16_UINT: case VK_FORMAT_R16_UINT:
......
...@@ -31,132 +31,6 @@ ...@@ -31,132 +31,6 @@
namespace { namespace {
sw::StreamType getStreamType(VkFormat format)
{
switch(format)
{
case VK_FORMAT_R8_UNORM:
case VK_FORMAT_R8G8_UNORM:
case VK_FORMAT_R8G8B8A8_UNORM:
case VK_FORMAT_R8_UINT:
case VK_FORMAT_R8G8_UINT:
case VK_FORMAT_R8G8B8A8_UINT:
case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
case VK_FORMAT_A8B8G8R8_UINT_PACK32:
return sw::STREAMTYPE_BYTE;
case VK_FORMAT_B8G8R8A8_UNORM:
return sw::STREAMTYPE_COLOR;
case VK_FORMAT_R8_SNORM:
case VK_FORMAT_R8_SINT:
case VK_FORMAT_R8G8_SNORM:
case VK_FORMAT_R8G8_SINT:
case VK_FORMAT_R8G8B8A8_SNORM:
case VK_FORMAT_R8G8B8A8_SINT:
case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
case VK_FORMAT_A8B8G8R8_SINT_PACK32:
return sw::STREAMTYPE_SBYTE;
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
return sw::STREAMTYPE_2_10_10_10_UINT;
case VK_FORMAT_R16_UNORM:
case VK_FORMAT_R16_UINT:
case VK_FORMAT_R16G16_UNORM:
case VK_FORMAT_R16G16_UINT:
case VK_FORMAT_R16G16B16A16_UNORM:
case VK_FORMAT_R16G16B16A16_UINT:
return sw::STREAMTYPE_USHORT;
case VK_FORMAT_R16_SNORM:
case VK_FORMAT_R16_SINT:
case VK_FORMAT_R16G16_SNORM:
case VK_FORMAT_R16G16_SINT:
case VK_FORMAT_R16G16B16A16_SNORM:
case VK_FORMAT_R16G16B16A16_SINT:
return sw::STREAMTYPE_SHORT;
case VK_FORMAT_R16_SFLOAT:
case VK_FORMAT_R16G16_SFLOAT:
case VK_FORMAT_R16G16B16A16_SFLOAT:
return sw::STREAMTYPE_HALF;
case VK_FORMAT_R32_UINT:
case VK_FORMAT_R32G32_UINT:
case VK_FORMAT_R32G32B32_UINT:
case VK_FORMAT_R32G32B32A32_UINT:
return sw::STREAMTYPE_UINT;
case VK_FORMAT_R32_SINT:
case VK_FORMAT_R32G32_SINT:
case VK_FORMAT_R32G32B32_SINT:
case VK_FORMAT_R32G32B32A32_SINT:
return sw::STREAMTYPE_INT;
case VK_FORMAT_R32_SFLOAT:
case VK_FORMAT_R32G32_SFLOAT:
case VK_FORMAT_R32G32B32_SFLOAT:
case VK_FORMAT_R32G32B32A32_SFLOAT:
return sw::STREAMTYPE_FLOAT;
default:
UNIMPLEMENTED("format");
}
return sw::STREAMTYPE_BYTE;
}
unsigned char getNumberOfChannels(VkFormat format)
{
switch(format)
{
case VK_FORMAT_R8_UNORM:
case VK_FORMAT_R8_SNORM:
case VK_FORMAT_R8_UINT:
case VK_FORMAT_R8_SINT:
case VK_FORMAT_R16_UNORM:
case VK_FORMAT_R16_SNORM:
case VK_FORMAT_R16_UINT:
case VK_FORMAT_R16_SINT:
case VK_FORMAT_R16_SFLOAT:
case VK_FORMAT_R32_UINT:
case VK_FORMAT_R32_SINT:
case VK_FORMAT_R32_SFLOAT:
return 1;
case VK_FORMAT_R8G8_UNORM:
case VK_FORMAT_R8G8_SNORM:
case VK_FORMAT_R8G8_UINT:
case VK_FORMAT_R8G8_SINT:
case VK_FORMAT_R16G16_UNORM:
case VK_FORMAT_R16G16_SNORM:
case VK_FORMAT_R16G16_UINT:
case VK_FORMAT_R16G16_SINT:
case VK_FORMAT_R16G16_SFLOAT:
case VK_FORMAT_R32G32_UINT:
case VK_FORMAT_R32G32_SINT:
case VK_FORMAT_R32G32_SFLOAT:
return 2;
case VK_FORMAT_R32G32B32_UINT:
case VK_FORMAT_R32G32B32_SINT:
case VK_FORMAT_R32G32B32_SFLOAT:
return 3;
case VK_FORMAT_R8G8B8A8_UNORM:
case VK_FORMAT_R8G8B8A8_SNORM:
case VK_FORMAT_R8G8B8A8_UINT:
case VK_FORMAT_R8G8B8A8_SINT:
case VK_FORMAT_B8G8R8A8_UNORM:
case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
case VK_FORMAT_A8B8G8R8_UINT_PACK32:
case VK_FORMAT_A8B8G8R8_SINT_PACK32:
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
case VK_FORMAT_R16G16B16A16_UNORM:
case VK_FORMAT_R16G16B16A16_SNORM:
case VK_FORMAT_R16G16B16A16_UINT:
case VK_FORMAT_R16G16B16A16_SINT:
case VK_FORMAT_R16G16B16A16_SFLOAT:
case VK_FORMAT_R32G32B32A32_UINT:
case VK_FORMAT_R32G32B32A32_SINT:
case VK_FORMAT_R32G32B32A32_SFLOAT:
return 4;
default:
UNIMPLEMENTED("format");
}
return 0;
}
// preprocessSpirv applies and freezes specializations into constants, and inlines all functions. // preprocessSpirv applies and freezes specializations into constants, and inlines all functions.
std::vector<uint32_t> preprocessSpirv( std::vector<uint32_t> preprocessSpirv(
std::vector<uint32_t> const &code, std::vector<uint32_t> const &code,
...@@ -333,9 +207,7 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo *pCreateIn ...@@ -333,9 +207,7 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo *pCreateIn
{ {
auto const &desc = vertexInputState->pVertexAttributeDescriptions[i]; auto const &desc = vertexInputState->pVertexAttributeDescriptions[i];
sw::Stream &input = context.input[desc.location]; sw::Stream &input = context.input[desc.location];
input.count = getNumberOfChannels(desc.format); input.format = desc.format;
input.type = getStreamType(desc.format);
input.normalized = !vk::Format(desc.format).isUnnormalizedInteger();
input.offset = desc.offset; input.offset = desc.offset;
input.binding = desc.binding; input.binding = desc.binding;
input.vertexStride = vertexStrides[desc.binding]; input.vertexStride = vertexStrides[desc.binding];
......
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