@@ -9,14 +9,11 @@ import {
99 SelectValue ,
1010} from '@/components/ui/select' ;
1111import { Button } from './button' ;
12- import { createShaders } from '../computation/WGSLShaders' ;
1312import { useAnalysisStore , useGlobalStore } from '@/GlobalStates' ;
1413import { IoCloseCircleSharp } from "react-icons/io5" ;
1514import { useShallow } from 'zustand/shallow' ;
16- import { Hider , KernelVisualizer , Input , Switcher } from '../ui' ;
17- import { HandleKernelNums } from '@/utils/HelperFuncs' ;
18-
19- const boilerplates = createShaders ( "f16" ) [ 'boilerPlates' ]
15+ import { Hider , Input , Switcher } from '../ui' ;
16+ import { templates } from './ShaderTemplates' ;
2017
2118const selectedPlates = {
2219 None : " " ,
@@ -25,86 +22,32 @@ const selectedPlates = {
2522 Convolution2D : "ConvolutionBoilerPlate2D"
2623}
2724
28- const kernelLoop3D = /* WGSL */ `
29- for (var kx: i32 = xy_start; kx < xy_end; kx++) {
30- for (var ky: i32 = xy_start; ky < xy_end; ky++) {
31- for (var kz: i32 = z_start; kz < z_end; kz++){
32- let in_coord = vec3<i32>(global_id) + vec3<i32>(kx, ky, kz);
33- if (in_coord.x >= 0 && in_coord.x < i32(xSize) &&
34- in_coord.y >= 0 && in_coord.y < i32(ySize) &&
35- in_coord.z >= 0 && in_coord.z < i32(zSize)) { //Ensure the sampled point is within dataspace
36- let xOffset = kx * i32(xStride);
37- let yOffset = ky * i32(yStride);
38- let zOffset = kz * i32(zStride);
39- let newIdx = i32(globalIdx) + xOffset + yOffset + zOffset;
40-
41- //Write your Kernel Code here
42- }
43- }
44- }
45- }
46- `
47- const kernelLoop2D = /* WGSL */ `
48- for (var kx: i32 = -xy_radius; kx <= xy_radius; kx++) {
49- for (var ky: i32 = -xy_radius; ky <= xy_radius; ky++) {
50- let in_coord = vec2<i32>(i32(global_id.x), i32(global_id.y)) + vec2<i32>(kx, ky);
51- if (in_coord.x >= 0 && in_coord.x < i32(xSize) &&
52- in_coord.y >= 0 && in_coord.y < i32(ySize)) { //Ensure the sampled point is within dataspace
53- let xOffset = kx * i32(xStride);
54- let yOffset = ky * i32(yStride);
55- let newIdx = i32(globalIdx) + xOffset + yOffset;
56-
57- //Write your Kernel Code here
58- }
59- }
60- }
61-
62- `
63-
64- const GenBoilerPlat = ( boilerPlate : string ) => {
65- let header = boilerplates [ boilerPlate as keyof typeof boilerplates ] ?. replace ( " " , "" ) ?? ""
66- function convolution ( boilerPlate : string ) {
67- switch ( boilerPlate ) {
68- case "ConvolutionBoilerPlate" :
69- return kernelLoop3D ;
70- case "ConvolutionBoilerPlate2D" :
71- return kernelLoop2D ;
72- default :
73- return ""
74- }
75- }
76- const codeRegion = `
77- //WRITE YOUR CODE HERE
78-
79- ${ convolution ( boilerPlate ) }
80- }
81- `
82- return header ? header + codeRegion : ""
83- }
84-
8525export const ShaderEditor = ( { visible} : { visible : boolean } ) => {
8626 const [ shader , setShader ] = useState < string | undefined > ( )
8727 const [ showUniforms , setShowUniforms ] = useState ( false )
8828 const [ newDim , setNewDim ] = useState ( 0 )
8929 const [ boilerPlate , setBoilerPlate ] = useState ( "" )
9030 const { resolvedTheme} = useTheme ( )
91- const { executeCustom, kernelDepth, kernelSize, reduceOnAxis, setKernelDepth, setKernelSize, setReduceOnAxis} = useAnalysisStore ( useShallow ( state => ( {
31+ const { executeCustom, kernelDepth, kernelSize, axis , reduceOnAxis, variable2 , setKernelDepth, setKernelSize, setReduceOnAxis} = useAnalysisStore ( useShallow ( state => ( {
9232 executeCustom : state . executeCustom ,
9333 kernelSize : state . kernelSize ,
9434 kernelDepth : state . kernelDepth ,
9535 reduceOnAxis : state . reduceOnAxis ,
36+ axis : state . axis ,
37+ variable2 : state . variable2 ,
9638 setKernelDepth : state . setKernelDepth ,
9739 setKernelSize : state . setKernelSize ,
9840 setReduceOnAxis : state . setReduceOnAxis
9941 } ) ) )
100- const { dimNames, dataShape} = useGlobalStore ( useShallow ( state => ( {
42+ const { dimNames, dataShape, variable } = useGlobalStore ( useShallow ( state => ( {
10143 dimNames : state . dimNames ,
102- dataShape : state . dataShape
44+ dataShape : state . dataShape ,
45+ variable : state . variable
10346 } ) ) )
10447 const [ outputShape , setOutPutShape ] = useState ( dataShape )
10548
10649 useEffect ( ( ) => {
107- if ( boilerPlate != "None" ) setShader ( GenBoilerPlat ( boilerPlate ) )
50+ if ( boilerPlate != "None" ) setShader ( templates [ boilerPlate as keyof typeof templates ] )
10851 else setShader ( "" )
10952 } , [ boilerPlate ] )
11053
@@ -118,7 +61,7 @@ export const ShaderEditor = ({visible} : {visible: boolean}) => {
11861 } , [ reduceOnAxis , newDim , dataShape ] )
11962 return (
12063 < div
121- className = 'flex fixed flex-col items-center w-[100%] h-[100%] z-10 left-1/2 -translate-x-1/2'
64+ className = 'fixed flex flex -col items-center w-[100%] h-[100%] z-10 left-1/2 -translate-x-1/2'
12265 style = { {
12366 backdropFilter :'blur(20px)' ,
12467 borderRadius :'10px' ,
@@ -128,65 +71,43 @@ export const ShaderEditor = ({visible} : {visible: boolean}) => {
12871 display : visible ? "" : "none"
12972 } }
13073 >
131- < Button
132- onClick = { ( ) => setShowUniforms ( x => ! x ) }
133- >
134- { ( showUniforms ? 'Hide' : 'Show' ) + ' Uniforms' }
135- </ Button >
136- < Hider className = 'w-[60%]' show = { showUniforms } >
137- < div className = 'flex justify-left ' >
138- < div className = 'mx-8' >
139- < div className = 'grid grid-cols-2 gap-2 place-items-center' >
140- < div className = 'grid place-items-center' >
141- < b > reduceDim</ b >
142- < Select onValueChange = { e => setNewDim ( parseInt ( e ) ) } >
143- < SelectTrigger >
144- < SelectValue placeholder = { dimNames [ newDim ] } />
145- </ SelectTrigger >
146- < SelectContent >
147- { dimNames . map ( ( dimName , idx ) => (
148- < SelectItem key = { idx } value = { String ( idx ) } >
149- { dimName }
150- </ SelectItem >
151- ) ) }
152- </ SelectContent >
153- </ Select >
154- </ div >
155- < div className = 'grid place-items-center' >
156- < b > dimLength</ b >
157- { dataShape [ newDim ] }
158- </ div >
159- </ div >
160-
161- < Switcher leftText = 'Reduce' rightText = 'Keep' state = { reduceOnAxis } onClick = { ( ) => setReduceOnAxis ( ! reduceOnAxis ) } />
162- < b > Output Shape</ b > < br />
163- { JSON . stringify ( outputShape ) }
164- </ div >
165- < div className = 'grid grid-cols-[80px_auto]' >
166- < div className = 'grid' >
167- < div >
168- < b > kernelSize</ b >
169- < Input type = 'number' min = '1' step = '2' value = { String ( kernelSize ) }
170- onChange = { e => setKernelSize ( parseInt ( e . target . value ) ) }
171- onBlur = { e => setKernelSize ( HandleKernelNums ( e . target . value ) ) }
172- />
173- </ div >
174- < div >
175- < b > kernelDepth</ b >
176- < Input type = 'number' min = '1' step = '2' value = { String ( kernelDepth ) }
177- onChange = { e => setKernelDepth ( parseInt ( e . target . value ) ) }
178- onBlur = { e => setKernelDepth ( HandleKernelNums ( e . target . value ) ) }
179- />
180- </ div >
181- </ div >
182- < KernelVisualizer size = { kernelSize } depth = { kernelDepth } />
183- </ div >
184- </ div >
185- </ Hider >
186- < div className = 'mt-8 mb-2 flex justify-start items-center' >
187- < Select onValueChange = { setBoilerPlate } >
74+ < Hider className = 'w-[60%] mt-4' show = { showUniforms } >
75+ < div style = { {
76+ all : "unset" ,
77+ display : "grid" ,
78+ gridTemplateColumns : "0.5fr 1.33fr 0.5fr 1.33fr 0.5fr 1.33fr" ,
79+ gap : "2px" ,
80+ borderRadius :'12px' ,
81+ padding : "8px" ,
82+ placeItems :'center' ,
83+ background :'var(--modal-shadow)' ,
84+ border : "1px solid var(--border)"
85+ } }
86+ >
87+ < b > reduceDim</ b >
88+ < p > This is the dimension kernels will move alonge. It is currently set to < b > { axis } ({ dimNames [ axis ] } )</ b > </ p >
89+ < b > kernelSize</ b >
90+ < p > This is the spatial radius of the kernel for convolution operations. It is currently set to < b > { kernelSize } </ b > </ p >
91+ < b > inputData</ b >
92+ < p > This is the input array</ p >
93+ < b > dimLength</ b >
94+ < p > This is the length of the dimension being reduced. It is currently < b > { dataShape [ axis ] } </ b > </ p >
95+ < b > kernelDepth</ b >
96+ < p > This is the depth radius of the kernel for convolution operations. It is currently set to < b > { kernelDepth } </ b > </ p >
97+ < b > outputData</ b >
98+ < p > This is the array computations are written to</ p >
99+ < b > firstData</ b >
100+ < p > When using two inputs, this is the first array. It is currently set to < b > { variable } </ b > </ p >
101+ < b > secondData</ b >
102+ < p > When using two inputs, this is the second array. It is currently set to < b > { variable2 } </ b > </ p >
103+ </ div >
104+ </ Hider >
105+ < div className = 'mt-8 mb-2 flex gap-4 items-center w-[60%]' >
106+ < div className = 'flex flex-col items-center self-end' >
107+ < b > Get started with presets</ b >
108+ < Select onValueChange = { setBoilerPlate } >
188109 < SelectTrigger style = { { width : '175px' , marginLeft : '18px' } } >
189- < SelectValue placeholder = { "Include Boilderplate " } />
110+ < SelectValue placeholder = { "Select Template " } />
190111 </ SelectTrigger >
191112 < SelectContent >
192113 { [ "None" , "Reduction" , "Convolution3D" , "Convolution2D" ] . map ( ( val , idx ) => (
@@ -196,14 +117,19 @@ export const ShaderEditor = ({visible} : {visible: boolean}) => {
196117 ) ) }
197118 </ SelectContent >
198119 </ Select >
199- < b > Get started with presets</ b >
120+ </ div >
121+ < Button
122+ onClick = { ( ) => setShowUniforms ( x => ! x ) }
123+ >
124+ { ( showUniforms ? 'Hide' : 'Show' ) + ' Uniforms' }
125+ </ Button >
200126 </ div >
201127 < div className = 'w-[60%] h-[70%] relative' >
202128 < IoCloseCircleSharp
203129 size = { 40 }
204130 style = { {
205131 position :'absolute' ,
206- left :0 ,
132+ right :0 ,
207133 bottom :"100%" ,
208134 zIndex :6 ,
209135 cursor :'pointer'
0 commit comments