Commit ee21a187 by Jamie Madill Committed by Commit Bot

Store angle::Format in gl::VertexAttribute.

Instead of storing type/size/normalized/pureInteger we instead store a pointer to the angle::Format. This makes some code logic simpler and will let us more easily check if a vertex attribute format changes in calls to VertexAttribPointer or VertexAttribFormat. This CL adds extra information to angle::Format to represent the vertex format info needed. It also caches the channel count so that it can be queried faster. Also renames "Int" -> "Sint" in UtilsVk for consistency. Bug: angleproject:3256 Change-Id: I5ef9b983dad8a58c341113c802500b89ce081566 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1684293 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com>
parent b00ecb9a
......@@ -2,7 +2,7 @@
"ANGLE format:src/libANGLE/renderer/FormatID_autogen.h":
"083c08bb743bf72a900079890b14184f",
"ANGLE format:src/libANGLE/renderer/Format_table_autogen.cpp":
"a4cf00b75621bc058c4a1b341bdf6989",
"24a7e010def51eb4342caa5392536ea9",
"ANGLE format:src/libANGLE/renderer/angle_format.py":
"7ce0869650454e1eebc93658d4d96844",
"ANGLE format:src/libANGLE/renderer/angle_format_data.json":
......@@ -10,7 +10,7 @@
"ANGLE format:src/libANGLE/renderer/angle_format_map.json":
"be9f9bdbdf785dda05920146e8c55dbb",
"ANGLE format:src/libANGLE/renderer/gen_angle_format_table.py":
"1443d23f2dc1e9d7dc86ae0d512e6814",
"37f4654bca2bebc7fdec1fc7ca9bc622",
"ANGLE load functions table:src/libANGLE/renderer/gen_load_functions_table.py":
"e65c50e84fc38ad34d0eb0bebb84aab6",
"ANGLE load functions table:src/libANGLE/renderer/load_functions_data.json":
......@@ -496,21 +496,21 @@
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/shaders/src/BlitResolveStencilNoExport.comp":
"3080e264f932ce3a219bb63c79b86636",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/shaders/src/BufferUtils.comp":
"0c8c050841543da0d7faca2559212aa8",
"b7c20e019199f8328ef37b11c6fbcadd",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/shaders/src/ConvertIndex.comp":
"ca35df77d258baa0636529d1f0f446a9",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/shaders/src/ConvertVertex.comp":
"93649f61036c2fa4739988ad71f413df",
"e1a64b49ac57bf7aa48913f818d6a522",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/shaders/src/FullScreenQuad.vert":
"805ec8b2f87d4bd4242dc5b1c58ba3b4",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/shaders/src/ImageClear.frag":
"7f562c60e5df018b0087ecb8642ac821",
"8889ae8014a657a0efd5607954126945",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/shaders/src/ImageCopy.frag":
"20c83ade1efb48a802dc34ca838a2be6",
"f0f3cc82d78198f114b698e1aea31267",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/vk_internal_shaders_autogen.cpp":
"7891716bf0c429ddacfbb2823f166dc6",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/vk_internal_shaders_autogen.h":
"63e63b37508787d66a0e4aab7e36ffd8",
"545807c51af450c31eb3fdf6d784d753",
"Vulkan internal shader programs:tools/glslang/glslang_validator.exe.sha1":
"289f30598865a987a21b79ae525fc66f",
"Vulkan internal shader programs:tools/glslang/glslang_validator.sha1":
......
......@@ -389,12 +389,12 @@ ANGLE_INLINE void VertexArray::setVertexAttribFormatImpl(VertexAttribute *attrib
GLint size,
VertexAttribType type,
bool normalized,
bool pureInteger,
GLuint relativeOffset)
{
attrib->size = size;
attrib->type = type;
attrib->normalized = normalized;
attrib->relativeOffset = relativeOffset;
angle::FormatID formatID = gl::GetVertexFormatID(type, normalized, size, pureInteger);
attrib->format = &angle::Format::Get(formatID);
attrib->relativeOffset = relativeOffset;
}
void VertexArray::setVertexAttribFormat(size_t attribIndex,
......@@ -405,12 +405,11 @@ void VertexArray::setVertexAttribFormat(size_t attribIndex,
GLuint relativeOffset)
{
VertexAttribute &attrib = mState.mVertexAttributes[attribIndex];
attrib.pureInteger = pureInteger;
ComponentType componentType = GetVertexAttributeComponentType(pureInteger, type);
SetComponentTypeMask(componentType, attribIndex, &mState.mVertexAttributesTypeMask);
setVertexAttribFormatImpl(&attrib, size, type, normalized, relativeOffset);
setVertexAttribFormatImpl(&attrib, size, type, normalized, pureInteger, relativeOffset);
setDirtyAttribBit(attribIndex, DIRTY_ATTRIB_FORMAT);
attrib.updateCachedElementLimit(mState.mVertexBindings[attrib.bindingIndex]);
......@@ -461,11 +460,10 @@ ANGLE_INLINE void VertexArray::setVertexAttribPointerImpl(const Context *context
GLintptr offset = boundBuffer ? reinterpret_cast<GLintptr>(pointer) : 0;
VertexAttribute &attrib = mState.mVertexAttributes[attribIndex];
attrib.pureInteger = pureInteger;
SetComponentTypeMask(componentType, attribIndex, &mState.mVertexAttributesTypeMask);
setVertexAttribFormatImpl(&attrib, size, type, normalized, 0);
setVertexAttribFormatImpl(&attrib, size, type, normalized, pureInteger, 0);
setVertexAttribBinding(context, attribIndex, static_cast<GLuint>(attribIndex));
GLsizei effectiveStride =
......
......@@ -156,6 +156,7 @@ class VertexArray final : public angle::ObserverInterface,
GLint size,
VertexAttribType type,
bool normalized,
bool pureInteger,
GLuint relativeOffset);
void bindVertexBufferImpl(const Context *context,
size_t bindingIndex,
......
......@@ -48,10 +48,7 @@ void VertexBinding::onContainerBindingChanged(const Context *context, int incr)
VertexAttribute::VertexAttribute(GLuint bindingIndex)
: enabled(false),
type(VertexAttribType::Float),
size(4u),
normalized(false),
pureInteger(false),
format(&angle::Format::Get(angle::FormatID::R32G32B32A32_FLOAT)),
pointer(nullptr),
relativeOffset(0),
vertexAttribArrayStride(0),
......@@ -61,10 +58,7 @@ VertexAttribute::VertexAttribute(GLuint bindingIndex)
VertexAttribute::VertexAttribute(VertexAttribute &&attrib)
: enabled(attrib.enabled),
type(attrib.type),
size(attrib.size),
normalized(attrib.normalized),
pureInteger(attrib.pureInteger),
format(attrib.format),
pointer(attrib.pointer),
relativeOffset(attrib.relativeOffset),
vertexAttribArrayStride(attrib.vertexAttribArrayStride),
......@@ -77,10 +71,7 @@ VertexAttribute &VertexAttribute::operator=(VertexAttribute &&attrib)
if (this != &attrib)
{
enabled = attrib.enabled;
type = attrib.type;
size = attrib.size;
normalized = attrib.normalized;
pureInteger = attrib.pureInteger;
format = attrib.format;
pointer = attrib.pointer;
relativeOffset = attrib.relativeOffset;
vertexAttribArrayStride = attrib.vertexAttribArrayStride;
......
......@@ -11,6 +11,7 @@
#include "libANGLE/Buffer.h"
#include "libANGLE/angletypes.h"
#include "libANGLE/renderer/Format.h"
namespace gl
{
......@@ -81,10 +82,7 @@ struct VertexAttribute final : private angle::NonCopyable
GLint64 getCachedElementLimit() const { return mCachedElementLimit; }
bool enabled; // For glEnable/DisableVertexAttribArray
VertexAttribType type;
GLuint size;
bool normalized;
bool pureInteger;
const angle::Format *format;
const void *pointer;
GLuint relativeOffset;
......@@ -102,36 +100,8 @@ struct VertexAttribute final : private angle::NonCopyable
ANGLE_INLINE size_t ComputeVertexAttributeTypeSize(const VertexAttribute &attrib)
{
switch (attrib.type)
{
case VertexAttribType::Byte:
return attrib.size * sizeof(GLbyte);
case VertexAttribType::UnsignedByte:
return attrib.size * sizeof(GLubyte);
case VertexAttribType::Short:
return attrib.size * sizeof(GLshort);
case VertexAttribType::UnsignedShort:
return attrib.size * sizeof(GLushort);
case VertexAttribType::Int:
return attrib.size * sizeof(GLint);
case VertexAttribType::UnsignedInt:
return attrib.size * sizeof(GLuint);
case VertexAttribType::Float:
return attrib.size * sizeof(GLfloat);
case VertexAttribType::HalfFloat:
return attrib.size * sizeof(GLhalf);
case VertexAttribType::Fixed:
return attrib.size * sizeof(GLfixed);
case VertexAttribType::Int2101010:
// Packed attribute types don't scale by their component size.
return 4;
case VertexAttribType::UnsignedInt2101010:
// Packed attribute types don't scale by their component size.
return 4;
default:
UNREACHABLE();
return 0;
}
ASSERT(attrib.format);
return attrib.format->pixelBytes;
}
// Warning: you should ensure binding really matches attrib.bindingIndex before using this function.
......
......@@ -1631,10 +1631,9 @@ angle::FormatID GetVertexFormatID(const VertexAttribute &attrib, VertexAttribTyp
{
if (!attrib.enabled)
{
return GetVertexFormatID(currentValueType, GL_FALSE, 4,
(currentValueType != VertexAttribType::Float));
return angle::FormatID::R32G32B32A32_FLOAT;
}
return GetVertexFormatID(attrib);
return attrib.format->id;
}
const VertexFormat &GetVertexFormatFromID(angle::FormatID vertexFormatID)
......
......@@ -252,11 +252,6 @@ angle::FormatID GetVertexFormatID(VertexAttribType type,
GLuint components,
bool pureInteger);
ANGLE_INLINE angle::FormatID GetVertexFormatID(const VertexAttribute &attrib)
{
return GetVertexFormatID(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
}
angle::FormatID GetVertexFormatID(const VertexAttribute &attrib, VertexAttribType currentValueType);
const VertexFormat &GetVertexFormatFromID(angle::FormatID vertexFormatID);
size_t GetVertexFormatSize(angle::FormatID vertexFormatID);
......
......@@ -520,16 +520,18 @@ void QueryVertexAttribBase(const VertexAttribute &attrib,
*params = CastFromStateValue<ParamType>(pname, static_cast<GLint>(attrib.enabled));
break;
case GL_VERTEX_ATTRIB_ARRAY_SIZE:
*params = CastFromGLintStateValue<ParamType>(pname, attrib.size);
*params = CastFromGLintStateValue<ParamType>(pname, attrib.format->channelCount);
break;
case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
*params = CastFromGLintStateValue<ParamType>(pname, attrib.vertexAttribArrayStride);
break;
case GL_VERTEX_ATTRIB_ARRAY_TYPE:
*params = CastFromGLintStateValue<ParamType>(pname, ToGLenum(attrib.type));
*params = CastFromGLintStateValue<ParamType>(
pname, gl::ToGLenum(attrib.format->vertexAttribType));
break;
case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
*params = CastFromStateValue<ParamType>(pname, static_cast<GLint>(attrib.normalized));
*params =
CastFromStateValue<ParamType>(pname, static_cast<GLint>(attrib.format->isNorm()));
break;
case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
*params = CastFromGLintStateValue<ParamType>(pname, binding.getBuffer().id());
......@@ -538,7 +540,7 @@ void QueryVertexAttribBase(const VertexAttribute &attrib,
*params = CastFromStateValue<ParamType>(pname, binding.getDivisor());
break;
case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
*params = CastFromGLintStateValue<ParamType>(pname, attrib.pureInteger);
*params = CastFromGLintStateValue<ParamType>(pname, attrib.format->isPureInt());
break;
case GL_VERTEX_ATTRIB_BINDING:
*params = CastFromGLintStateValue<ParamType>(pname, attrib.bindingIndex);
......
......@@ -41,7 +41,9 @@ struct Format final : private angle::NonCopyable
GLuint pixelBytes,
GLuint componentAlignmentMask,
bool isBlock,
bool isFixed);
bool isFixed,
bool isScaled,
gl::VertexAttribType vertexAttribType);
static const Format &Get(FormatID id) { return gFormatInfoTable[static_cast<int>(id)]; }
......@@ -49,14 +51,17 @@ struct Format final : private angle::NonCopyable
constexpr bool hasDepthOrStencilBits() const;
constexpr bool isLUMA() const;
constexpr GLuint channelCount() const;
constexpr bool isInt() const;
constexpr bool isSint() const;
constexpr bool isUint() const;
constexpr bool isSnorm() const;
constexpr bool isUnorm() const;
constexpr bool isFloat() const;
constexpr bool isInt() const { return isSint() || isUint(); }
constexpr bool isNorm() const { return isSnorm() || isUnorm(); }
constexpr bool isPureInt() const { return isInt() && !isScaled; }
bool operator==(const Format &other) const { return this->id == other.id; }
FormatID id;
......@@ -93,10 +98,29 @@ struct Format final : private angle::NonCopyable
// 0x0.
GLuint componentAlignmentMask;
GLuint channelCount;
bool isBlock;
bool isFixed;
bool isScaled;
// For vertex formats only. Returns the "type" value for glVertexAttribPointer etc.
gl::VertexAttribType vertexAttribType;
};
constexpr GLuint GetChannelCount(GLuint redBits,
GLuint greenBits,
GLuint blueBits,
GLuint alphaBits,
GLuint luminanceBits,
GLuint depthBits,
GLuint stencilBits)
{
return (redBits > 0 ? 1 : 0) + (greenBits > 0 ? 1 : 0) + (blueBits > 0 ? 1 : 0) +
(alphaBits > 0 ? 1 : 0) + (luminanceBits > 0 ? 1 : 0) + (depthBits > 0 ? 1 : 0) +
(stencilBits > 0 ? 1 : 0);
}
constexpr Format::Format(FormatID id,
GLenum glFormat,
GLenum fboFormat,
......@@ -115,7 +139,9 @@ constexpr Format::Format(FormatID id,
GLuint pixelBytes,
GLuint componentAlignmentMask,
bool isBlock,
bool isFixed)
bool isFixed,
bool isScaled,
gl::VertexAttribType vertexAttribType)
: id(id),
glInternalFormat(glFormat),
fboImplementationInternalFormat(fboFormat),
......@@ -133,8 +159,17 @@ constexpr Format::Format(FormatID id,
stencilBits(stencilBits),
pixelBytes(pixelBytes),
componentAlignmentMask(componentAlignmentMask),
channelCount(GetChannelCount(redBits,
greenBits,
blueBits,
alphaBits,
luminanceBits,
depthBits,
stencilBits)),
isBlock(isBlock),
isFixed(isFixed)
isFixed(isFixed),
isScaled(isScaled),
vertexAttribType(vertexAttribType)
{}
constexpr bool Format::hasDepthOrStencilBits() const
......@@ -149,13 +184,7 @@ constexpr bool Format::isLUMA() const
return redBits == 0 && (luminanceBits > 0 || alphaBits > 0);
}
constexpr GLuint Format::channelCount() const
{
return (redBits > 0) + (greenBits > 0) + (blueBits > 0) + (alphaBits > 0) +
(luminanceBits > 0) + (depthBits > 0) + (stencilBits > 0);
}
constexpr bool Format::isInt() const
constexpr bool Format::isSint() const
{
return componentType == GL_INT;
}
......
......@@ -222,12 +222,7 @@ angle::Result StreamingVertexBufferInterface::reserveVertexSpace(const gl::Conte
// StaticVertexBufferInterface Implementation
StaticVertexBufferInterface::AttributeSignature::AttributeSignature()
: type(gl::VertexAttribType::InvalidEnum),
size(0),
stride(0),
normalized(false),
pureInteger(false),
offset(0)
: formatID(angle::FormatID::NONE), stride(0), offset(0)
{}
bool StaticVertexBufferInterface::AttributeSignature::matchesAttribute(
......@@ -236,8 +231,7 @@ bool StaticVertexBufferInterface::AttributeSignature::matchesAttribute(
{
size_t attribStride = ComputeVertexAttributeStride(attrib, binding);
if (type != attrib.type || size != attrib.size || static_cast<GLuint>(stride) != attribStride ||
normalized != attrib.normalized || pureInteger != attrib.pureInteger)
if (formatID != attrib.format->id || static_cast<GLuint>(stride) != attribStride)
{
return false;
}
......@@ -250,10 +244,7 @@ bool StaticVertexBufferInterface::AttributeSignature::matchesAttribute(
void StaticVertexBufferInterface::AttributeSignature::set(const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding)
{
type = attrib.type;
size = attrib.size;
normalized = attrib.normalized;
pureInteger = attrib.pureInteger;
formatID = attrib.format->id;
offset = stride = static_cast<GLuint>(ComputeVertexAttributeStride(attrib, binding));
offset = static_cast<size_t>(ComputeVertexAttributeOffset(attrib, binding)) %
ComputeVertexAttributeStride(attrib, binding);
......
......@@ -13,6 +13,7 @@
#include "common/PackedEnums.h"
#include "common/angleutils.h"
#include "libANGLE/Error.h"
#include "libANGLE/renderer/Format.h"
#include <GLES2/gl2.h>
......@@ -172,11 +173,8 @@ class StaticVertexBufferInterface : public VertexBufferInterface
void set(const gl::VertexAttribute &attrib, const gl::VertexBinding &binding);
private:
gl::VertexAttribType type;
GLuint size;
angle::FormatID formatID;
GLuint stride;
bool normalized;
bool pureInteger;
size_t offset;
};
......
......@@ -102,7 +102,7 @@ bool DirectStoragePossible(const gl::Context *context,
// TODO(jmadill): add VertexFormatCaps
BufferFactoryD3D *factory = bufferD3D->getFactory();
angle::FormatID vertexFormatID = gl::GetVertexFormatID(attrib);
angle::FormatID vertexFormatID = attrib.format->id;
// CPU-converted vertex data must be converted (naturally).
if ((factory->getVertexConversionType(vertexFormatID) & VERTEX_CONVERT_CPU) != 0)
......@@ -110,7 +110,7 @@ bool DirectStoragePossible(const gl::Context *context,
return false;
}
if (attrib.type != gl::VertexAttribType::Float)
if (attrib.format->vertexAttribType != gl::VertexAttribType::Float)
{
unsigned int elementSize = 0;
angle::Result error =
......@@ -207,7 +207,7 @@ VertexDataManager::CurrentValueState::CurrentValueState(BufferFactoryD3D *factor
data.Values.FloatValues[1] = std::numeric_limits<float>::quiet_NaN();
data.Values.FloatValues[2] = std::numeric_limits<float>::quiet_NaN();
data.Values.FloatValues[3] = std::numeric_limits<float>::quiet_NaN();
data.Type = gl::VertexAttribType::Float;
data.Type = gl::VertexAttribType::Float;
}
VertexDataManager::CurrentValueState::CurrentValueState(CurrentValueState &&other)
......
......@@ -3648,10 +3648,9 @@ angle::Result Renderer11::getVertexSpaceRequired(const gl::Context *context,
ASSERT(elementCount > 0);
angle::FormatID formatID = gl::GetVertexFormatID(attrib);
const D3D_FEATURE_LEVEL featureLevel = mRenderer11DeviceCaps.featureLevel;
const d3d11::VertexFormat &vertexFormatInfo =
d3d11::GetVertexFormatInfo(formatID, featureLevel);
d3d11::GetVertexFormatInfo(attrib.format->id, featureLevel);
const d3d11::DXGIFormatSize &dxgiFormatInfo =
d3d11::GetDXGIFormatSizeInfo(vertexFormatInfo.nativeFormat);
unsigned int elementSize = dxgiFormatInfo.pixelBytes;
......
......@@ -71,7 +71,7 @@ static constexpr rx::FastCopyFunctionMap NoCopyFunctions;
const Format gFormatInfoTable[] = {{
// clang-format off
{{ FormatID::NONE, GL_NONE, GL_NONE, nullptr, NoCopyFunctions, nullptr, nullptr, GL_NONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, false, false }},
{{ FormatID::NONE, GL_NONE, GL_NONE, nullptr, NoCopyFunctions, nullptr, nullptr, GL_NONE, 0, 0, 0, 0, 0, 0, 0, 0, 0, false, false, false, gl::VertexAttribType::InvalidEnum }},
{angle_format_info_cases} // clang-format on
}};
......@@ -183,7 +183,7 @@ def get_color_write_function(angle_format):
return 'WriteColor<' + channel_struct + ', ' + write_component_type + '>'
format_entry_template = """ {{ FormatID::{id}, {glInternalFormat}, {fboImplementationInternalFormat}, {mipGenerationFunction}, {fastCopyFunctions}, {colorReadFunction}, {colorWriteFunction}, {namedComponentType}, {R}, {G}, {B}, {A}, {L}, {D}, {S}, {pixelBytes}, {componentAlignmentMask}, {isBlock}, {isFixed} }},
format_entry_template = """ {{ FormatID::{id}, {glInternalFormat}, {fboImplementationInternalFormat}, {mipGenerationFunction}, {fastCopyFunctions}, {colorReadFunction}, {colorWriteFunction}, {namedComponentType}, {R}, {G}, {B}, {A}, {L}, {D}, {S}, {pixelBytes}, {componentAlignmentMask}, {isBlock}, {isFixed}, {isScaled}, {vertexAttribType} }},
"""
......@@ -227,6 +227,39 @@ def get_component_alignment_mask(channels, bits):
return "std::numeric_limits<GLuint>::max()"
def get_vertex_attrib_type(format_id):
has_u = "_U" in format_id
has_s = "_S" in format_id
has_float = "_FLOAT" in format_id
has_fixed = "_FIXED" in format_id
has_r8 = "R8" in format_id
has_r16 = "R16" in format_id
has_r32 = "R32" in format_id
has_r10 = "R10" in format_id
if has_fixed:
return "Fixed"
if has_float:
return "HalfFloat" if has_r16 else "Float"
if has_r8:
return "Byte" if has_s else "UnsignedByte"
if has_r10:
return "Int2101010" if has_s else "UnsignedInt2101010"
if has_r16:
return "Short" if has_s else "UnsignedShort"
if has_r32:
return "Int" if has_s else "UnsignedInt"
# Many ANGLE formats don't correspond with vertex formats.
return "InvalidEnum"
def json_to_table_data(format_id, json, angle_to_gl):
table_data = ""
......@@ -288,6 +321,9 @@ def json_to_table_data(format_id, json, angle_to_gl):
parsed["bits"])
parsed["isBlock"] = "true" if is_block else "false"
parsed["isFixed"] = "true" if "FIXED" in format_id else "false"
parsed["isScaled"] = "true" if "SCALED" in format_id else "false"
parsed["vertexAttribType"] = "gl::VertexAttribType::" + get_vertex_attrib_type(format_id)
return format_entry_template.format(**parsed)
......
......@@ -30,8 +30,7 @@ namespace
{
bool SameVertexAttribFormat(const VertexAttribute &a, const VertexAttribute &b)
{
return a.size == b.size && a.type == b.type && a.normalized == b.normalized &&
a.pureInteger == b.pureInteger && a.relativeOffset == b.relativeOffset;
return a.format == b.format && a.relativeOffset == b.relativeOffset;
}
bool SameVertexBuffer(const VertexBinding &a, const VertexBinding &b)
......@@ -460,10 +459,7 @@ void VertexArrayGL::updateAttribPointer(const gl::Context *context, size_t attri
callVertexAttribPointer(static_cast<GLuint>(attribIndex), attrib, binding.getStride(),
binding.getOffset());
mAppliedAttributes[attribIndex].size = attrib.size;
mAppliedAttributes[attribIndex].type = attrib.type;
mAppliedAttributes[attribIndex].normalized = attrib.normalized;
mAppliedAttributes[attribIndex].pureInteger = attrib.pureInteger;
mAppliedAttributes[attribIndex].format = attrib.format;
// After VertexAttribPointer, attrib.relativeOffset is set to 0 and attrib.bindingIndex is set
// to attribIndex in driver. If attrib.relativeOffset != 0 or attrib.bindingIndex !=
......@@ -482,17 +478,19 @@ void VertexArrayGL::callVertexAttribPointer(GLuint attribIndex,
GLsizei stride,
GLintptr offset) const
{
const GLvoid *pointer = reinterpret_cast<const GLvoid *>(offset);
if (attrib.pureInteger)
const GLvoid *pointer = reinterpret_cast<const GLvoid *>(offset);
const angle::Format &format = *attrib.format;
if (format.isPureInt())
{
ASSERT(!attrib.normalized);
mFunctions->vertexAttribIPointer(attribIndex, attrib.size, gl::ToGLenum(attrib.type),
stride, pointer);
ASSERT(!format.isNorm());
mFunctions->vertexAttribIPointer(attribIndex, format.channelCount,
gl::ToGLenum(format.vertexAttribType), stride, pointer);
}
else
{
mFunctions->vertexAttribPointer(attribIndex, attrib.size, gl::ToGLenum(attrib.type),
attrib.normalized, stride, pointer);
mFunctions->vertexAttribPointer(attribIndex, format.channelCount,
gl::ToGLenum(format.vertexAttribType), format.isNorm(),
stride, pointer);
}
}
......@@ -512,23 +510,22 @@ void VertexArrayGL::updateAttribFormat(size_t attribIndex)
return;
}
if (attrib.pureInteger)
const angle::Format &format = *attrib.format;
if (format.isPureInt())
{
ASSERT(!attrib.normalized);
mFunctions->vertexAttribIFormat(static_cast<GLuint>(attribIndex), attrib.size,
gl::ToGLenum(attrib.type), attrib.relativeOffset);
ASSERT(!format.isNorm());
mFunctions->vertexAttribIFormat(static_cast<GLuint>(attribIndex), format.channelCount,
gl::ToGLenum(format.vertexAttribType),
attrib.relativeOffset);
}
else
{
mFunctions->vertexAttribFormat(static_cast<GLuint>(attribIndex), attrib.size,
gl::ToGLenum(attrib.type), attrib.normalized,
mFunctions->vertexAttribFormat(static_cast<GLuint>(attribIndex), format.channelCount,
gl::ToGLenum(format.vertexAttribType), format.isNorm(),
attrib.relativeOffset);
}
mAppliedAttributes[attribIndex].size = attrib.size;
mAppliedAttributes[attribIndex].type = attrib.type;
mAppliedAttributes[attribIndex].normalized = attrib.normalized;
mAppliedAttributes[attribIndex].pureInteger = attrib.pureInteger;
mAppliedAttributes[attribIndex].format = attrib.format;
mAppliedAttributes[attribIndex].relativeOffset = attrib.relativeOffset;
}
......
......@@ -46,34 +46,43 @@ uint32_t GetBufferUtilsFlags(size_t dispatchSize, const vk::Format &format)
uint32_t flags = dispatchSize % 64 == 0 ? BufferUtils_comp::kIsAligned : 0;
const angle::Format &bufferFormat = format.bufferFormat();
flags |= bufferFormat.isInt()
? BufferUtils_comp::kIsInt
: bufferFormat.isUint() ? BufferUtils_comp::kIsUint : BufferUtils_comp::kIsFloat;
if (bufferFormat.isSint())
{
flags |= BufferUtils_comp::kIsSint;
}
else if (bufferFormat.isUint())
{
flags |= BufferUtils_comp::kIsUint;
}
else
{
flags |= BufferUtils_comp::kIsFloat;
}
return flags;
}
uint32_t GetConvertVertexFlags(const UtilsVk::ConvertVertexParameters &params)
{
bool srcIsInt = params.srcFormat->isInt();
bool srcIsSint = params.srcFormat->isSint();
bool srcIsUint = params.srcFormat->isUint();
bool srcIsSnorm = params.srcFormat->isSnorm();
bool srcIsUnorm = params.srcFormat->isUnorm();
bool srcIsFixed = params.srcFormat->isFixed;
bool srcIsFloat = params.srcFormat->isFloat();
bool destIsInt = params.destFormat->isInt();
bool destIsSint = params.destFormat->isSint();
bool destIsUint = params.destFormat->isUint();
bool destIsFloat = params.destFormat->isFloat();
// Assert on the types to make sure the shader supports its. These are based on
// ConvertVertex_comp::Conversion values.
ASSERT(!destIsInt || srcIsInt); // If destination is int, src must be int too
ASSERT(!destIsSint || srcIsSint); // If destination is sint, src must be sint too
ASSERT(!destIsUint || srcIsUint); // If destination is uint, src must be uint too
ASSERT(!srcIsFixed || destIsFloat); // If source is fixed, dest must be float
// One of each bool set must be true
ASSERT(srcIsInt || srcIsUint || srcIsSnorm || srcIsUnorm || srcIsFixed || srcIsFloat);
ASSERT(destIsInt || destIsUint || destIsFloat);
ASSERT(srcIsSint || srcIsUint || srcIsSnorm || srcIsUnorm || srcIsFixed || srcIsFloat);
ASSERT(destIsSint || destIsUint || destIsFloat);
// We currently don't have any big-endian devices in the list of supported platforms. The
// shader is capable of supporting big-endian architectures, but the relevant flag (IsBigEndian)
......@@ -86,17 +95,17 @@ uint32_t GetConvertVertexFlags(const UtilsVk::ConvertVertexParameters &params)
uint32_t flags = 0;
if (srcIsInt && destIsInt)
if (srcIsSint && destIsSint)
{
flags |= ConvertVertex_comp::kIntToInt;
flags |= ConvertVertex_comp::kSintToSint;
}
else if (srcIsUint && destIsUint)
{
flags |= ConvertVertex_comp::kUintToUint;
}
else if (srcIsInt)
else if (srcIsSint)
{
flags |= ConvertVertex_comp::kIntToFloat;
flags |= ConvertVertex_comp::kSintToFloat;
}
else if (srcIsUint)
{
......@@ -139,9 +148,18 @@ uint32_t GetImageClearFlags(const angle::Format &format, uint32_t attachmentInde
uint32_t flags = ImageClear_frag::kAttachment0 + attachmentIndex * kAttachmentFlagStep;
flags |= format.isInt()
? ImageClear_frag::kIsInt
: format.isUint() ? ImageClear_frag::kIsUint : ImageClear_frag::kIsFloat;
if (format.isSint())
{
flags |= ImageClear_frag::kIsSint;
}
else if (format.isUint())
{
flags |= ImageClear_frag::kIsUint;
}
else
{
flags |= ImageClear_frag::kIsFloat;
}
return flags;
}
......@@ -151,7 +169,7 @@ uint32_t GetFormatFlags(const angle::Format &format,
uint32_t uintFlag,
uint32_t floatFlag)
{
if (format.isInt())
if (format.isSint())
{
return intFlag;
}
......@@ -169,9 +187,9 @@ uint32_t GetImageCopyFlags(const vk::Format &srcFormat, const vk::Format &destFo
uint32_t flags = 0;
flags |= GetFormatFlags(srcAngleFormat, ImageCopy_frag::kSrcIsInt, ImageCopy_frag::kSrcIsUint,
flags |= GetFormatFlags(srcAngleFormat, ImageCopy_frag::kSrcIsSint, ImageCopy_frag::kSrcIsUint,
ImageCopy_frag::kSrcIsFloat);
flags |= GetFormatFlags(destAngleFormat, ImageCopy_frag::kDestIsInt,
flags |= GetFormatFlags(destAngleFormat, ImageCopy_frag::kDestIsSint,
ImageCopy_frag::kDestIsUint, ImageCopy_frag::kDestIsFloat);
return flags;
......@@ -688,11 +706,11 @@ angle::Result UtilsVk::convertVertexBuffer(ContextVk *contextVk,
dest->onWrite(contextVk, VK_ACCESS_SHADER_WRITE_BIT);
ConvertVertexShaderParams shaderParams;
shaderParams.Ns = params.srcFormat->channelCount();
shaderParams.Bs = params.srcFormat->pixelBytes / params.srcFormat->channelCount();
shaderParams.Ns = params.srcFormat->channelCount;
shaderParams.Bs = params.srcFormat->pixelBytes / params.srcFormat->channelCount;
shaderParams.Ss = params.srcStride;
shaderParams.Nd = params.destFormat->channelCount();
shaderParams.Bd = params.destFormat->pixelBytes / params.destFormat->channelCount();
shaderParams.Nd = params.destFormat->channelCount;
shaderParams.Bd = params.destFormat->pixelBytes / params.destFormat->channelCount;
shaderParams.Sd = shaderParams.Nd * shaderParams.Bd;
// The component size is expected to either be 1, 2 or 4 bytes.
ASSERT(4 % shaderParams.Bs == 0);
......
......@@ -238,7 +238,7 @@ angle::Result VertexArrayVk::convertVertexBufferGPU(ContextVk *contextVk,
const angle::Format &srcFormat = vertexFormat.angleFormat();
const angle::Format &destFormat = vertexFormat.bufferFormat();
ASSERT(binding.getStride() % (srcFormat.pixelBytes / srcFormat.channelCount()) == 0);
ASSERT(binding.getStride() % (srcFormat.pixelBytes / srcFormat.channelCount) == 0);
unsigned srcFormatSize = srcFormat.pixelBytes;
unsigned destFormatSize = destFormat.pixelBytes;
......@@ -438,14 +438,15 @@ angle::Result VertexArrayVk::syncDirtyAttrib(ContextVk *contextVk,
if (attrib.enabled)
{
gl::Buffer *bufferGL = binding.getBuffer().get();
const vk::Format &vertexFormat = renderer->getFormat(GetVertexFormatID(attrib));
const vk::Format &vertexFormat = renderer->getFormat(attrib.format->id);
GLuint stride;
if (bufferGL)
{
BufferVk *bufferVk = vk::GetImpl(bufferGL);
const angle::Format &angleFormat = vertexFormat.angleFormat();
bool bindingIsAligned = BindingIsAligned(binding, angleFormat, attrib.size);
bool bindingIsAligned =
BindingIsAligned(binding, angleFormat, angleFormat.channelCount);
if (vertexFormat.vertexLoadRequiresConversion || !bindingIsAligned)
{
......@@ -556,7 +557,7 @@ angle::Result VertexArrayVk::updateClientAttribs(const gl::Context *context,
const gl::VertexBinding &binding = bindings[attrib.bindingIndex];
ASSERT(attrib.enabled && binding.getBuffer().get() == nullptr);
const vk::Format &vertexFormat = renderer->getFormat(GetVertexFormatID(attrib));
const vk::Format &vertexFormat = renderer->getFormat(attrib.format->id);
GLuint stride = vertexFormat.bufferFormat().pixelBytes;
ASSERT(GetVertexInputAlignment(vertexFormat) <= vk::kVertexBufferAlignment);
......
......@@ -12,7 +12,7 @@
// need for bound checking
// - Format:
// * IsFloat
// * IsInt
// * IsSint
// * IsUint
// - Function:
// * IsClear: the buffer will be cleared
......@@ -27,7 +27,7 @@ layout (local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
#define ADD_TYPE_PREFIX(type) type
#define BUFFER_FORMAT rgba32f
#define GVEC4 vec4
#elif IsInt
#elif IsSint
#define ADD_TYPE_PREFIX(type) i ## type
#define BUFFER_FORMAT rgba32i
#define GVEC4 ivec4
......
......@@ -11,7 +11,7 @@
],
"Format": [
"IsFloat",
"IsInt",
"IsSint",
"IsUint"
],
"Function": [
......
......@@ -37,18 +37,18 @@
// need for bound checking.
// * IsBigEndian
// - Conversion:
// * IntToInt: covers byte, short and int types (distinguished by Bs and Bd).
// * SintToSint: covers byte, short and int types (distinguished by Bs and Bd).
// * UintToUint: covers ubyte, ushort and uint types (distinguished by Bs and Bd).
// * IntToFloat: Same types as IntToInt for source (including scaled). Converts to float.
// * SintToFloat: Same types as SintToSint for source (including scaled). Converts to float.
// * UintToFloat: Same types as UintToUint for source (including uscaled). Converst to float.
// * SnormToFloat: Similar to IntToFloat, but normalized.
// * UnormToFloat: Similar to UintToFloat, but normalized.
// * FixedToFloat: 16.16 signed fixed-point to floating point.
// * FloatToFloat: float.
//
// IntToInt, UintToUint and FloatToFloat correspond to CopyNativeVertexData() and
// SintToSint, UintToUint and FloatToFloat correspond to CopyNativeVertexData() and
// Copy8SintTo16SintVertexData() in renderer/copyvertex.inc, FixedToFloat corresponds to
// Copy32FixedTo32FVertexData, IntToFloat and UintToFloat correspond to CopyTo32FVertexData with
// Copy32FixedTo32FVertexData, SintToFloat and UintToFloat correspond to CopyTo32FVertexData with
// normalized=false and SnormToFloat and UnormToFloat correspond to CopyTo32FVertexData with
// normalized=true.
//
......@@ -56,7 +56,7 @@
#version 450 core
// Source type
#if IntToInt || IntToFloat
#if SintToSint || SintToFloat
#define SrcType int
#elif UintToUint || UintToFloat
#define SrcType uint
......@@ -67,13 +67,13 @@
#endif
// Destination type
#if IntToInt
#if SintToSint
#define DestType int
#define IsDestFloat 0
#elif UintToUint
#define DestType uint
#define IsDestFloat 0
#elif IntToFloat || UintToFloat || SnormToFloat || UnormToFloat || FixedToFloat || FloatToFloat
#elif SintToFloat || UintToFloat || SnormToFloat || UnormToFloat || FixedToFloat || FloatToFloat
#define DestType float
#define IsDestFloat 1
#else
......@@ -206,7 +206,7 @@ SrcType loadSourceComponent(uint cd)
uint valueAsUint = (block >> shiftBits) & valueMask;
// Convert to SrcType
#if IntToInt || IntToFloat
#if SintToSint || SintToFloat
bool isNegative = (valueAsUint & (1 << (valueBits - 1))) != 0;
// Sign extend
SrcType value = SrcType(valueAsUint | (isNegative ? 0xFFFFFFFF << valueBits : 0));
......@@ -244,7 +244,7 @@ uint makeDestinationComponent(uint cd, DestType value)
// Return valueAsUint, shifted to the right spot. Multiple calls to this function should be |ed
// and eventually written to the destination.
#if IntToInt || UintToUint
#if SintToSint || UintToUint
uint vertex = cd / Nd;
uint component = cd % Nd;
......
......@@ -10,9 +10,9 @@
"IsAligned"
],
"Conversion": [
"IntToInt",
"SintToSint",
"UintToUint",
"IntToFloat",
"SintToFloat",
"UintToFloat",
"SnormToFloat",
"UnormToFloat",
......
......@@ -9,7 +9,7 @@
#if IsFloat
#define Type vec4
#elif IsInt
#elif IsSint
#define Type ivec4
#elif IsUint
#define Type uvec4
......
......@@ -18,7 +18,7 @@
],
"Format": [
"IsFloat",
"IsInt",
"IsSint",
"IsUint"
]
}
......@@ -14,7 +14,7 @@
#if SrcIsFloat
#define SRC_RESOURCE(type) type
#define SrcType vec4
#elif SrcIsInt
#elif SrcIsSint
#define SRC_RESOURCE(type) MAKE_SRC_RESOURCE(i, type)
#define SrcType ivec4
#elif SrcIsUint
......@@ -32,7 +32,7 @@
#if DestIsFloat
#define DestType vec4
#elif DestIsInt
#elif DestIsSint
#define DestType ivec4
#elif DestIsUint
#define DestType uvec4
......
......@@ -11,12 +11,12 @@
],
"SrcFormat": [
"SrcIsFloat",
"SrcIsInt",
"SrcIsSint",
"SrcIsUint"
],
"DestFormat": [
"DestIsFloat",
"DestIsInt",
"DestIsSint",
"DestIsUint"
]
}
......
......@@ -108,7 +108,7 @@ void Format::initImageFallback(RendererVk *renderer, const ImageFormatInitInfo *
size_t skip = renderer->getFeatures().forceFallbackFormat.enabled ? 1 : 0;
SupportTest testFunction = HasFullTextureFormatSupport;
const angle::Format &format = angle::Format::Get(info[0].format);
if (format.isInt() || format.isUint() || (format.isFloat() && format.redBits >= 32))
if (format.isInt() || (format.isFloat() && format.redBits >= 32))
{
// Integer formats don't support filtering in GL, so don't test for it.
// Filtering of 32-bit float textures is not supported on Android, and
......@@ -303,7 +303,7 @@ size_t GetVertexInputAlignment(const vk::Format &format)
{
const angle::Format &bufferFormat = format.bufferFormat();
size_t pixelBytes = bufferFormat.pixelBytes;
return format.vkBufferFormatIsPacked ? pixelBytes : (pixelBytes / bufferFormat.channelCount());
return format.vkBufferFormatIsPacked ? pixelBytes : (pixelBytes / bufferFormat.channelCount);
}
GLenum GetSwizzleStateComponent(const gl::SwizzleState &swizzleState, GLenum component)
......
......@@ -62,7 +62,7 @@ enum Function
enum Format
{
kIsFloat = 0x00000000,
kIsInt = 0x00000004,
kIsSint = 0x00000004,
kIsUint = 0x00000008,
};
constexpr size_t kArrayLen = 0x0000000C;
......@@ -85,9 +85,9 @@ enum flags
};
enum Conversion
{
kIntToInt = 0x00000000,
kSintToSint = 0x00000000,
kUintToUint = 0x00000002,
kIntToFloat = 0x00000004,
kSintToFloat = 0x00000004,
kUintToFloat = 0x00000006,
kSnormToFloat = 0x00000008,
kUnormToFloat = 0x0000000A,
......@@ -118,7 +118,7 @@ enum AttachmentIndex
enum Format
{
kIsFloat = 0x00000000,
kIsInt = 0x00000008,
kIsSint = 0x00000008,
kIsUint = 0x00000010,
};
constexpr size_t kArrayLen = 0x00000018;
......@@ -133,13 +133,13 @@ enum flags
enum SrcFormat
{
kSrcIsFloat = 0x00000000,
kSrcIsInt = 0x00000002,
kSrcIsSint = 0x00000002,
kSrcIsUint = 0x00000004,
};
enum DestFormat
{
kDestIsFloat = 0x00000000,
kDestIsInt = 0x00000008,
kDestIsSint = 0x00000008,
kDestIsUint = 0x00000010,
};
constexpr size_t kArrayLen = 0x00000016;
......
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