0
\$\begingroup\$

I want to comiple a compute shader from text, but it failed with 0x8e16d728 error.

// #pragma kernel CSMain //line 1,//uncomment this line will generate warning "unknown pragma kernel"

 RWTexture2D<float4> Result : register (u0);

 Texture2D<float4> ImageInput : register (t0);
 cbuffer ImageSize : register(b0) {
     int width;
     int height;
 }


[numthreads(16, 16, 1)]
void CSMain(uint3 id : SV_DispatchThreadID)
{
    uint2 size = uint2(width, height);
    // uint2 size = uint2(ImageSizes[0], ImageSizes[1]);
    uint2 flip = uint2(id.x, size.y - id.y);
    float4 flipped = ImageInput[flip];
    uint2 xy = id.xy;
    Result[xy] = flipped;
}

Here is the compile function :

static HRESULT compileCS(ID3D11Device* pDevice, int csByteLength, const char* csByteString, ComPtr<ID3D11ComputeShader>& shader) {
    HRESULT hr = E_FAIL;
    if (shader != nullptr)
    {
        return S_OK;
    }

    UINT flags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined(DEBUG) || defined(_DEBUG)
    flags |= D3DCOMPILE_DEBUG;
#endif
    // Prefer higher CS shader profile when possible as CS 5.0 provides better performance on 11-class hardware.
    LPCSTR profile = (pDevice->GetFeatureLevel() >= D3D_FEATURE_LEVEL_11_0) ? "cs_5_0" : "cs_4_0";
    const D3D_SHADER_MACRO defines[] =
    {
        "EXAMPLE_DEFINE", "1",
        NULL, NULL };
    ComPtr<ID3DBlob> shaderBlob = nullptr;
    ComPtr<ID3DBlob> errorBlob = nullptr;
    hr == D3DCompile(csByteString,
        csByteLength,
        nullptr,
        defines,
        D3D_COMPILE_STANDARD_FILE_INCLUDE,
        "CSMain",
        profile,
        flags,
        0,
        &shaderBlob,
        &errorBlob);
    if (FAILED(hr))
    {
        if (errorBlob)
        {
            const char* error = (const char*)errorBlob->GetBufferPointer();
            auto bufferSize = errorBlob->GetBufferSize();
            Log(error);
        }
        else
        {
            LogFormat("compile shader failed hr = %#08x", hr);
        }
        return hr;
    }
    Log("compile cs success");
    //编译成功
    hr = pDevice->CreateComputeShader(shaderBlob->GetBufferPointer(), shaderBlob->GetBufferSize(), nullptr, shader.ReleaseAndGetAddressOf());
    if (FAILED(hr))
    {
        Log("Create shader from blob failed!");
        return hr;
    }
    return hr;
}

When I uncomment line 1 in the hlsl,the error changes to another strange error code 0x8e16d8a8.

Note that errorBlob only shows warning when line 1 is uncommented, and shows nothing when commented, just the error code from hr.

I also tried compile from fxc, it can compile and generate bytecode (although when line 1 is uncommented while compiling, it generates the same "unknown pragma kernel" warning), but another error occured when calling CreateComputeShader..

Now I'm lost, can you help me?

\$\endgroup\$
4
  • \$\begingroup\$ What is the full error/warning? Also, you are saying '==' when trying to set your HRESULT. \$\endgroup\$
    – coulomb
    May 16 at 16:52
  • \$\begingroup\$ @coulomb thank you! that is exactly the bug! I still don't know why fxc compiled byte code can't be loaded by CreateComputeShader though. but anyway, I can proceed my work now! \$\endgroup\$ May 17 at 2:18
  • \$\begingroup\$ @coulomb how can I mark your comment as answer? \$\endgroup\$ May 17 at 2:22
  • \$\begingroup\$ I’ll make it into an official answer \$\endgroup\$
    – coulomb
    May 17 at 19:10

1 Answer 1

0
\$\begingroup\$

You are saying ‘==‘ instead of ‘=‘ when setting your HRESULT.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .