@@ -11437,12 +11437,15 @@ _SOKOL_PRIVATE void _sg_d3d11_append_buffer(_sg_buffer_t* buf, const sg_range* d
11437
11437
}
11438
11438
}
11439
11439
11440
+ // see: https://learn.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-resources-subresources
11441
+ // also see: https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-d3d11calcsubresource
11440
11442
_SOKOL_PRIVATE void _sg_d3d11_update_image(_sg_image_t* img, const sg_image_data* data) {
11441
11443
SOKOL_ASSERT(img && data);
11442
11444
SOKOL_ASSERT(_sg.d3d11.ctx);
11443
11445
SOKOL_ASSERT(img->d3d11.res);
11444
11446
const int num_faces = (img->cmn.type == SG_IMAGETYPE_CUBE) ? 6:1;
11445
11447
const int num_slices = (img->cmn.type == SG_IMAGETYPE_ARRAY) ? img->cmn.num_slices:1;
11448
+ const int num_depth_slices = (img->cmn.type == SG_IMAGETYPE_3D) ? img->cmn.num_slices:1;
11446
11449
UINT subres_index = 0;
11447
11450
HRESULT hr;
11448
11451
D3D11_MAPPED_SUBRESOURCE d3d11_msr;
@@ -11452,26 +11455,35 @@ _SOKOL_PRIVATE void _sg_d3d11_update_image(_sg_image_t* img, const sg_image_data
11452
11455
SOKOL_ASSERT(subres_index < (SG_MAX_MIPMAPS * SG_MAX_TEXTUREARRAY_LAYERS));
11453
11456
const int mip_width = _sg_miplevel_dim(img->cmn.width, mip_index);
11454
11457
const int mip_height = _sg_miplevel_dim(img->cmn.height, mip_index);
11455
- const int src_pitch = _sg_row_pitch(img->cmn.pixel_format, mip_width, 1);
11458
+ const int src_row_pitch = _sg_row_pitch(img->cmn.pixel_format, mip_width, 1);
11459
+ const int src_depth_pitch = _sg_surface_pitch(img->cmn.pixel_format, mip_width, mip_height, 1);
11456
11460
const sg_range* subimg_data = &(data->subimage[face_index][mip_index]);
11457
11461
const size_t slice_size = subimg_data->size / (size_t)num_slices;
11462
+ SOKOL_ASSERT(slice_size == (size_t)(src_depth_pitch * num_depth_slices));
11458
11463
const size_t slice_offset = slice_size * (size_t)slice_index;
11459
11464
const uint8_t* slice_ptr = ((const uint8_t*)subimg_data->ptr) + slice_offset;
11460
11465
hr = _sg_d3d11_Map(_sg.d3d11.ctx, img->d3d11.res, subres_index, D3D11_MAP_WRITE_DISCARD, 0, &d3d11_msr);
11461
11466
_sg_stats_add(d3d11.num_map, 1);
11462
11467
if (SUCCEEDED(hr)) {
11463
- // FIXME: need to handle difference in depth-pitch for 3D textures as well!
11464
- if (src_pitch == (int)d3d11_msr.RowPitch) {
11465
- memcpy(d3d11_msr.pData, slice_ptr, slice_size);
11466
- } else {
11467
- SOKOL_ASSERT(src_pitch < (int)d3d11_msr.RowPitch);
11468
- const uint8_t* src_ptr = slice_ptr;
11469
- uint8_t* dst_ptr = (uint8_t*) d3d11_msr.pData;
11470
- for (int row_index = 0; row_index < mip_height; row_index++) {
11471
- memcpy(dst_ptr, src_ptr, (size_t)src_pitch);
11472
- src_ptr += src_pitch;
11473
- dst_ptr += d3d11_msr.RowPitch;
11468
+ const uint8_t* src_ptr = slice_ptr;
11469
+ uint8_t* dst_ptr = (uint8_t*)d3d11_msr.pData;
11470
+ for (int depth_index = 0; depth_index < num_depth_slices; depth_index++) {
11471
+ if (src_row_pitch == (int)d3d11_msr.RowPitch) {
11472
+ const size_t copy_size = slice_size / (size_t)num_depth_slices;
11473
+ SOKOL_ASSERT((copy_size * (size_t)num_depth_slices) == slice_size);
11474
+ memcpy(dst_ptr, src_ptr, copy_size);
11475
+ } else {
11476
+ SOKOL_ASSERT(src_row_pitch < (int)d3d11_msr.RowPitch);
11477
+ const uint8_t* src_row_ptr = src_ptr;
11478
+ uint8_t* dst_row_ptr = dst_ptr;
11479
+ for (int row_index = 0; row_index < mip_height; row_index++) {
11480
+ memcpy(dst_row_ptr, src_row_ptr, (size_t)src_row_pitch);
11481
+ src_row_ptr += src_row_pitch;
11482
+ dst_row_ptr += d3d11_msr.RowPitch;
11483
+ }
11474
11484
}
11485
+ src_ptr += src_depth_pitch;
11486
+ dst_ptr += d3d11_msr.DepthPitch;
11475
11487
}
11476
11488
_sg_d3d11_Unmap(_sg.d3d11.ctx, img->d3d11.res, subres_index);
11477
11489
_sg_stats_add(d3d11.num_unmap, 1);
0 commit comments