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; ...@@ -28,24 +28,26 @@ class ContextMtl;
namespace mtl namespace mtl
{ {
struct StencilDesc struct alignas(1) StencilDesc
{ {
bool operator==(const StencilDesc &rhs) const; bool operator==(const StencilDesc &rhs) const;
// Set default values // Set default values
void reset(); void reset();
MTLStencilOperation stencilFailureOperation; // Use uint8_t instead of MTLStencilOperation to compact space
MTLStencilOperation depthFailureOperation; uint8_t stencilFailureOperation : 3;
MTLStencilOperation depthStencilPassOperation; 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; uint8_t readMask : 8;
uint32_t writeMask; uint8_t writeMask : 8;
}; };
struct DepthStencilDesc struct alignas(4) DepthStencilDesc
{ {
DepthStencilDesc(); DepthStencilDesc();
DepthStencilDesc(const DepthStencilDesc &src); DepthStencilDesc(const DepthStencilDesc &src);
...@@ -75,11 +77,12 @@ struct DepthStencilDesc ...@@ -75,11 +77,12 @@ struct DepthStencilDesc
StencilDesc backFaceStencil; StencilDesc backFaceStencil;
StencilDesc frontFaceStencil; StencilDesc frontFaceStencil;
MTLCompareFunction depthCompareFunction; // Use uint8_t instead of MTLCompareFunction to compact space
bool depthWriteEnabled; uint8_t depthCompareFunction : 3;
bool depthWriteEnabled : 1;
}; };
struct SamplerDesc struct alignas(4) SamplerDesc
{ {
SamplerDesc(); SamplerDesc();
SamplerDesc(const SamplerDesc &src); SamplerDesc(const SamplerDesc &src);
...@@ -96,15 +99,17 @@ struct SamplerDesc ...@@ -96,15 +99,17 @@ struct SamplerDesc
size_t hash() const; size_t hash() const;
MTLSamplerAddressMode rAddressMode; // Use uint8_t instead of MTLSamplerAddressMode to compact space
MTLSamplerAddressMode sAddressMode; uint8_t rAddressMode : 3;
MTLSamplerAddressMode tAddressMode; uint8_t sAddressMode : 3;
uint8_t tAddressMode : 3;
MTLSamplerMinMagFilter minFilter; // Use uint8_t instead of MTLSamplerMinMagFilter to compact space
MTLSamplerMinMagFilter magFilter; uint8_t minFilter : 1;
MTLSamplerMipFilter mipFilter; uint8_t magFilter : 1;
uint8_t mipFilter : 2;
uint32_t maxAnisotropy; uint8_t maxAnisotropy : 5;
}; };
struct VertexAttributeDesc struct VertexAttributeDesc
...@@ -114,9 +119,12 @@ struct VertexAttributeDesc ...@@ -114,9 +119,12 @@ struct VertexAttributeDesc
return format == rhs.format && offset == rhs.offset && bufferIndex == rhs.bufferIndex; return format == rhs.format && offset == rhs.offset && bufferIndex == rhs.bufferIndex;
} }
inline bool operator!=(const VertexAttributeDesc &rhs) const { return !(*this == rhs); } inline bool operator!=(const VertexAttributeDesc &rhs) const { return !(*this == rhs); }
MTLVertexFormat format;
NSUInteger offset; // Use uint8_t instead of MTLVertexFormat to compact space
NSUInteger bufferIndex; 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 struct VertexBufferLayoutDesc
...@@ -127,9 +135,11 @@ struct VertexBufferLayoutDesc ...@@ -127,9 +135,11 @@ struct VertexBufferLayoutDesc
} }
inline bool operator!=(const VertexBufferLayoutDesc &rhs) const { return !(*this == rhs); } inline bool operator!=(const VertexBufferLayoutDesc &rhs) const { return !(*this == rhs); }
MTLVertexStepFunction stepFunction; uint32_t stepRate;
NSUInteger stepRate; uint32_t stride;
NSUInteger stride;
// Use uint8_t instead of MTLVertexStepFunction to compact space
uint8_t stepFunction;
}; };
struct VertexDesc struct VertexDesc
...@@ -155,20 +165,24 @@ struct BlendDesc ...@@ -155,20 +165,24 @@ struct BlendDesc
void updateBlendOps(const gl::BlendState &blendState); void updateBlendOps(const gl::BlendState &blendState);
void updateBlendEnabled(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; // Use uint8_t instead of MTLBlendOperation to compact space
MTLBlendOperation rgbBlendOperation; uint8_t alphaBlendOperation : 3;
uint8_t rgbBlendOperation : 3;
MTLBlendFactor destinationAlphaBlendFactor; // Use uint8_t instead of MTLBlendFactor to compact space
MTLBlendFactor destinationRGBBlendFactor; // NOTE(hqle): enum MTLBlendFactorSource1Color and above are unused.
MTLBlendFactor sourceAlphaBlendFactor; uint8_t destinationAlphaBlendFactor : 4;
MTLBlendFactor sourceRGBBlendFactor; 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; bool operator==(const RenderPipelineColorAttachmentDesc &rhs) const;
inline bool operator!=(const RenderPipelineColorAttachmentDesc &rhs) const inline bool operator!=(const RenderPipelineColorAttachmentDesc &rhs) const
...@@ -184,7 +198,8 @@ struct RenderPipelineColorAttachmentDesc : public BlendDesc ...@@ -184,7 +198,8 @@ struct RenderPipelineColorAttachmentDesc : public BlendDesc
void update(const BlendDesc &blendState); void update(const BlendDesc &blendState);
MTLPixelFormat pixelFormat; // Use uint16_t instead of MTLPixelFormat to compact space
uint16_t pixelFormat : 16;
}; };
struct RenderPipelineOutputDesc struct RenderPipelineOutputDesc
...@@ -192,10 +207,13 @@ struct RenderPipelineOutputDesc ...@@ -192,10 +207,13 @@ struct RenderPipelineOutputDesc
bool operator==(const RenderPipelineOutputDesc &rhs) const; bool operator==(const RenderPipelineOutputDesc &rhs) const;
RenderPipelineColorAttachmentDesc colorAttachments[kMaxRenderTargets]; 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: // Some SDK levels don't declare MTLPrimitiveTopologyClass. Needs to do compile time check here:
...@@ -212,7 +230,7 @@ constexpr PrimitiveTopologyClass kPrimitiveTopologyClassTriangle = ...@@ -212,7 +230,7 @@ constexpr PrimitiveTopologyClass kPrimitiveTopologyClassTriangle =
constexpr PrimitiveTopologyClass kPrimitiveTopologyClassPoint = MTLPrimitiveTopologyClassPoint; constexpr PrimitiveTopologyClass kPrimitiveTopologyClassPoint = MTLPrimitiveTopologyClassPoint;
#endif #endif
struct RenderPipelineDesc struct alignas(4) RenderPipelineDesc
{ {
RenderPipelineDesc(); RenderPipelineDesc();
RenderPipelineDesc(const RenderPipelineDesc &src); RenderPipelineDesc(const RenderPipelineDesc &src);
...@@ -228,7 +246,8 @@ struct RenderPipelineDesc ...@@ -228,7 +246,8 @@ struct RenderPipelineDesc
RenderPipelineOutputDesc outputDescriptor; RenderPipelineOutputDesc outputDescriptor;
PrimitiveTopologyClass inputPrimitiveTopology; // Use uint8_t instead of PrimitiveTopologyClass to compact space.
uint8_t inputPrimitiveTopology : 2;
bool rasterizationEnabled; bool rasterizationEnabled;
}; };
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
#include "libANGLE/renderer/metal/mtl_resources.h" #include "libANGLE/renderer/metal/mtl_resources.h"
#include "libANGLE/renderer/metal/mtl_utils.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) #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