Skip to content

Commit 14ac1c1

Browse files
author
GH Action
committed
1 parent a9db3a2 commit 14ac1c1

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/sokol/c/sokol_gfx.h

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11437,12 +11437,15 @@ _SOKOL_PRIVATE void _sg_d3d11_append_buffer(_sg_buffer_t* buf, const sg_range* d
1143711437
}
1143811438
}
1143911439

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
1144011442
_SOKOL_PRIVATE void _sg_d3d11_update_image(_sg_image_t* img, const sg_image_data* data) {
1144111443
SOKOL_ASSERT(img && data);
1144211444
SOKOL_ASSERT(_sg.d3d11.ctx);
1144311445
SOKOL_ASSERT(img->d3d11.res);
1144411446
const int num_faces = (img->cmn.type == SG_IMAGETYPE_CUBE) ? 6:1;
1144511447
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;
1144611449
UINT subres_index = 0;
1144711450
HRESULT hr;
1144811451
D3D11_MAPPED_SUBRESOURCE d3d11_msr;
@@ -11452,26 +11455,35 @@ _SOKOL_PRIVATE void _sg_d3d11_update_image(_sg_image_t* img, const sg_image_data
1145211455
SOKOL_ASSERT(subres_index < (SG_MAX_MIPMAPS * SG_MAX_TEXTUREARRAY_LAYERS));
1145311456
const int mip_width = _sg_miplevel_dim(img->cmn.width, mip_index);
1145411457
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);
1145611460
const sg_range* subimg_data = &(data->subimage[face_index][mip_index]);
1145711461
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));
1145811463
const size_t slice_offset = slice_size * (size_t)slice_index;
1145911464
const uint8_t* slice_ptr = ((const uint8_t*)subimg_data->ptr) + slice_offset;
1146011465
hr = _sg_d3d11_Map(_sg.d3d11.ctx, img->d3d11.res, subres_index, D3D11_MAP_WRITE_DISCARD, 0, &d3d11_msr);
1146111466
_sg_stats_add(d3d11.num_map, 1);
1146211467
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+
}
1147411484
}
11485+
src_ptr += src_depth_pitch;
11486+
dst_ptr += d3d11_msr.DepthPitch;
1147511487
}
1147611488
_sg_d3d11_Unmap(_sg.d3d11.ctx, img->d3d11.res, subres_index);
1147711489
_sg_stats_add(d3d11.num_unmap, 1);

0 commit comments

Comments
 (0)