카테고리 없음
Metal const, device, constant
newpolaris
2019. 1. 19. 11:24
The resource is stored in memory only accessible to the GPU. In iOS and tvOS, the resource is stored in system memory. In macOS, the resource is stored in video memory.
http://metalkit.org/2017/04/30/working-with-memory-in-metal.html
// Create a vertex buffer by allocating storage that can be read by the GPU
_vertexBuffer = [_device newBufferWithLength:vertexData.length
options:MTLResourceStorageModeShared];
// Copy the vertex data into the vertex buffer by accessing a pointer via
// the buffer's `contents` property
memcpy(_vertexBuffer.contents, vertexData.bytes, vertexData.length);
vertexShader(uint vertexID [[vertex_id]],
constant AAPLVertex *vertices [[ buffer(AAPLVertexInputIndexVertices) ]],
constant vector_uint2 *viewportSizePointer [[buffer(AAPLVertexInputIndexViewportSize)]])
아래와 같이 수정하면 정상적으로 나온다
device const AAPLVertex *vertices [[buffer(AAPLVertexInputIndexVertices) ]],
https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf
SPEC 상에도 별 내용 없네;
row / col 늘릴 때 생기는거 보니 일정량 이상일 때 문제되는 듯;
아래와 같이 써도 마찬가지;
_vertexBuffer = [device newBufferWithBytes:vertices.data()
length:sizeof(Vertex) * vertices.size()
options:MTLResourceStorageModeManaged];