yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1// cpu-shader-object-layout.h 2#pragma once 3#include "cpu-base.h" 4 5namespace gfx 6{ 7using namespace Slang ; 8 9namespace cpu 10{ 11 12struct BindingRangeInfo 13{ 14slang ::BindingType bindingType ; 15Index count ; 16Index baseIndex ;// Flat index for sub-objects 17Index subObjectIndex ; 18 19// TODO: The `uniformOffset` field should be removed, 20// since it cannot be supported by the Slang reflection 21// API once we fix some design issues. 22// 23// It is only being used today for pre-allocation of sub-objects 24// for constant buffers and parameter blocks (which should be 25// deprecated/removed anyway). 26// 27// Note: We would need to bring this field back, plus 28// a lot of other complexity, if we ever want to support 29// setting of resources/buffers directly by a binding 30// range index and array index. 31// 32Index uniformOffset ;// Uniform offset for a resource typed field. 33 34bool isSpecializable ; 35}; 36 37struct SubObjectRangeInfo 38{ 39RefPtr < ShaderObjectLayoutImpl > layout ; 40Index bindingRangeIndex ; 41}; 42 43class ShaderObjectLayoutImpl :public ShaderObjectLayoutBase 44{ 45public : 46// TODO: Once memory lifetime stuff is handled, there is 47// no specific need to even track binding or sub-object 48// ranges for CPU. 49 50size_t m_size = 0 ; 51List < SubObjectRangeInfo > subObjectRanges ; 52List < BindingRangeInfo > m_bindingRanges ; 53 54Index m_subObjectCount = 0 ; 55Index m_resourceCount = 0 ; 56 57ShaderObjectLayoutImpl ( 58RendererBase * renderer , 59slang ::ISession * session , 60slang ::TypeLayoutReflection * layout ); 61 62size_t getSize (); 63Index getResourceCount ()const ; 64Index getSubObjectCount ()const ; 65List < SubObjectRangeInfo >& getSubObjectRanges (); 66BindingRangeInfo getBindingRange (Index index ); 67Index getBindingRangeCount ()const ; 68}; 69 70class EntryPointLayoutImpl :public ShaderObjectLayoutImpl 71{ 72private : 73slang ::EntryPointLayout * m_entryPointLayout = nullptr ; 74 75public : 76EntryPointLayoutImpl ( 77RendererBase * renderer , 78slang ::ISession * session , 79slang ::EntryPointLayout * entryPointLayout ) 80 :ShaderObjectLayoutImpl (renderer ,session ,entryPointLayout -> getTypeLayout ()) 81 ,m_entryPointLayout (entryPointLayout ) 82 { 83 } 84 85const char * getEntryPointName (); 86}; 87 88class RootShaderObjectLayoutImpl :public ShaderObjectLayoutImpl 89{ 90public : 91slang ::ProgramLayout * m_programLayout = nullptr ; 92List < RefPtr < EntryPointLayoutImpl >>m_entryPointLayouts ; 93 94RootShaderObjectLayoutImpl ( 95RendererBase * renderer , 96slang ::ISession * session , 97slang ::ProgramLayout * programLayout ); 98 99int getKernelIndex (UnownedStringSlice kernelName ); 100void getKernelThreadGroupSize (int kernelIndex ,UInt * threadGroupSizes ); 101 102EntryPointLayoutImpl * getEntryPoint (Index index ); 103}; 104 105}// namespace cpu 106}// namespace gfx