2014 snapchat source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.1 KiB

  1. //
  2. // SCNightModeEnhancementMetalRenderCommand.m
  3. // Snapchat
  4. //
  5. // Created by Chao Pang on 12/21/17.
  6. //
  7. #import "SCNightModeEnhancementMetalRenderCommand.h"
  8. #import "SCCameraTweaks.h"
  9. #import "SCMetalUtils.h"
  10. #import <SCFoundation/NSString+SCFormat.h>
  11. @import Metal;
  12. @implementation SCNightModeEnhancementMetalRenderCommand
  13. #pragma mark - SCMetalRenderCommand
  14. - (id<MTLComputeCommandEncoder>)encodeMetalCommand:(id<MTLCommandBuffer>)commandBuffer
  15. pipelineState:(id<MTLComputePipelineState>)pipelineState
  16. textureResource:(SCMetalTextureResource *)textureResource
  17. {
  18. id<MTLComputeCommandEncoder> commandEncoder = [commandBuffer computeCommandEncoder];
  19. [commandEncoder setComputePipelineState:pipelineState];
  20. #if !TARGET_IPHONE_SIMULATOR
  21. SampleBufferMetadata sampleBufferMetadata = {
  22. .isoSpeedRating = textureResource.sampleBufferMetadata.isoSpeedRating,
  23. .exposureTime = textureResource.sampleBufferMetadata.exposureTime,
  24. .brightness = textureResource.sampleBufferMetadata.brightness,
  25. };
  26. id<MTLBuffer> metadataBuffer = [textureResource.device newBufferWithLength:sizeof(SampleBufferMetadata)
  27. options:MTLResourceOptionCPUCacheModeDefault];
  28. memcpy(metadataBuffer.contents, &sampleBufferMetadata, sizeof(SampleBufferMetadata));
  29. [commandEncoder setTexture:textureResource.sourceYTexture atIndex:0];
  30. [commandEncoder setTexture:textureResource.sourceUVTexture atIndex:1];
  31. [commandEncoder setTexture:textureResource.destinationYTexture atIndex:2];
  32. [commandEncoder setTexture:textureResource.destinationUVTexture atIndex:3];
  33. [commandEncoder setBuffer:metadataBuffer offset:0 atIndex:0];
  34. #endif
  35. return commandEncoder;
  36. }
  37. #pragma mark - SCMetalModuleFunctionProvider
  38. - (NSString *)functionName
  39. {
  40. return @"kernel_night_mode_enhancement";
  41. }
  42. - (BOOL)requiresDepthData
  43. {
  44. return NO;
  45. }
  46. - (NSString *)description
  47. {
  48. return [NSString
  49. sc_stringWithFormat:@"SCNightModeEnhancementMetalRenderCommand (shader function = %@)", self.functionName];
  50. }
  51. @end