Search Unity

What's the DX11 flag and options of an Unity render texture?

Discussion in 'General Graphics' started by John-Chen350, Oct 11, 2016.

  1. John-Chen350

    John-Chen350

    Joined:
    Jan 14, 2015
    Posts:
    53
    Just curious.. I'm newbie to DX11 graphics but familiar with Unity one.

    I've tried to implement some function which requires to provide a texture pointer to some native library; yet my copies of texture2d (DX11) is always wrong when the same thing by Unity proven to be correct. Therefore I'm curious about the underlying options and flags set by Unity..
     
    Last edited: Oct 11, 2016
  2. John-Chen350

    John-Chen350

    Joined:
    Jan 14, 2015
    Posts:
    53
    hmm.. No one knows?
     
  3. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    8 years later and I'm still wondering as well,
    Especially since unfortunately, there's no way to get the texture flags/options that were used to create a a now-existing DX11 texture that we might have.

    I've since-ditched this engine for many reasons on all my personal projects, but still work with it for work.
    I found that using Texture2D.CreateExternalTexture(...) works when I used these flags in C++. Apologies for the slightly incomplete code snippet, cause it's from a large codebase I didn't write and I have yet to learn DX11 in native C++!

    Code (C++):
    1. D3D11_TEXTURE2D_DESC renderTargetDesc = { 0 };
    2.  
    3. renderTargetDesc.Width = static_cast<UINT>(width);
    4. renderTargetDesc.Height = static_cast<UINT>(height);
    5. renderTargetDesc.MipLevels = 1;
    6. renderTargetDesc.ArraySize = 1;
    7. renderTargetDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // Common render target format
    8. renderTargetDesc.SampleDesc.Count = 1;  // Single-sample texture
    9. renderTargetDesc.SampleDesc.Quality = 0; // The highest quality
    10. renderTargetDesc.Usage = D3D11_USAGE_DEFAULT;
    11. renderTargetDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
    12. renderTargetDesc.CPUAccessFlags = D3D11_CPU_ACCESS_FLAG::D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_FLAG::D3D11_CPU_ACCESS_WRITE;
    13. renderTargetDesc.MiscFlags = 0; // No additional flags
    I haven't fully tested though on the CPUAccessFlags, so we might be able to remove those.