MCPcopy Create free account
hub / github.com/defold/defold / WebGPUGetOrCreateSampler

Function WebGPUGetOrCreateSampler

engine/graphics/src/webgpu/graphics_webgpu.cpp:118–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116DM_REGISTER_GRAPHICS_ADAPTER(GraphicsAdapterWebGPU, &g_webgpu_adapter, WebGPUIsSupported, WebGPURegisterFunctionTable, WebGPUGetContext, ADAPTER_FAMILY_PRIORITY_WEBGPU);
117
118static WGPUSampler WebGPUGetOrCreateSampler(WebGPUContext* context, TextureFilter minfilter, TextureFilter magfilter, TextureWrap uwrap, TextureWrap vwrap, float max_anisotropy)
119{
120 HashState64 sampler_hash_state;
121 dmHashInit64(&sampler_hash_state, false);
122 dmHashUpdateBuffer64(&sampler_hash_state, &minfilter, sizeof(minfilter));
123 dmHashUpdateBuffer64(&sampler_hash_state, &magfilter, sizeof(magfilter));
124 dmHashUpdateBuffer64(&sampler_hash_state, &uwrap, sizeof(uwrap));
125 dmHashUpdateBuffer64(&sampler_hash_state, &vwrap, sizeof(vwrap));
126 dmHashUpdateBuffer64(&sampler_hash_state, &max_anisotropy, sizeof(max_anisotropy));
127
128 const uint64_t sampler_hash = dmHashFinal64(&sampler_hash_state);
129 if (WGPUSampler* cached_sampler = context->m_SamplerCache.Get(sampler_hash))
130 return *cached_sampler;
131
132#if defined(DM_GRAPHICS_WEBGPU2)
133 WGPUSamplerDescriptor desc = WGPU_SAMPLER_DESCRIPTOR_INIT;
134#else
135 WGPUSamplerDescriptor desc = {};
136#endif
137 desc.lodMinClamp = 0;
138 desc.lodMaxClamp = 32;
139
140 desc.maxAnisotropy = uint16_t(max_anisotropy);
141 desc.addressModeU = g_webgpu_address_mode[uwrap];
142 desc.addressModeV = g_webgpu_address_mode[vwrap];
143
144 if (magfilter == TEXTURE_FILTER_DEFAULT)
145 magfilter = context->m_BaseContext.m_DefaultTextureMagFilter;
146 switch (magfilter)
147 {
148 case TEXTURE_FILTER_NEAREST:
149 desc.magFilter = WGPUFilterMode_Nearest;
150 break;
151 case TEXTURE_FILTER_LINEAR:
152 desc.magFilter = WGPUFilterMode_Linear;
153 break;
154 default:
155 assert(false);
156 }
157
158 if (minfilter == TEXTURE_FILTER_DEFAULT)
159 minfilter = context->m_BaseContext.m_DefaultTextureMinFilter;
160 switch (minfilter)
161 {
162 case TEXTURE_FILTER_NEAREST:
163 desc.magFilter = WGPUFilterMode_Nearest;
164 desc.lodMaxClamp = 0.25f;
165 break;
166 case TEXTURE_FILTER_LINEAR:
167 desc.magFilter = WGPUFilterMode_Linear;
168 desc.lodMaxClamp = 0.25f;
169 break;
170 case TEXTURE_FILTER_NEAREST_MIPMAP_NEAREST:
171 desc.minFilter = WGPUFilterMode_Nearest;
172 desc.mipmapFilter = WGPUMipmapFilterMode_Nearest;
173 break;
174 case TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR:
175 desc.minFilter = WGPUFilterMode_Nearest;

Callers 2

InitializeWebGPUContextFunction · 0.85

Calls 9

dmHashInit64Function · 0.85
dmHashUpdateBuffer64Function · 0.85
dmHashFinal64Function · 0.85
assertFunction · 0.50
GetMethod · 0.45
FullMethod · 0.45
SetCapacityMethod · 0.45
CapacityMethod · 0.45
PutMethod · 0.45

Tested by

no test coverage detected