Skip to content

Instantly share code, notes, and snippets.

View lukaszmargielewski's full-sized avatar

Lukasz Margielewski lukaszmargielewski

View GitHub Profile
@lukaszmargielewski
lukaszmargielewski / gist:0a3b16d4661dd7d7e00d
Last active March 11, 2021 15:04
iOS Metal client side code for compute pipeline
// For stackoverflow question:
// http://stackoverflow.com/questions/30445801/ios8-metal-compute-pipeline-slower-than-cpu
// I. CODE INVOKED ONCE, AT THE INIT STAGE:
_mtlCharTable = [_mtlDevice newBufferWithBytes:_charTable->pointer length:_charTable->bytesTotal options:0];
_mtlSearchMasks = [_mtlDevice newBufferWithBytesNoCopy:_searchIndexes.mask length:_searchIndexes.bytesTotalMask options:0 deallocator:nil];
//iPhone 6: maxTotalThreadsPerThreadgroup: 512, threadExecutionWidth: 32
uint threadsPerThreadGroup = [_mtlComputePipelineState maxTotalThreadsPerThreadgroup];// / 4.0;
protocol AProtocol {}
protocol ABProtocol: AProtocol {}
struct ABStruct: ABProtocol {}
struct Wrapper<T> {
let object: T
}
@lukaszmargielewski
lukaszmargielewski / gist:1a799cab758938e16781
Created October 7, 2015 11:33
UITableView height auto
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath isOffscreen:YES];
cell.bounds = CGRectMake(0.0f, 0.0f, CGRectGetWidth(tableView.bounds), 10000);
[cell updateConstraintsIfNeeded];
[cell layoutIfNeeded];
CGFloat heightText = cell.shows_lower_panel ? CGRectGetMaxY(cell.countImageView.frame) : MAX(CGRectGetMaxY(cell.circleImageView.frame), CGRectGetMaxY(ccc.titleLabel.frame));
@lukaszmargielewski
lukaszmargielewski / gist:6b64d06d2d106d110126
Last active August 29, 2015 14:22
iOS Metal shader searching text naive
#include <metal_stdlib>
using namespace metal;
// Every kernel processes 1 row of the char table:
kernel void lmCharSearch(
const device char *charTable [[ buffer(0) ]],
constant uint &charsInRow [[ buffer(1) ]],
constant uint &rowCount [[ buffer(2) ]],
const device char *searchPhrase [[ buffer(3) ]],