MTLBuffer를 정의하고 데이터를 버퍼에 직접 채울 수 (또는 가능한 효율적으로)하고 싶습니다.만든 후 MTLBuffer 값 변경
다음을 수행하면 셰이더에서 사용되는 값은 MTLBuffer
을 만든 후에 설정되는 3.0 및 4.0이 아닌 1.0 및 2.0 (각각 X 및 Y)입니다. 나는 선택을 인식하지 않는 것 didModifyRange:
하지만 pointDataBuffer
를 호출 할 필요가 같은
int bufferLength = 128 * 128;
float pointBuffer[bufferLength * 2]; // 2 for X and Y
//Populate array with test values
for (int i = 0; i < (bufferLength * 2); i += 2) {
pointBuffer[i] = 1.0; //X
pointBuffer[i + 1] = 2.0; //Y
}
id<MTLBuffer> pointDataBuffer = [device newBufferWithBytes:&pointBuffer length:sizeof(pointBuffer) options:MTLResourceOptionCPUCacheModeDefault];
//Populate array with updated test values
for (int i = 0; i < (bufferLength * 2); i += 2) {
pointBuffer[i] = 3.0; //X
pointBuffer[i + 1] = 4.0; //Y
}
//In the (Swift) class with the pipeline:
commandEncoder!.setBuffer(pointDataBuffer, offset: 0, index: 4)
는 문서를 기반으로 보인다.
MTLBuffer를 다시 만들지 않고 배열을 업데이트 할 수있는 방법이 있습니까?