Example #1
0
int main(int argc, char** argv)
{
    if(argc < 2)
    {
        usage();
        return 1;
    }

    std::vector<char> data;
    std::ifstream in(argv[1]);
    char c;
    in >> std::noskipws;
    while(in >> c)
        data.push_back(c);
    in.close();

    dxbc_container* dxbc = dxbc_parse(&data[0], data.size());
    if(dxbc)
    {
        std::cout << *dxbc;
        dxbc_chunk_header* sm4_chunk = dxbc_find_shader_bytecode(&data[0], data.size());
        if(sm4_chunk)
        {
            sm4_program* sm4 = sm4_parse(sm4_chunk + 1, bswap_le32(sm4_chunk->size));
            if(sm4)
            {
                std::cout << *sm4;
                delete sm4;
            }
        }
        delete dxbc;
    }
}
Example #2
0
int main(int argc, char** argv)
{
    if(argc < 2)
    {
        usage();
        return EXIT_FAILURE;
    }

    std::vector<char> data;
    FILE *pFile = NULL;
#ifdef _MSC_VER
    fopen_s(&pFile, argv[1], "rb" );
#else
    pFile = fopen(argv[1], "rb" );
#endif
    if ( !pFile )
    {
       printf("Could not open file: %s\n", pFile );
       return EXIT_FAILURE;
    }

    fseek(pFile, 0, SEEK_END);
    uint32_t nFileSize = ftell(pFile);
    fseek(pFile, 0, SEEK_SET);

    if (nFileSize < sizeof(dxbc_container_header))
    {
      printf("File is too small!\n");
      return EXIT_FAILURE;
    }

    data.resize(nFileSize);
    if (fread(&data[0], 1, nFileSize, pFile) != nFileSize)
    {
       printf("Failed reading file!\n");
       return EXIT_FAILURE;
    }
    fclose(pFile);

    dxbc_container* dxbc = dxbc_parse(&data[0], data.size());
    if(dxbc)
    {
        std::cout << *dxbc;
        dxbc_chunk_header* sm4_chunk = dxbc_find_shader_bytecode(&data[0], data.size());
        if(sm4_chunk)
        {
            sm4_program* sm4 = sm4_parse(sm4_chunk + 1, bswap_le32(sm4_chunk->size));
            if(sm4)
            {
                std::cout << *sm4;
                delete sm4;
            }
        }
        delete dxbc;
    }

    return EXIT_SUCCESS;
}
Example #3
0
std::pair<void*, size_t> dxbc_assemble(struct dxbc_chunk_header** chunks, unsigned num_chunks)
{
   size_t data_size = 0;
   for(unsigned i = 0; i < num_chunks; ++i)
      data_size += sizeof(uint32_t) + sizeof(dxbc_chunk_header) + bswap_le32(chunks[i]->size);

   size_t total_size = sizeof(dxbc_container_header) + data_size;
   dxbc_container_header* header = (dxbc_container_header*)malloc(total_size);
   if(!header)
      return std::make_pair((void*)0, 0);

   header->fourcc = bswap_le32(FOURCC_DXBC);
   memset(header->unk, 0, sizeof(header->unk));
   header->one = bswap_le32(1);
   header->total_size = bswap_le32(total_size);
   header->chunk_count = num_chunks;

   uint32_t* chunk_offsets = (uint32_t*)(header + 1);
   uint32_t off = sizeof(struct dxbc_container_header) + num_chunks * sizeof(uint32_t);
   for(unsigned i = 0; i < num_chunks; ++i)
   {
      chunk_offsets[i] = bswap_le32(off);
      unsigned chunk_full_size = sizeof(dxbc_chunk_header) + bswap_le32(chunks[i]->size);
      memcpy((char*)header + off, chunks[i], chunk_full_size);
      off += chunk_full_size;
   }

   return std::make_pair((void*)header, total_size);
}