3131
3232#include "RadientTypes.h"
3333#include "RadientAssetResolver.h"
34+ #include "RadientDataBlob.h"
3435
3536#include "../../../DiligentCore/Primitives/interface/Object.h"
3637
@@ -284,14 +285,6 @@ struct RadientMeshAssetDesc
284285typedef struct RadientMeshAssetDesc RadientMeshAssetDesc ;
285286
286287
287- /// Texture load attributes.
288- /// Optional callback used to release memory passed through RadientTextureLoadInfo::pData or
289- /// RadientTextureLoadInfo::pTextureData->pData.
290- /// The callback is invoked when Radient no longer needs the source memory.
291- /// The callback may be invoked from any thread.
292- /// The callback must not throw exceptions.
293- typedef void (* RadientTextureReleaseDataCallbackType )(const void * pData , Uint64 DataSize , void * pUserData );
294-
295288/// Texture format.
296289DILIGENT_TYPED_ENUM (RADIENT_TEXTURE_FORMAT , Uint8 ){
297290 /// Unknown format.
@@ -381,27 +374,45 @@ DILIGENT_TYPED_ENUM(RADIENT_TEXTURE_FORMAT, Uint8){
381374 /// Four 32-bit floating-point components.
382375 RADIENT_TEXTURE_FORMAT_RGBA32_FLOAT };
383376
384- /// Texture source data.
377+ /// Decoded mip 0 data for a 2D texture. The descriptor is copied by LoadTexture .
385378struct RadientTextureData
386379{
387- /// Texture width in pixels.
380+ /// Texture width in pixels. Must be nonzero; defaults to zero.
388381 Uint32 Width DEFAULT_INITIALIZER (0 );
389382
390- /// Texture height in pixels.
383+ /// Texture height in pixels. Must be nonzero; defaults to zero.
391384 Uint32 Height DEFAULT_INITIALIZER (0 );
392385
393- /// Texture format.
386+ /// Pixel format. Must not be RADIENT_TEXTURE_FORMAT_UNKNOWN, which is the default .
394387 RADIENT_TEXTURE_FORMAT Format DEFAULT_INITIALIZER (RADIENT_TEXTURE_FORMAT_UNKNOWN );
395388
396- /// Pointer to mip 0 pixel data.
397- const void * pData DEFAULT_INITIALIZER (nullptr );
389+ /// Required blob containing mip 0 pixel data, starting at byte zero.
390+ /// Accepts read-only or mutable blobs. Its size must cover every active source row:
391+ /// (Height - 1) * effective stride + active row size. The effective stride is Stride
392+ /// when nonzero, otherwise the active row size derived from Format and Width.
393+ /// The final row does not require trailing padding; extra bytes are ignored.
394+ /// The read pointer must be aligned to the format's component size (1, 2, or 4 bytes).
395+ /// Insufficient size or component misalignment returns RADIENT_STATUS_INVALID_ARGUMENT.
396+ /// LoadTexture retains the blob and acquires read access before returning, then
397+ /// consumes the pixels directly without copying or repacking the source rows.
398+ /// Read access lasts while loading or upload preparation references these pixels.
399+ /// Other readers are allowed; writes and resizing remain blocked until all readers
400+ /// finish. An active writer causes LoadTexture to return RADIENT_STATUS_INVALID_OPERATION.
401+ /// The caller may release its blob reference after LoadTexture returns. For REFERENCE
402+ /// storage, the bytes remain alive and unchanged for the blob's entire lifetime;
403+ /// RadientDataBlobCreateInfo::OnDestroy can release their owner. Last-reader callbacks
404+ /// may run during LoadTexture or later on a worker thread; they do not indicate GPU
405+ /// upload completion. Defaults to nullptr, which is invalid for decoded texture input.
406+ IRadientDataBlob * pDataBlob DEFAULT_INITIALIZER (nullptr );
398407
399408 /// Row stride, in bytes. If zero, Radient derives tightly packed stride from Format and Width.
400- /// Stride must be at least the active row size.
409+ /// Stride must be at least the active row size and, when Height is greater than one,
410+ /// a multiple of the format's component size, so each row remains component-aligned.
401411 Uint32 Stride DEFAULT_INITIALIZER (0 );
402412};
403413typedef struct RadientTextureData RadientTextureData ;
404414
415+ /// Texture load attributes. Selects encoded bytes, decoded pixels, or a URI source.
405416struct RadientTextureLoadInfo
406417{
407418 /// Source URI. For memory-backed textures, this is optional and may be used as the texture identity
@@ -412,31 +423,31 @@ struct RadientTextureLoadInfo
412423 /// value by the active asset resolver.
413424 const Char * BaseURI DEFAULT_INITIALIZER (nullptr );
414425
415- /// Optional pointer to encoded texture data.
416- const void * pData DEFAULT_INITIALIZER (nullptr );
417-
418- /// Size of the encoded texture data, in bytes.
419- Uint64 DataSize DEFAULT_INITIALIZER (0 );
420-
421- /// Optional pointer to texture data. Only 2D texture data is currently supported.
422- /// Mip 0 data must be provided; Radient always generates mip levels.
426+ /// Optional blob containing the complete encoded texture, starting at byte zero.
427+ /// Accepts read-only or mutable blobs. The blob must be non-empty and its size must fit in size_t.
428+ /// Mutually exclusive with pTextureData. Radient retains the blob and acquires read access during
429+ /// LoadTexture(), before returning. The data pointer and size are checked within this read scope.
430+ /// The encoded bytes are consumed directly; LoadTexture() does not copy them.
431+ /// Read access remains active until Radient no longer needs the source bytes, including any
432+ /// decoder references used during upload preparation. The caller may release its blob reference
433+ /// after LoadTexture() returns. For REFERENCE storage, the caller keeps the referenced bytes alive
434+ /// and unchanged throughout the blob's lifetime; OnDestroy can release their owner. Other readers
435+ /// may access the blob while Radient is reading it. Mutable blobs cannot be written or resized
436+ /// until all readers finish. Finish any write access before calling LoadTexture(); an active writer
437+ /// causes the call to return RADIENT_STATUS_INVALID_OPERATION without creating a texture asset.
438+ /// If acquiring read access fails, no matching EndRead() or last-reader callback is performed.
439+ /// Once acquired, access is released on completion or failure. OnLastReaderReleased, if set,
440+ /// may run before LoadTexture() returns or later on a worker thread. This notification reports
441+ /// that all readers have finished; it does not indicate GPU upload completion or end the lifetime
442+ /// requirement for REFERENCE storage. See RadientDataBlobCreateInfo for callback details.
443+ IRadientDataBlob * pDataBlob DEFAULT_INITIALIZER (nullptr );
444+
445+ /// Optional pointer to decoded texture data, mutually exclusive with pDataBlob.
446+ /// Only 2D texture data is currently supported. Mip 0 data must be provided; Radient always
447+ /// generates mip levels. The descriptor is copied during LoadTexture(), and its pDataBlob
448+ /// is retained with read access while the pixels are needed; see RadientTextureData::pDataBlob.
423449 const RadientTextureData * pTextureData DEFAULT_INITIALIZER (nullptr );
424450
425- /// Optional callback to release pData or pTextureData->pData when Radient no longer needs it.
426- /// For pTextureData, DataSize is the minimum source span described by RadientTextureData::pData.
427- /// If this callback is null and memory-backed source data is not null, Radient makes an internal copy of the data.
428- /// If this callback is non-null and LoadTexture() validation accepts a memory-backed source, ownership
429- /// of the source memory transfers to Radient before LoadTexture() returns. The callback is invoked exactly
430- /// once even if a later loading step fails and LoadTexture() returns an error status. If LoadTexture()
431- /// returns RADIENT_STATUS_INVALID_ARGUMENT during input validation, ownership remains with the caller and
432- /// the callback is not invoked.
433- /// The caller must not read, write, reuse, or release transferred source memory until the callback is invoked.
434- /// The callback may be invoked from any thread and must not throw exceptions.
435- RadientTextureReleaseDataCallbackType ReleaseData DEFAULT_INITIALIZER (nullptr );
436-
437- /// User data passed to ReleaseData.
438- void * pReleaseDataUserData DEFAULT_INITIALIZER (nullptr );
439-
440451 /// Interpret the texture as sRGB.
441452 Bool IsSRGB DEFAULT_INITIALIZER (False );
442453};
@@ -669,9 +680,10 @@ DILIGENT_BEGIN_INTERFACE(IRadientAssetManager, IObject)
669680 /// The returned status reports source loading and GPU upload scheduling. A successful status
670681 /// does not guarantee that the texture is already available for sampling.
671682 /// Returns RADIENT_STATUS_PENDING when loading continues asynchronously.
672- /// If LoadInfo.ReleaseData is non-null and input validation accepts a memory-backed source, ownership
673- /// transfers to Radient before this method returns. The callback will be invoked exactly once even if
674- /// this method returns a non-INVALID_ARGUMENT failure caused by a later admission or loading step.
683+ /// Encoded input in LoadInfo.pDataBlob or decoded input in LoadInfo.pTextureData->pDataBlob
684+ /// is retained with read access until the source bytes are no longer needed. An active writer
685+ /// prevents loading and returns RADIENT_STATUS_INVALID_OPERATION. The caller may release its
686+ /// blob reference after the call. Rejected loads leave ownership with the caller.
675687 VIRTUAL RADIENT_STATUS METHOD (LoadTexture )(THIS_
676688 const RadientTextureLoadInfo REF LoadInfo ,
677689 IRadientTextureAsset * * ppTexture ) PURE ;
0 commit comments