Asked by:
Using ID3D11ClassLinkage::CreateClassInstance method

Question
-
Hello,
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
- Edited by ThyVanitas Friday, January 11, 2013 2:27 PM
Friday, January 11, 2013 10:22 AM
All replies
-
Have you looked at this MSDN page?
http://msdn.microsoft.com/en-us/library/windows/desktop/ff471421(v=vs.85).aspx
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.
Friday, January 11, 2013 7:58 PM -
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 http://msdn.microsoft.com/en-us/library/windows/desktop/ff476360(v=vs.85).aspx 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.
- Edited by ThyVanitas Friday, January 11, 2013 9:59 PM
Friday, January 11, 2013 9:11 PM -
@TheVanitas Did you ever find an answer to this, i have a similar problemSunday, March 1, 2015 12:27 PM