ThyVanitas on Fri, 11 Jan 2013 10:22:14


My environment is:

Win 8 Pro, 64bit

Visual Studio 2012

I am implementing shader dynamic linking functionality for compute shader. In particular, I am having an interface and a few subclasses without variable members. The shader code is straightforward.

interface MathOperation
    float4 Execute(float4 arg1, float4 arg2);

class MaxOperation : MathOperation
    float4 Execute(float4 arg1, float4 arg2)
        return max(arg1, arg2);  

class MinOperation : MathOperation
    float4 Execute(float4 arg1, float4 arg2)
        return min(arg1, arg2);  

// Declaring interface varibale in the code. Concrete class instances are not declared.
MathOperation g_Operation;

 According to msdn, I have to use ID3D11ClassLinkage::CreateClassInstance method to create concrete class instance. The method requires as the 2nd argument ConstantBufferOffset, that is constant buffer that contains class data. The classes that do not have members cannot be put in constant buffer as they are going to be optimized out. Indeed, I have tried to put MathOperation and MinOperation class instances into constant buffer and shader reflection API returns only 1 interface via GetNumInterfaceSlots function. 

What is the purpose of this parameter? How to use ID3D11ClassLinkage::CreateClassInstance method?

I have not found any example demonstrating that and the sample from DirectX SDK covers the case with member variables only.

Many thanks, indeed   



Chuck Walbourn - MSFT on Fri, 11 Jan 2013 19:58:42

Have you looked at this MSDN page?

PS: Be sure to note that Dynamic Shader Linkage (the hardware feature required for ClassLinkage) requires Feature Level 11.0 or Feature Level 11.1 hardware.

ThyVanitas on Fri, 11 Jan 2013 21:11:29

I have been consulting this page hugely. Indeed, it demonstrates how to use classes with member variables.

Please have a look below what is says about classes without variable members. 

Each class that will be used in place of an interface instance must either be declared as a variable in a constant buffer or created by the application at runtime using the ID3D11ClassLinkage::CreateClassInstance method. 

Also, this claims that 

A class instance must have at least 1 data member in order to be available for the runtime to use with ID3D11ClassLinkage::GetClassInstance. Any instance with no members will be optimized out of a compiled shader blob as a zero-sized object. If you have a class with no data members, use ID3D11ClassLinkage::CreateClassInstance instead. 

That is why, CreateClassInstance() should be my choice. 

I have Geforce GTX 680 video card and use feature level 11.0.

I do not understand how to use the function.

AndimusPrime on Sun, 01 Mar 2015 12:27:56

@TheVanitas Did you ever find an answer to this, i have a similar problem