Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualmhagain

Posted 12 February 2013 - 05:45 PM

The Effects11 source code is available and can be examined; you'll find it at e.g. C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Samples\C++\Effects11

 

Looking through how it handles cbuffer updates, the way it works is that it builds a chunk of memory representing the cbuffer data, then each Effect->Set call will root through that and copy your data to the appropriate place (setting a dirty flag while doing so), like so:

 

template<typename IBaseInterface, BOOL IsAnnotation>
HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::SetFloat(float Value)
{
    LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloat";
    if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
    DirtyVariable();
    return CopyScalarValue<ETVT_Float, ETVT_Int, float, FALSE>(Value, Data.pNumericInt, pFuncName);
}

 

Then, before draw calls are issued, it checks if the dirty flag is set and if so it uploads the entire buffer via UpdateSubresource, like so:

 

// Update constant buffer contents if necessary
D3DX11INLINE void CheckAndUpdateCB_FX(ID3D11DeviceContext *pContext, SConstantBuffer *pCB)
{
    if (pCB->IsDirty && !pCB->IsNonUpdatable)
    {
        // CB out of date; rebuild it
        pContext->UpdateSubresource(pCB->pD3DObject, 0, NULL, pCB->pBackingStore, pCB->Size, pCB->Size);
        pCB->IsDirty = FALSE;
    }
}

 

You can probably do a little better than that yourself (you can also do much worse if you don't manage your cbuffers properly, of course).

 

It's probably not a good idea to mix the two ways as all it takes is one dirty flag (i.e. one cbuffer variable set via Effects) to cause the entire cbuffer to be marked dirty, which will stomp over anything you set yourself.


#2mhagain

Posted 12 February 2013 - 05:41 PM

The Effects11 source code is available and can be examined; you'll find it at e.g. C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Samples\C++\Effects11

 

Looking through how it handles cbuffer updates, the way it works is that it builds a chunk of memory representing the cbuffer data, then each Effect->Set call will root through that and copy your data to the appropriate place (setting a dirty flag while doing so), like so:

 

template<typename IBaseInterface, BOOL IsAnnotation>
HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::SetFloat(float Value)
{
    LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloat";
    if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
    DirtyVariable();
    return CopyScalarValue<ETVT_Float, ETVT_Int, float, FALSE>(Value, Data.pNumericInt, pFuncName);
}

 

Then, before draw calls are issued, it checks if the dirty flag is set and if so it uploads the entire buffer via UpdateSubresource, like so:

 

// Update constant buffer contents if necessary
D3DX11INLINE void CheckAndUpdateCB_FX(ID3D11DeviceContext *pContext, SConstantBuffer *pCB)
{
    if (pCB->IsDirty && !pCB->IsNonUpdatable)
    {
        // CB out of date; rebuild it
        pContext->UpdateSubresource(pCB->pD3DObject, 0, NULL, pCB->pBackingStore, pCB->Size, pCB->Size);
        pCB->IsDirty = FALSE;
    }
}

You can probably do a little better than that yourself (you can also do much worse if you don't manage your cbuffers properly, of course).


#1mhagain

Posted 12 February 2013 - 05:41 PM

The Effects11 source code is available and can be examined; you'll find it at:

 

Looking through how it handles cbuffer updates, the way it works is that it builds a chunk of memory representing the cbuffer data, then each Effect->Set call will root through that and copy your data to the appropriate place (setting a dirty flag while doing so), like so:

 

template<typename IBaseInterface, BOOL IsAnnotation>
HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::SetFloat(float Value)
{
    LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloat";
    if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
    DirtyVariable();
    return CopyScalarValue<ETVT_Float, ETVT_Int, float, FALSE>(Value, Data.pNumericInt, pFuncName);
}

 

Then, before draw calls are issued, it checks if the dirty flag is set and if so it uploads the entire buffer via UpdateSubresource, like so:

 

// Update constant buffer contents if necessary
D3DX11INLINE void CheckAndUpdateCB_FX(ID3D11DeviceContext *pContext, SConstantBuffer *pCB)
{
    if (pCB->IsDirty && !pCB->IsNonUpdatable)
    {
        // CB out of date; rebuild it
        pContext->UpdateSubresource(pCB->pD3DObject, 0, NULL, pCB->pBackingStore, pCB->Size, pCB->Size);
        pCB->IsDirty = FALSE;
    }
}

You can probably do a little better than that yourself (you can also do much worse if you don't manage your cbuffers properly, of course).


PARTNERS