public static void CheckEffect() { string resGroup = ResGroup.Effect.ToString().ToLower(); string[] assetBundleNames = AssetDatabase.GetAllAssetBundleNames(); Dictionary <string, TexRef> paths = new Dictionary <string, TexRef>(); foreach (var assetBundleName in assetBundleNames) { if (assetBundleName.StartsWith(resGroup) == false) { continue; } string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName); foreach (var assetPath in assetPaths) { foreach (var dependenciesPath in AssetDatabase.GetDependencies(assetPath)) { Texture2D tex = AssetDatabase.LoadAssetAtPath <Texture2D>(dependenciesPath); if (tex == null) { continue; } TexRef texRef = null; if (paths.TryGetValue(dependenciesPath, out texRef)) { texRef.AddRef(assetPath); } else { paths.Add(dependenciesPath, new TexRef(dependenciesPath, tex.width, tex.height, assetPath, CheckTexture(tex))); } } } } using (StreamWriter streamWriter = new StreamWriter(File.Create("Assets/EffectCheck.csv"))) { streamWriter.WriteLine(TexRef.OutHead()); foreach (var item in paths) { streamWriter.Write(item.Value.ToString()); streamWriter.WriteLine(); } streamWriter.Close(); } AssetDatabase.Refresh(); Selection.objects = new[] { AssetDatabase.LoadAssetAtPath <TextAsset>("Assets/EffectCheck.csv") }; EditorUtility.UnloadUnusedAssetsImmediate(); }
internal CudaFractalEngine(Device device) { if (device == null) { throw new ArgumentException("Invalid device passed to CudaFractalEngine.", "device"); } this.device = device; context = device.CreateContext(); iterBlockCount = Util.Clamp(device.MultiprocessorCount * 2, 2, 64); System.IO.MemoryStream ptxStream = new System.IO.MemoryStream(Kernels.KernelResources.kernels_ptx); module = context.LoadModule(ptxStream); initIteratorsKernel = module.GetKernel("init_iterators_kernel"); resetIteratorsKernel = module.GetKernel("reset_iterators_kernel"); iterateKernel = module.GetKernel("iterate_kernel"); updateStatsKernel = module.GetKernel("update_stats_kernel"); resetOutputKernel = module.GetKernel("reset_output_kernel"); updateOutputKernel = module.GetKernel("update_output_kernel"); glOutputBufferID = 0; mainStream = new Cuda.Stream(); iterPosStateBuffer = DeviceBuffer.Alloc(8, IteratorCount); iterColorStateBuffer = DeviceBuffer.Alloc(8, IteratorCount); iterStatBuffer = DeviceBuffer.Alloc(Marshal.SizeOf(typeof(NativeIterStatEntry)), IteratorCount); globalStatBuffer = DeviceBuffer.Alloc(Marshal.SizeOf(typeof(NativeGlobalStatEntry)), 1); entropyXBuffer = DeviceBuffer.Alloc(16, IteratorCount); entropyCBuffer = DeviceBuffer.Alloc(4, IteratorCount); entropySeedBuffer = DeviceBuffer.Alloc(4, IteratorCount); uint[] seeds = new uint[IteratorCount]; for (int i = 0; i < IteratorCount; i++) { seeds[i] = (uint)rand.Next(65536); } CudaMem.Copy(seeds, entropySeedBuffer); paletteImage = CudaArray.Null; paletteTex = module.GetTexRef("paletteTex"); resetBeginEvt = new Event(); resetEndEvt = new Event(); cycleIterEvt = new Event(); cycleStatEvt = new Event(); cycleEndEvt = new Event(); toneBeginEvt = new Event(); toneEndEvt = new Event(); initIteratorsKernel.SetBlockShape(IterBlockSize, 1, 1); initIteratorsKernel.SetGridDim(IterBlockCount, 1); initIteratorsKernel.SetSharedSize(0); resetIteratorsKernel.SetBlockShape(IterBlockSize, 1, 1); resetIteratorsKernel.SetGridDim(IterBlockCount, 1); resetIteratorsKernel.SetSharedSize(0); iterateKernel.SetBlockShape(IterBlockSize, 1, 1); iterateKernel.SetGridDim(IterBlockCount, 1); iterateKernel.SetSharedSize(0); updateStatsKernel.SetBlockShape(1, 1, 1); updateStatsKernel.SetGridDim(1, 1); updateStatsKernel.SetSharedSize(0); initIteratorsKernel.Launch(entropyXBuffer.Ptr.RawPtr, entropyCBuffer.Ptr.RawPtr, entropySeedBuffer.Ptr.RawPtr); context.Synchronize(); }
private static Material CreateMaterial(LibraryMaterials.Material colladaMaterial) { //TODO: better material information support List <TexRef> texRefs = new List <TexRef>(); //Find effect if (colladaMaterial.InstanceEffectElement != null) { var eff = colladaMaterial.InstanceEffectElement.Url.GetElement <LibraryEffects.Effect>(colladaMaterial.Root); //var profiles = eff.ProfileElements; var profileCommon = eff.GetChild <LibraryEffects.Effect.ProfileCommon>(); if (profileCommon != null) { var lightingType = profileCommon.TechniqueElement.LightingTypeElement; var colorTextures = lightingType.GetChildren <BaseFXColorTexture>(); foreach (BaseFXColorTexture ct in colorTextures) { var tex = ct.TextureElement; if (tex != null) { var image = tex.Root.GetIDEntry <IImage>(tex.TextureID); if (image == null) { continue; } TexRef texRef = null; if (image is Image14X img14x) { var source = img14x.GetChild <Image14X.ISource>(); //Only two ISources are InitFrom and Data if (source is Image14X.InitFrom initFrom) { string path = initFrom.StringContent.Value; if (path.StartsWith("file://")) { path = path.Substring(7); } texRef = new TexRefPath(Path.GetFullPath(path)); } else if (source is Image14X.Data rawData) { texRef = new TexRefInternal(rawData.StringContent.Values, img14x.Format); } } else if (image is Image15X img15x) { var source = img15x.GetChild <Image15X.InitFrom>(); if (source.RefElement != null) { string path = source.RefElement.StringContent.Value; if (path.StartsWith("file://")) { path = path.Substring(7); } texRef = new TexRefPath(Path.GetFullPath(path)); } else if (source.EmbeddedElement != null) { texRef = new TexRefInternal(source.EmbeddedElement.StringContent.Values, source.EmbeddedElement.Format); } } texRefs.Add(texRef); } } //if (lightingType is Constant constant) //{ //} //else if (lightingType is Lambert lambert) //{ //} //else if (lightingType is Phong phong) //{ //} //else if (lightingType is Blinn blinn) //{ //} } } Material m = new Material { Textures = texRefs.ToArray(), Name = colladaMaterial.Name ?? (colladaMaterial.ID ?? "Unnamed Material") }; return(m); }
public CudaFractalEngine() { device = Device.Devices[0]; context = device.CreateContext(); iterBlockCount = Util.Clamp(device.MultiprocessorCount * 2, 2, 64); //System.Reflection.Assembly loadedAssembly = typeof(CudaFractalEngine).Assembly; //System.IO.Stream stream = loadedAssembly.GetManifestResourceStream(typeof(CudaFractalEngine), "kernels.ptx"); System.IO.MemoryStream stream = new System.IO.MemoryStream(CudaResources.kernels_ptx); module = context.LoadModule(stream); initIteratorsKernel = module.GetKernel("init_iterators_kernel"); resetIteratorsKernel = module.GetKernel("reset_iterators_kernel"); iterateKernel = module.GetKernel("iterate_kernel"); updateStatsKernel = module.GetKernel("update_stats_kernel"); resetOutputKernel = module.GetKernel("reset_output_kernel"); updateOutputKernel = module.GetKernel("update_output_kernel"); glOutputBufferID = 0; mainStream = new Cuda.Stream(); iterPosStateBuffer = DeviceBuffer2D.Alloc(8, IterBlockSize, IterBlockCount); module.WriteConstant("iterPosStateBuffer", iterPosStateBuffer); iterColorStateBuffer = DeviceBuffer2D.Alloc(16, IterBlockSize, IterBlockCount); module.WriteConstant("iterColorStateBuffer", iterColorStateBuffer); entropyXBuffer = DeviceBuffer2D.Alloc(16, IterBlockSize, IterBlockCount); module.WriteConstant("entropyXBuffer", entropyXBuffer); entropyCBuffer = DeviceBuffer2D.Alloc(4, IterBlockSize, IterBlockCount); module.WriteConstant("entropyCBuffer", entropyCBuffer); entropySeedBuffer = DeviceBuffer2D.Alloc(4, IterBlockSize, IterBlockCount); module.WriteConstant("entropySeedBuffer", entropySeedBuffer); HostBuffer2D <uint> hostEntropySeedBuffer = HostBuffer2D <uint> .Alloc(IterBlockSize, IterBlockCount); uint rnd; for (int y = 0; y < IterBlockCount; y++) { for (int x = 0; x < IterBlockSize; x++) { rnd = (uint)rand.Next(65536); hostEntropySeedBuffer[y, x] = rnd; } } CudaMem.Copy(hostEntropySeedBuffer, entropySeedBuffer); hostEntropySeedBuffer.Free(); dotCountBuffer = DeviceBuffer2D.Alloc(8, IterBlockSize, IterBlockCount); module.WriteConstant("dotCountBuffer", dotCountBuffer); peakDensityBuffer = DeviceBuffer2D.Alloc(4, IterBlockSize, IterBlockCount); module.WriteConstant("peakDensityBuffer", peakDensityBuffer); totalIterCountMem = DevicePtr.AllocRaw(8); module.WriteConstant("totalIterCountMem", totalIterCountMem); totalDotCountMem = DevicePtr.AllocRaw(8); module.WriteConstant("totalDotCountMem", totalDotCountMem); densityMem = DevicePtr.AllocRaw(4); module.WriteConstant("densityMem", densityMem); peakDensityMem = DevicePtr.AllocRaw(4); module.WriteConstant("peakDensityMem", peakDensityMem); scaleConstantMem = DevicePtr.AllocRaw(4); module.WriteConstant("scaleConstantMem", scaleConstantMem); paletteImage = CudaArray.Null; paletteTex = module.GetTexRef("paletteTex"); resetBeginEvt = new Event(); resetEndEvt = new Event(); cycleIterEvt = new Event(); cycleStatEvt = new Event(); cycleEndEvt = new Event(); toneBeginEvt = new Event(); toneEndEvt = new Event(); initIteratorsKernel.SetBlockShape(IterBlockSize, 1, 1); initIteratorsKernel.SetGridDim(IterBlockCount, 1); initIteratorsKernel.SetSharedSize(0); resetIteratorsKernel.SetBlockShape(IterBlockSize, 1, 1); resetIteratorsKernel.SetGridDim(IterBlockCount, 1); resetIteratorsKernel.SetSharedSize(0); iterateKernel.SetBlockShape(IterBlockSize, 1, 1); iterateKernel.SetGridDim(IterBlockCount, 1); iterateKernel.SetSharedSize(0); updateStatsKernel.SetBlockShape(1, 1, 1); updateStatsKernel.SetGridDim(1, 1); updateStatsKernel.SetSharedSize(0); initIteratorsKernel.Launch(); context.Synchronize(); }