Jump to content
  • Advertisement
Sign in to follow this  
Juliean

DX11 D3DCompile default include interface

This topic is 2124 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

 

I'm trying to get rid of all D3DX11-functionality, and one of the first suspects is the D3DX11CompileFromMemory-function. However, I'm having troubles with the IID3DInclude-interface you got to specify. Documentation says, you can just use:

#define D3D_COMPILE_STANDARD_FILE_INCLUDE ((ID3DInclude*)(UINT_PTR)1)

for a standard include interface, however when I use that macro, I always get a "failed to read at memory 1" error. Now there is very little tutorials/complete source code that actually use D3DCompile. Is there anything I've missed so this fails, or some other thing I'll have to consider?

Share this post


Link to post
Share on other sites
Advertisement

I looks like your DX SDK is to old. At least the June 2010 SDK is missing this function. So you either need to use a newer SDK or implement the interface yourself. Since I just hat to implement this interface a few days ago too this may help you to start:

class CDXInclude : public ID3DInclude
{
public:
  CDXInclude(const std::string& baseFile);

  HRESULT __stdcall Open(D3D_INCLUDE_TYPE IncludeType, LPCSTR pFileName,
                         LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes);

  HRESULT __stdcall Close(LPCVOID pData);

private:
  std::string m_baseDir;
  std::list<std::unique_ptr<char[]>> m_data;
};

CDXInclude::CDXInclude(const std::string& baseFile)
{
  size_t pos = baseFile.rfind('/');
  if(pos != std::string::npos)
    m_baseDir = baseFile.substr(0, pos) + '/';
}

HRESULT CDXInclude::Open(D3D_INCLUDE_TYPE IncludeType, LPCSTR pFileName,
                         LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes)
{
  // Open file
  std::ifstream file(m_baseDir + pFileName, std::ios::binary);
  if(!file.is_open())
  {
    *ppData = NULL;
    *pBytes = 0;
    return S_OK;
  }

  // Get filesize
  file.seekg(0, std::ios::end);
  UINT size = static_cast<UINT>(file.tellg());
  file.seekg(0, std::ios::beg);

  // Create buffer and read file
  std::unique_ptr<char[]> data(new char[size]);
  file.read(data.get(), size);
  *ppData = data.get();
  *pBytes = size;
  m_data.push_back(std::move(data));
  return S_OK;
}

HRESULT CDXInclude::Close(LPCVOID pData)
{
  m_data.remove_if(shared_equals_raw(pData));
  return S_OK;
}

Note: I'm using some C++11 functions but instead you can use simple pointers if you want.

Edited by sebi707

Share this post


Link to post
Share on other sites

Thanks, I'll use your implementation as a starting point. I don't plan on using the newer SDK unless I start with DX11.1 / 2 to target Windows8, so that should do fine for now.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!