Created
May 19, 2018 16:35
-
-
Save dnevera/53eb8d24ed722d3a4a58dc44d60d4f6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Установка областей чтения семплов | |
public var centers:[float2] = [float2]() { | |
didSet{ | |
if centers.count > 0 { | |
// создать MTL-буфер из которого будем читать центры областей в шейдере | |
centersBuffer = context.device.makeBuffer(length: MemoryLayout<float2>.size * centers.count, options: [])! | |
// создаем MTL-буфер в который будем писать значения цветов в шейдере | |
colorsBuffer = context.device.makeBuffer(length: MemoryLayout<float3>.size * centers.count, options: .storageModeShared)! | |
// пишем в буфер центры | |
memcpy(centersBuffer.contents(), centers, centersBuffer.length) | |
// выделяем память массив цветов, в который потом скопируем то что прилетело | |
// в буфер в шейдере | |
_colors = [float3](repeating:float3(0), count:centers.count) | |
// определим размерность грида вычислений GPU | |
patchColorsKernel.preferedDimension = MTLSize(width: centers.count, height: 1, depth: 1) | |
// сбросим фильтр | |
dirty = true | |
// запустим вычисления на шейдерах | |
process() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment