direct x 着色器的类型名称 ID3D10Blob 背后的词源是什么?

What's the etymology behind type name ID3D10Blob for direct x shaders?

直接 x 着色器的类型名称 ID3D10Blob 背后的词源是什么?

我正在阅读 http://www.directxtutorial.com/Lesson.aspx?lessonid=11-4-5 并试图推理 windows 中的命名约定。

我看到 ID3D10Blob 为 (I)(D3D10)(Blob)。

I = 界面? D3D10 = direct3d 10? Blob = ?

我在网上看到 "Binary large object" 的 Blob,但我不确定在这种情况下它是否具有相同的含义。

blob 术语是什么意思?

TL;DR: 它只是一个简单的 ref-counted 容器,用于存放 D3DCompiler COM 接口使用的 variable-length 二进制数据块。

HLSL 编译器生成一个 'shader blob',它只是一个不透明的二进制对象。它有大小和数据。它实际上可以是任何东西,但在 "COM" 对象的世界中,随着 Direct3D 10 的引入,它在 Windows Vista 中实现为 ID3D10Blob

从历史上看,Direct3D 9 和更早版本有一个 'fixed-function' 渲染管道,这意味着您可以在没有 HLSL 着色器的情况下使用它。对于 Direct3D 10,'fixed-function' 已被删除,因此完全需要 HLSL 才能使用它。因此,一个版本的 Direct3D HLSL 编译器被添加到 OS.

ID3DBlob 接口是用于 Direct3D 11 或 Direct3D 12 的接口,但如果你仔细观察,它是一样的。

typedef ID3D10Blob ID3DBlob;

Direct3D API 本身实际上并不使用这个特定的 'blob' 接口。在 C++ STL 世界中,您可以使用 std::vector<uint8_t> 作为着色器 blob:

    inline std::vector<uint8_t> ReadData(_In_z_ const wchar_t* name)
    {
        std::ifstream inFile(name, std::ios::in | std::ios::binary | std::ios::ate);
        if (!inFile)
            throw std::exception("ReadData");

        std::streampos len = inFile.tellg();
        if (!inFile)
            throw std::exception("ReadData");

        std::vector<uint8_t> blob;
        blob.resize(size_t(len));

        inFile.seekg(0, std::ios::beg);
        if (!inFile)
            throw std::exception("ReadData");

        inFile.read(reinterpret_cast<char*>(blob.data()), len);
        if (!inFile)
            throw std::exception("ReadData");

        inFile.close();

        return blob;
    }

…

    auto vertexShaderBlob = ReadData(L"VertexShader.cso");

    ThrowIfFailed(
        device->CreateVertexShader(vertexShaderBlob.data(), vertexShaderBlob.size(),
            nullptr, m_spVertexShader.ReleaseAndGetAddressOf()));

    auto pixelShaderBlob = ReadData(L"PixelShader.cso");

    ThrowIfFailed(
        device->CreatePixelShader(pixelShaderBlob.data(), pixelShaderBlob.size(),
            nullptr, m_spPixelShader.ReleaseAndGetAddressOf()));

参见 Microsoft Docs and this blog post