Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/metal/mtl_texture.mm
| Show First 20 Lines • Show All 716 Lines • ▼ Show 20 Lines | switch (type_) { | ||||
| id<MTLComputePipelineState> pso = texture_update_1d_get_kernel( | id<MTLComputePipelineState> pso = texture_update_1d_get_kernel( | ||||
| compute_specialization_kernel); | compute_specialization_kernel); | ||||
| TextureUpdateParams params = {mip, | TextureUpdateParams params = {mip, | ||||
| {extent[0], 1, 1}, | {extent[0], 1, 1}, | ||||
| {offset[0], 0, 0}, | {offset[0], 0, 0}, | ||||
| ((ctx->pipeline_state.unpack_row_length == 0) ? | ((ctx->pipeline_state.unpack_row_length == 0) ? | ||||
| extent[0] : | extent[0] : | ||||
| ctx->pipeline_state.unpack_row_length)}; | ctx->pipeline_state.unpack_row_length)}; | ||||
| [compute_encoder setComputePipelineState:pso]; | |||||
| [compute_encoder setBytes:¶ms length:sizeof(params) atIndex:0]; | /* Bind resources via compute state for optimal state caching performance. */ | ||||
| [compute_encoder setBuffer:staging_buffer offset:staging_buffer_offset atIndex:1]; | MTLComputeState &cs = ctx->main_command_buffer.get_compute_state(); | ||||
| [compute_encoder setTexture:texture_handle atIndex:0]; | cs.bind_pso(pso); | ||||
| cs.bind_compute_bytes(¶ms, sizeof(params), 0); | |||||
| cs.bind_compute_buffer(staging_buffer, staging_buffer_offset, 1); | |||||
| cs.bind_compute_texture(texture_handle, 0); | |||||
| [compute_encoder | [compute_encoder | ||||
| dispatchThreads:MTLSizeMake(extent[0], 1, 1) /* Width, Height, Layer */ | dispatchThreads:MTLSizeMake(extent[0], 1, 1) /* Width, Height, Layer */ | ||||
| threadsPerThreadgroup:MTLSizeMake(64, 1, 1)]; | threadsPerThreadgroup:MTLSizeMake(64, 1, 1)]; | ||||
| } | } | ||||
| else if (type_ == GPU_TEXTURE_1D_ARRAY) { | else if (type_ == GPU_TEXTURE_1D_ARRAY) { | ||||
| id<MTLComputePipelineState> pso = texture_update_1d_array_get_kernel( | id<MTLComputePipelineState> pso = texture_update_1d_array_get_kernel( | ||||
| compute_specialization_kernel); | compute_specialization_kernel); | ||||
| TextureUpdateParams params = {mip, | TextureUpdateParams params = {mip, | ||||
| {extent[0], extent[1], 1}, | {extent[0], extent[1], 1}, | ||||
| {offset[0], offset[1], 0}, | {offset[0], offset[1], 0}, | ||||
| ((ctx->pipeline_state.unpack_row_length == 0) ? | ((ctx->pipeline_state.unpack_row_length == 0) ? | ||||
| extent[0] : | extent[0] : | ||||
| ctx->pipeline_state.unpack_row_length)}; | ctx->pipeline_state.unpack_row_length)}; | ||||
| [compute_encoder setComputePipelineState:pso]; | |||||
| [compute_encoder setBytes:¶ms length:sizeof(params) atIndex:0]; | /* Bind resources via compute state for optimal state caching performance. */ | ||||
| [compute_encoder setBuffer:staging_buffer offset:staging_buffer_offset atIndex:1]; | MTLComputeState &cs = ctx->main_command_buffer.get_compute_state(); | ||||
| [compute_encoder setTexture:texture_handle atIndex:0]; | cs.bind_pso(pso); | ||||
| cs.bind_compute_bytes(¶ms, sizeof(params), 0); | |||||
| cs.bind_compute_buffer(staging_buffer, staging_buffer_offset, 1); | |||||
| cs.bind_compute_texture(texture_handle, 0); | |||||
| [compute_encoder | [compute_encoder | ||||
| dispatchThreads:MTLSizeMake(extent[0], extent[1], 1) /* Width, layers, nil */ | dispatchThreads:MTLSizeMake(extent[0], extent[1], 1) /* Width, layers, nil */ | ||||
| threadsPerThreadgroup:MTLSizeMake(8, 8, 1)]; | threadsPerThreadgroup:MTLSizeMake(8, 8, 1)]; | ||||
| } | } | ||||
| } | } | ||||
| } break; | } break; | ||||
| /* 2D */ | /* 2D */ | ||||
| Show All 37 Lines | switch (type_) { | ||||
| id<MTLComputePipelineState> pso = texture_update_2d_get_kernel( | id<MTLComputePipelineState> pso = texture_update_2d_get_kernel( | ||||
| compute_specialization_kernel); | compute_specialization_kernel); | ||||
| TextureUpdateParams params = {mip, | TextureUpdateParams params = {mip, | ||||
| {extent[0], extent[1], 1}, | {extent[0], extent[1], 1}, | ||||
| {offset[0], offset[1], 0}, | {offset[0], offset[1], 0}, | ||||
| ((ctx->pipeline_state.unpack_row_length == 0) ? | ((ctx->pipeline_state.unpack_row_length == 0) ? | ||||
| extent[0] : | extent[0] : | ||||
| ctx->pipeline_state.unpack_row_length)}; | ctx->pipeline_state.unpack_row_length)}; | ||||
| [compute_encoder setComputePipelineState:pso]; | |||||
| [compute_encoder setBytes:¶ms length:sizeof(params) atIndex:0]; | /* Bind resources via compute state for optimal state caching performance. */ | ||||
| [compute_encoder setBuffer:staging_buffer offset:staging_buffer_offset atIndex:1]; | MTLComputeState &cs = ctx->main_command_buffer.get_compute_state(); | ||||
| [compute_encoder setTexture:texture_handle atIndex:0]; | cs.bind_pso(pso); | ||||
| cs.bind_compute_bytes(¶ms, sizeof(params), 0); | |||||
| cs.bind_compute_buffer(staging_buffer, staging_buffer_offset, 1); | |||||
| cs.bind_compute_texture(texture_handle, 0); | |||||
| [compute_encoder | [compute_encoder | ||||
| dispatchThreads:MTLSizeMake( | dispatchThreads:MTLSizeMake( | ||||
| extent[0], extent[1], 1) /* Width, Height, Layer */ | extent[0], extent[1], 1) /* Width, Height, Layer */ | ||||
| threadsPerThreadgroup:MTLSizeMake(8, 8, 1)]; | threadsPerThreadgroup:MTLSizeMake(8, 8, 1)]; | ||||
| } | } | ||||
| else if (type_ == GPU_TEXTURE_2D_ARRAY) { | else if (type_ == GPU_TEXTURE_2D_ARRAY) { | ||||
| id<MTLComputePipelineState> pso = texture_update_2d_array_get_kernel( | id<MTLComputePipelineState> pso = texture_update_2d_array_get_kernel( | ||||
| compute_specialization_kernel); | compute_specialization_kernel); | ||||
| TextureUpdateParams params = {mip, | TextureUpdateParams params = {mip, | ||||
| {extent[0], extent[1], extent[2]}, | {extent[0], extent[1], extent[2]}, | ||||
| {offset[0], offset[1], offset[2]}, | {offset[0], offset[1], offset[2]}, | ||||
| ((ctx->pipeline_state.unpack_row_length == 0) ? | ((ctx->pipeline_state.unpack_row_length == 0) ? | ||||
| extent[0] : | extent[0] : | ||||
| ctx->pipeline_state.unpack_row_length)}; | ctx->pipeline_state.unpack_row_length)}; | ||||
| [compute_encoder setComputePipelineState:pso]; | |||||
| [compute_encoder setBytes:¶ms length:sizeof(params) atIndex:0]; | /* Bind resources via compute state for optimal state caching performance. */ | ||||
| [compute_encoder setBuffer:staging_buffer offset:staging_buffer_offset atIndex:1]; | MTLComputeState &cs = ctx->main_command_buffer.get_compute_state(); | ||||
| [compute_encoder setTexture:texture_handle atIndex:0]; | cs.bind_pso(pso); | ||||
| cs.bind_compute_bytes(¶ms, sizeof(params), 0); | |||||
| cs.bind_compute_buffer(staging_buffer, staging_buffer_offset, 1); | |||||
| cs.bind_compute_texture(texture_handle, 0); | |||||
| [compute_encoder dispatchThreads:MTLSizeMake(extent[0], | [compute_encoder dispatchThreads:MTLSizeMake(extent[0], | ||||
| extent[1], | extent[1], | ||||
| extent[2]) /* Width, Height, Layer */ | extent[2]) /* Width, Height, Layer */ | ||||
| threadsPerThreadgroup:MTLSizeMake(4, 4, 4)]; | threadsPerThreadgroup:MTLSizeMake(4, 4, 4)]; | ||||
| } | } | ||||
| } | } | ||||
| } break; | } break; | ||||
| Show All 20 Lines | switch (type_) { | ||||
| id<MTLComputePipelineState> pso = texture_update_3d_get_kernel( | id<MTLComputePipelineState> pso = texture_update_3d_get_kernel( | ||||
| compute_specialization_kernel); | compute_specialization_kernel); | ||||
| TextureUpdateParams params = {mip, | TextureUpdateParams params = {mip, | ||||
| {extent[0], extent[1], extent[2]}, | {extent[0], extent[1], extent[2]}, | ||||
| {offset[0], offset[1], offset[2]}, | {offset[0], offset[1], offset[2]}, | ||||
| ((ctx->pipeline_state.unpack_row_length == 0) ? | ((ctx->pipeline_state.unpack_row_length == 0) ? | ||||
| extent[0] : | extent[0] : | ||||
| ctx->pipeline_state.unpack_row_length)}; | ctx->pipeline_state.unpack_row_length)}; | ||||
| [compute_encoder setComputePipelineState:pso]; | |||||
| [compute_encoder setBytes:¶ms length:sizeof(params) atIndex:0]; | /* Bind resources via compute state for optimal state caching performance. */ | ||||
| [compute_encoder setBuffer:staging_buffer offset:staging_buffer_offset atIndex:1]; | MTLComputeState &cs = ctx->main_command_buffer.get_compute_state(); | ||||
| [compute_encoder setTexture:texture_handle atIndex:0]; | cs.bind_pso(pso); | ||||
| cs.bind_compute_bytes(¶ms, sizeof(params), 0); | |||||
| cs.bind_compute_buffer(staging_buffer, staging_buffer_offset, 1); | |||||
| cs.bind_compute_texture(texture_handle, 0); | |||||
| [compute_encoder | [compute_encoder | ||||
| dispatchThreads:MTLSizeMake( | dispatchThreads:MTLSizeMake( | ||||
| extent[0], extent[1], extent[2]) /* Width, Height, Depth */ | extent[0], extent[1], extent[2]) /* Width, Height, Depth */ | ||||
| threadsPerThreadgroup:MTLSizeMake(4, 4, 4)]; | threadsPerThreadgroup:MTLSizeMake(4, 4, 4)]; | ||||
| } | } | ||||
| } break; | } break; | ||||
| /* CUBE */ | /* CUBE */ | ||||
| ▲ Show 20 Lines • Show All 647 Lines • ▼ Show 20 Lines | switch (type_) { | ||||
| ctx->main_command_buffer.ensure_begin_compute_encoder(); | ctx->main_command_buffer.ensure_begin_compute_encoder(); | ||||
| id<MTLComputePipelineState> pso = texture_read_2d_get_kernel( | id<MTLComputePipelineState> pso = texture_read_2d_get_kernel( | ||||
| compute_specialization_kernel); | compute_specialization_kernel); | ||||
| TextureReadParams params = { | TextureReadParams params = { | ||||
| mip, | mip, | ||||
| {width, height, 1}, | {width, height, 1}, | ||||
| {x_off, y_off, 0}, | {x_off, y_off, 0}, | ||||
| }; | }; | ||||
| [compute_encoder setComputePipelineState:pso]; | |||||
| [compute_encoder setBytes:¶ms length:sizeof(params) atIndex:0]; | /* Bind resources via compute state for optimal state caching performance. */ | ||||
| [compute_encoder setBuffer:destination_buffer offset:0 atIndex:1]; | MTLComputeState &cs = ctx->main_command_buffer.get_compute_state(); | ||||
| [compute_encoder setTexture:read_texture atIndex:0]; | cs.bind_pso(pso); | ||||
| cs.bind_compute_bytes(¶ms, sizeof(params), 0); | |||||
| cs.bind_compute_buffer(destination_buffer, 0, 1); | |||||
| cs.bind_compute_texture(read_texture, 0); | |||||
| [compute_encoder dispatchThreads:MTLSizeMake(width, height, 1) /* Width, Height, Layer */ | [compute_encoder dispatchThreads:MTLSizeMake(width, height, 1) /* Width, Height, Layer */ | ||||
| threadsPerThreadgroup:MTLSizeMake(8, 8, 1)]; | threadsPerThreadgroup:MTLSizeMake(8, 8, 1)]; | ||||
| copy_successful = true; | copy_successful = true; | ||||
| } | } | ||||
| } break; | } break; | ||||
| case GPU_TEXTURE_2D_ARRAY: { | case GPU_TEXTURE_2D_ARRAY: { | ||||
| if (can_use_simple_read) { | if (can_use_simple_read) { | ||||
| Show All 27 Lines | switch (type_) { | ||||
| ctx->main_command_buffer.ensure_begin_compute_encoder(); | ctx->main_command_buffer.ensure_begin_compute_encoder(); | ||||
| id<MTLComputePipelineState> pso = texture_read_2d_array_get_kernel( | id<MTLComputePipelineState> pso = texture_read_2d_array_get_kernel( | ||||
| compute_specialization_kernel); | compute_specialization_kernel); | ||||
| TextureReadParams params = { | TextureReadParams params = { | ||||
| mip, | mip, | ||||
| {width, height, depth}, | {width, height, depth}, | ||||
| {x_off, y_off, z_off}, | {x_off, y_off, z_off}, | ||||
| }; | }; | ||||
| [compute_encoder setComputePipelineState:pso]; | |||||
| [compute_encoder setBytes:¶ms length:sizeof(params) atIndex:0]; | /* Bind resources via compute state for optimal state caching performance. */ | ||||
| [compute_encoder setBuffer:destination_buffer offset:0 atIndex:1]; | MTLComputeState &cs = ctx->main_command_buffer.get_compute_state(); | ||||
| [compute_encoder setTexture:read_texture atIndex:0]; | cs.bind_pso(pso); | ||||
| cs.bind_compute_bytes(¶ms, sizeof(params), 0); | |||||
| cs.bind_compute_buffer(destination_buffer, 0, 1); | |||||
| cs.bind_compute_texture(read_texture, 0); | |||||
| [compute_encoder | [compute_encoder | ||||
| dispatchThreads:MTLSizeMake(width, height, depth) /* Width, Height, Layer */ | dispatchThreads:MTLSizeMake(width, height, depth) /* Width, Height, Layer */ | ||||
| threadsPerThreadgroup:MTLSizeMake(8, 8, 1)]; | threadsPerThreadgroup:MTLSizeMake(8, 8, 1)]; | ||||
| copy_successful = true; | copy_successful = true; | ||||
| } | } | ||||
| } break; | } break; | ||||
| case GPU_TEXTURE_CUBE_ARRAY: { | case GPU_TEXTURE_CUBE_ARRAY: { | ||||
| ▲ Show 20 Lines • Show All 556 Lines • Show Last 20 Lines | |||||