static void serpent_decrypt(const uint32_t in_blk[4], uint32_t out_blk[4], const uint32_t *l_key) { uint32_t a,b,c,d,e,f,g,h; uint32_t t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16; #ifdef BLOCK_SWAP a = byteswap32(in_blk[3]); b = byteswap32(in_blk[2]); c = byteswap32(in_blk[1]); d = byteswap32(in_blk[0]); #else a = in_blk[0]; b = in_blk[1]; c = in_blk[2]; d = in_blk[3]; #endif k_xor(32,a,b,c,d); ib7(a,b,c,d,e,f,g,h); k_xor(31,e,f,g,h); irot(e,f,g,h); ib6(e,f,g,h,a,b,c,d); k_xor(30,a,b,c,d); irot(a,b,c,d); ib5(a,b,c,d,e,f,g,h); k_xor(29,e,f,g,h); irot(e,f,g,h); ib4(e,f,g,h,a,b,c,d); k_xor(28,a,b,c,d); irot(a,b,c,d); ib3(a,b,c,d,e,f,g,h); k_xor(27,e,f,g,h); irot(e,f,g,h); ib2(e,f,g,h,a,b,c,d); k_xor(26,a,b,c,d); irot(a,b,c,d); ib1(a,b,c,d,e,f,g,h); k_xor(25,e,f,g,h); irot(e,f,g,h); ib0(e,f,g,h,a,b,c,d); k_xor(24,a,b,c,d); irot(a,b,c,d); ib7(a,b,c,d,e,f,g,h); k_xor(23,e,f,g,h); irot(e,f,g,h); ib6(e,f,g,h,a,b,c,d); k_xor(22,a,b,c,d); irot(a,b,c,d); ib5(a,b,c,d,e,f,g,h); k_xor(21,e,f,g,h); irot(e,f,g,h); ib4(e,f,g,h,a,b,c,d); k_xor(20,a,b,c,d); irot(a,b,c,d); ib3(a,b,c,d,e,f,g,h); k_xor(19,e,f,g,h); irot(e,f,g,h); ib2(e,f,g,h,a,b,c,d); k_xor(18,a,b,c,d); irot(a,b,c,d); ib1(a,b,c,d,e,f,g,h); k_xor(17,e,f,g,h); irot(e,f,g,h); ib0(e,f,g,h,a,b,c,d); k_xor(16,a,b,c,d); irot(a,b,c,d); ib7(a,b,c,d,e,f,g,h); k_xor(15,e,f,g,h); irot(e,f,g,h); ib6(e,f,g,h,a,b,c,d); k_xor(14,a,b,c,d); irot(a,b,c,d); ib5(a,b,c,d,e,f,g,h); k_xor(13,e,f,g,h); irot(e,f,g,h); ib4(e,f,g,h,a,b,c,d); k_xor(12,a,b,c,d); irot(a,b,c,d); ib3(a,b,c,d,e,f,g,h); k_xor(11,e,f,g,h); irot(e,f,g,h); ib2(e,f,g,h,a,b,c,d); k_xor(10,a,b,c,d); irot(a,b,c,d); ib1(a,b,c,d,e,f,g,h); k_xor( 9,e,f,g,h); irot(e,f,g,h); ib0(e,f,g,h,a,b,c,d); k_xor( 8,a,b,c,d); irot(a,b,c,d); ib7(a,b,c,d,e,f,g,h); k_xor( 7,e,f,g,h); irot(e,f,g,h); ib6(e,f,g,h,a,b,c,d); k_xor( 6,a,b,c,d); irot(a,b,c,d); ib5(a,b,c,d,e,f,g,h); k_xor( 5,e,f,g,h); irot(e,f,g,h); ib4(e,f,g,h,a,b,c,d); k_xor( 4,a,b,c,d); irot(a,b,c,d); ib3(a,b,c,d,e,f,g,h); k_xor( 3,e,f,g,h); irot(e,f,g,h); ib2(e,f,g,h,a,b,c,d); k_xor( 2,a,b,c,d); irot(a,b,c,d); ib1(a,b,c,d,e,f,g,h); k_xor( 1,e,f,g,h); irot(e,f,g,h); ib0(e,f,g,h,a,b,c,d); k_xor( 0,a,b,c,d); #ifdef BLOCK_SWAP out_blk[3] = byteswap32(a); out_blk[2] = byteswap32(b); out_blk[1] = byteswap32(c); out_blk[0] = byteswap32(d); #else out_blk[0] = a; out_blk[1] = b; out_blk[2] = c; out_blk[3] = d; #endif };
//private void PlatformDemoState::cacheMeshes() { xy::CubeBuilder cb(100.f); m_meshRenderer.loadModel(MeshID::Cube, cb); xy::IQMBuilder ib("assets/models/mrfixit.iqm"); m_meshRenderer.loadModel(MeshID::Fixit, ib); xy::IQMBuilder ib2("assets/models/platform_01.iqm"); m_meshRenderer.loadModel(MeshID::Platform, ib2); xy::IQMBuilder ib3("assets/models/batcat.iqm"); m_meshRenderer.loadModel(MeshID::Batcat, ib3); xy::QuadBuilder qb({ 1500.f, 550.f }); m_meshRenderer.loadModel(MeshID::Quad, qb); xy::SphereBuilder sb(34.f, 6u); m_meshRenderer.loadModel(MeshID::Sphere, sb); auto& demoMaterial = m_meshRenderer.addMaterial(MatId::Demo, xy::Material::TexturedBumped, true); demoMaterial.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/platform/cube_diffuse.png") }); demoMaterial.addProperty({ "u_normalMap", m_textureResource.get("assets/images/platform/cube_normal.png") }); demoMaterial.addProperty({ "u_maskMap", m_textureResource.get("assets/images/platform/cube_mask.png") }); demoMaterial.getRenderPass(xy::RenderPass::ID::ShadowMap)->setCullFace(xy::CullFace::Front); auto& fixitMaterialBody = m_meshRenderer.addMaterial(MatId::MrFixitBody, xy::Material::TexturedSkinnedBumped, true); fixitMaterialBody.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/fixit/fixitBody.png") }); fixitMaterialBody.addProperty({ "u_normalMap", m_textureResource.get("assets/images/fixit/fixitBody_normal.png") }); fixitMaterialBody.addProperty({ "u_maskMap", m_textureResource.get("assets/images/fixit/fixitBody_mask.tga") }); fixitMaterialBody.getRenderPass(xy::RenderPass::ID::ShadowMap)->setCullFace(xy::CullFace::Front); auto& fixitMaterialHead = m_meshRenderer.addMaterial(MatId::MrFixitHead, xy::Material::TexturedSkinnedBumped, true); fixitMaterialHead.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/fixit/fixitHead.png") }); fixitMaterialHead.addProperty({ "u_normalMap", m_textureResource.get("assets/images/fixit/fixitHead_normal.png") }); fixitMaterialHead.addProperty({ "u_maskMap", m_textureResource.get("assets/images/fixit/fixitHead_mask.png") }); fixitMaterialHead.getRenderPass(xy::RenderPass::ID::ShadowMap)->setCullFace(xy::CullFace::Front); auto& platformMaterial01 = m_meshRenderer.addMaterial(MatId::Platform01, xy::Material::Textured, true, true); platformMaterial01.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/platform/plat_01.png") }); auto& platformMaterial04 = m_meshRenderer.addMaterial(MatId::Platform04, xy::Material::Textured, true, true); platformMaterial04.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/platform/plat_04.png") }); auto& catMat = m_meshRenderer.addMaterial(MatId::BatcatMat, xy::Material::TexturedSkinnedBumped, true); auto& tex = m_textureResource.get("assets/images/platform/batcat_diffuse.png"); tex.setRepeated(true); catMat.addProperty({ "u_diffuseMap", tex }); auto& tex2 = m_textureResource.get("assets/images/platform/batcat_normal.png"); tex2.setRepeated(true); catMat.addProperty({ "u_normalMap", tex2 }); auto& tex3 = m_textureResource.get("assets/images/platform/batcat_mask.png"); tex3.setRepeated(true); catMat.addProperty({ "u_maskMap", tex3 }); catMat.getRenderPass(xy::RenderPass::ID::ShadowMap)->setCullFace(xy::CullFace::Front); m_textureResource.setFallbackColour(sf::Color(230, 120, 0)); auto& sphereMat = m_meshRenderer.addMaterial(MatId::SphereTest, xy::Material::TexturedBumped, true); sphereMat.addProperty({ "u_diffuseMap", m_textureResource.get("assets/images/sphere_test.png") }); sphereMat.addProperty({ "u_normalMap", m_textureResource.get("assets/images/sphere_normal.png") }); sphereMat.addProperty({ "u_maskMap", m_textureResource.get("I don't want a mask texture!!") }); sphereMat.getRenderPass(xy::RenderPass::ID::ShadowMap)->setCullFace(xy::CullFace::Front); auto& lightMaterial = m_meshRenderer.addMaterial(MatId::LightSource, xy::Material::Coloured); lightMaterial.addProperty({ "u_colour", sf::Color(135, 135, 80) }); lightMaterial.addProperty({ "u_maskColour", sf::Color::Blue }); auto light = xy::Component::create<xy::PointLight>(m_messageBus, 800.f, 500.f, sf::Color(255, 255, 100)); light->setDepth(400.f); light->enableShadowCasting(true); auto model = m_meshRenderer.createModel(MeshID::Cube, m_messageBus); model->setPosition({ 0.f, 0.f, light->getWorldPosition().z }); model->setSubMaterial(lightMaterial, 0); auto entity = xy::Entity::create(m_messageBus); entity->setPosition(xy::DefaultSceneSize / 2.f); entity->setScale(0.25f, 0.25f); entity->addComponent(light); entity->addComponent(model); m_scene.addEntity(entity, xy::Scene::Layer::FrontFront); //--------------- light = xy::Component::create<xy::PointLight>(m_messageBus, 600.f, 500.f, sf::Color(255, 255, 100)); light->setDepth(300.f); light->setIntensity(2.5f); light->enableShadowCasting(true); model = m_meshRenderer.createModel(MeshID::Cube, m_messageBus); model->setPosition({ 0.f, 0.f, light->getWorldPosition().z }); model->setSubMaterial(lightMaterial, 0); entity = xy::Entity::create(m_messageBus); entity->setPosition(2000.f, 200.f); entity->setScale(0.35f, 0.35f); entity->addComponent(light); entity->addComponent(model); m_scene.addEntity(entity, xy::Scene::Layer::FrontFront); }
void testCacheMeshes(IDXGIAdapter* adapter, int argc, char** argv) { ID3D11Device* device = 0; ID3D11DeviceContext* context = 0; D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, 0, 0, 0, 0, D3D11_SDK_VERSION, &device, 0, &context); setupShaders(device, context); bool stat = false; double atvr_sum = 0; double atvr_count = 0; unsigned int total_invocations = 0; unsigned int total_vertices = 0; for (int i = 1; i < argc; ++i) { const char* path = argv[i]; if (strcmp(path, "--stat") == 0) { stat = true; continue; } ObjFile file; if (!objParseFile(file, path)) { printf("Error loading %s: file not found\n", path); continue; } if (!objValidate(file)) { printf("Error loading %s: invalid file data\n", path); continue; } std::vector<unsigned int> ib1; for (size_t i = 0; i < file.f_size; i += 3) ib1.push_back(file.f[i]); unsigned int vertex_count = file.v_size / 3; unsigned int index_count = ib1.size(); unsigned int invocations1 = queryVSInvocations(device, context, ib1.data(), index_count); if (stat) { std::vector<unsigned int> ib2(ib1.size()); meshopt_optimizeVertexCache(&ib2[0], &ib1[0], ib1.size(), vertex_count); unsigned int invocations = queryVSInvocations(device, context, ib2.data(), index_count); atvr_sum += double(invocations) / double(vertex_count); atvr_count += 1; total_invocations += invocations; total_vertices += vertex_count; } else { printf("%s: baseline %f\n", path, double(invocations1) / double(vertex_count)); std::vector<unsigned int> ib3(ib1.size()); meshopt_optimizeVertexCache(&ib3[0], &ib1[0], ib1.size(), vertex_count); unsigned int invocations3 = queryVSInvocations(device, context, ib3.data(), index_count); printf("%s: forsyth %f\n", path, double(invocations3) / double(vertex_count)); for (unsigned int cache_size = 12; cache_size <= 24; ++cache_size) { std::vector<unsigned int> ib2(ib1.size()); meshopt_optimizeVertexCacheFifo(&ib2[0], &ib1[0], ib1.size(), vertex_count, cache_size); unsigned int invocations2 = queryVSInvocations(device, context, ib2.data(), index_count); printf("%s: tipsify(%d) %f\n", path, cache_size, double(invocations2) / double(vertex_count)); } } } if (stat) { printf("ATVR: average %f cumulative %f; %d vertices\n", atvr_sum / atvr_count, double(total_invocations) / double(total_vertices), total_vertices); } }