/*------------------------------------------------------------------------------------- * * Copyright (c) Microsoft Corporation * Licensed under the MIT license * *-------------------------------------------------------------------------------------*/ #if !defined(__cplusplus) #error C++11 required #endif #pragma once #include #include #include #define DSTORAGE_SDK_VERSION 202 interface ID3D12Resource; interface ID3D12Fence; interface IDStorageStatusArray; /// /// The priority of a DirectStorage queue. /// enum DSTORAGE_PRIORITY : INT8 { DSTORAGE_PRIORITY_LOW = -1, DSTORAGE_PRIORITY_NORMAL = 0, DSTORAGE_PRIORITY_HIGH = 1, DSTORAGE_PRIORITY_REALTIME = 2, /// /// The following values can be used for iterating over all priority levels. /// DSTORAGE_PRIORITY_FIRST = DSTORAGE_PRIORITY_LOW, DSTORAGE_PRIORITY_LAST = DSTORAGE_PRIORITY_REALTIME, DSTORAGE_PRIORITY_COUNT = 4 }; /// /// The minimum valid queue capacity. /// #define DSTORAGE_MIN_QUEUE_CAPACITY 0x80 /// /// The maximum valid queue capacity. /// #define DSTORAGE_MAX_QUEUE_CAPACITY 0x2000 /// /// The source type of a DirectStorage request. /// enum DSTORAGE_REQUEST_SOURCE_TYPE : UINT64 { /// /// The source of the DirectStorage request is a file. /// DSTORAGE_REQUEST_SOURCE_FILE = 0, /// /// The source of the DirectStorage request is a block of memory. /// DSTORAGE_REQUEST_SOURCE_MEMORY = 1, }; /// /// The destination type of a DirectStorage request. /// enum DSTORAGE_REQUEST_DESTINATION_TYPE : UINT64 { /// /// The destination of the DirectStorage request is a block of memory. /// DSTORAGE_REQUEST_DESTINATION_MEMORY = 0, /// /// The destination of the DirectStorage request is an ID3D12Resource /// that is a buffer. /// DSTORAGE_REQUEST_DESTINATION_BUFFER = 1, /// /// The destination of the DirectStorage request is an ID3D12Resource /// that is a texture. /// DSTORAGE_REQUEST_DESTINATION_TEXTURE_REGION = 2, /// /// The destination of the DirectStorage request is an ID3D12Resource /// that is a texture that will receive all subresources in a /// single request. /// DSTORAGE_REQUEST_DESTINATION_MULTIPLE_SUBRESOURCES = 3, /// /// The destination of the DirectStorage request is an ID3D12Resource /// that is tiled. /// DSTORAGE_REQUEST_DESTINATION_TILES = 4 }; /// /// The DSTORAGE_QUEUE_DESC structure contains the properties of a DirectStorage /// queue for the queue's creation. /// struct DSTORAGE_QUEUE_DESC { /// /// The source type of requests that this DirectStorage queue can accept. /// DSTORAGE_REQUEST_SOURCE_TYPE SourceType; /// /// The maximum number of requests that the queue can hold. /// UINT16 Capacity; /// /// The priority of the requests in this queue. /// DSTORAGE_PRIORITY Priority; /// /// Optional name of the queue. Used for debugging. /// _In_opt_z_ const CHAR *Name; /// /// Optional device to use for writing to destination resources and /// performing GPU decompression. The destination resource's device /// must match this device. /// /// This member may be null. If you specify a null device, then the /// destination type must be DSTORAGE_REQUEST_DESTINATION_MEMORY. /// ID3D12Device* Device; }; /// /// The DSTORAGE_QUEUE_INFO structure contains the properties and current state /// of a DirectStorage queue. /// struct DSTORAGE_QUEUE_INFO { /// /// The DSTORAGE_QUEUE_DESC structure used for the queue's creation. /// DSTORAGE_QUEUE_DESC Desc; /// /// The number of available empty slots. If a queue is empty, then the number /// of empty slots equals capacity - 1. The reserved slot is used to /// distinguish between empty and full cases. /// UINT16 EmptySlotCount; /// /// The number of entries that would need to be enqueued in order to trigger /// automatic submission. /// UINT16 RequestCountUntilAutoSubmit; }; /// /// The type of compression format used at the decompression stage. /// Your application can implement custom decompressors, starting from /// DSTORAGE_CUSTOM_COMPRESSION_0. /// enum DSTORAGE_COMPRESSION_FORMAT : UINT8 { /// /// The data is uncompressed. /// DSTORAGE_COMPRESSION_FORMAT_NONE = 0, /// /// The data is compressed using the built-in GDEFLATE format. /// DSTORAGE_COMPRESSION_FORMAT_GDEFLATE = 1, /// /// The data is stored in an application-defined custom format. The /// application must use IDStorageCustomDecompressionQueue to implement /// custom decompression. Additional custom compression formats can be /// used, for example `(DSTORAGE_CUSTOM_COMPRESSION_0 + 1)`. DSTORAGE_CUSTOM_COMPRESSION_0 = 0x80, }; /// /// Options for a DirectStorage request. /// struct DSTORAGE_REQUEST_OPTIONS { /// /// DSTORAGE_COMPRESSION_FORMAT indicating how the data is compressed. /// DSTORAGE_COMPRESSION_FORMAT CompressionFormat : 8; /// /// Reserved fields. Must be 0. /// UINT8 Reserved1[7]; /// /// DSTORAGE_REQUEST_SOURCE_TYPE enum value indicating whether the /// source of the request is a file or a block of memory. /// DSTORAGE_REQUEST_SOURCE_TYPE SourceType : 1; /// /// DSTORAGE_REQUEST_DESTINATION_TYPE enum value indicating the /// destination of the request. Block of memory, resource. /// DSTORAGE_REQUEST_DESTINATION_TYPE DestinationType : 7; /// /// Reserved fields. Must be 0. /// UINT64 Reserved : 48; }; /// /// Flags controlling DirectStorage debug layer. /// enum DSTORAGE_DEBUG { /// /// DirectStorage debug layer is disabled. /// DSTORAGE_DEBUG_NONE = 0x00, /// /// Print error information to a debugger. /// DSTORAGE_DEBUG_SHOW_ERRORS = 0x01, /// /// Trigger a debug break each time an error is detected. /// DSTORAGE_DEBUG_BREAK_ON_ERROR = 0x02, /// /// Include object names in ETW events. /// DSTORAGE_DEBUG_RECORD_OBJECT_NAMES = 0x04 }; DEFINE_ENUM_FLAG_OPERATORS(DSTORAGE_DEBUG); /// /// Represents a file to be accessed by DirectStorage. /// DECLARE_INTERFACE_IID_(IDStorageFile, IUnknown, "5de95e7b-955a-4868-a73c-243b29f4b8da") { /// /// Closes the file, regardless of the reference count on this object. /// /// After an IDStorageFile object is closed, it can no longer be used in /// DirectStorage requests. This does not modify the reference count on this /// object; Release() must be called as usual. /// virtual void STDMETHODCALLTYPE Close() = 0; /// /// Retrieves file information for an opened file. /// /// Receives the file information. /// Standard HRESULT error code. virtual HRESULT STDMETHODCALLTYPE GetFileInformation(_Out_ BY_HANDLE_FILE_INFORMATION* info) = 0; }; /// /// Describes a source for a request with SourceType /// DSTORAGE_REQUEST_SOURCE_FILE. /// struct DSTORAGE_SOURCE_FILE { /// /// The file to perform this read request from. /// IDStorageFile* Source; /// /// The offset, in bytes, in the file to start the read request at. /// UINT64 Offset; /// /// Number of bytes to read from the file. /// UINT32 Size; }; /// /// Describes the source for a request with SourceType /// DSTORAGE_REQUEST_SOURCE_MEMORY. /// struct DSTORAGE_SOURCE_MEMORY { /// /// Address of the source buffer to be read from. /// void const* Source; /// /// Number of bytes to read from the source buffer. /// UINT32 Size; }; /// /// Describes the destination for a request with DestinationType /// DSTORAGE_REQUEST_DESTINATION_MEMORY. /// struct DSTORAGE_DESTINATION_MEMORY { /// /// Address of the buffer to receive the final result of this request. /// void* Buffer; /// /// Number of bytes to write to the destination buffer. /// UINT32 Size; }; /// /// Describes the destination for a request with DestinationType /// DSTORAGE_REQUEST_DESTINATION_BUFFER. /// struct DSTORAGE_DESTINATION_BUFFER { /// /// Address of the resource to receive the final result of this request. /// ID3D12Resource* Resource; /// /// The offset, in bytes, in the buffer resource to write into. /// UINT64 Offset; /// /// Number of bytes to write to the destination buffer. /// UINT32 Size; }; /// /// Describes the destination for a request with DestinationType /// DSTORAGE_REQUEST_DESTINATION_TEXTURE_REGION. /// struct DSTORAGE_DESTINATION_TEXTURE_REGION { /// /// Address of the resource to receive the final result of this request. /// ID3D12Resource* Resource; /// /// Describes the destination texture copy location. The subresource /// referred to must be in the D3D12_RESOURCE_STATE_COMMON state. /// UINT SubresourceIndex; /// /// Coordinates and size of the destination region to copy, in pixels. /// D3D12_BOX Region; }; /// /// Describes the destination for a request with DestinationType /// DSTORAGE_REQUEST_DESTINATION_MULTIPLE_SUBRESOURCES. /// struct DSTORAGE_DESTINATION_MULTIPLE_SUBRESOURCES { /// /// Address of the resource to receive the final result of this request. The /// source is expected to contain full data for all subresources, starting /// from FirstSubresource. /// ID3D12Resource* Resource; /// /// Describes the first subresource of the destination texture copy /// location. The subresource referred to must be in the /// D3D12_RESOURCE_STATE_COMMON state. /// UINT FirstSubresource; }; /// /// Describes the destination for a request with DestinationType /// DSTORAGE_REQUEST_DESTINATION_TILES. /// struct DSTORAGE_DESTINATION_TILES { /// /// Address of the resource to receive the final result of this request. The /// source buffer is expected to contain data arranged as if it were the /// source to a CopyTiles call with these parameters. /// ID3D12Resource* Resource; /// /// The starting coordinates of the tiled region. /// D3D12_TILED_RESOURCE_COORDINATE TiledRegionStartCoordinate; /// /// The size of the tiled region. /// D3D12_TILE_REGION_SIZE TileRegionSize; }; /// /// Describes the source specified for a DirectStorage request. For a request, /// the value of `request.Options.SourceType` determines which of these union /// fields is active. /// union DSTORAGE_SOURCE { DSTORAGE_SOURCE_MEMORY Memory; DSTORAGE_SOURCE_FILE File; }; /// /// Describes the destination for a DirectStorage request. For a request, the /// value of `request.Options.DestinationType` determines which of these union /// fields is active. /// union DSTORAGE_DESTINATION { DSTORAGE_DESTINATION_MEMORY Memory; DSTORAGE_DESTINATION_BUFFER Buffer; DSTORAGE_DESTINATION_TEXTURE_REGION Texture; DSTORAGE_DESTINATION_MULTIPLE_SUBRESOURCES MultipleSubresources; DSTORAGE_DESTINATION_TILES Tiles; }; /// /// Represents a DirectStorage request. /// struct DSTORAGE_REQUEST { /// /// Combination of decompression and other options for this request. /// DSTORAGE_REQUEST_OPTIONS Options; /// /// The source for this request. /// DSTORAGE_SOURCE Source; /// /// The destination for this request. /// DSTORAGE_DESTINATION Destination; /// /// The uncompressed size in bytes for the destination for this request. /// If the request is not compressed, then this can be left as 0. /// /// For compressed data, if the destination is memory, then the uncompressed size must /// exactly equal the destination size. For other destination types, the uncompressed /// size may be greater than the destination size. /// /// If the destination is to memory or buffer, then the destination size should /// be specified in the corresponding struct (for example, DSTORAGE_DESTINATION_MEMORY). /// For textures, it's the value of pTotalBytes returned by GetCopyableFootprints. /// For tiles, it's 64k * number of tiles. /// UINT32 UncompressedSize; /// /// An arbitrary UINT64 number used for cancellation matching. /// UINT64 CancellationTag; /// /// Optional name of the request. Used for debugging. If specified, the /// string should be accessible until the request completes. /// _In_opt_z_ const CHAR *Name; }; /// /// The maximum number of characters that will be stored for a request's name. /// #define DSTORAGE_REQUEST_MAX_NAME 64 /// /// The type of command that failed, as reported by /// DSTORAGE_ERROR_FIRST_FAILURE. /// enum DSTORAGE_COMMAND_TYPE { DSTORAGE_COMMAND_TYPE_NONE = -1, DSTORAGE_COMMAND_TYPE_REQUEST = 0, DSTORAGE_COMMAND_TYPE_STATUS = 1, DSTORAGE_COMMAND_TYPE_SIGNAL = 2, DSTORAGE_COMMAND_TYPE_EVENT = 3, }; /// /// The parameters passed to the EnqueueRequest call, and optional /// filename if the request is for a file source. /// struct DSTORAGE_ERROR_PARAMETERS_REQUEST { /// /// For a file source request, the name of the file the request was /// targeted to. /// WCHAR Filename[MAX_PATH]; /// /// The name of the request if one was specified. /// CHAR RequestName[DSTORAGE_REQUEST_MAX_NAME]; /// /// The parameters passed to the EnqueueRequest call. /// DSTORAGE_REQUEST Request; }; /// /// The parameters passed to the EnqueueStatus call. /// struct DSTORAGE_ERROR_PARAMETERS_STATUS { IDStorageStatusArray* StatusArray; UINT32 Index; }; /// /// The parameters passed to the EnqueueSignal call. /// struct DSTORAGE_ERROR_PARAMETERS_SIGNAL { ID3D12Fence* Fence; UINT64 Value; }; /// /// The parameters passed to the EnqueueSetEvent call. /// struct DSTORAGE_ERROR_PARAMETERS_EVENT { HANDLE Handle; }; /// /// Structure to receive the detailed record of the first failed DirectStorage /// request. /// struct DSTORAGE_ERROR_FIRST_FAILURE { /// /// The HRESULT code of the failure. /// HRESULT HResult; /// /// Type of the Enqueue command that caused the failure. /// DSTORAGE_COMMAND_TYPE CommandType; /// /// The parameters passed to the Enqueue call. /// union { DSTORAGE_ERROR_PARAMETERS_REQUEST Request; DSTORAGE_ERROR_PARAMETERS_STATUS Status; DSTORAGE_ERROR_PARAMETERS_SIGNAL Signal; DSTORAGE_ERROR_PARAMETERS_EVENT Event; }; }; /// /// Structure to receive the detailed record of a failed DirectStorage request. /// struct DSTORAGE_ERROR_RECORD { /// /// The number of failed requests in the queue since the last /// RetrieveErrorRecord call. /// UINT32 FailureCount; /// /// Detailed record about the first failed command in the enqueue order. /// DSTORAGE_ERROR_FIRST_FAILURE FirstFailure; }; /// /// Defines common staging buffer sizes. /// enum DSTORAGE_STAGING_BUFFER_SIZE : UINT32 { /// /// There is no staging buffer. Use this value to force DirectStorage to /// deallocate any memory it has allocated for staging buffers. /// DSTORAGE_STAGING_BUFFER_SIZE_0 = 0, /// /// The default staging buffer size of 32MB. /// DSTORAGE_STAGING_BUFFER_SIZE_32MB = 32 * 1048576, }; /// /// Flags used with GetRequests1 when requesting /// items from the custom decompression queue. /// enum DSTORAGE_GET_REQUEST_FLAGS : UINT32 { /// /// Request entries that use custom decompression formats /// >= DSTORAGE_CUSTOM_COMPRESSION_0. /// DSTORAGE_GET_REQUEST_FLAG_SELECT_CUSTOM = 0x01, /// /// Request entries that use built in compression formats /// that DirectStorage understands. /// DSTORAGE_GET_REQUEST_FLAG_SELECT_BUILTIN = 0x02, /// /// Request all entries. This includes custom decompression and /// built-in compressed formats. /// DSTORAGE_GET_REQUEST_FLAG_SELECT_ALL = (DSTORAGE_GET_REQUEST_FLAG_SELECT_CUSTOM | DSTORAGE_GET_REQUEST_FLAG_SELECT_BUILTIN) }; DEFINE_ENUM_FLAG_OPERATORS(DSTORAGE_GET_REQUEST_FLAGS); /// /// Specifies information about a custom decompression request. /// enum DSTORAGE_CUSTOM_DECOMPRESSION_FLAGS : UINT32 { /// /// No additional information. /// DSTORAGE_CUSTOM_DECOMPRESSION_FLAG_NONE = 0x00, /// /// The uncompressed destination buffer is located in an /// upload heap, and is marked as WRITE_COMBINED. /// DSTORAGE_CUSTOM_DECOMPRESSION_FLAG_DEST_IN_UPLOAD_HEAP = 0x01, }; DEFINE_ENUM_FLAG_OPERATORS(DSTORAGE_CUSTOM_DECOMPRESSION_FLAGS); /// /// A custom decompression request. Use IDStorageCustomDecompressionQueue to /// retrieve these requests. /// struct DSTORAGE_CUSTOM_DECOMPRESSION_REQUEST { /// /// An identifier provided by DirectStorage. This should be used to /// identify the request in DSTORAGE_CUSTOM_DECOMPRESSION_RESULT. This /// identifier is unique among uncompleted requests, but may be reused after /// a request has completed. /// UINT64 Id; /// /// The compression format. This will be >= DSTORAGE_CUSTOM_COMPRESSION_0 /// if DSTORAGE_CUSTOM_DECOMPRESSION_CUSTOMONLY is used to retrieve requests. /// DSTORAGE_COMPRESSION_FORMAT CompressionFormat; /// /// Reserved for future use. /// UINT8 Reserved[3]; /// /// Flags containing additional details about the decompression request. /// DSTORAGE_CUSTOM_DECOMPRESSION_FLAGS Flags; /// /// The size of SrcBuffer in bytes. /// UINT64 SrcSize; /// /// The compressed source buffer. /// void const* SrcBuffer; /// /// The size of DstBuffer in bytes. /// UINT64 DstSize; /// /// The uncompressed destination buffer. SrcBuffer should be decompressed to /// DstBuffer. /// void* DstBuffer; }; /// /// The result of a custom decompression operation. If the request failed, then /// the Result code is passed back through the standard DirectStorage /// status/error reporting mechanism. /// struct DSTORAGE_CUSTOM_DECOMPRESSION_RESULT { /// /// The identifier for the request, from DSTORAGE_CUSTOM_DECOMPRESSION_REQUEST. /// UINT64 Id; /// /// The result of this decompression. S_OK indicates success. /// HRESULT Result; }; /// /// A queue of decompression requests. This can be obtained using QueryInterface /// against the factory. Your application must take requests from this queue, /// decompress them, and report that decompression is complete. That allows an /// application to provide its own custom decompression. /// DECLARE_INTERFACE_IID_(IDStorageCustomDecompressionQueue, IUnknown, "97179b2f-2c21-49ca-8291-4e1bf4a160df") { /// /// Obtains an event to wait on. This event is set when there are pending /// decompression requests. /// virtual HANDLE STDMETHODCALLTYPE GetEvent() = 0; /// /// Populates the given array of request structs with new pending requests. /// Your application must arrange to fulfill all these requests, and then /// call SetRequestResults to indicate completion. /// virtual HRESULT STDMETHODCALLTYPE GetRequests( _In_ UINT32 maxRequests, _Out_writes_to_(maxRequests, *numRequests) DSTORAGE_CUSTOM_DECOMPRESSION_REQUEST* requests, _Out_ UINT32* numRequests) = 0; /// /// Your application calls this to indicate that requests have been /// completed. /// /// The number of results in `results`. /// An array of results, the size is specified by /// `numResults.` /// Standard HRESULT error code. virtual HRESULT STDMETHODCALLTYPE SetRequestResults( _In_ UINT32 numResults, _In_reads_(numResults) DSTORAGE_CUSTOM_DECOMPRESSION_RESULT* results) = 0; }; /// /// An extension of IDStorageCustomDecompressionQueue that allows an /// application to retrieve specific types of custom decompression /// requests from the decompression queue. /// DECLARE_INTERFACE_IID_( IDStorageCustomDecompressionQueue1, IDStorageCustomDecompressionQueue, "0D47C6C9-E61A-4706-93B4-68BFE3F4AA4A") { /// /// Populates the given array of request structs with new pending requests /// based on the specified custom decompression request type. /// The application must arrange to fulfill all these requests, and then /// call SetRequestResults to indicate completion. /// virtual HRESULT STDMETHODCALLTYPE GetRequests1( _In_ DSTORAGE_GET_REQUEST_FLAGS flags, _In_ UINT32 maxRequests, _Out_writes_to_(maxRequests, *numRequests) DSTORAGE_CUSTOM_DECOMPRESSION_REQUEST* requests, _Out_ UINT32 * numRequests) = 0; }; /// /// Represents the static DirectStorage object used to create DirectStorage /// queues, open files for DirectStorage access, and other global operations. /// DECLARE_INTERFACE_IID_(IDStorageFactory, IUnknown, "6924ea0c-c3cd-4826-b10a-f64f4ed927c1") { /// /// Creates a DirectStorage queue object. /// /// Descriptor to specify the properties of the queue. /// Specifies the DirectStorage queue interface, such as /// __uuidof(IDStorageQueue). /// Receives the new queue created. /// Standard HRESULT error code. virtual HRESULT STDMETHODCALLTYPE CreateQueue(const DSTORAGE_QUEUE_DESC *desc, REFIID riid, _COM_Outptr_ void **ppv) = 0; /// /// Opens a file for DirectStorage access. /// /// Path of the file to be opened. /// Specifies the DirectStorage file interface, such as /// __uuidof(IDStorageFile). /// Receives the new file opened. /// Standard HRESULT error code. virtual HRESULT STDMETHODCALLTYPE OpenFile(_In_z_ const WCHAR *path, REFIID riid, _COM_Outptr_ void **ppv) = 0; /// /// Creates a DirectStorage status array object. /// /// Specifies the number of statuses that the array can /// hold. /// Specifies object's name that will appear in // the ETW events if enabled through the debug layer. This is an optional // parameter. /// Specifies the DirectStorage status interface, such as /// __uuidof(IDStorageStatusArray). /// Receives the new status array object created. /// Standard HRESULT error code. virtual HRESULT STDMETHODCALLTYPE CreateStatusArray(UINT32 capacity, _In_opt_ PCSTR name, REFIID riid, _COM_Outptr_ void **ppv) = 0; /// /// Sets flags used to control the debug layer. /// /// A set of flags controlling the debug layer. virtual void STDMETHODCALLTYPE SetDebugFlags(UINT32 flags) = 0; /// /// Sets the size of staging buffer(s) used to temporarily store content loaded /// from the storage device before they are decompressed. If only uncompressed /// memory sourced queues writing to cpu memory destinations are used, then the /// staging buffer may be 0-sized. /// /// Size, in bytes, of each staging buffer used /// to complete a request. /// /// /// The default staging buffer is DSTORAGE_STAGING_BUFFER_SIZE_32MB. /// If multiple staging buffers are necessary to complete a request, then each /// separate staging buffer is allocated to this staging buffer size. /// /// If the destination is a GPU resource, then some but not all of the staging /// buffers will be allocated from VRAM. /// /// Requests that exceed the specified size to SetStagingBufferSize will fail. /// virtual HRESULT STDMETHODCALLTYPE SetStagingBufferSize(UINT32 size) = 0; }; /// /// Represents an array of status entries to receive completion results for the /// read requests before them. /// /// /// A status entry receives completion status for all the requests in the /// DStorageQueue between where it is enqueued and the previously enqueued /// status entry. Only when all requests enqueued before the status entry /// complete (that is, IsComplete for the entry returns true), the status entry /// can be enqueued again. /// DECLARE_INTERFACE_IID_(IDStorageStatusArray, IUnknown, "82397587-7cd5-453b-a02e-31379bd64656") { /// /// Returns a Boolean value indicating that all requests enqueued prior to the /// specified status entry have completed. /// /// Specifies the index of the status entry to retrieve. /// Boolean value indicating completion. /// This is equivalent to `GetHResult(index) != E_PENDING`. virtual bool STDMETHODCALLTYPE IsComplete(UINT32 index) = 0; /// /// Returns the HRESULT code of all requests between the specified status /// entry and the status entry enqueued before it. /// /// Specifies the index of the status entry to retrieve. /// HRESULT code of the requests. /// /// /// /// If any requests have not completed yet, the return value is E_PENDING. /// /// /// If all requests have completed, and there were failure(s), then the return /// value stores the failure code of the first failed request in the enqueue /// order. /// /// /// If all requests have completed successfully, then the return value is S_OK. /// /// /// virtual HRESULT STDMETHODCALLTYPE GetHResult(UINT32 index) = 0; }; /// /// Represents a DirectStorage queue to perform read operations. /// DECLARE_INTERFACE_IID_(IDStorageQueue, IUnknown, "cfdbd83f-9e06-4fda-8ea5-69042137f49b") { /// /// Enqueues a read request to the queue. The request remains in the queue /// until Submit is called, or until the queue is half full. /// If there are no free entries in the queue, then the enqueue operation /// blocks until one becomes available. /// /// The read request to be queued. virtual void STDMETHODCALLTYPE EnqueueRequest(const DSTORAGE_REQUEST *request) = 0; /// /// Enqueues a status write. The status write happens when all requests /// before the status write entry complete. If there were failure(s) /// since the previous status write entry, then the HResult of the enqueued /// status entry stores the failure code of the first failed request in the /// enqueue order. /// If there are no free entries in the queue, then the enqueue operation /// blocks until one becomes available. /// /// IDStorageStatusArray object. /// Index of the status entry in the /// IDStorageStatusArray object to receive the status. virtual void STDMETHODCALLTYPE EnqueueStatus(IDStorageStatusArray *statusArray, UINT32 index) = 0; /// /// Enqueues fence write. The fence write happens when all requests before /// the fence entry complete. /// If there are no free entries in the queue, then the enqueue operation will /// block until one becomes available. /// /// An ID3D12Fence to be written. /// The value to write to the fence. virtual void STDMETHODCALLTYPE EnqueueSignal(ID3D12Fence *fence, UINT64 value) = 0; /// /// Submits all requests enqueued so far to DirectStorage to be executed. /// virtual void STDMETHODCALLTYPE Submit() = 0; /// /// Attempts to cancel a group of previously enqueued read requests. All /// previously enqueued requests whose CancellationTag matches the formula /// (CancellationTag & mask) == value will be cancelled. /// A cancelled request might or might not complete its original read request. /// A cancelled request is not counted as a failure in either /// IDStorageStatus or DSTORAGE_ERROR_RECORD. /// /// The mask for the cancellation formula. /// The value for the cancellation formula. virtual void STDMETHODCALLTYPE CancelRequestsWithTag(UINT64 mask, UINT64 value) = 0; /// /// Closes the DirectStorage queue, regardless of the reference count on this /// object. /// /// After the Close function returns, the queue will no longer complete any /// more requests, even if some are submitted. This does not modify the /// reference count on this object; Release() must be called as usual. /// virtual void STDMETHODCALLTYPE Close() = 0; /// /// Obtains an event to wait on. When there is any error happening for read /// requests in this queue, the event will be signaled, and you may call /// RetrieveErrorRecord to retrieve diagnostic information. /// /// HANDLE to an event. virtual HANDLE STDMETHODCALLTYPE GetErrorEvent() = 0; /// /// When the error event is signaled, this function can be called to /// retrieve a DSTORAGE_ERROR_RECORD. Once the error record is retrieved, /// this function should not be called until the next time the error event /// is signaled. /// /// Receives the error record. virtual void STDMETHODCALLTYPE RetrieveErrorRecord(_Out_ DSTORAGE_ERROR_RECORD *record) = 0; /// /// Obtains information about the queue. It includes the DSTORAGE_QUEUE_DESC /// structure used for the queue's creation as well as the number of empty slots /// and number of entries that need to be enqueued to trigger automatic /// submission. /// /// Receives the queue information. virtual void STDMETHODCALLTYPE Query(_Out_ DSTORAGE_QUEUE_INFO *info) = 0; }; /// /// Represents a DirectStorage queue to perform read operations. /// DECLARE_INTERFACE_IID_(IDStorageQueue1, IDStorageQueue, "dd2f482c-5eff-41e8-9c9e-d2374b278128") { /// /// Enqueues an operation to set the specified event object to a signaled state. /// The event object is set when all requests before it complete. /// If there are no free entries in the queue the enqueue operation will /// block until one becomes available. /// /// A handle to an event object. virtual void STDMETHODCALLTYPE EnqueueSetEvent(HANDLE handle) = 0; }; /// /// Flags returned with GetCompressionSupport that describe the features /// used by the runtime to decompress content. /// enum DSTORAGE_COMPRESSION_SUPPORT : UINT32 { /// /// None /// DSTORAGE_COMPRESSION_SUPPORT_NONE = 0x0, /// /// Optimized driver support for GPU decompression will be used. /// DSTORAGE_COMPRESSION_SUPPORT_GPU_OPTIMIZED = 0x01, /// /// Built-in GPU decompression fallback shader will be used. This can occur if /// optimized driver support is not available and the D3D12 device used for this /// DirectStorage queue supports the required capabilities. /// DSTORAGE_COMPRESSION_SUPPORT_GPU_FALLBACK = 0x02, /// /// CPU fallback implementation will be used. /// This can occur if: /// * Optimized driver support and built-in GPU decompression is not available. /// * GPU decompression support has been explicitly disabled using /// DSTORAGE_CONFIGURATION. /// * DirectStorage runtime encounters a failure during initialization of its /// GPU decompression system. /// DSTORAGE_COMPRESSION_SUPPORT_CPU_FALLBACK = 0x04, /// /// Executes work on a compute queue. /// DSTORAGE_COMPRESSION_SUPPORT_USES_COMPUTE_QUEUE = 0x08, /// /// Executes work on a copy queue. /// DSTORAGE_COMPRESSION_SUPPORT_USES_COPY_QUEUE = 0x010, }; DEFINE_ENUM_FLAG_OPERATORS(DSTORAGE_COMPRESSION_SUPPORT); /// /// Represents a DirectStorage queue to perform read operations. /// DECLARE_INTERFACE_IID_(IDStorageQueue2, IDStorageQueue1, "b1c9d643-3a49-44a2-b46f-653649470d18") { /// /// Obtains support information about the queue for a specified compression format. /// It includes the chosen path that the DirectStorage runtime will use for decompression. /// /// Specifies the compression format to retrieve information /// about. virtual DSTORAGE_COMPRESSION_SUPPORT STDMETHODCALLTYPE GetCompressionSupport(DSTORAGE_COMPRESSION_FORMAT format) = 0; }; /// /// Disables built-in decompression. /// /// Set NumBuiltInCpuDecompressionThreads in DSTORAGE_CONFIGURATION to /// this value to disable built-in decompression. No decompression threads /// will be created and the title is fully responsible for checking /// the custom decompression queue and pulling off ALL entries to decompress. /// #define DSTORAGE_DISABLE_BUILTIN_CPU_DECOMPRESSION -1 /// /// DirectStorage Configuration. Zero initializing this will result in the default values. /// struct DSTORAGE_CONFIGURATION { /// /// Sets the number of threads to use for submitting IO operations. /// Specifying 0 means use the system's best guess at a good value. /// Default == 0. /// UINT32 NumSubmitThreads; /// /// Sets the number of threads to be used by the DirectStorage runtime to /// decompress data using the CPU for built-in compressed formats /// that cannot be decompressed using the GPU. /// /// Specifying 0 means to use the system's best guess at a good value. /// /// Specifying DSTORAGE_DISABLE_BUILTIN_CPU_DECOMPRESSION means no decompression /// threads will be created and the title is fully responsible for checking /// the custom decompression queue and pulling off ALL entries to decompress. /// /// Default == 0. /// INT32 NumBuiltInCpuDecompressionThreads; /// /// Forces the use of the IO mapping layer, even when running on an /// operation system that doesn't require it. This may be useful during /// development, but should be set to the FALSE for release. Default=FALSE. /// BOOL ForceMappingLayer; /// /// Disables the use of the bypass IO optimization, even if it is available. /// This might be useful during development, but should be set to FALSE /// for release unless ForceFileBuffering is set to TRUE. /// Default == FALSE. /// BOOL DisableBypassIO; /// /// Disables the reporting of telemetry data when set to TRUE. /// Telemetry data is enabled by default in the DirectStorage runtime. /// Default == FALSE. /// BOOL DisableTelemetry; /// /// Disables the use of a decompression metacommand, even if one /// is available. This will force the runtime to use the built-in GPU decompression /// fallback shader. /// This may be useful during development, but should be set to the FALSE /// for release. Default == FALSE. /// BOOL DisableGpuDecompressionMetacommand; /// /// Disables the use of GPU based decompression, even if it is available. /// This will force the runtime to use the CPU. Default=FALSE. /// BOOL DisableGpuDecompression; }; /// /// DirectStorage Configuration. Zero initializing this will result in the default values. /// struct DSTORAGE_CONFIGURATION1 { /// /// Sets the number of threads to use for submitting IO operations. /// Specifying 0 means use the system's best guess at a good value. /// Default == 0. /// UINT32 NumSubmitThreads; /// /// Sets the number of threads to be used by the DirectStorage runtime to /// decompress data using the CPU for built-in compressed formats /// that cannot be decompressed using the GPU. /// /// Specifying 0 means to use the system's best guess at a good value. /// /// Specifying DSTORAGE_DISABLE_BUILTIN_CPU_DECOMPRESSION means no decompression /// threads will be created and the title is fully responsible for checking /// the custom decompression queue and pulling off ALL entries to decompress. /// /// Default == 0. /// INT32 NumBuiltInCpuDecompressionThreads; /// /// Forces the use of the IO mapping layer, even when running on an /// operation system that doesn't require it. This may be useful during /// development, but should be set to the FALSE for release. Default=FALSE. /// BOOL ForceMappingLayer; /// /// Disables the use of the bypass IO optimization, even if it is available. /// This might be useful during development, but should be set to FALSE /// for release unless ForceFileBuffering is set to TRUE. /// Default == FALSE. /// BOOL DisableBypassIO; /// /// Disables the reporting of telemetry data when set to TRUE. /// Telemetry data is enabled by default in the DirectStorage runtime. /// Default == FALSE. /// BOOL DisableTelemetry; /// /// Disables the use of a decompression metacommand, even if one /// is available. This will force the runtime to use the built-in GPU decompression /// fallback shader. /// This may be useful during development, but should be set to the FALSE /// for release. Default == FALSE. /// BOOL DisableGpuDecompressionMetacommand; /// /// Disables the use of GPU based decompression, even if it is available. /// This will force the runtime to use the CPU. Default=FALSE. /// BOOL DisableGpuDecompression; /// /// Forces the use of the built-in file caching behaviors supported /// within the Windows operating system by not setting /// FILE_FLAG_NO_BUFFERING when opening files. /// /// DisableBypassIO must be set to TRUE when using this option or /// E_DSTORAGE_FILEBUFFERING_REQUIRES_DISABLED_BYPASSIO will be returned. /// /// It is the title's responsibility to know when to use this setting. /// This feature should ONLY be enabled for slower HDD drives that will /// benefit from the OS file buffering features. /// /// WARNING: Enabling file buffering on high speed drives may reduce /// overall performance when reading from that drive because BypassIO /// is also disabled. Default=FALSE. /// BOOL ForceFileBuffering; }; /// /// Settings controlling DirectStorage compression codec behavior. /// enum DSTORAGE_COMPRESSION : INT32 { /// /// Compress data at a fast rate which may not yield the best /// compression ratio. /// DSTORAGE_COMPRESSION_FASTEST = -1, /// /// Compress data at an average rate with a good compression ratio. /// DSTORAGE_COMPRESSION_DEFAULT = 0, /// /// Compress data at slow rate with the best compression ratio. /// DSTORAGE_COMPRESSION_BEST_RATIO = 1 }; /// /// Represents the DirectStorage object for compressing and decompressing the buffers. /// /// Use DStorageCreateCompressionCodec to get an instance of this. /// /// DECLARE_INTERFACE_IID_(IDStorageCompressionCodec, IUnknown, "84ef5121-9b43-4d03-b5c1-cc34606b262d") { /// /// Compresses a buffer of data using a known compression format at the specifed /// compression level. /// /// Points to a buffer containing uncompressed data. /// Size, in bytes, of the uncompressed data buffer. /// Specifies the compression settings to use. /// Points to a buffer where compressed data will be /// written. /// Size, in bytes, of the buffer which will receive /// the compressed data /// Size, in bytes, of the actual size written to compressedBuffer /// Standard HRESULT error code. virtual HRESULT STDMETHODCALLTYPE CompressBuffer( const void* uncompressedData, size_t uncompressedDataSize, DSTORAGE_COMPRESSION compressionSetting, void* compressedBuffer, size_t compressedBufferSize, size_t* compressedDataSize) = 0; /// /// Decompresses data previously compressed using CompressBuffer. /// /// Points to a buffer containing compressed data. /// Size, in bytes, of the compressed data buffer. /// Points to a buffer where uncompressed data will be /// written. /// Size, in bytes, of the buffer which will receive /// the uncompressed data /// Size, in bytes, of the actual size written to uncompressedBuffer /// Standard HRESULT error code. virtual HRESULT STDMETHODCALLTYPE DecompressBuffer( const void* compressedData, size_t compressedDataSize, void* uncompressedBuffer, size_t uncompressedBufferSize, size_t* uncompressedDataSize) = 0; /// /// Returns an upper bound estimated size in bytes required to compress the specified data size. /// /// Size, in bytes, of the data to be compressed virtual size_t STDMETHODCALLTYPE CompressBufferBound(size_t uncompressedDataSize) = 0; }; extern "C" { /// /// Configures DirectStorage. This must be called before the first call to /// DStorageGetFactory. If this is not called, then default values are used. /// /// Specifies the configuration. /// Standard HRESULT error code. The configuration can only be changed /// when no queue is created and no files are open, /// E_DSTORAGE_STAGING_BUFFER_LOCKED is returned if this is not the case. HRESULT WINAPI DStorageSetConfiguration(DSTORAGE_CONFIGURATION const* configuration); /// /// Configures DirectStorage. This must be called before the first call to /// DStorageGetFactory. If this is not called, then default values are used. /// /// Specifies the configuration. /// Standard HRESULT error code. The configuration can only be changed /// when no queue is created and no files are open, /// E_DSTORAGE_STAGING_BUFFER_LOCKED is returned if this is not the case. HRESULT WINAPI DStorageSetConfiguration1(DSTORAGE_CONFIGURATION1 const* configuration); /// /// Returns the static DirectStorage factory object used to create DirectStorage queues, /// open files for DirectStorage access, and other global operations. /// /// Specifies the DirectStorage factory interface, such as /// __uuidof(IDStorageFactory) /// Receives the DirectStorage factory object. /// Standard HRESULT error code. HRESULT WINAPI DStorageGetFactory(REFIID riid, _COM_Outptr_ void** ppv); /// /// Returns an object used to compress/decompress content. /// Compression codecs are not thread safe so multiple /// instances are required if the codecs need to be used /// by multiple threads. /// /// Specifies how the data is compressed. /// Specifies maximum number of threads this codec /// will use. Specifying 0 means to use the system's best guess at a good value. /// Specifies the DirectStorage compressor/decompressor interface, such as /// __uuidof(IDStorageCompressionCodec) /// Receives the DirectStorage object. /// Standard HRESULT error code. HRESULT WINAPI DStorageCreateCompressionCodec(DSTORAGE_COMPRESSION_FORMAT format, UINT32 numThreads, REFIID riid, _COM_Outptr_ void** ppv); }