Commit 3c00eee2 by Le Hoang Quyen Committed by Commit Bot

Metal: Use bit fields for state descriptor caching.

This reduces size of state descriptors and increase hashing performance. Bug: angleproject:2634 Change-Id: Ida1a17a4fb30a053dafc82a3f7501b448e16e818 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2192570 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 3e1e1087
......@@ -28,24 +28,26 @@ class ContextMtl;
namespace mtl
{
struct StencilDesc
struct alignas(1) StencilDesc
{
bool operator==(const StencilDesc &rhs) const;
// Set default values
void reset();
MTLStencilOperation stencilFailureOperation;
MTLStencilOperation depthFailureOperation;
MTLStencilOperation depthStencilPassOperation;
// Use uint8_t instead of MTLStencilOperation to compact space
uint8_t stencilFailureOperation : 3;
uint8_t depthFailureOperation : 3;
uint8_t depthStencilPassOperation : 3;
MTLCompareFunction stencilCompareFunction;
// Use uint8_t instead of MTLCompareFunction to compact space
uint8_t stencilCompareFunction : 3;
uint32_t readMask;
uint32_t writeMask;
uint8_t readMask : 8;
uint8_t writeMask : 8;
};
struct DepthStencilDesc
struct alignas(4) DepthStencilDesc
{
DepthStencilDesc();
DepthStencilDesc(const DepthStencilDesc &src);
......@@ -75,11 +77,12 @@ struct DepthStencilDesc
StencilDesc backFaceStencil;
StencilDesc frontFaceStencil;
MTLCompareFunction depthCompareFunction;
bool depthWriteEnabled;
// Use uint8_t instead of MTLCompareFunction to compact space
uint8_t depthCompareFunction : 3;
bool depthWriteEnabled : 1;
};
struct SamplerDesc
struct alignas(4) SamplerDesc
{
SamplerDesc();
SamplerDesc(const SamplerDesc &src);
......@@ -96,15 +99,17 @@ struct SamplerDesc
size_t hash() const;
MTLSamplerAddressMode rAddressMode;
MTLSamplerAddressMode sAddressMode;
MTLSamplerAddressMode tAddressMode;
// Use uint8_t instead of MTLSamplerAddressMode to compact space
uint8_t rAddressMode : 3;
uint8_t sAddressMode : 3;
uint8_t tAddressMode : 3;
MTLSamplerMinMagFilter minFilter;
MTLSamplerMinMagFilter magFilter;
MTLSamplerMipFilter mipFilter;
// Use uint8_t instead of MTLSamplerMinMagFilter to compact space
uint8_t minFilter : 1;
uint8_t magFilter : 1;
uint8_t mipFilter : 2;
uint32_t maxAnisotropy;
uint8_t maxAnisotropy : 5;
};
struct VertexAttributeDesc
......@@ -114,9 +119,12 @@ struct VertexAttributeDesc
return format == rhs.format && offset == rhs.offset && bufferIndex == rhs.bufferIndex;
}
inline bool operator!=(const VertexAttributeDesc &rhs) const { return !(*this == rhs); }
MTLVertexFormat format;
NSUInteger offset;
NSUInteger bufferIndex;
// Use uint8_t instead of MTLVertexFormat to compact space
uint8_t format : 6;
// Offset is only used for default attributes buffer. So 8 bits are enough.
uint8_t offset : 8;
uint8_t bufferIndex : 5;
};
struct VertexBufferLayoutDesc
......@@ -127,9 +135,11 @@ struct VertexBufferLayoutDesc
}
inline bool operator!=(const VertexBufferLayoutDesc &rhs) const { return !(*this == rhs); }
MTLVertexStepFunction stepFunction;
NSUInteger stepRate;
NSUInteger stride;
uint32_t stepRate;
uint32_t stride;
// Use uint8_t instead of MTLVertexStepFunction to compact space
uint8_t stepFunction;
};
struct VertexDesc
......@@ -155,20 +165,24 @@ struct BlendDesc
void updateBlendOps(const gl::BlendState &blendState);
void updateBlendEnabled(const gl::BlendState &blendState);
MTLColorWriteMask writeMask;
// Use uint8_t instead of MTLColorWriteMask to compact space
uint8_t writeMask : 4;
MTLBlendOperation alphaBlendOperation;
MTLBlendOperation rgbBlendOperation;
// Use uint8_t instead of MTLBlendOperation to compact space
uint8_t alphaBlendOperation : 3;
uint8_t rgbBlendOperation : 3;
MTLBlendFactor destinationAlphaBlendFactor;
MTLBlendFactor destinationRGBBlendFactor;
MTLBlendFactor sourceAlphaBlendFactor;
MTLBlendFactor sourceRGBBlendFactor;
// Use uint8_t instead of MTLBlendFactor to compact space
// NOTE(hqle): enum MTLBlendFactorSource1Color and above are unused.
uint8_t destinationAlphaBlendFactor : 4;
uint8_t destinationRGBBlendFactor : 4;
uint8_t sourceAlphaBlendFactor : 4;
uint8_t sourceRGBBlendFactor : 4;
bool blendingEnabled;
bool blendingEnabled : 1;
};
struct RenderPipelineColorAttachmentDesc : public BlendDesc
struct alignas(2) RenderPipelineColorAttachmentDesc : public BlendDesc
{
bool operator==(const RenderPipelineColorAttachmentDesc &rhs) const;
inline bool operator!=(const RenderPipelineColorAttachmentDesc &rhs) const
......@@ -184,7 +198,8 @@ struct RenderPipelineColorAttachmentDesc : public BlendDesc
void update(const BlendDesc &blendState);
MTLPixelFormat pixelFormat;
// Use uint16_t instead of MTLPixelFormat to compact space
uint16_t pixelFormat : 16;
};
struct RenderPipelineOutputDesc
......@@ -192,10 +207,13 @@ struct RenderPipelineOutputDesc
bool operator==(const RenderPipelineOutputDesc &rhs) const;
RenderPipelineColorAttachmentDesc colorAttachments[kMaxRenderTargets];
MTLPixelFormat depthAttachmentPixelFormat;
MTLPixelFormat stencilAttachmentPixelFormat;
uint8_t numColorAttachments;
// Use uint16_t instead of MTLPixelFormat to compact space
uint16_t depthAttachmentPixelFormat : 16;
uint16_t stencilAttachmentPixelFormat : 16;
static_assert(kMaxRenderTargets <= 4, "kMaxRenderTargets must be <= 4");
uint8_t numColorAttachments : 3;
};
// Some SDK levels don't declare MTLPrimitiveTopologyClass. Needs to do compile time check here:
......@@ -212,7 +230,7 @@ constexpr PrimitiveTopologyClass kPrimitiveTopologyClassTriangle =
constexpr PrimitiveTopologyClass kPrimitiveTopologyClassPoint = MTLPrimitiveTopologyClassPoint;
#endif
struct RenderPipelineDesc
struct alignas(4) RenderPipelineDesc
{
RenderPipelineDesc();
RenderPipelineDesc(const RenderPipelineDesc &src);
......@@ -228,7 +246,8 @@ struct RenderPipelineDesc
RenderPipelineOutputDesc outputDescriptor;
PrimitiveTopologyClass inputPrimitiveTopology;
// Use uint8_t instead of PrimitiveTopologyClass to compact space.
uint8_t inputPrimitiveTopology : 2;
bool rasterizationEnabled;
};
......
......@@ -18,7 +18,8 @@
#include "libANGLE/renderer/metal/mtl_resources.h"
#include "libANGLE/renderer/metal/mtl_utils.h"
#define ANGLE_OBJC_CP_PROPERTY(DST, SRC, PROPERTY) (DST).PROPERTY = ToObjC((SRC).PROPERTY)
#define ANGLE_OBJC_CP_PROPERTY(DST, SRC, PROPERTY) \
(DST).PROPERTY = static_cast<__typeof__((DST).PROPERTY)>(ToObjC((SRC).PROPERTY))
#define ANGLE_PROP_EQ(LHS, RHS, PROP) ((LHS).PROP == (RHS).PROP)
......
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