| 170 | } |
| 171 | |
| 172 | void SkrImageUploadTask::from_image(const SkrImageData& image) |
| 173 | { |
| 174 | _image_data = image; |
| 175 | |
| 176 | SkrZoneScopedN("CreateGUITexture(VRAMService)"); |
| 177 | |
| 178 | auto vram_service = _render_device->vram_service(); |
| 179 | auto request = vram_service->open_texture_request(); |
| 180 | const auto& pixel_data = _image_data.pixel_data(); |
| 181 | CGPUTextureDescriptor tdesc = {}; |
| 182 | tdesc.descriptors = CGPU_RESOURCE_TYPE_TEXTURE; |
| 183 | tdesc.depth = _image_data.image_depth(); |
| 184 | tdesc.height = _image_data.size().height; |
| 185 | tdesc.width = _image_data.size().width; |
| 186 | tdesc.format = _image_data.cgpu_format(); |
| 187 | request->set_transfer_queue(_render_device->cgpu_queue()); |
| 188 | request->set_memory_src(pixel_data->get_data(), pixel_data->get_size()); |
| 189 | request->set_texture(_render_device->cgpu_device(), &tdesc); |
| 190 | request->add_callback(SKR_IO_STAGE_COMPLETED, +[](skr_io_future_t* future, skr_io_request_t* request, void* usrdata) { |
| 191 | auto task = static_cast<SkrImageUploadTask*>(usrdata); |
| 192 | |
| 193 | auto device = task->_render_device->cgpu_device(); |
| 194 | const auto& image_data = task->_image_data; |
| 195 | |
| 196 | task->_texture = task->_vram_destination->get_texture(); |
| 197 | CGPUTextureViewDescriptor view_desc = {}; |
| 198 | view_desc.texture = task->_texture; |
| 199 | view_desc.format = image_data.cgpu_format(); |
| 200 | view_desc.array_layer_count = 1; |
| 201 | view_desc.base_array_layer = 0; |
| 202 | view_desc.mip_level_count = 1; |
| 203 | view_desc.base_mip_level = 0; |
| 204 | view_desc.aspects = CGPU_TVA_COLOR; |
| 205 | view_desc.dims = CGPU_TEX_DIMENSION_2D; |
| 206 | view_desc.usages = CGPU_TVU_SRV; |
| 207 | task->_texture_view = cgpu_create_texture_view(device, &view_desc); |
| 208 | |
| 209 | const char8_t* color_texture_name = u8"color_texture"; |
| 210 | CGPUXBindTableDescriptor bind_table_desc = {}; |
| 211 | bind_table_desc.root_signature = task->_root_signature; |
| 212 | bind_table_desc.names = &color_texture_name; |
| 213 | bind_table_desc.names_count = 1; |
| 214 | task->_bind_table = cgpux_create_bind_table(device, &bind_table_desc); |
| 215 | auto data = make_zeroed<CGPUDescriptorData>(); |
| 216 | data.name = color_texture_name; |
| 217 | data.count = 1; |
| 218 | data.binding_type = CGPU_RESOURCE_TYPE_TEXTURE; |
| 219 | data.textures = &task->_texture_view; |
| 220 | cgpux_bind_table_update(task->_bind_table, &data, 1); |
| 221 | |
| 222 | skr_atomicu32_store_release(&task->_async_is_okey, 1); |
| 223 | }, this); |
| 224 | _vram_destination = vram_service->request(request, &_ram_request); |
| 225 | } |
| 226 | |
| 227 | } // namespace skr::gui |
nothing calls this directly
no test coverage detected