> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 간편한 하드웨어 압축 해제

> 간편한 하드웨어 압축 해제

XBOX Series 콘솔은 DirectStorage를 사용한 zlib 압축 콘텐츠에 대해 하드웨어 압축 해제를 지원합니다. 여기서 제공되는 것은 기본 소프트웨어 zlib `inflate` 함수의 드롭인 대체품입니다. 이 코드를 사용하면 개발자가 최소한의 코드 변경으로 가속 하드웨어 압축 해제 지원을 추가할 수 있습니다. 이는 압축 해제 시간을 즉각적으로 개선하는 동시에 다른 작업에 사용할 수 있는 CPU 리소스를 확보해 줍니다.

하드웨어 압축 해제에 사용되는 DirectStorage 객체를 생성하기 위해 일회성 초기화가 필요합니다.

```cpp theme={null}
Microsoft::WRL::ComPtr<IDStorageFactoryX> inflateDropInFactory;
Microsoft::WRL::ComPtr<IDStorageQueueX> inflateDropInQueue;
Microsoft::WRL::ComPtr<IDStorageStatusArrayX> inflateDropInStatus;

void CreateDSObjects()
{
    DX::ThrowIfFailed(DStorageGetFactory(__uuidof(IDStorageFactoryX), (void**)(inflateDropInFactory.ReleaseAndGetAddressOf())));
    DSTORAGE_QUEUE_DESC queueDesc = {};
    queueDesc.SourceType = DSTORAGE_REQUEST_SOURCE_MEMORY;
    queueDesc.Priority = DSTORAGE_PRIORITY_REALTIME;
    queueDesc.Capacity = DSTORAGE_MIN_QUEUE_CAPACITY;
    inflateDropInFactory->CreateQueue(&queueDesc, __uuidof(IDStorageQueueX), (void**)(inflateDropInQueue.ReleaseAndGetAddressOf()));
    inflateDropInFactory->CreateStatusArray(1, nullptr, __uuidof(IDStorageStatusArrayX), (void**)(inflateDropInStatus.ReleaseAndGetAddressOf()));
}
```

하드웨어 압축 해제에는 최소 설정 비용이 있기 때문에 더 작은 블록 크기의 경우 소프트웨어 압축 해제를 사용하는 것이 더 빠를 수 있습니다. 아래에 소스 버퍼로 ASCII 텍스트를 사용한 시간 표가 제공됩니다. 소프트웨어 압축 해제기와 콘텐츠에 대한 최적의 교차 크기를 찾으려면 프로파일링을 해야 합니다.

이 코드에는 압축된 콘텐츠가 지원되는 [IETF RFC 1950](https://www.ietf.org/rfc/rfc1950.txt) zlib 표준을 준수한다는 가정이 있습니다. 자세한 내용은 [DirectStorage 및 XBTC를 사용한 압축 콘텐츠 최적화(microsoft.com)](https://developer.microsoft.com/games/xbox/docs/gdk/directstorage-compression)를 참조하세요.

```cpp theme={null}
int inflateDropIn(z_streamp strm, int flush)
{
    bool fallback(false);
    if (strm->avail_out <= strm->total_in)
        fallback = true;
    if (flush != Z_FINISH)
        fallback = true;
    if (strm->avail_out < c_hardwareSizeCrossOverSize)
        fallback = true;
    if (fallback)
        return inflate(strm, flush);

    DSTORAGE_REQUEST request = {};
    request.Options.ZlibDecompress = true;
    request.Options.SourceType = DSTORAGE_REQUEST_SOURCE_MEMORY;
    request.Source = strm->next_in;
    request.SourceSize = strm->total_in;
    request.Destination = strm->next_out;
    request.DestinationSize = strm->avail_out;
    inflateDropInQueue->EnqueueRequest(&request);
    inflateDropInQueue->EnqueueStatus(inflateDropInStatus.Get(), 0);
    inflateDropInQueue->Submit();
    while (!inflateDropInStatus->IsComplete(0))
    {
        _mm_pause();
    }
    return Z_STREAM_END;
}
```

이 표는 소스 버퍼로 ASCII 텍스트를 사용하여 3.8GHz에서 실행 중인 XBOX Series X|S의 기본 소프트웨어 zlib 압축 해제기와 하드웨어 압축 해제기의 시간을 측정한 것을 제공합니다. 압축 비율이 다르면 소프트웨어와 하드웨어 중 어느 쪽이 더 빠른지에 대한 교차점이 다르게 나타납니다. 소프트웨어 압축 해제기와 콘텐츠에 대한 최적의 교차 크기를 찾으려면 프로파일링을 해야 합니다.

블록 크기는 바이트 단위이고 시간은 마이크로초 단위입니다.

| **블록 크기** | **CPU 시간** | **하드웨어 시간** |
| - | - | - |
| 128 | 2.91 | 75.39 |
| 256 | 3.67 | 65.29 |
| 512 | 4.14 | 65.54 |
| 1,024 | 5.59 | 66.63 |
| 2,048 | 7.65 | 66.29 |
| 4,096 | 10.96 | 83.93 |
| 8,192 | 13.69 | 69.04 |
| 10,240 | 15.08 | 67.09 |
| 12,288 | 16.16 | 67.66 |
| 14,336 | 17.37 | 70.58 |
| 16,384 | 18.40 | 72.56 |
| 20,480 | 20.58 | 70.34 |
| 24,576 | 22.88 | 71.52 |
| 28,672 | 25.34 | 71.34 |
| 32,768 | 27.71 | 73.03 |
| 36,864 | 29.73 | 72.35 |
| 40,960 | 31.56 | 77.67 |
| 45,056 | 34.34 | 73.22 |
| 65,536 | 46.76 | 76.69 |
| 131,072 | 83.96 | 89.13 |
| 262,144 | 158.32 | 111.58 |
| 524,288 | 308.01 | 177.95 |


## Related topics

- [DirectStorage 개요](https://docs.xbox.com/ko/build/console-features/storage/directstorage/directstorage-overview.md)
- [XBOX Series X|S 오디오 하드웨어 개요](https://docs.xbox.com/ko/build/console-features/audio/overviews/scarlett-audio.md)
- [DirectStorage(콘텐츠)](https://docs.xbox.com/ko/build/console-features/storage/directstorage-toc.md)
- [XMA2 개요](https://docs.xbox.com/ko/build/console-features/audio/overviews/xma2-overview.md)
- [XBOX Texture Compressor (XBTC) 도구 참고서](https://docs.xbox.com/ko/build/core-features/graphics/newfeatures/xbtc/index.md)
