S32 GFXD3D9ShaderConstHandle::getSamplerRegister() const
{
   if ( !mValid || !isSampler() )
      return -1;

   // We always store sampler type and register index in the pixelHandle,
   // sampler registers are shared between vertex and pixel shaders anyway.

   return mPixelHandle.offset;   
}
示例#2
0
bool getReflectionDataD3D9(ID3DBlob* _code, UniformArray& _uniforms)
{
    // see reference for magic values: https://msdn.microsoft.com/en-us/library/ff552891(VS.85).aspx
    const uint32_t D3DSIO_COMMENT = 0x0000FFFE;
    const uint32_t D3DSIO_END = 0x0000FFFF;
    const uint32_t D3DSI_OPCODE_MASK = 0x0000FFFF;
    const uint32_t D3DSI_COMMENTSIZE_MASK = 0x7FFF0000;
    const uint32_t CTAB_CONSTANT = MAKEFOURCC('C', 'T', 'A', 'B');

    // parse the shader blob for the constant table
    const size_t codeSize = _code->GetBufferSize();
    const uint32_t* ptr = (const uint32_t*)_code->GetBufferPointer();
    const uint32_t* end = (const uint32_t*)( (const uint8_t*)ptr + codeSize);
    const CTHeader* header = NULL;

    ptr++;	// first byte is shader type / version; skip it since we already know

    while (ptr < end && *ptr != D3DSIO_END)
    {
        uint32_t cur = *ptr++;
        if ( (cur & D3DSI_OPCODE_MASK) != D3DSIO_COMMENT)
        {
            continue;
        }

        // try to find CTAB comment block
        uint32_t commentSize = (cur & D3DSI_COMMENTSIZE_MASK) >> 16;
        uint32_t fourcc = *ptr;
        if (fourcc == CTAB_CONSTANT)
        {
            // found the constant table data
            header = (const CTHeader*)(ptr + 1);
            uint32_t tableSize = (commentSize - 1) * 4;
            if (tableSize < sizeof(CTHeader) || header->Size != sizeof(CTHeader) )
            {
                fprintf(stderr, "Error: Invalid constant table data\n");
                return false;
            }
            break;
        }

        // this is a different kind of comment section, so skip over it
        ptr += commentSize - 1;
    }

    if (!header)
    {
        fprintf(stderr, "Error: Could not find constant table data\n");
        return false;
    }

    const uint8_t* headerBytePtr = (const uint8_t*)header;
    const char* creator = (const char*)(headerBytePtr + header->Creator);

    BX_TRACE("Creator: %s 0x%08x", creator, header->Version);
    BX_TRACE("Num constants: %d", header->Constants);
    BX_TRACE("#   cl ty RxC   S  By Name");

    const CTInfo* ctInfoArray = (const CTInfo*)(headerBytePtr + header->ConstantInfo);
    for (uint32_t ii = 0; ii < header->Constants; ++ii)
    {
        const CTInfo& ctInfo = ctInfoArray[ii];
        const CTType& ctType = *(const CTType*)(headerBytePtr + ctInfo.TypeInfo);
        const char* name = (const char*)(headerBytePtr + ctInfo.Name);

        BX_TRACE("%3d %2d %2d [%dx%d] %d %s[%d] c%d (%d)"
                 , ii
                 , ctType.Class
                 , ctType.Type
                 , ctType.Rows
                 , ctType.Columns
                 , ctType.StructMembers
                 , name
                 , ctType.Elements
                 , ctInfo.RegisterIndex
                 , ctInfo.RegisterCount
                );

        D3D11_SHADER_TYPE_DESC desc;
        desc.Class = (D3D_SHADER_VARIABLE_CLASS)ctType.Class;
        desc.Type = (D3D_SHADER_VARIABLE_TYPE)ctType.Type;
        desc.Rows = ctType.Rows;
        desc.Columns = ctType.Columns;

        UniformType::Enum type = findUniformType(desc);
        if (UniformType::Count != type)
        {
            Uniform un;
            un.name = '$' == name[0] ? name + 1 : name;
            un.type = isSampler(desc.Type)
                      ? UniformType::Enum(BGFX_UNIFORM_SAMPLERBIT | type)
                      : type
                      ;
            un.num = (uint8_t)ctType.Elements;
            un.regIndex = ctInfo.RegisterIndex;
            un.regCount = ctInfo.RegisterCount;

            _uniforms.push_back(un);
        }
    }

    return true;
}