MCPcopy Index your code
hub / github.com/processing/p5.js / _initShader

Method _initShader

src/webgpu/p5.RendererWebGPU.js:895–973  ·  view source on GitHub ↗
(shader)

Source from the content-addressed store, hash-verified

893 }
894
895 _initShader(shader) {
896 const device = this.device;
897
898 if (shader.shaderType === 'compute') {
899 // Compute shader initialization
900 shader.computeModule = device.createShaderModule({ code: shader.computeSrc() });
901 shader._computePipelineCache = null;
902 shader._workgroupSize = null;
903
904 // Create compute pipeline (deferred until first compute() call)
905 shader.getPipeline = ({ workgroupSize }) => {
906 if (!shader._computePipelineCache) {
907 shader._computePipelineCache = device.createComputePipeline({
908 layout: shader._pipelineLayout,
909 compute: {
910 module: shader.computeModule,
911 entryPoint: 'main'
912 }
913 });
914 shader._workgroupSize = workgroupSize;
915 }
916 return shader._computePipelineCache;
917 };
918
919 return;
920 }
921
922 // Render shader initialization
923 shader.vertModule = device.createShaderModule({ code: shader.vertSrc() });
924 shader.fragModule = device.createShaderModule({ code: shader.fragSrc() });
925
926 shader._pipelineCache = new Map();
927 shader.getPipeline = ({ topology, blendMode, sampleCount, format, depthFormat, clipping, clipApplied }) => {
928 const key = `${topology}_${blendMode}_${sampleCount}_${format}_${depthFormat}_${clipping}_${clipApplied}`;
929 if (!shader._pipelineCache.has(key)) {
930 const pipeline = device.createRenderPipeline({
931 layout: shader._pipelineLayout,
932 vertex: {
933 module: shader.vertModule,
934 entryPoint: 'main',
935 buffers: this._getVertexLayout(shader),
936 },
937 fragment: {
938 module: shader.fragModule,
939 entryPoint: 'main',
940 targets: [{
941 format,
942 blend: this._getBlendState(blendMode),
943 }],
944 },
945 primitive: { topology },
946 multisample: { count: sampleCount },
947 ...(depthFormat ? {
948 depthStencil: {
949 format: depthFormat,
950 depthWriteEnabled: !clipping,
951 depthCompare: 'less-equal',
952 stencilFront: {

Callers

nothing calls this directly

Calls 7

_getVertexLayoutMethod · 0.95
_getBlendStateMethod · 0.95
computeSrcMethod · 0.80
vertSrcMethod · 0.80
fragSrcMethod · 0.80
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected