Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/MetalPetal/MetalPetal
Browse files Browse the repository at this point in the history
  • Loading branch information
YuAo committed Feb 11, 2019
2 parents bc85373 + 65c2128 commit 1eede3d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
8 changes: 4 additions & 4 deletions Frameworks/MetalPetal/MTIFunctionDescriptor.m
Expand Up @@ -11,7 +11,7 @@

@interface MTIFunctionDescriptor ()

@property (nonatomic, readonly) NSUInteger hashValue;
@property (nonatomic, readonly) NSUInteger cachedHashValue;

@end

Expand All @@ -30,7 +30,7 @@ - (instancetype)initWithName:(NSString *)name libraryURL:( NSURL * _Nullable )UR
MTIHasher hasher = MTIHasherMake(0);
MTIHasherCombine(&hasher, _name.hash);
MTIHasherCombine(&hasher, _libraryURL.hash);
_hashValue = MTIHasherFinalize(&hasher);
_cachedHashValue = MTIHasherFinalize(&hasher);
}
return self;
}
Expand All @@ -45,7 +45,7 @@ - (instancetype)initWithName:(NSString *)name constantValues:(MTLFunctionConstan
MTIHasherCombine(&hasher, _name.hash);
MTIHasherCombine(&hasher, _libraryURL.hash);
MTIHasherCombine(&hasher, _constantValues.hash);
_hashValue = MTIHasherFinalize(&hasher);
_cachedHashValue = MTIHasherFinalize(&hasher);
}
return self;
}
Expand Down Expand Up @@ -77,7 +77,7 @@ - (BOOL)isEqual:(id)object {
}

- (NSUInteger)hash {
return _hashValue;
return _cachedHashValue;
}

- (id)copyWithZone:(NSZone *)zone {
Expand Down
9 changes: 7 additions & 2 deletions Frameworks/MetalPetal/MTIImageRenderingContext.mm
Expand Up @@ -21,6 +21,7 @@
#include <unordered_map>
#include <vector>
#include <memory>
#include <cstdint>

namespace MTIImageRendering {
struct ObjcPointerIdentityEqual {
Expand All @@ -29,8 +30,12 @@ bool operator()(const id s1, const id s2) const {
}
};
struct ObjcPointerHash {
size_t operator()(const id s1) const {
return (size_t)s1;
size_t operator()(const id pointer) const {
auto addr = reinterpret_cast<uintptr_t>(pointer);
#if SIZE_MAX < UINTPTR_MAX
addr %= SIZE_MAX; /* truncate the address so it is small enough to fit in a size_t */
#endif
return addr;
}
};
};
Expand Down
6 changes: 3 additions & 3 deletions Frameworks/MetalPetal/MTISamplerDescriptor.m
Expand Up @@ -12,7 +12,7 @@ @interface MTISamplerDescriptor ()

@property (nonatomic,copy) MTLSamplerDescriptor *metalSamplerDescriptor;

@property (nonatomic, readonly) NSUInteger hashValue;
@property (nonatomic, readonly) NSUInteger cachedHashValue;

@end

Expand All @@ -21,7 +21,7 @@ @implementation MTISamplerDescriptor
- (instancetype)initWithMTLSamplerDescriptor:(MTLSamplerDescriptor *)samplerDescriptor {
if (self = [super init]) {
_metalSamplerDescriptor = [samplerDescriptor copy];
_hashValue = [samplerDescriptor hash];
_cachedHashValue = [samplerDescriptor hash];
}
return self;
}
Expand All @@ -45,7 +45,7 @@ - (BOOL)isEqual:(id)object {
}

- (NSUInteger)hash {
return _hashValue;
return _cachedHashValue;
}

+ (MTISamplerDescriptor *)defaultSamplerDescriptor {
Expand Down
10 changes: 5 additions & 5 deletions Frameworks/MetalPetal/MTITextureDescriptor.m
Expand Up @@ -12,7 +12,7 @@ @interface MTITextureDescriptor ()

@property (nonatomic,copy) MTLTextureDescriptor *metalTextureDescriptor;

@property (nonatomic,readonly) NSUInteger hashValue;
@property (nonatomic,readonly) NSUInteger cachedHashValue;

@end

Expand All @@ -23,7 +23,7 @@ - (instancetype)initWithPixelFormat:(MTLPixelFormat)pixelFormat width:(NSUIntege
MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:pixelFormat width:width height:height mipmapped:mipmapped];
textureDescriptor.usage = usage;
_metalTextureDescriptor = textureDescriptor;
_hashValue = [textureDescriptor hash];
_cachedHashValue = [textureDescriptor hash];
}
return self;
}
Expand All @@ -34,15 +34,15 @@ - (instancetype)initWithPixelFormat:(MTLPixelFormat)pixelFormat width:(NSUIntege
textureDescriptor.usage = usage;
textureDescriptor.resourceOptions = resourceOptions;
_metalTextureDescriptor = textureDescriptor;
_hashValue = [textureDescriptor hash];
_cachedHashValue = [textureDescriptor hash];
}
return self;
}

- (instancetype)initWithMTLTextureDescriptor:(MTLTextureDescriptor *)textureDescriptor {
if (self = [super init]) {
_metalTextureDescriptor = [textureDescriptor copy];
_hashValue = [textureDescriptor hash];
_cachedHashValue = [textureDescriptor hash];
}
return self;
}
Expand Down Expand Up @@ -74,7 +74,7 @@ - (BOOL)isEqual:(id)object {
}

- (NSUInteger)hash {
return _hashValue;
return _cachedHashValue;
}

- (MTLTextureType)textureType {
Expand Down

0 comments on commit 1eede3d

Please sign in to comment.